From 33c2144fe40e505ce7530eaa7f9a445660d9623f Mon Sep 17 00:00:00 2001
From: Arina Neshlyaeva <arina.neshlyaeva@intel.com>
Date: Thu, 5 May 2022 16:57:51 -0700
Subject: [PATCH] Reworked sincos for gen

---
 builtins/target-xe.ll | 32 ++++++++++++++++++++++++++++++++
 builtins/util-xe.m4   |  4 ----
 fail_db.txt           |  2 --
 stdlib.ispc           | 10 ++++------
 4 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/builtins/target-xe.ll b/builtins/target-xe.ll
index dceabfd88..277f7d372 100644
--- a/builtins/target-xe.ll
+++ b/builtins/target-xe.ll
@@ -1477,6 +1477,22 @@ define <WIDTH x float> @__tan_varying_float(<WIDTH x float>) nounwind readnone {
   ret <WIDTH x float> %res
 }
 
+define void @__sincos_uniform_float(float, float*, float*) nounwind {
+  %cos = call float @llvm.genx.cos.f32(float %0)
+  %sin = call float @llvm.genx.sin.f32(float %0)
+  store float %sin, float* %1
+  store float %cos, float* %2
+  ret void
+}
+
+define void @__sincos_varying_float(<WIDTH x float>, <WIDTH x float>*, <WIDTH x float>*) nounwind {
+  %cos = call <WIDTH x float> @llvm.genx.cos.XE_SUFFIX(float)(<WIDTH x float> %0)
+  %sin = call <WIDTH x float> @llvm.genx.sin.XE_SUFFIX(float)(<WIDTH x float> %0)
+  store <WIDTH x float> %sin, <WIDTH x float>* %1
+  store <WIDTH x float> %cos, <WIDTH x float>* %2
+  ret void
+}
+
 declare half @llvm.genx.sin.f16(half) nounwind readnone
 define half @__sin_uniform_half(half) nounwind readnone {
   %res = call half @llvm.genx.sin.f16(half %0)
@@ -1515,6 +1531,22 @@ define <WIDTH x half> @__tan_varying_half(<WIDTH x half>) nounwind readnone {
   ret <WIDTH x half> %res
 }
 
+define void @__sincos_uniform_half(half, half*, half*) nounwind {
+  %cos = call half @llvm.genx.cos.f16(half %0)
+  %sin = call half @llvm.genx.sin.f16(half %0)
+  store half %sin, half* %1
+  store half %cos, half* %2
+  ret void
+}
+
+define void @__sincos_varying_half(<WIDTH x half>, <WIDTH x half>*, <WIDTH x half>*) nounwind {
+  %cos = call <WIDTH x half> @llvm.genx.cos.XE_SUFFIX(half)(<WIDTH x half> %0)
+  %sin = call <WIDTH x half> @llvm.genx.sin.XE_SUFFIX(half)(<WIDTH x half> %0)
+  store <WIDTH x half> %sin, <WIDTH x half>* %1
+  store <WIDTH x half> %cos, <WIDTH x half>* %2
+  ret void
+}
+
 trigonometry_decl()
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/builtins/util-xe.m4 b/builtins/util-xe.m4
index 46ada7c0f..1403fa257 100644
--- a/builtins/util-xe.m4
+++ b/builtins/util-xe.m4
@@ -6731,25 +6731,21 @@ global_atomic_varying(WIDTH, umax, i64, uint64)
 define(`trigonometry_decl',`
     declare <WIDTH x half> @__asin_varying_half(<WIDTH x half>) nounwind readnone
     declare <WIDTH x half> @__acos_varying_half(<WIDTH x half>) nounwind readnone
-    declare void @__sincos_varying_half(<WIDTH x half>, <WIDTH x half>*, <WIDTH x half>*) nounwind
     declare <WIDTH x half> @__atan_varying_half(<WIDTH x half>) nounwind readnone
     declare <WIDTH x half> @__atan2_varying_half(<WIDTH x half>,<WIDTH x half>) nounwind readnone
 
     declare float @__asin_uniform_half(half) nounwind readnone
     declare float @__acos_uniform_half(half) nounwind readnone
-    declare void @__sincos_uniform_half(half, half*, half*) nounwind
     declare half @__atan_uniform_half(half) nounwind readnone
     declare half @__atan2_uniform_half(half,half) nounwind readnone
 
     declare <WIDTH x float> @__asin_varying_float(<WIDTH x float>) nounwind readnone
     declare <WIDTH x float> @__acos_varying_float(<WIDTH x float>) nounwind readnone
-    declare void @__sincos_varying_float(<WIDTH x float>, <WIDTH x float>*, <WIDTH x float>*) nounwind
     declare <WIDTH x float> @__atan_varying_float(<WIDTH x float>) nounwind readnone
     declare <WIDTH x float> @__atan2_varying_float(<WIDTH x float>,<WIDTH x float>) nounwind readnone
 
     declare float @__asin_uniform_float(float) nounwind readnone
     declare float @__acos_uniform_float(float) nounwind readnone
-    declare void @__sincos_uniform_float(float, float*, float*) nounwind
     declare float @__atan_uniform_float(float) nounwind readnone
     declare float @__atan2_uniform_float(float,float) nounwind readnone
 ')
diff --git a/fail_db.txt b/fail_db.txt
index 6795f75b6..e1daebba0 100644
--- a/fail_db.txt
+++ b/fail_db.txt
@@ -15,9 +15,7 @@
 ./tests/recursion.ispc runfail    xe64       gen9-x16 unspec   Linux LLVM 12.0 clang++12.0 O0 spv *
 ./tests/short-vec-6.ispc runfail    xe64       gen9-x16 unspec   Linux LLVM 12.0 clang++12.0 O0 spv *
 ./tests/short-vec-6.ispc runfail    xe64        gen9-x8 unspec   Linux LLVM 13.0 clang++13.0 O0 spv *
-./tests/transcendentals-sincos-varying-float16.ispc runfail    xe64        gen9-x8 unspec   Linux LLVM 13.0 clang++13.0 O0 spv *
 ./tests/short-vec-6.ispc runfail    xe64       gen9-x16 unspec   Linux LLVM 13.0 clang++13.0 O0 spv *
-./tests/transcendentals-sincos-varying-float16.ispc runfail    xe64       gen9-x16 unspec   Linux LLVM 13.0 clang++13.0 O0 spv *
 ./tests/varying-float16-rsqrt.ispc runfail    xe64       gen9-x16 unspec   Linux LLVM 13.0 clang++13.0 O0 spv *
 ./tests/varying-float16-rsqrt.ispc runfail    xe64       gen9-x16 unspec   Linux LLVM 13.0 clang++13.0 O2 spv *
 ./tests/varying-float16-rsqrt.ispc runfail    xe64       xelp-x16 tgllp   Linux LLVM 13.0 clang++13.0 O2 spv *
diff --git a/stdlib.ispc b/stdlib.ispc
index 63d2164ba..43e6ebd96 100644
--- a/stdlib.ispc
+++ b/stdlib.ispc
@@ -2720,7 +2720,7 @@ __declspec(safe) static inline uniform float acos(uniform float v) {
 
 __declspec(safe) static inline void sincos(float x_full, varying float *uniform sin_result,
                                            varying float *uniform cos_result) {
-    if (__have_native_trigonometry && !__is_xe_target) {
+    if (__have_native_trigonometry) {
         __sincos_varying_float(x_full, sin_result, cos_result);
         return;
     }
@@ -2789,7 +2789,7 @@ __declspec(safe) static inline void sincos(float x_full, varying float *uniform
 
 __declspec(safe) static inline void sincos(uniform float x_full, uniform float *uniform sin_result,
                                            uniform float *uniform cos_result) {
-    if (__have_native_trigonometry && !__is_xe_target) {
+    if (__have_native_trigonometry) {
         __sincos_uniform_float(x_full, sin_result, cos_result);
         return;
     }
@@ -3674,8 +3674,7 @@ __declspec(safe) static inline uniform float16 acos(uniform float16 x_full) {
 __declspec(safe) static inline void sincos(float16 x_full, varying float16 *uniform sin_result,
                                            varying float16 *uniform cos_result) {
     if (__have_native_trigonometry) {
-        *sin_result = __sin_varying_half(x_full);
-        *cos_result = __cos_varying_half(x_full);
+        __sincos_varying_half(x_full, sin_result, cos_result);
     } else {
         *sin_result = (float16)sin((float)x_full);
         *cos_result = (float16)cos((float)x_full);
@@ -3686,8 +3685,7 @@ __declspec(safe) static inline void sincos(float16 x_full, varying float16 *unif
 __declspec(safe) static inline void sincos(uniform float16 x_full, uniform float16 *uniform sin_result,
                                            uniform float16 *uniform cos_result) {
     if (__have_native_trigonometry) {
-        *sin_result = __sin_uniform_half(x_full);
-        *cos_result = __cos_uniform_half(x_full);
+        __sincos_uniform_half(x_full, sin_result, cos_result);
     } else {
         *sin_result = (uniform float16)sin((uniform float)x_full);
         *cos_result = (uniform float16)cos((uniform float)x_full);
