Conversation

why must the wii u use a big-endian cpu

1
0
0
@kemona_halftau I wish more things used big-endian CPUs because it would mean fewer endianness portability bugs if people actually tested on big endian. every aarch64 CPU has a big-endian mode but hardly anyone uses it
1
0
1
i dont know what im talking about, this is probably very wrong
Show content

@noisytoot true, but there are some valid reasons why some software/libraries assume little-endian for example casting a pointer to a 64-bit value into a pointer for a 32-bit value without needing to shift the address, or for just efficiently reading some file format or network protocol packet without doing byte-swapping (although tcp/ip uses big-endian values)

1
0
1
re: i dont know what im talking about, this is probably very wrong
Show content

@kemona_halftau true for the first part (I don’t know what to suggest other than not writing code that does that if you want it to be portable), but you can efficiently read and write data in a fixed endianness without writing endianness-specific code or doing unnecessary byte-swaps:

uint16_t load_u16le(const uint16_t *p) {
    const uint8_t *b = (uint8_t *) p;
    return b[0] | (((uint16_t)b[1]) << 8);
}

compilers know what this is and will optimize it away on little-endian systems

1
0
1
re: i dont know what im talking about, this is probably very wrong
Show content

@noisytoot i did not know that! wow, compilers are smart!!

0
0
1