News for hackers. Stuff that matters.
Re:Will It Optimize? See how well you can anticipate gcc's o... by praptak on Sunday April 07, 2013 @08:54AM (#5507042)
I did some similar experiments myself a long time ago. Something mildly surprising for me at that time was that this got optimized to a single roll instruction:

    uint32_t roll(uint32_t const x) {
        return (x << 15) | (x >> 17);
    }
I haven't managed to make GCC generate a non-constant roll (i.e. (x << c) | (x >> (32-c)) ), probably because it couldn't infer that c is in the [0,31] range.
Re:Will It Optimize? See how well you can anticipate gcc's o... by Jabbles on Sunday April 07, 2013 @09:52AM (#5507196)
If c were outside that range, the result would be undefined, and the compiler would not need to consider that possibility.
Re:Will It Optimize? See how well you can anticipate gcc's o... by colanderman on Sunday April 07, 2013 @10:45AM (#5507351)
What version of GCC are you using? The non-constant case compiles to "roll" as far back as GCC 4.4.
Re:Will It Optimize? See how well you can anticipate gcc's o... by praptak on Sunday April 07, 2013 @12:25PM (#5507663)
It was a really long time ago - around the time of the NIST contest for the AES, so around 2001. And thanks for the "roll" update :)