4 ms·
> Executing more instructions for a (really) common operation doesn't mean an ISA is somehow better designed or "more RISC", it means it executes more instructi
by tom_mellior 6y ago
> Executing more instructions for a (really) common operation doesn't mean an ISA is somehow better designed or "more RISC", it means it executes more instructions.
True. But as bonzini points out (or rather, hints at) in https://news.ycombinator.com/item?id=24958644 https://news.ycombinator.com/item?id=24958644, the really common operation for array indexing is inside a counted loop, and there the compiler will optimize the address computation and not shift-and-add on every iteration.
See https://gcc.godbolt.org/z/x5Mr66 https://gcc.godbolt.org/z/x5Mr66 for an example:
for (int i = 0; i < n; i++) {
sum += p[i];
}
compiles to a four-instruction loop on x86-64 (if you convince GCC not to unroll the loop):
.L3:
addsd xmm0, QWORD PTR [rdi]
add rdi, 8
cmp rax, rdi
jne .L3
and also to a four-instruction loop on RISC-V:
.L3:
fld fa5,0(a0)
addi a0,a0,8
fadd.d fa0,fa0,fa5
bne a5,a0,.L3
This isn't a complete refutation of the author's point, but it does mitigate the impact somewhat.
- PeCaN 6y agoThat's fair. It's definitely not a killer, (or even in my opinion the worst thing about RISC-V,) just another one of these random little annoyances that I'm not really sure why RISC-V doesn't include.
- ncmncm 6y agoOne common use of array indexing walks the array sequentially. But hash tables are used here and there, also in loops. Some people know them as "dictionaries" or "key/value stores".