Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8023

SDK • Re: 32-bit access to byte array?

$
0
0
You can tell the compiler to align your buffer like so:

Code:

uint8_t __attribute__((aligned(4))) screen_buf[320][240*2];
Other then that, there really isn't anything special involved, a normal memcpy will work just fine:

Code:

void fill_buffer(uint32_t start_pos) {    for (uint32_t i = start_pos; i < 120; ++i) {        memcpy(&screen_buf[100][i*4], &i, 4);    }}
which compiles to something like the following:

Code:

fill_buffer:        ldr     r3, .L8.L6:        cmp     r0, #119        bls     .L7        bx      lr.L7:        lsls    r2, r0, #2        str     r0, [r3, r2]        adds    r0, r0, #1        b       .L6
Unions work as well as long as you're writing just C, but is at least formally undefined for C++ ...

EDIT: Fixed the assembly to actual be thumb code; also the assembly is straight off of godbolt so it may look a bit different from the real thing

Statistics: Posted by Tharre — Thu Jun 05, 2025 10:13 pm



Viewing all articles
Browse latest Browse all 8023

Trending Articles