5 ms·
> #1: Avoiding shifting versus doing division: Nope. Crappy compilers and bad architectures will yield bad results. Know what you're doing. Which compiler, amo
by gioele 13y ago
> #1: Avoiding shifting versus doing division: Nope. Crappy compilers and bad architectures will yield bad results. Know what you're doing.
Which compiler, among those still used in 2014, does not convert a division by 2 into a shift?
- angersock 13y agoMemory escapes me...is a shift guaranteed by the standard (and if so, which) to sign-extend or not sign-extend?
- kristoffer 13y agoA right shift of a signed integer is implementation defined.
- kps 13y agoNo, it isn't. A right shift of a signed, negative value is implementation-defined (which means, something in particular happens, and the compiler or its documentation is supposed to tell you what). A left shift of a signed value is undefined (which means, the compiler is allowed to launch the missiles, or fail to launch the missiles, whichever is worse for you) if a nonzero bit could conceivable get into the sign.
- deleted 13y ago[deleted]
- gilgoomesh 13y agoIt's not just division by 2. Most compilers will convert any division by a constant into either a shift (powers of 2) or a multiply (all other). But there are lots of oddball compilers for CPUs, DSPs, and other embedded quasi processors you've never heard of. Many don't really optimise at all.