(no title)
huachimingo | 3 years ago
/logical comparison/ int greater_abs(int num, int x){ return (num > x) || (num+x < 0); }
/squared approach/ int greater_abs2(int num, int x){ return num*num > x; }
See it by yourself, with (and without) optimizations: https://godbolt.org/
What would happen if x is a compile-time constant?
dahart|3 years ago
masklinn|3 years ago
Godbolt uses whatever compilers, targets, and optimisations you ask it to.
It is, in fact, a very useful tool for comparing different compilers, architectures, and optimization settings.
throwaway744678|3 years ago
saghm|3 years ago
zasdffaa|3 years ago
In the 2nd, which I assume should be
then it depends on the micro-arch, as it's one basic block so no branches and assuming a deep pipeline on x64, one multiplier (pipelined), probably this is faster for 'random-ish' num and x.unknown|3 years ago
[deleted]
dhosek|3 years ago
omegalulw|3 years ago
WalterGR|3 years ago
How frequently am I calling `abs`?
unknown|3 years ago
[deleted]
jjice|3 years ago
astrange|3 years ago
unknown|3 years ago
[deleted]