Hacker News new | ask | show | jobs
by api 862 days ago
Even modern C and C++ code generally ports just fine as long as you avoid things with unspecified behavior like exotic casts and weird pointer tricks. Have to watch endianness too but that doesn’t actually come up all that often. Also AFAIK there are no longer any big-endian architectures in common use.

Newer languages are even easier. Rust and Go almost always port with zero issues. Obviously the same goes for scripting and VM based languages like Java.

The architecture matters less than it used to.

3 comments

Are you aware that x86 and ARM/POWER/RISCV memory consistency model are really different? You can encounter very sneaky multitreading bug when running on ARM/POWER/RISCV a program that you have only tested on x86.

Apple has actually put a lot of effort to make the x86 to ARM transition as smooth as possible regarding memory consistency model, this is a strong indication that it's not as trivial as you seem to think.

You have to be doing pretty strange things with threads, without using mutexes or atomic instructions, to have a problem with this.

RISC-V has a standardised (optional) TSO memory model mode, plus "fence.tso" instruction that works in normal mode, even on CPUs that predate it (it defaults to the stronger "fence rw,rw" in that case). Well, assuming the CPU core designer read the spec carefully and doesn't trap on unknown "fence" instructions (looking at you, THead...)

If you’re higher up the stack, sure. If you want performance, you want to keep the dev/prod environment alike so that you can properly optimize
Sure if you are counting cache misses or optimizing for a specific compute unit. Few people do that outside of AI, crypto, AV codecs, simulation, etc. If you are doing that you may need to specialize per arch anyway because you’re probably using vector units.

I was speaking to whether the code will work. The answer is almost always yes. Optimizations at a higher level such as algorithm choice or where allocations are performed also are architecture neutral. This is most optimization.

s390x (IBM Z) is a big endian holdout, with IBM in the wings still quietly paying for s390x ports of various open source software.