4 ms·
This was really interesting, I (being a C buff, beard and all) love this kind of low-level hacking to get critical infrastructure to work on a platform. Many of
by unwind 3y ago
This was really interesting, I (being a C buff, beard and all) love this kind of low-level hacking to get critical infrastructure to work on a platform. Many of the gotchas they experienced seemed familiar (such as char's lack of signed-ness) from helping beginners with the language, too.
It was surprising that the OP calls C's shift operators (<< and >>) rotate, especially surprising in the context of low-level/assembly programming where rotate is very often a separate instruction. A rotate will bring bits "around", while a shift just inserts 0s or sign bit copies.
- benj111 3y agoA shift is basically a rotate and mask. If wonder if they came from a machine where there was no shift instruction?
- unwind 3y agoNot for the signed ("arithmetic") case when you need to duplicate the sign bit into the topmost bit. You can't replicate that with a rotate, it's a distinct operation.
- benj111 3y agoNo but if this hypothetical instruction set doesn't even include shifts, it wouldn't be surprising if it missed other instructions.
- fweimer 3y agoNote that this specific aspect discussed here isn't about getting things working as such. Cross-compilation of RISC-V has been absolutely trivial for many years. For example, support for riscv64-*-linux-gnu architectures was added to build-many-glibcs.py more than five years ago: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=0fd5d876d2e016b611ada62410bd8a6298f327d3 https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=0fd5d... This gives you ABI-verified cross-compilers for GNU/Linux. Other similar scripts exist, and may even build more complete sysroots. The difference to the approach referenced here is that build-many-glibcs.py and similar efforts start out from a native GNU toolchain (contemporary GCC with the C and C++ front ends, binutils, GNU make, and so on) plus some extensions (such as Python). Most people already have such an environment and trust it to some degree, so there is no need to bootstrap off some minimal seed.