> Is it the mod operator?

Seems to be very likely.

For
    
    
    a1 = a1 % (((long long )1) << m2);
    
    
    Run

it is easy to detect for the compiler that you are doing a modulo division by a 
power of two, which is a plain bit masking operation. (Well, when signed 
numbers are involved, an additional bit test may be necessary.)

For
    
    
    a1 = a1 mod (1 shl m2)
    
    
    Run

shl() is a proc call with unknown result, so no change for backend compiler to 
discover it, so a full division is done, which is slow, very slow compared to 
most other operations. See Agner Fogg.

So you may try a mask or shift op in Nim. Division by 1^x should be something 
like and masking with (1^x - 1), so maybe
    
    
    a1 = a1 and ((1 shl m2) - 1)
    
    
    Run

Well that is more a guess that early in the morning, you may think about it 
yourself, and be carefully when numbers are signed, maybe casts may be 
necessary. Such masking ops are generally simpler with unsigned numbers. 

Reply via email to