Skip to content

[libclc] Move fp32 sincos helpers to CLC library #132753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libclc/clc/include/clc/math/clc_sincos_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef __CLC_MATH_CLC_SINCOS_HELPERS_H__
#define __CLC_MATH_CLC_SINCOS_HELPERS_H__

#define __FLOAT_ONLY
#define __CLC_BODY <clc/math/clc_sincos_helpers.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __FLOAT_ONLY

#endif // __CLC_MATH_CLC_SINCOS_HELPERS_H__
16 changes: 16 additions & 0 deletions libclc/clc/include/clc/math/clc_sincos_helpers.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

_CLC_DECL _CLC_OVERLOAD __CLC_FLOATN __clc_sinf_piby4(__CLC_FLOATN x,
__CLC_FLOATN y);
_CLC_DECL _CLC_OVERLOAD __CLC_FLOATN __clc_cosf_piby4(__CLC_FLOATN x,
__CLC_FLOATN y);

_CLC_DECL _CLC_OVERLOAD __CLC_INTN __clc_argReductionS(private __CLC_FLOATN *r,
private __CLC_FLOATN *rr,
__CLC_FLOATN x);
14 changes: 14 additions & 0 deletions libclc/clc/include/clc/math/gentype.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#define __CLC_UINTN __CLC_XCONCAT(uint, __CLC_VECSIZE)
#define __CLC_ULONGN __CLC_XCONCAT(ulong, __CLC_VECSIZE)

#define __CLC_AS_HALFN __CLC_XCONCAT(__clc_as_, __CLC_HALFN)
#define __CLC_AS_FLOATN __CLC_XCONCAT(__clc_as_, __CLC_FLOATN)
#define __CLC_AS_DOUBLEN __CLC_XCONCAT(__clc_as_, __CLC_DOUBLEN)

#define __CLC_AS_CHARN __CLC_XCONCAT(__clc_as_, __CLC_CHARN)
#define __CLC_AS_SHORTN __CLC_XCONCAT(__clc_as_, __CLC_SHORTN)
#define __CLC_AS_INTN __CLC_XCONCAT(__clc_as_, __CLC_INTN)
Expand Down Expand Up @@ -67,6 +71,7 @@
#define __CLC_SCALAR_GENTYPE float
#define __CLC_FPSIZE 32
#define __CLC_FP_LIT(x) x##F
#define __CLC_GENTYPE_NAN FLT_NAN

#define __CLC_S_GENTYPE __CLC_XCONCAT(int, __CLC_VECSIZE)
#define __CLC_U_GENTYPE __CLC_XCONCAT(uint, __CLC_VECSIZE)
Expand Down Expand Up @@ -123,6 +128,7 @@

#undef __CLC_U_GENTYPE
#undef __CLC_S_GENTYPE
#undef __CLC_GENTYPE_NAN
#undef __CLC_FP_LIT
#undef __CLC_FPSIZE
#undef __CLC_SCALAR_GENTYPE
Expand All @@ -134,6 +140,7 @@
#define __CLC_SCALAR_GENTYPE double
#define __CLC_FPSIZE 64
#define __CLC_FP_LIT(x) (x)
#define __CLC_GENTYPE_NAN DBL_NAN

#define __CLC_S_GENTYPE __CLC_XCONCAT(long, __CLC_VECSIZE)
#define __CLC_U_GENTYPE __CLC_XCONCAT(ulong, __CLC_VECSIZE)
Expand Down Expand Up @@ -190,6 +197,7 @@

#undef __CLC_U_GENTYPE
#undef __CLC_S_GENTYPE
#undef __CLC_GENTYPE_NAN
#undef __CLC_FP_LIT
#undef __CLC_FPSIZE
#undef __CLC_SCALAR_GENTYPE
Expand All @@ -203,6 +211,7 @@
#define __CLC_SCALAR_GENTYPE half
#define __CLC_FPSIZE 16
#define __CLC_FP_LIT(x) x##H
#define __CLC_GENTYPE_NAN HALF_NAN

#define __CLC_S_GENTYPE __CLC_XCONCAT(short, __CLC_VECSIZE)
#define __CLC_U_GENTYPE __CLC_XCONCAT(ushort, __CLC_VECSIZE)
Expand Down Expand Up @@ -259,6 +268,7 @@

#undef __CLC_U_GENTYPE
#undef __CLC_S_GENTYPE
#undef __CLC_GENTYPE_NAN
#undef __CLC_FP_LIT
#undef __CLC_FPSIZE
#undef __CLC_SCALAR_GENTYPE
Expand All @@ -278,6 +288,10 @@
#undef __CLC_AS_INTN
#undef __CLC_AS_LONGN

#undef __CLC_AS_HALFN
#undef __CLC_AS_FLOATN
#undef __CLC_AS_DOUBLEN

#undef __CLC_AS_UCHARN
#undef __CLC_AS_USHORTN
#undef __CLC_AS_UINTN
Expand Down
1 change: 1 addition & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ math/clc_nextafter.cl
math/clc_rint.cl
math/clc_round.cl
math/clc_rsqrt.cl
math/clc_sincos_helpers.cl
math/clc_sqrt.cl
math/clc_sw_fma.cl
math/clc_trunc.cl
Expand Down
32 changes: 32 additions & 0 deletions libclc/clc/lib/generic/math/clc_sincos_helpers.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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/clc_convert.h>
#include <clc/integer/clc_clz.h>
#include <clc/integer/clc_mul_hi.h>
#include <clc/internal/clc.h>
#include <clc/math/clc_fma.h>
#include <clc/math/clc_mad.h>
#include <clc/math/clc_trunc.h>
#include <clc/math/math.h>

#define bitalign(hi, lo, shift) ((hi) << (32 - (shift))) | ((lo) >> (shift));

#define FULL_MUL(A, B, HI, LO) \
LO = A * B; \
HI = __clc_mul_hi(A, B)

#define FULL_MAD(A, B, C, HI, LO) \
LO = ((A) * (B) + (C)); \
HI = __clc_mul_hi(A, B); \
HI += LO < C ? 1U : 0U;

#define __FLOAT_ONLY
#define __CLC_BODY <clc_sincos_helpers.inc>

#include <clc/math/gentype.inc>
Loading