Skip to content

Commit 500e729

Browse files
committed
add floor library function
This change exposes the floor library function for HLSL, excluding long, int, and long long doubles. Floor is supported for all scalar, vector, and matrix types. Long and long long double support is missing in this patch because those types don't exist in HLSL. Int is missing because the floor function only works on floating type arguments. The full documentation of the HLSL floor function is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-floor Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D139137
1 parent faa75f9 commit 500e729

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,36 @@ double3 ceil(double3);
101101
__attribute__((clang_builtin_alias(__builtin_elementwise_ceil)))
102102
double4 ceil(double4);
103103

104+
// floor builtins
105+
#ifdef __HLSL_ENABLE_16_BIT
106+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
107+
half floor(half);
108+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
109+
half2 floor(half2);
110+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
111+
half3 floor(half3);
112+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
113+
half4 floor(half4);
114+
#endif
115+
116+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) float
117+
floor(float);
118+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
119+
float2 floor(float2);
120+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
121+
float3 floor(float3);
122+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
123+
float4 floor(float4);
124+
125+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) double
126+
floor(double);
127+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
128+
double2 floor(double2);
129+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
130+
double3 floor(double3);
131+
__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
132+
double4 floor(double4);
133+
104134
// cos builtins
105135
#ifdef __HLSL_ENABLE_16_BIT
106136
__attribute__((clang_builtin_alias(__builtin_elementwise_cos))) half cos(half);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
2+
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3+
// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
4+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
5+
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
6+
// RUN: -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
7+
8+
using hlsl::floor;
9+
10+
// CHECK: define noundef half @
11+
// CHECK: call half @llvm.floor.f16(
12+
// NO_HALF: define noundef float @"?test_floor_half@@YA$halff@$halff@@Z"(
13+
// NO_HALF: call float @llvm.floor.f32(float %0)
14+
half test_floor_half ( half p0 ) {
15+
return floor ( p0 );
16+
}
17+
// CHECK: define noundef <2 x half> @
18+
// CHECK: call <2 x half> @llvm.floor.v2f16(
19+
// NO_HALF: define noundef <2 x float> @"?test_floor_half2@@YAT?$__vector@$halff@$01@__clang@@T12@@Z"(
20+
// NO_HALF: call <2 x float> @llvm.floor.v2f32(
21+
half2 test_floor_half2 ( half2 p0 ) {
22+
return floor ( p0 );
23+
}
24+
// CHECK: define noundef <3 x half> @
25+
// CHECK: call <3 x half> @llvm.floor.v3f16(
26+
// NO_HALF: define noundef <3 x float> @"?test_floor_half3@@YAT?$__vector@$halff@$02@__clang@@T12@@Z"(
27+
// NO_HALF: call <3 x float> @llvm.floor.v3f32(
28+
half3 test_floor_half3 ( half3 p0 ) {
29+
return floor ( p0 );
30+
}
31+
// CHECK: define noundef <4 x half> @
32+
// CHECK: call <4 x half> @llvm.floor.v4f16(
33+
// NO_HALF: define noundef <4 x float> @"?test_floor_half4@@YAT?$__vector@$halff@$03@__clang@@T12@@Z"(
34+
// NO_HALF: call <4 x float> @llvm.floor.v4f32(
35+
half4 test_floor_half4 ( half4 p0 ) {
36+
return floor ( p0 );
37+
}
38+
39+
// CHECK: define noundef float @
40+
// CHECK: call float @llvm.floor.f32(
41+
float test_floor_float ( float p0 ) {
42+
return floor ( p0 );
43+
}
44+
// CHECK: define noundef <2 x float> @
45+
// CHECK: call <2 x float> @llvm.floor.v2f32(
46+
float2 test_floor_float2 ( float2 p0 ) {
47+
return floor ( p0 );
48+
}
49+
// CHECK: define noundef <3 x float> @
50+
// CHECK: call <3 x float> @llvm.floor.v3f32(
51+
float3 test_floor_float3 ( float3 p0 ) {
52+
return floor ( p0 );
53+
}
54+
// CHECK: define noundef <4 x float> @
55+
// CHECK: call <4 x float> @llvm.floor.v4f32(
56+
float4 test_floor_float4 ( float4 p0 ) {
57+
return floor ( p0 );
58+
}
59+
60+
// CHECK: define noundef double @
61+
// CHECK: call double @llvm.floor.f64(
62+
double test_floor_double ( double p0 ) {
63+
return floor ( p0 );
64+
}
65+
// CHECK: define noundef <2 x double> @
66+
// CHECK: call <2 x double> @llvm.floor.v2f64(
67+
double2 test_floor_double2 ( double2 p0 ) {
68+
return floor ( p0 );
69+
}
70+
// CHECK: define noundef <3 x double> @
71+
// CHECK: call <3 x double> @llvm.floor.v3f64(
72+
double3 test_floor_double3 ( double3 p0 ) {
73+
return floor ( p0 );
74+
}
75+
// CHECK: define noundef <4 x double> @
76+
// CHECK: call <4 x double> @llvm.floor.v4f64(
77+
double4 test_floor_double4 ( double4 p0 ) {
78+
return floor ( p0 );
79+
}

0 commit comments

Comments
 (0)