Is 32 bit comparison faster than 64 bit comparison?


Is the comparison of 32 bits faster than the comparison of 64 bits?

I was looking at this file

They have this piece of code

    /* |x| ~< pi/4 */
    ix &= 0x7fffffff;
    if(ix <= 0x3fe921fb) return __kernel_cos(x,z);

I understand the first line, which calculates the absolute value of x. But why is the comparison so complicated? Is there any improvement in performance by comparing the first 32 bits and not all 64 bits? Could I write

long unsigned int ix = *(long unsigned int * (&x));
ix &= 0x7fffffffffffffff;
if (ix < 3fe921fb54442d18) 
/* What comes next */

and expect the same performance in terms of speed on a 64-bit machine? Though I agree this would consume more memory.

0x3fe921fb54442d18 is pi/2.

asked on Stack Overflow Apr 16, 2021 by Sayan

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0