3 ms·
Regarding the point "Don’t use floating-point operations when integers will do." I agree that using integer arithmetic can result in cleaner, easier to reason a
by blux 9y ago
Regarding the point "Don’t use floating-point operations when integers will do." I agree that using integer arithmetic can result in cleaner, easier to reason about code when applicable. It then follows that because of these traits the software will faster.
But integer arithmetic is not necessarily faster than floating point arithmetic in general; see for example: https://youtu.be/3K2LmnaLLF8?t=31m10s https://youtu.be/3K2LmnaLLF8?t=31m10s.
- AstralStorm 9y agoOnly if you either have to pay the extra cost of handling overflows, underflows, saturation or normalization. (First three involve conditionals which may be mispredicted, last a division or multiplication.) Likewise correct rounding. (Multiple math ops and sometimes a conditional too.) Or when the platform has no integer vector math for your type of choice. Which is still somewhat common.
- gopalv 9y ago> But integer arithmetic is not necessarily faster than floating point arithmetic in general; GPUs was the first place I feel like floats got a much better pathway than any other data type - graphical pixel manipulations also can get away with much higher arithmetic errors, because it's all going to get rounded down to a pixel eventually. On the other hand, the only place where I've really worked heavily with fixed point was on a graphical interface toolkit (MIDP on ARM I was working with would've had to use softfp for floats, so fixed point was hugely superior).
- AstralStorm 9y agoCome on, all reasonable ARM have NEON and VFPv3 (including cortex M) about the only place I saw something that didn't was an old internet router. Hardware completely unsuited to maths. Softfp does not preclude the use of floating point math at all. It means you pay an extra cost when passing floats as arguments. (Which means you should rather use a hardfp math library if possible.)
- gopalv 9y ago> Come on, all reasonable ARM have NEON and VFPv3 (including cortex M) about the only place I saw something that didn't was an old internet router ARM MIDP UI code in 2003-2004 - very interesting chip (ARM926EJ-S [1]) ... not that I ever invented anything new to do all this, all of what I did was learn & repeat tricks from 1980s arcade consoles. [1] - https://en.wikipedia.org/wiki/Jazelle#BXJ:_Branch_to_Java https://en.wikipedia.org/wiki/Jazelle#BXJ:_Branch_to_Java