Re: Unaligned access trade-offs for SFrame FRE layout
Segher Boessenkool <[email protected]> Tue, 16 Sep 2025 11:44:26 -0500
| Newsgroups | org.kernel.vger.linux-toolchains |
|---|---|
| Message-ID | <aMmT6q1jERmMq-AR@gate> |
On Tue, Sep 16, 2025 at 09:32:30AM -0700, Fangrui Song wrote:
> The read32le(p) function is either a standard read or a byte-swapped
> read.
You should never overcomplicate things by doing byte-swaps. Instead,
just say what you mean:
u32 read32le(u8 *p)
{
return p[0] + 0x100*p[1] + 0x10000*p[2] + 0x1000000*p[3];
}
or something like that. The compiler can optimise such things just
fine! There is no need to go via extra indirections.
Segher