[libclc] Move minmag & maxmag to the CLC library (#137982)

This commit is contained in:
Fraser Cormack
2025-05-01 09:43:40 +01:00
committed by GitHub
parent 9b1051281e
commit 6c4dd8d1d2
11 changed files with 119 additions and 56 deletions

View File

@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// 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_MAXMAG_H__
#define __CLC_MATH_CLC_MAXMAG_H__
#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION __clc_maxmag
#include <clc/math/gentype.inc>
#undef __CLC_FUNCTION
#endif // __CLC_MATH_CLC_MAXMAG_H__

View File

@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// 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_MINMAG_H__
#define __CLC_MATH_CLC_MINMAG_H__
#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION __clc_minmag
#include <clc/math/gentype.inc>
#undef __CLC_FUNCTION
#endif // __CLC_MATH_CLC_MINMAG_H__

View File

@@ -58,6 +58,8 @@ math/clc_log10.cl
math/clc_log1p.cl
math/clc_log2.cl
math/clc_mad.cl
math/clc_maxmag.cl
math/clc_minmag.cl
math/clc_modf.cl
math/clc_nan.cl
math/clc_native_cos.cl

View File

@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// 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/internal/clc.h>
#include <clc/math/clc_fabs.h>
#include <clc/math/clc_fmax.h>
#include <clc/relational/clc_isequal.h>
#include <clc/relational/clc_isgreater.h>
#include <clc/relational/clc_isnan.h>
#include <clc/relational/clc_select.h>
#define __CLC_BODY <clc_maxmag.inc>
#include <clc/math/gentype.inc>

View File

@@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_maxmag(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
const __CLC_GENTYPE res = __clc_select(
y, x,
__CLC_CONVERT_BIT_INTN(__clc_isgreater(__clc_fabs(x), __clc_fabs(y))));
return __clc_select(
res, __clc_fmax(x, y),
__CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y) ||
__clc_isequal(__clc_fabs(x), __clc_fabs(y))));
}

View File

@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// 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/internal/clc.h>
#include <clc/math/clc_fabs.h>
#include <clc/math/clc_fmin.h>
#include <clc/relational/clc_isequal.h>
#include <clc/relational/clc_isless.h>
#include <clc/relational/clc_isnan.h>
#include <clc/relational/clc_select.h>
#define __CLC_BODY <clc_minmag.inc>
#include <clc/math/gentype.inc>

View File

@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// 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_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_minmag(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
const __CLC_GENTYPE res = __clc_select(
y, x, __CLC_CONVERT_BIT_INTN(__clc_isless(__clc_fabs(x), __clc_fabs(y))));
return __clc_select(
res, __clc_fmin(x, y),
__CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y) ||
__clc_isequal(__clc_fabs(x), __clc_fabs(y))));
}

View File

@@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
#include <clc/utils.h>
#include <clc/math/clc_maxmag.h>
#define __CLC_BODY <maxmag.inc>
#define FUNCTION maxmag
#define __CLC_BODY <clc/shared/binary_def.inc>
#include <clc/math/gentype.inc>

View File

@@ -1,22 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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 == 64
#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_long, __CLC_VECSIZE)
#elif __CLC_FPSIZE == 32
#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_int, __CLC_VECSIZE)
#elif __CLC_FPSIZE == 16
#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_short, __CLC_VECSIZE)
#endif
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE maxmag(__CLC_GENTYPE x, __CLC_GENTYPE y) {
const __CLC_GENTYPE res = select(y, x, __CLC_CONVERT_NATN(isgreater(fabs(x), fabs(y))));
return select(res, fmax(x, y), __CLC_CONVERT_NATN(isnan(x) | isnan(y) | isequal(fabs(x), fabs(y))));
}
#undef __CLC_CONVERT_NATN

View File

@@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//
#include <clc/clc.h>
#include <clc/utils.h>
#include <clc/math/clc_minmag.h>
#define __CLC_BODY <minmag.inc>
#define FUNCTION minmag
#define __CLC_BODY <clc/shared/binary_def.inc>
#include <clc/math/gentype.inc>

View File

@@ -1,30 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifdef __CLC_SCALAR
#define __CLC_VECSIZE
#endif
#if __CLC_FPSIZE == 64
#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_long, __CLC_VECSIZE)
#elif __CLC_FPSIZE == 32
#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_int, __CLC_VECSIZE)
#elif __CLC_FPSIZE == 16
#define __CLC_CONVERT_NATN __CLC_XCONCAT(convert_short, __CLC_VECSIZE)
#endif
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE minmag(__CLC_GENTYPE x, __CLC_GENTYPE y) {
const __CLC_GENTYPE res = select(y, x, __CLC_CONVERT_NATN(isless(fabs(x), fabs(y))));
return select(res, fmin(x, y), __CLC_CONVERT_NATN(isnan(x) | isnan(y) | isequal(fabs(x), fabs(y))));
}
#undef __CLC_CONVERT_NATN
#ifdef __CLC_SCALAR
#undef __CLC_VECSIZE
#endif