News for hackers. Stuff that matters.
Re:How we found that the Linux nios2 memset() implementation... by asveikau on Saturday April 23, 2016 @11:11AM (#11555851)
It's been my experience that it's easy to write GCC inline asm that works the first few times you use it, but subtly breaks depending on what the optimizer does with the code around it. Those input/output/clobber arguments can be tricky to get right and wrongness can be hard to spot.
Re:How we found that the Linux nios2 memset() implementation... by pja on Saturday April 23, 2016 @11:22AM (#11555907)
Yeah, and as one of the comments to that blog post says, for bit twiddling operations like this, modern compilers are good enough to generate the optimal assembler the vast majority of the time: If you write the equivalent C code

    uint32 fill16 = (fill << 8) | fill;
    uint32 fill32 = (fill16 << 16) | fill16;
(copied from the comment, so hopefully correct!) you get the benefit of a) not having to fiddle with abstruse register allocation semantics but b) you’re letting gcc use its register allocator to set things up optimally based on the surrounding optimised code.

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.

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.

Re:How we found that the Linux nios2 memset() implementation... by pkaye on Saturday April 23, 2016 @12:36PM (#11556217)
Doing firmware development, I do find many of the C compilers generate sub-optimal bit field type manipulation code.
Re:How we found that the Linux nios2 memset() implementation... by pklausler on Saturday April 23, 2016 @02:59PM (#11556904)
uint32 fill32 = 0x01010101 * fill;