This is an archive of the discontinued LLVM Phabricator instance.

Add codegen for llvm exp/exp2 elementwise builtins
ClosedPublic

Authored by bob80905 on Mar 3 2023, 1:11 PM.

Details

Summary

Add codegen for llvm exp/exp2 elementwise builtin
The exp/exp2 elementwise builtins are necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types.
The new builtins are restricted to floating point types only.

Diff Detail

Event Timeline

bob80905 created this revision.Mar 3 2023, 1:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2023, 1:11 PM
bob80905 requested review of this revision.Mar 3 2023, 1:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2023, 1:11 PM

Patch itself seems fine enough, but I want to give others a chance to poke at it. The name makes me grumbly, but if there is sufficient 'prior art' here, I'm ok with it.

clang/docs/LanguageExtensions.rst
642

The naming difference between these is a little clunky, but I dont use these enough to know if this is a common pattern. Its weird to me that _exp means "e^x", but _exp2 means "2^x".

beanz added inline comments.Mar 7 2023, 9:20 AM
clang/docs/LanguageExtensions.rst
642

Agreed that it seems odd, but in C and C++ math libraries exp is base-e, and exp2 is base-2:

https://cplusplus.com/reference/cmath/exp/
https://cplusplus.com/reference/cmath/exp2/

It is probably best to be consistent with C here even if it is unintuitive at first glance.

erichkeane added inline comments.Mar 7 2023, 9:21 AM
clang/docs/LanguageExtensions.rst
642

Agreed, thanks for the data point! I'm ok with it.

fhahn added inline comments.Mar 8 2023, 9:00 AM
clang/docs/LanguageExtensions.rst
643

the wording using or seems a bit confusing as it might be interpreted as either-or (but I am not a native speaker). It might be slightly better to perhaps just drop the or?

bob80905 updated this revision to Diff 503511.Mar 8 2023, 2:03 PM
  • remove or to eliminate any ambiguity
fhahn accepted this revision.Mar 9 2023, 10:26 AM

LGTM, thanks!

This revision is now accepted and ready to land.Mar 9 2023, 10:26 AM
This revision was automatically updated to reflect the committed changes.