Gmane
From: Roland Dreier <roland <at> topspin.com>
Subject: Re: Patch 4/6 randomize the stack pointer
Newsgroups: gmane.linux.kernel
Date: 2005-01-28 00:23:08 GMT (3 years, 37 weeks, 2 days, 2 hours and 28 minutes ago)
    Julien> Not very important but ((get_random_int() % 4096) << 4)
    Julien> could be optimized into get_random_int() & 0xFFF0.

    HPA> .. and gcc knows that.

    HPA>    8:   25 ff 0f 00 00          and    $0xfff,%eax
    HPA>    d:   83 c4 0c                add    $0xc,%esp
    HPA>   10:   c1 e0 04                shl    $0x4,%eax

Actually gcc isn't quite that smart (since it obviously can't
understand the semantics of get_random int()).  The original point was
that the "shl $0x4" can be avoided by directly &'ing with 0xfff0, not
that "% 4096" can be strength reduced to "& 0xfff".

 - R.