[libclc] [libclc] Move lgamma, lgamma_r & tgamma to CLC library (PR #134053)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 2 03:27:27 PDT 2025
================
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/clcmacro.h>
+#include <clc/internal/clc.h>
+#include <clc/math/clc_fabs.h>
+#include <clc/math/clc_lgamma.h>
+#include <clc/math/clc_sinpi.h>
+#include <clc/math/clc_exp.h>
+#include <clc/math/math.h>
+
+_CLC_OVERLOAD _CLC_DEF float __clc_tgamma(float x) {
+ const float pi = 3.1415926535897932384626433832795f;
+ float ax = __clc_fabs(x);
+ float lg = __clc_lgamma(ax);
+ float g = __clc_exp(lg);
+
+ if (x < 0.0f) {
+ float z = __clc_sinpi(x);
+ g = g * ax * z;
+ g = pi / g;
+ g = g == 0 ? __clc_as_float(PINFBITPATT_SP32) : g;
+ g = z == 0 ? __clc_as_float(QNANBITPATT_SP32) : g;
+ }
+
+ return g;
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_tgamma, float);
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF double __clc_tgamma(double x) {
+ const double pi = 3.1415926535897932384626433832795;
+ double ax = __clc_fabs(x);
+ double lg = __clc_lgamma(ax);
+ double g = __clc_exp(lg);
+
+ if (x < 0.0) {
+ double z = __clc_sinpi(x);
+ g = g * ax * z;
+ g = pi / g;
+ g = g == 0 ? __clc_as_double(PINFBITPATT_DP64) : g;
+ g = z == 0 ? __clc_as_double(QNANBITPATT_DP64) : g;
----------------
frasercrmck wrote:
Done, and used fabs in more places.
https://github.com/llvm/llvm-project/pull/134053
More information about the cfe-commits
mailing list