RFR: JDK-8299688: Adopt C++14 compatible std::bit_cast introduced in C++20 [v4]
Kim Barrett
kbarrett at openjdk.org
Sat Feb 4 22:52:54 UTC 2023
On Mon, 23 Jan 2023 19:00:09 GMT, Justin King <jcking at openjdk.org> wrote:
>> I also don't like the direct call to __builtins either, gcc to my knowledge automatically replaces the appropriate builtins when optimization is specified
>
> Apple Clang seemed to have a bug with the version we are using in GHA. I bumped them to 12.5.1 and the error disappeared.
>
> `__builtin_bit_cast` is used to implement std::bit_cast for Clang/GCC. It is purely a compiler construct IIRC and has no runtime function equivalent. It's always replaced with machine code for performing a byte-wise copy and ensures no shenanigans occur. Additionally std::bit_cast is the only way to convert between floating point and integral without invoking undefined behavior, though the union trick does currently work. The other option is std::memcpy.
I know what `__builtin_bit_cast` is. I don't think we need to use it, so shouldn't uglify the code to do so.
There is also a risk of different semantics depending whether the builtin is used or not. For example,
`std::bit_cast` between a floating point type and an integral type is constexpr, so presumably the builtin
is similarly constexpr. But the non-builtin implementation isn't.
-------------
PR: https://git.openjdk.org/jdk/pull/11865
More information about the hotspot-dev
mailing list