Skip to content

Commit 7decd04

Browse files
authored
[Clang] Add __builtin_elementwise_exp10 in the same fashion as exp/exp2 (#130746)
Clang has __builtin_elementwise_exp and __builtin_elementwise_exp2 intrinsics, but no __builtin_elementwise_exp10. There doesn't seem to be a good reason not to expose the exp10 flavour of this intrinsic too. This commit introduces this intrinsic following the same pattern as the exp and exp2 versions. Fixes: SWDEV-519541
1 parent 418e07b commit 7decd04

File tree

12 files changed

+67
-0
lines changed

12 files changed

+67
-0
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ of different sizes and signs is forbidden in binary and ternary builtins.
786786
T __builtin_elementwise_bitreverse(T x) return the integer represented after reversing the bits of x integer types
787787
T __builtin_elementwise_exp(T x) returns the base-e exponential, e^x, of the specified value floating point types
788788
T __builtin_elementwise_exp2(T x) returns the base-2 exponential, 2^x, of the specified value floating point types
789+
T __builtin_elementwise_exp10(T x) returns the base-10 exponential, 10^x, of the specified value floating point types
789790

790791
T __builtin_elementwise_sqrt(T x) return the square root of a floating-point number floating point types
791792
T __builtin_elementwise_roundeven(T x) round x to the nearest integer value in floating point format, floating point types

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Non-comprehensive list of changes in this release
128128
-------------------------------------------------
129129

130130
- Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719).
131+
- Added `__builtin_elementwise_exp10`.
131132

132133
New Compiler Flags
133134
------------------

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,12 @@ def ElementwiseExp2 : Builtin {
13401340
let Prototype = "void(...)";
13411341
}
13421342

1343+
def ElementwiseExp10 : Builtin {
1344+
let Spellings = ["__builtin_elementwise_exp10"];
1345+
let Attributes = [NoThrow, Const, CustomTypeChecking];
1346+
let Prototype = "void(...)";
1347+
}
1348+
13431349
def ElementwiseFloor : Builtin {
13441350
let Spellings = ["__builtin_elementwise_floor"];
13451351
let Attributes = [NoThrow, Const, CustomTypeChecking];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4309,6 +4309,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43094309
case Builtin::BI__builtin_elementwise_exp2:
43104310
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
43114311
*this, E, llvm::Intrinsic::exp2, "elt.exp2"));
4312+
case Builtin::BI__builtin_elementwise_exp10:
4313+
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4314+
*this, E, llvm::Intrinsic::exp10, "elt.exp10"));
43124315
case Builtin::BI__builtin_elementwise_log:
43134316
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
43144317
*this, E, llvm::Intrinsic::log, "elt.log"));

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
27232723
case Builtin::BI__builtin_elementwise_cosh:
27242724
case Builtin::BI__builtin_elementwise_exp:
27252725
case Builtin::BI__builtin_elementwise_exp2:
2726+
case Builtin::BI__builtin_elementwise_exp10:
27262727
case Builtin::BI__builtin_elementwise_floor:
27272728
case Builtin::BI__builtin_elementwise_log:
27282729
case Builtin::BI__builtin_elementwise_log2:

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
26492649
case Builtin::BI__builtin_elementwise_cosh:
26502650
case Builtin::BI__builtin_elementwise_exp:
26512651
case Builtin::BI__builtin_elementwise_exp2:
2652+
case Builtin::BI__builtin_elementwise_exp10:
26522653
case Builtin::BI__builtin_elementwise_floor:
26532654
case Builtin::BI__builtin_elementwise_fmod:
26542655
case Builtin::BI__builtin_elementwise_log:

clang/test/CodeGen/builtins-elementwise-math.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,21 @@ void test_builtin_elementwise_exp2(float f1, float f2, double d1, double d2,
710710
vf2 = __builtin_elementwise_exp2(vf1);
711711
}
712712

