ABS usage in HotSpot [Was: RFR: 8282365: Consolidate and improve division by constant idealizations [v35]]

Andrew Haley aph-open at littlepinkcloud.com
Wed Dec 13 12:07:10 UTC 2023


On 12/7/23 22:54, Kim Barrett wrote:
> src/hotspot/share/utilities/globalDefinitions.hpp line 1107:
> 
>> 1105:   using U = std::make_unsigned_t<T>;
>> 1106:   return (x >= 0) ? x : U(0) - U(x);
>> 1107: }
> I understand what this to change to ABS is doing, though it's not obvious.  (Dodging overflow UB
> for -x when x is the minimum value of a signed integral type.)  I'm not entirely sure that's a wise move.

Me either. In the case of integer types we have uabs(), which returns
an unsigned value and cannot overflow, so we don't need to dodge any UB.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the hotspot-compiler-dev mailing list