[HN Gopher] Faster remainders when divisor is a constant: beatin...
       ___________________________________________________________________
        
       Faster remainders when divisor is a constant: beating compilers and
       libdivide
        
       Author : marcodiego
       Score  : 34 points
       Date   : 2021-12-08 17:24 UTC (5 hours ago)
        
 (HTM) web link (lemire.me)
 (TXT) w3m dump (lemire.me)
        
       | kristianp wrote:
       | (2019)
        
       | inglor_cz wrote:
       | Oh, a memory...
       | 
       | The only time I was able to beat compiler optimization was in an
       | algebraic task where remainders of M mod P were needed, but the
       | number M was fairly often between P and 2P, sometimes 3P, but
       | rarely higher. (Due to the intrinsic character of the algorithm
       | used.)
       | 
       | Of course, the compiler could not have known that in advance, but
       | I did, so I tried subtracting P from M once or twice and checking
       | whether it was already under P.
       | 
       | That was like 40 per cent faster than a single division of 32-bit
       | numbers. But it was 2005, so YMMV.
        
         | thethirdone wrote:
         | What made it not possible for the compiler to notice that M was
         | small?
         | 
         | I have been thinking about "Sufficiently Smart Compilers"
         | recently and it seems like in most cases a SSC would be able to
         | guess the distribution of numbers being divided.
        
       ___________________________________________________________________
       (page generated 2021-12-08 23:00 UTC)