Skip to content

[libclc] Add (fast) normalize to CLC; add half overloads #139759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025

Conversation

frasercrmck
Copy link
Contributor

@frasercrmck frasercrmck commented May 13, 2025

For simplicity the half overloads just call into the float versions of the builtin. Otherwise there are no codegen changes to any target.

@frasercrmck frasercrmck requested a review from arsenm May 13, 2025 16:08
@frasercrmck frasercrmck added the libclc libclc OpenCL library label May 13, 2025
Copy link

github-actions bot commented May 13, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@frasercrmck frasercrmck force-pushed the libclc-clc-normalize branch from 939d417 to 8f72f0f Compare May 20, 2025 10:52
@arsenm
Copy link
Contributor

arsenm commented May 20, 2025

I wasn't sure if this was necessary so this commit replaces the vector2 versions of the constants with the vector3/vector4 ones. The OpenCL-CTS seems okay with it. If this is incorrect then it's not very difficult to split them back out again.

Does it pass with -cl-denorms-are-zero and with denormal support?

@frasercrmck
Copy link
Contributor Author

I wasn't sure if this was necessary so this commit replaces the vector2 versions of the constants with the vector3/vector4 ones. The OpenCL-CTS seems okay with it. If this is incorrect then it's not very difficult to split them back out again.

Does it pass with -cl-denorms-are-zero and with denormal support?

The OpenCL-CTS doesn't actually test the geometrics builtins with that option - that's just for bruteforce.

It passes on an OpenCL implementation which advertises support for single-precision denormals, yes.

@arsenm
Copy link
Contributor

arsenm commented May 22, 2025

The OpenCL-CTS doesn't actually test the geometrics builtins with that option - that's just for bruteforce.

Sounds like a bug

It passes on an OpenCL implementation which advertises support for single-precision denormals, yes.

Ideally would check it works with denormal flushing forced on, that's the main risk I can see. If I were to stare at this long enough I could probably guess at where the constant was derived from

For simplicity the half overloads just call into the float versions of
the builtin.

Note that in the move some floating-point constants were combined. The
vector2 versions of normalize used slightly different constants to the
vector3 and vector4 versions of the same builtin. For float it was
0x1.0p-65 vs 0x1.0p-66 and for double 0x1.0p-513 vs 0x1.0p-514.

I wasn't sure if this was necessary so this commit replaces the vector2
versions of the constants with the vector3/vector4 ones. The OpenCL-CTS
seems okay with it. If this is incorrect then it's not very difficult to
split them back out again.
@frasercrmck frasercrmck force-pushed the libclc-clc-normalize branch from 8f72f0f to b7a74a8 Compare June 4, 2025 13:39
@frasercrmck
Copy link
Contributor Author

The OpenCL-CTS doesn't actually test the geometrics builtins with that option - that's just for bruteforce.

Sounds like a bug

It passes on an OpenCL implementation which advertises support for single-precision denormals, yes.

Ideally would check it works with denormal flushing forced on, that's the main risk I can see. If I were to stare at this long enough I could probably guess at where the constant was derived from

Yeah, it sounds simpler just to keep the old constants. I've done that now, and there's no codegen changes. I'll update the PR description.

@frasercrmck frasercrmck merged commit 8c3019e into llvm:main Jun 5, 2025
9 checks passed
@frasercrmck frasercrmck deleted the libclc-clc-normalize branch June 5, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libclc libclc OpenCL library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants