[PATCH] D132589: [HLSL] Add acos library functionThis change exposes the acos library function for HLSL scalar types,excluding long long doubles. Acos is supported for all scalar, vector,and matrix types. This patch only adds a subset of scalar type support.

Joshua Batista via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 24 12:15:28 PDT 2022


bob80905 created this revision.
bob80905 added reviewers: beanz, pow2clk.
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.

...rt.

Long long double support is missing in this patch because that type
doesn't exist in HLSL.

The full documentation of the HLSL acos function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-acos


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132589

Files:
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/test/CodeGenHLSL/builtins/acos.hlsl


Index: clang/test/CodeGenHLSL/builtins/acos.hlsl
===================================================================
--- /dev/null
+++ clang/test/CodeGenHLSL/builtins/acos.hlsl
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -o - | FileCheck %s
+
+double acos_d(double x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef double @"?acos_d@@YANN at Z"(
+// CHECK: call noundef double @acos(double noundef %0) #2
+
+float acos_f(float x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef float @"?acos_f@@YAMM at Z"(
+// CHECK: call noundef float @acosf(float noundef %0)
+
+long double acos_ld(long double x)
+{
+  return acos(x);
+}
+
+// CHECK: define noundef double @"?acos_ld@@YAOO at Z"(
+// CHECK: call noundef double @acosl(double noundef %0)
+
+/*
+long long double acos_lld(long long double x)
+{
+  return acos(x);
+}
+*/
\ No newline at end of file
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===================================================================
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -12,4 +12,12 @@
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
+
+__attribute__((clang_builtin_alias(__builtin_acos))) double acos(double In);
+__attribute__((clang_builtin_alias(__builtin_acosf))) float acos(float In);
+__attribute__((clang_builtin_alias(__builtin_acosl))) long double acos(long double In);
+//__attribute__((clang_builtin_alias(__builtin_acosf128))) __float128 acos(__float128 In);
+
+
+
 #endif //_HLSL_HLSL_INTRINSICS_H_


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132589.455326.patch
Type: text/x-patch
Size: 1713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220824/27b7cb84/attachment.bin>


More information about the cfe-commits mailing list