Optimize multiplications/divisions by 2 using bit shifts in hot paths - Mailing list pgsql-hackers

From Chao Li
Subject Optimize multiplications/divisions by 2 using bit shifts in hot paths
Date
Msg-id CAEoWx2kWew-NMm7cRbAvy4FU0hqVCDUnBbU-P+gHou7ZS6HLRg@mail.gmail.com
Whole thread Raw
Responses Re: Optimize multiplications/divisions by 2 using bit shifts in hot paths
List pgsql-hackers
Hi Hackers,

This patch uses left/right shift operators to optimize *2 and /2 operations in some functions that are in critical paths.

For unsigned int, *2 and /2 exactly equal to <<1 and >>1.

For signed int:
 * /2 exactly equals to >>1 when a value is non-negative, this patch ensures only changes non-negative variables
 * *2 might be different from <<1 if a value is close to MAX_INT, however, in that case x*2 will result in a undefined result, thus existing code should have ensured *2 should not exceed MAX_INT.

"make check" passes with this patch.

Best regards,
Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachment

pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: Having postgresql.org link to cgit instead of gitweb
Next
From: David Rowley
Date:
Subject: Re: Optimize multiplications/divisions by 2 using bit shifts in hot paths