[clang] Adding `asuint` implementation to hlsl (PR #107292)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 6 14:09:53 PDT 2024


https://github.com/llvm-beanz commented:

One question I have about this is do we actually need new builtins? These are just doing bit casts correct?

Could we implement them entirely in the header? Something like:

```hlsl
template <typename T, typename U>
T bit_cast(U Val) { return __builtin_bit_cast(T, Val); }

uint asuint(float F) { return bit_cast<uint>(F); }
```

This seems to work for me in godbolt: https://godbolt.org/z/8b61a1WMr

We may want to apply the `[[alwaysinline]]` attribute, but it seems like a reasonable approach. Thoughts?



https://github.com/llvm/llvm-project/pull/107292


More information about the cfe-commits mailing list