Re:How we found that the Linux nios2 memset() implementation...
by slededit on Sunday April 24, 2016 @02:01AM
(#11558746)
No compiler (MSVC, gcc, icc) outputs the "bts" instruction for operations like:
bitfield[val / 32] = val % 32;
which could implicitly perform the modulo.
Using the intrinsic provided significant performance improvements, and we got still more when the rest of the inner loop was rewritten purely in assembly.
My own experience with writing memset / memcpy equivalents 10 years ago on x86 was that gcc did a better job of it. Don’t try and outsmart the compiler for this kind of common case unless you know the compiler generates inefficient code - compiler writers have generally got there before you.