Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:09:58+00:00 2026-06-05T02:09:58+00:00

A bit of introduction to the problem, I tried searching about this on google/stack

  • 0

A bit of introduction to the problem,
I tried searching about this on google/stack before I post this but most of them were unclear.
I have a cortex-a8 based board on which I’m running a bare metal RTOS, The display (framebuffer) is a bit slow because I haven’t implemented DMA for my target right now but is not all that slow, however I noticed an opportunity of improvement. On my CPU and toolchain combo, 32 bit math, data access is faster than 16 bit access and the display is 16 bit rgb565 so some of the framebuffer ops are a bit slower than what they could have been (Some of them use memcpy, memmove and memset which takes care of data alignment etc..)

What I attempted was to cram two pixels into one 32 bit data type and use that to access memory (aligned as far as i remember, even if not, my cpu supports inaligned memory access in hardware so the problem shouldn’t be this.) Note that I’m not talking of speed of my implementation but a weird effect I’m getting which I suspect is because How I’m cramming the two pixels into one 32 bit data type.

Here is most part of my fb_putc

if (((unsigned char)c > 32) && ((unsigned char) c < 127)) {
    check_for_scroll(49);

    // fontdata starts from ASCII 33 shifted by logarithm(base2, font_height)
    c -= 33;
    c <<= 4;

    uint16_t pallete_16[2] = {fb.fg_color, fb.tg_color};

    uint32_t y;
    uint32_t *pixel_32;
    uint32_t fb_shifter;
    uint32_t pixel_32_holder;
    uint32_t fb_bg_32 = ((pallete_16[1] << 16) | (pallete_16[1]));
    /*
     * Each pixel is 16 bits, we access them using 32 bit data type,
     * which is faster for aligned memory access. Also many architectures
     * have free bit shifts with each instruction so we use that too.
     */
    pixel_32 = (uint32_t *) fb.config->base;
    pixel_32 += ( ((fb.cursor.y * (FONT_HEIGHT * fb.config->width)) + ((fb.cursor.x * (FONT_WIDTH))))
                    / ((sizeof(uint32_t))/(sizeof(uint16_t))) );
    for (y = 0; y < 16; y++) {
        for ( unsigned x = 7; x >= 0; x -= 2 )
        {
            if (fontdata[c + y] & (1 << x)) {   
                pixel_32_holder = (pallete_16[0] << 16);
            } else {
                pixel_32_holder = (pallete_16[1] << 16);
            }
            if (fontdata[c + y] & (1 << (x -1))) {
                pixel_32_holder |= (pallete_16[0] & 0xffff);
            } else {
                pixel_32_holder |= (pallete_16[1] & 0xffff);
            }
            *pixel_32++ = pixel_32_holder;
        }
        // Panel stride = width (480) - font_width (8)
        pixel_32 += (472 / ((sizeof(uint32_t))/(sizeof(uint16_t))));
    }

    fb.cursor.x++;
}

Any help regarding where I went wrong? I’m a bit new to programming and am doing this as hobby.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:10:00+00:00Added an answer on June 5, 2026 at 2:10 am

    Your idea of combining 2 pixels before writing them to memory is correct. The write buffer hardware of ARM will be used more efficiently this way and the code will run faster. I don’t think mixing C and ASM in that form will produce the best results. Sticking with pure ASM will guarantee that you’re using conditionally executed instructions. Also, the use of an array for your palette may cause the compiler to output very inefficient code. Here’s a way to do it more efficiently in pure ASM. Unrolling the loop is a good idea. This is the code to handle each byte of bitonal font data.

    @ Register usage
    @ R0 = source data pointer
    @ R1 = destination data pointer
    @ R2 = foreground color (loaded outside of loop)
    @ R3 = background color (loaded outside of loop)
    @ R4,R5 = temp registers
    @ Assumes that the most significant short of each 32-bit word is on the left
    
      ldrb r4,[r0],#1  @ source bitonal image data
    @ first pair of pixels
      tst r4,#0x80
      movne r5,r5,r2,LSL #16
      moveq r5,r5,r3,LSL #16
      tst r4,#0x40
      orrne r5,r5,r2
      orreq r5,r5,r3
      str r5,[r1],#4
    @ second pair of pixels
      tst r4,#0x20
      movne r5,r5,r2,LSL #16
      moveq r5,r5,r3,LSL #16
      tst r4,#0x10
      orrne r5,r5,r2
      orreq r5,r5,r3
      str r5,[r1],#4
    @ third pair of pixels
      tst r4,#0x8
      movne r5,r5,r2,LSL #16
      moveq r5,r5,r3,LSL #16
      tst r4,#0x4
      orrne r5,r5,r2
      orreq r5,r5,r3
      str r5,[r1],#4
    @ fourth pair of pixels
      tst r4,#0x2
      movne r5,r5,r2,LSL #16
      moveq r5,r5,r3,LSL #16
      tst r4,#0x1
      orrne r5,r5,r2
      orreq r5,r5,r3
      str r5,[r1],#4
    

    Update slightly simpler code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit of an edge case, but any idea why &&= would behave this way?
I started reading 'Introduction to Algorithms' today, but I've gotten a bit confused over
Bit of a newb but just having a small problem using jquery cycle all
First a bit of an introduction. I will send a POST to a url
Bit of a strange question here i know. but i wanted to know if
Bit of an odd question but is there a way of seeing what objects
Bit of a bizarre question, but does anyone know the actual limit to the
Bit confused here, I have an on-demand instance but do I get charged even
Bit of a noob question but: I have a custom class defined as: public
Bit of a backstory to this one... I have an ASP.NET Login App on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.