Efficient code: a quiz

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Just adding to this, they are all the same, compilers have the closed form solution to operations with constants:
**For embedded:**
ARM clang:
GCC
**For desktop:**
Clang results in the same asm for x86:
GCC also:
MSVC also:
However, when dividing by a *non-constant* on GCC the *__aeabi_uidiv* intrinsic is called. On arm-clang *udiv* instruction is used. So if you do have the ability to use a compile time constant for a division it enables the compiler to do more than it normally would.
I didn't specify arch here, it likely changes the results slightly, this was just to add to the video :)

davidledger
Автор

Thou I totally agree, I would rather go with bit shift then division. After all, when one dealing with embeded software, bit-wise constructions are all over the place and developer must understand such code.

TaganMorgul
Автор

What if we use shift operator and explain the operation in comments?
I think by that way no need for compiler optimization which will result in faster compilation and code will be readable through comments.

RakeshKumarOfcl