Skip to content

Commit ea688c0

Browse files
authored
[libclc] Move fdim to CLC library; simplify (#137811)
This commit moves the fdim builtin to the CLC library. It simultaneously simplifies the codegen, unifying it between scalar and vector and avoiding bithacking for vector types.
1 parent bd3dde0 commit ea688c0

File tree

7 files changed

+61
-84
lines changed

7 files changed

+61
-84
lines changed
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_FDIM_H__
10+
#define __CLC_MATH_CLC_FDIM_H__
11+
12+
#define __CLC_BODY <clc/shared/binary_decl.inc>
13+
#define __CLC_FUNCTION __clc_fdim
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_BODY
18+
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_MATH_CLC_FDIM_H__

libclc/clc/include/clc/math/gentype.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#define __CLC_CONVERT_UINTN __CLC_XCONCAT(__clc_convert_, __CLC_UINTN)
5858
#define __CLC_CONVERT_ULONGN __CLC_XCONCAT(__clc_convert_, __CLC_ULONGN)
5959

60+
#define __CLC_CONVERT_BIT_INTN __CLC_XCONCAT(__clc_convert_, __CLC_BIT_INTN)
61+
6062
// See definitions of __CLC_S_GENTYPE/__CLC_U_GENTYPE below, which depend on the
6163
// specific size of floating-point type. These are the signed and unsigned
6264
// integers of the same bitwidth and element count as the GENTYPE. They match
@@ -329,6 +331,8 @@
329331
#undef __CLC_CONVERT_UINTN
330332
#undef __CLC_CONVERT_ULONGN
331333

334+
#undef __CLC_CONVERT_BIT_INTN
335+
332336
#undef __CLC_ULONGN
333337
#undef __CLC_UINTN
334338
#undef __CLC_USHORTN

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ math/clc_exp2.cl
4141
math/clc_expm1.cl
4242
math/clc_exp_helper.cl
4343
math/clc_fabs.cl
44+
math/clc_fdim.cl
4445
math/clc_fma.cl
4546
math/clc_fmax.cl
4647
math/clc_fmin.cl
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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/clc_convert.h>
10+
#include <clc/float/definitions.h>
11+
#include <clc/internal/clc.h>
12+
#include <clc/math/clc_fmax.h>
13+
#include <clc/math/math.h>
14+
#include <clc/relational/clc_isnan.h>
15+
#include <clc/relational/clc_select.h>
16+
17+
#define __CLC_BODY <clc_fdim.inc>
18+
#include <clc/math/gentype.inc>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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_fdim(__CLC_GENTYPE x,
10+
__CLC_GENTYPE y) {
11+
return __clc_select(
12+
__builtin_elementwise_max(x - y, (__CLC_GENTYPE)__CLC_FP_LIT(0.0)),
13+
__CLC_GENTYPE_NAN,
14+
__CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y)));
15+
}

libclc/generic/lib/math/fdim.cl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc.h>
10-
#include <clc/math/math.h>
10+
#include <clc/math/clc_fdim.h>
1111

12-
#define __CLC_BODY <fdim.inc>
12+
#define FUNCTION fdim
13+
#define __CLC_BODY <clc/shared/binary_def.inc>
1314
#include <clc/math/gentype.inc>

libclc/generic/lib/math/fdim.inc

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)