Right, and probably in C++ too! I just noticed the trivia about C++ supporting big-endian better in C++20, so thought of what Julia does, and since it’s not important at all (on any non-legacy hardware), why introduce it then in C++20? I can only think of legacy like SPARC64 supporting big-endian only, and it actually has tier 1 support in Zig. Plus IBM s390x mainframe the only big-endian that I can think of living for a bit longer.
Could/should Julia support big-endian, at best as second-class? I mean could it implicitly do htol
when reinterpreting, i.e. a no-op on little-endian, and no longer zero-cost, but cheap bswap
then on big-endian?
Most upcoming languages, e.g. Rust have only tier 1 support for little endian.
MIPS was big-endian, but the Chinese offshoot:
- All LoongArch systems are little-endian.
- LoongArch is not binary compatible with either MIPS or RISC-V, although the ISA and ABI show heavy influence of the two.
Rust has in tier 2:
loongarch64-unknown-linux-gnu |
LoongArch64 Linux, LP64D ABI (kernel 5.19, glibc 2.36) |
loongarch64-unknown-linux-musl |
LoongArch64 Linux, LP64D ABI (kernel 5.19, musl 1.2.5) |
powerpc-unknown-linux-gnu |
PowerPC Linux (kernel 3.2, glibc 2.17) |
powerpc64-unknown-linux-gnu |
PPC64 Linux (kernel 3.2, glibc 2.17) |
powerpc64le-unknown-linux-gnu |
PPC64LE Linux (kernel 3.10, glibc 2.17) |
riscv64gc-unknown-linux-gnu |
RISC-V Linux (kernel 4.20, glibc 2.29) |
riscv64gc-unknown-linux-musl |
RISC-V Linux (kernel 4.20, musl 1.2.3) |
s390x-unknown-linux-gnu |
S390x Linux (kernel 3.2, glibc 2.17) |
…
|aarch64-unknown-linux-ohos
|✓|ARM64 OpenHarmony|
and in tier 3:
|aarch64-nintendo-switch-freestanding
|*||ARM64 Nintendo Switch, Horizon|
|aarch64-unknown-teeos
|?||ARM64 TEEOS|
…
|aarch64_be-unknown-linux-gnu
|✓|✓|ARM64 Linux (big-endian)|
…
|armeb-unknown-linux-gnueabi
|✓|?|Arm BE8 the default Arm big-endian architecture since Armv6.|
|i686-unknown-hurd-gnu
|✓|✓|32-bit GNU/Hurd 1|
…
|i686-unknown-redox
|✓||i686 Redox OS|
I’m more interested in supporting potentially interesting operating systems (and maybe older game hardware).
To answer my own question, in Julia to test/confirm you run on little-endian machine you would do:
if ENDIAN_BOM == 0x04030201
but I’m thinking, to explicitly not have to do that, or use htol
which does similar implicitly, could code be made just work?
ENDIAN_BOM
The 32-bit byte-order-mark indicates the native byte order of the host machine. Little-endian machines will contain the value 0x04030201
. Big-endian machines will contain the value 0x01020304
.