Skip to content

Commit d51525b

Browse files
authored
[libclc] Move lgamma, lgamma_r & tgamma to CLC library (#134053)
Also enable half-precision variants of tgamma, which were previously missing. Note that unlike recent work, these builtins are not vectorized as part of this commit. Ultimately all three call into lgamma_r, which has heavy control flow (including switch statements) that would be difficult to vectorize. Additionally the lgamma_r algorithm is copyrighted to SunPro so may need a rewrite in the future anyway. There are no codegen changes (to non-SPIR-V targets) with this commit, aside from the new half builtins.
1 parent 87bebd3 commit d51525b

File tree

14 files changed

+799
-563
lines changed

14 files changed

+799
-563
lines changed

libclc/generic/include/clc/math/lgamma_r.inc renamed to libclc/clc/include/clc/math/clc_lgamma.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, global __CLC_INTN *iptr);
10-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, local __CLC_INTN *iptr);
11-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, private __CLC_INTN *iptr);
9+
#ifndef __CLC_MATH_CLC_LGAMMA_H__
10+
#define __CLC_MATH_CLC_LGAMMA_H__
11+
12+
#define __CLC_BODY <clc/math/unary_decl.inc>
13+
#define __CLC_FUNCTION __clc_lgamma
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_BODY
18+
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_MATH_CLC_LGAMMA_H__
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_MATH_CLC_LGAMMA_R_H__
10+
#define __CLC_MATH_CLC_LGAMMA_R_H__
11+
12+
#define __CLC_FUNCTION __clc_lgamma_r
13+
#define __CLC_BODY <clc/math/unary_decl_with_int_ptr.inc>
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_BODY
18+
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_MATH_CLC_LGAMMA_R_H__
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_MATH_CLC_TGAMMA_H__
10+
#define __CLC_MATH_CLC_TGAMMA_H__
11+
12+
#define __CLC_BODY <clc/math/unary_decl.inc>
13+
#define __CLC_FUNCTION __clc_tgamma
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_BODY
18+
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_MATH_CLC_TGAMMA_H__

libclc/generic/lib/math/lgamma_r.inc renamed to libclc/clc/include/clc/math/unary_def_via_fp32.inc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, __CLC_ADDRSPACE __CLC_INTN *iptr) {
10-
__CLC_INTN private_iptr;
11-
__CLC_GENTYPE ret = lgamma_r(x, &private_iptr);
12-
*iptr = private_iptr;
13-
return ret;
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x) {
10+
return __CLC_CONVERT_GENTYPE(__CLC_FUNCTION(__CLC_CONVERT_FLOATN(x)));
1411
}

libclc/clc/lib/generic/SOURCES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ math/clc_floor.cl
4545
math/clc_frexp.cl
4646
math/clc_hypot.cl
4747
math/clc_ldexp.cl
48+
math/clc_lgamma.cl
49+
math/clc_lgamma_r.cl
4850
math/clc_log.cl
4951
math/clc_log10.cl
5052
math/clc_log1p.cl
@@ -79,6 +81,7 @@ math/clc_sqrt.cl
7981
math/clc_sw_fma.cl
8082
math/clc_tables.cl
8183
math/clc_tanpi.cl
84+
math/clc_tgamma.cl
8285
math/clc_trunc.cl
8386
relational/clc_all.cl
8487
relational/clc_any.cl
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/internal/clc.h>
10+
#include <clc/math/clc_lgamma_r.h>
11+
12+
#define __CLC_BODY <clc_lgamma.inc>
13+
#include <clc/math/gentype.inc>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_lgamma(__CLC_GENTYPE x) {
10+
__CLC_INTN s;
11+
return __clc_lgamma_r(x, &s);
12+
}

0 commit comments

Comments
 (0)