[libclc] [libclc] Move sinh, cosh & tanh to the CLC library (PR #134063)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 2 03:37:39 PDT 2025
================
@@ -0,0 +1,201 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#if __CLC_FPSIZE == 32
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_cosh(__CLC_GENTYPE x) {
+ // After dealing with special cases the computation is split into regions as
+ // follows. abs(x) >= max_cosh_arg: cosh(x) = sign(x)*Inf abs(x) >=
+ // small_threshold: cosh(x) = sign(x)*exp(abs(x))/2 computed using the
+ // splitexp and scaleDouble functions as for exp_amd().
+ // abs(x) < small_threshold:
+ // compute p = exp(y) - 1 and then z = 0.5*(p+(p/(p+1.0)))
+ // cosh(x) is then z.
+
+ const __CLC_GENTYPE max_cosh_arg = 0x1.65a9fap+6f;
+ const __CLC_GENTYPE small_threshold = 0x1.0a2b24p+3f;
+
+ __CLC_UINTN ux = __CLC_AS_UINTN(x);
+ __CLC_UINTN aux = ux & EXSIGNBIT_SP32;
+ __CLC_GENTYPE y = __CLC_AS_GENTYPE(aux);
----------------
frasercrmck wrote:
good catch, thanks.
https://github.com/llvm/llvm-project/pull/134063
More information about the cfe-commits
mailing list