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 577129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:07:13+00:00 2026-05-13T14:07:13+00:00

I need to rewrite about 4KB of data in reverse order, at bit level

  • 0

I need to rewrite about 4KB of data in reverse order, at bit level (last bit of last byte becoming first bit of first byte), as fast as possible. Are there any clever sniplets to do it?

Rationale: The data is display contents of LCD screen in an embedded device that is usually positioned in a way that the screen is on your shoulders level. The screen has “6 o’clock” orientation, that is to be viewed from below – like lying flat or hanging above your eyes level. This is fixable by rotating the screen 180 degrees, but then I need to reverse the screen data (generated by library), which is 1 bit = 1 pixel, starting with upper left of the screen. The CPU isn’t very powerful, and the device has enough work already, plus several frames a second would be desirable so performance is an issue; RAM not so much.

edit:
Single core, ARM 9 series. 64MB, (to be scaled down to 32MB later), Linux. The data is pushed from system memory to the LCD driver over 8-bit IO port.

The CPU is 32bit and performs much better at this word size than at byte level.

  • 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-05-13T14:07:14+00:00Added an answer on May 13, 2026 at 2:07 pm

    There’s a classic way to do this. Let’s say unsigned int is your 32-bit word. I’m using C99 because the restrict keyword lets the compiler perform extra optimizations in this speed-critical code that would otherwise be unavailable. These keywords inform the compiler that “src” and “dest” do not overlap. This also assumes you are copying an integral number of words, if you’re not, then this is just a start.

    I also don’t know which bit shifting / rotation primitives are fast on the ARM and which are slow. This is something to consider. If you need more speed, consider disassembling the output from the C compiler and going from there. If using GCC, try O2, O3, and Os to see which one is fastest. You might reduce stalls in the pipeline by doing two words at the same time.

    This uses 23 operations per word, not counting load and store. However, these 23 operations are all very fast and none of them access memory. I don’t know if a lookup table would be faster or not.

    void
    copy_rev(unsigned int *restrict dest,
             unsigned int const *restrict src,
             unsigned int n)
    {
        unsigned int i, x;
        for (i = 0; i < n; ++i) {
            x = src[i];
            x = (x >> 16) | (x << 16);
            x = ((x >> 8) & 0x00ff00ffU) | ((x & 0x00ff00ffU) << 8);
            x = ((x >> 4) & 0x0f0f0f0fU) | ((x & 0x0f0f0f0fU) << 4);
            x = ((x >> 2) & 0x33333333U) | ((x & 0x33333333U) << 2);
            x = ((x >> 1) & 0x55555555U) | ((x & 0x555555555) << 1);
            dest[n-1-i] = x;
        }
    }
    

    This page is a great reference: http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious

    Final note: Looking at the ARM assembly reference, there is a “REV” opcode which reverses the byte order in a word. This would shave 7 operations per loop off the above code.

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

Sidebar

Related Questions

I need some help. I'm not sure about the order on request for mod_rewrite
i digg on the internet about .htaccess and rewrite rules i need to do
I need to rewrite some Perl code in python. So I'm looking for the
Here is a simplified version of the code I use. I need to rewrite
I need some help on mod rewrite 301 , to redirect my old website
I'm trying to use URL rewrite in my new project. But I also need
Need a way to allow sorting except for last item with in a list.
We have a project using LINQ to SQL, for which I need to rewrite
I need to truncate string and rewrite it back to array I have got
I have about 100 TextBoxes in a Form. I need to validate them if

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.