bob80905 created this revision. bob80905 added a reviewer: beanz. Herald added a subscriber: Anastasia. Herald added a project: All. bob80905 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This change exposes the ceil library function for HLSL scalar types, excluding long and long long doubles. Ceil is supported for all scalar, vector, and matrix types. This patch only adds a subset of scalar type support. Long and long long double support is missing in this patch because those types don't exist in HLSL. The full documentation of the HLSL ceil function is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-ceil Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D134319 Files: clang/lib/Headers/hlsl/hlsl_intrinsics.h clang/test/CodeGenHLSL/builtins/ceil.hlsl Index: clang/test/CodeGenHLSL/builtins/ceil.hlsl =================================================================== --- /dev/null +++ clang/test/CodeGenHLSL/builtins/ceil.hlsl @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.2-library %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \ +// RUN: -o - | FileCheck %s --check-prefix=NO_HALF + +double ceil_d(double x) +{ + return ceil(x); +} + +// CHECK: define noundef double @"?ceil_d@@YANN@Z"( +// CHECK: call double @llvm.ceil.f64(double %0) + +float ceil_f(float x) +{ + return ceil(x); +} + +// CHECK: define noundef float @"?ceil_f@@YAMM@Z"( +// CHECK: call float @llvm.ceil.f32(float %0) + +half ceil_h(half x) +{ + return ceil(x); +} + +// CHECK: define noundef half @"?ceil_h@@YA$f16@$f16@@Z"( +// CHECK: call half @llvm.ceil.f16(half %0) +// NO_HALF: define noundef float @"?ceil_h@@YA$halff@$halff@@Z"( +// NO_HALF: call float @llvm.ceil.f32(float %0) Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h =================================================================== --- clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -15,11 +15,6 @@ // abs builtins -__attribute__((clang_builtin_alias(__builtin_abs))) int abs(int In); -__attribute__((clang_builtin_alias(__builtin_labs))) int64_t abs(int64_t In); -__attribute__((clang_builtin_alias(__builtin_fabsf))) float abs(float In); -__attribute__((clang_builtin_alias(__builtin_fabs))) double abs(double In); - #ifdef __HLSL_ENABLE_16_BIT __attribute__((clang_builtin_alias(__builtin_elementwise_abs))) int16_t abs(int16_t); @@ -76,5 +71,12 @@ __attribute__((clang_builtin_alias(__builtin_sqrtf16))) half sqrt(half In); #endif +// ceil builtins +__attribute__((clang_builtin_alias(__builtin_ceil))) double ceil(double In); +__attribute__((clang_builtin_alias(__builtin_ceilf))) float ceil(float In); + +#ifdef __HLSL_ENABLE_16_BIT +__attribute__((clang_builtin_alias(__builtin_ceilf16))) half ceil(half In); +#endif #endif //_HLSL_HLSL_INTRINSICS_H_
Index: clang/test/CodeGenHLSL/builtins/ceil.hlsl =================================================================== --- /dev/null +++ clang/test/CodeGenHLSL/builtins/ceil.hlsl @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.2-library %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \ +// RUN: -o - | FileCheck %s --check-prefix=NO_HALF + +double ceil_d(double x) +{ + return ceil(x); +} + +// CHECK: define noundef double @"?ceil_d@@YANN@Z"( +// CHECK: call double @llvm.ceil.f64(double %0) + +float ceil_f(float x) +{ + return ceil(x); +} + +// CHECK: define noundef float @"?ceil_f@@YAMM@Z"( +// CHECK: call float @llvm.ceil.f32(float %0) + +half ceil_h(half x) +{ + return ceil(x); +} + +// CHECK: define noundef half @"?ceil_h@@YA$f16@$f16@@Z"( +// CHECK: call half @llvm.ceil.f16(half %0) +// NO_HALF: define noundef float @"?ceil_h@@YA$halff@$halff@@Z"( +// NO_HALF: call float @llvm.ceil.f32(float %0) Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h =================================================================== --- clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -15,11 +15,6 @@ // abs builtins -__attribute__((clang_builtin_alias(__builtin_abs))) int abs(int In); -__attribute__((clang_builtin_alias(__builtin_labs))) int64_t abs(int64_t In); -__attribute__((clang_builtin_alias(__builtin_fabsf))) float abs(float In); -__attribute__((clang_builtin_alias(__builtin_fabs))) double abs(double In); - #ifdef __HLSL_ENABLE_16_BIT __attribute__((clang_builtin_alias(__builtin_elementwise_abs))) int16_t abs(int16_t); @@ -76,5 +71,12 @@ __attribute__((clang_builtin_alias(__builtin_sqrtf16))) half sqrt(half In); #endif +// ceil builtins +__attribute__((clang_builtin_alias(__builtin_ceil))) double ceil(double In); +__attribute__((clang_builtin_alias(__builtin_ceilf))) float ceil(float In); + +#ifdef __HLSL_ENABLE_16_BIT +__attribute__((clang_builtin_alias(__builtin_ceilf16))) half ceil(half In); +#endif #endif //_HLSL_HLSL_INTRINSICS_H_
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits