2 ms·
Some (older, smaller) processors don't have an integer division instruction. Avoid division at all costs on these processors unless you are not worried about sp
by twoodfin 13y ago
Some (older, smaller) processors don't have an integer division instruction. Avoid division at all costs on these processors unless you are not worried about space or execution speed.
...unless you know your compiler is capable of converting the division into cheaper operations via strength reduction, per your well-considered rule.
- kps 13y ago… which will (normally) only happen if the dividend is unsigned. Another reason to prefer unsigned ints is that the C standards make signed overflow undefined. This is becoming increasingly important as code for embedded systems is built using ‘big’ optimizing compilers, rather than the simple ‘portable assemblers’ assumed by the old old rules of thumb like manually converting divides to shifts. “If you lie to the compiler, it will get its revenge.” — Henry Spencer
- nitrogen 13y agoAnother option is reciprocal multiplication, possibly with a larger integer type. Reciprocal multiplication is an important element of my software's ability to run a Kinect at ~30fps on an ARM cpu with no FPU and no division instruction.