713+
void test_builtin_elementwise_exp10(float f1, float f2, double d1, double d2,
714+
float4 vf1, float4 vf2) {
715+
// CHECK-LABEL: define void @test_builtin_elementwise_exp10(
716+
// CHECK: [[F1:%.+]] = load float, ptr %f1.addr, align 4
717+
// CHECK-NEXT: call float @llvm.exp10.f32(float [[F1]])
718+
f2 = __builtin_elementwise_exp10(f1);
719+
720+
// CHECK: [[D1:%.+]] = load double, ptr %d1.addr, align 8
721+
// CHECK-NEXT: call double @llvm.exp10.f64(double [[D1]])
722+
d2 = __builtin_elementwise_exp10(d1);
723+
724+
// CHECK: [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
725+
// CHECK-NEXT: call <4 x float> @llvm.exp10.v4f32(<4 x float> [[VF1]])
726+
vf2 = __builtin_elementwise_exp10(vf1);
727+
}
713728

714729
void test_builtin_elementwise_floor(float f1, float f2, double d1, double d2,
715730
float4 vf1, float4 vf2) {

clang/test/CodeGen/strictfp-elementwise-builtins.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ float4 strict_elementwise_exp2(float4 a) {
127127
return __builtin_elementwise_exp2(a);
128128
}
129129

130+
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_exp10Dv4_f
131+
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
132+
// CHECK-NEXT: entry:
133+
// CHECK-NEXT: [[ELT_EXP10:%.*]] = tail call <4 x float> @llvm.exp10.v4f32(<4 x float> [[A]]) #[[ATTR4]]
134+
// CHECK-NEXT: ret <4 x float> [[ELT_EXP10]]
135+
//
136+
float4 strict_elementwise_exp10(float4 a) {
137+
return __builtin_elementwise_exp10(a);
138+
}
139+
130140
// CHECK-LABEL: define dso_local noundef <4 x float> @_Z24strict_elementwise_floorDv4_f
131141
// CHECK-SAME: (<4 x float> noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
132142
// CHECK-NEXT: entry:

clang/test/Sema/builtins-elementwise-math.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,26 @@ void test_builtin_elementwise_exp2(int i, float f, double d, float4 v, int3 iv,
526526
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
527527
}
528528

529+
void test_builtin_elementwise_exp10(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
530+
531+
struct Foo s = __builtin_elementwise_exp10(f);
532+
// expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
533+
534+
i = __builtin_elementwise_exp10();
535+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
536+
537+
i = __builtin_elementwise_exp10(i);
538+
// expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
539+
540+
i = __builtin_elementwise_exp10(f, f);
541+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
542+
543+
u = __builtin_elementwise_exp10(u);
544+
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
545+
546+
uv = __builtin_elementwise_exp10(uv);
547+
// expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
548+
}
529549

530550
void test_builtin_elementwise_floor(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
531551

clang/test/SemaCXX/builtins-elementwise-math.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ void test_builtin_elementwise_exp2() {
134134
static_assert(!is_const<decltype(__builtin_elementwise_exp2(b))>::value);
135135
}
136136

137+
void test_builtin_elementwise_exp10() {
138+
const float a = 42.0;
139+
float b = 42.3;
140+
static_assert(!is_const<decltype(__builtin_elementwise_exp10(a))>::value);
141+
static_assert(!is_const<decltype(__builtin_elementwise_exp10(b))>::value);
142+
}
143+
137144
void test_builtin_elementwise_asin() {
138145
const float a = 42.0;
139146
float b = 42.3;

clang/test/SemaHLSL/BuiltIns/exp-errors.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected -DTEST_FUNC=__builtin_elementwise_exp
33
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected -DTEST_FUNC=__builtin_elementwise_exp2
4+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected -DTEST_FUNC=__builtin_elementwise_exp10
45
float test_too_few_arg() {
56
return TEST_FUNC();
67
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}

clang/test/SemaHLSL/BuiltIns/half-float-only-errors.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_cosh
77
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_exp
88
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_exp2
9+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_exp10
910
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_floor
1011
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log
1112
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -DTEST_FUNC=__builtin_elementwise_log2

0 commit comments

Comments
 (0)