It may be useful to note that when C ++ sees a modulo 2 operation as %2 , it is usually optimized without performing bitwise operations.
Although it would be helpful to understand all such tricks, it should be nice to know that the compiler (or the compiler author) is doing the hard work to get all the optimization options.
What you should remember if you use constants and work with permissions 2, optimization is more likely, since compilers use the capabilities of the machine binary operator.
Going further, I would suggest gaining knowledge on how systems work at a low level.
To this end, the training tricks you link to here will be very useful .
However, cryptic coding with complex operations stuck together
(say, to do all this in less bytes of source code) is not good.
It would be nice to know that you can change two 32-bit variables in place, without a third temporary variable, using XOR operations. But it would be more useful to know that hto cross-compilation requires processing large and small numbers for 2/4 byte variables and bit fields .
Speaking of bit fields, it recalls another talk about glass-likeness about their popularity . It would also be a good read (although not completely related to your question).
To summarize, I fully learn with you what tricks can be done. I want to use them to make my code more efficient - and I firmly feel that these will be such concepts as what programmers can do to improve cache optimization , for example, which will help to improve implementation.
nik
source share