3 ms·
Output → Compile to binary object. Appears I was testing on a version with the int counter replaced with size_t (namely, https://godbolt.org/z/sTW64EEYv https:
by dzaima 3y ago
Output → Compile to binary object.
Appears I was testing on a version with the int counter replaced with size_t (namely, https://godbolt.org/z/sTW64EEYv https://godbolt.org/z/sTW64EEYv vs https://godbolt.org/z/zKqjTa5fz https://godbolt.org/z/zKqjTa5fz). Regardless, indeed, your sumarray_opt one is shorter still, and with less instructions in the loop. Though beating compilers by an instruction or two is nothing particularly new, being possible often even on x86.
- kragen 3y agoi did see that option but when i selected it i got no output; maybe i have to look for the output somewhere else? the thing i was surprised by was not really that i could beat it by an instruction or two by rewriting the c code, but that i could reduce the number of instructions in the inner loop by 37% with no apparent tradeoffs by hand-applying an optimization that the compiler already does apply, itself, on arm