libclc: do not use int64 in sincos helpers (#188056)

int64 is optional, thus we do not want to force its usage for clspv.

GitOrigin-RevId: e0a1e78738b2ac2644db4b0a7d27dffc621aacdb
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1103711..4a289e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -190,7 +190,8 @@
     list(APPEND target_extra_defines CLC_SPIRV)
     set(opt_flags)
   elseif(ARCH STREQUAL clspv OR ARCH STREQUAL clspv64)
-    list(APPEND target_compile_flags -Wno-unknown-assumption)
+    list(APPEND target_compile_flags -Wno-unknown-assumption
+                                     -U__opencl_c_int64)
     list(APPEND target_extra_defines CLC_CLSPV)
   elseif(ARCH STREQUAL amdgcn)
     list(APPEND target_compile_flags "SHELL:-Xclang -mcode-object-version=none")
diff --git a/clc/lib/generic/math/clc_sincos_helpers.cl b/clc/lib/generic/math/clc_sincos_helpers.cl
index bb41e6c..5a4c501 100644
--- a/clc/lib/generic/math/clc_sincos_helpers.cl
+++ b/clc/lib/generic/math/clc_sincos_helpers.cl
@@ -22,6 +22,18 @@
 #include "clc/relational/clc_isinf.h"
 #include "clc/relational/clc_isnan.h"
 
+#ifndef __opencl_c_int64
+#include "clc/integer/clc_mul_hi.h"
+#define __CLC_FULL_MUL(A, B, HI, LO)                                           \
+  LO = A * B;                                                                  \
+  HI = __clc_mul_hi(A, B)
+
+#define __CLC_FULL_MAD(A, B, C, HI, LO)                                        \
+  LO = ((A) * (B) + (C));                                                      \
+  HI = __clc_mul_hi(A, B);                                                     \
+  HI += LO < C ? 1U : 0U;
+#endif
+
 #define bitalign(hi, lo, shift) __builtin_elementwise_fshr(hi, lo, shift)
 
 #define __CLC_FLOAT_ONLY
diff --git a/clc/lib/generic/math/clc_sincos_helpers.inc b/clc/lib/generic/math/clc_sincos_helpers.inc
index de82df6..f2c0bbf 100644
--- a/clc/lib/generic/math/clc_sincos_helpers.inc
+++ b/clc/lib/generic/math/clc_sincos_helpers.inc
@@ -184,6 +184,17 @@
   const __CLC_UINTN b0 = 0xFE5163ABU;
 
   __CLC_UINTN p0, p1, p2, p3, p4, p5, p6, p7;
+#ifndef __opencl_c_int64
+  __CLC_UINTN c0, c1;
+
+  __CLC_FULL_MUL(xm, b0, c0, p0);
+  __CLC_FULL_MAD(xm, b1, c0, c1, p1);
+  __CLC_FULL_MAD(xm, b2, c1, c0, p2);
+  __CLC_FULL_MAD(xm, b3, c0, c1, p3);
+  __CLC_FULL_MAD(xm, b4, c1, c0, p4);
+  __CLC_FULL_MAD(xm, b5, c0, c1, p5);
+  __CLC_FULL_MAD(xm, b6, c1, p7, p6);
+#else
   __CLC_ULONGN a;
 
   __CLC_ULONGN xm_u64 = __CLC_CONVERT_ULONGN(xm);
@@ -215,6 +226,7 @@
   a = xm_u64 * __CLC_CONVERT_ULONGN(b6) + a;
   p6 = __CLC_CONVERT_UINTN(a);
   p7 = __CLC_CONVERT_UINTN(a >> 32);
+#endif
 
   __CLC_UINTN fbits =
       (__CLC_UINTN)224 + (__CLC_UINTN)23 - __CLC_CONVERT_UINTN(xe);