c - What is the replacement of mod operator? -
this question has answer here:
i have code segment requires remainder of 2 ints. using modulus operator usual hearing takes more time. asking there way remainder more efficiently mod operation... following code
int rem=gid%bpp
gid
being int , bpp
being 2,4,8,16,32.
it appears question bpp
power of 2, in case can use instead:
int rem = gid & (bpp - 1);
however should not optimise prematurely - unless have profiled , know mod operation bottleneck should leave in original, more readable form.
Comments
Post a Comment