Skip to content

[libclc] Move fdim to CLC library; simplify #137811

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 1 commit into from
Apr 29, 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_fdim.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_FDIM_H__
#define __CLC_MATH_CLC_FDIM_H__

#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION __clc_fdim

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif // __CLC_MATH_CLC_FDIM_H__
4 changes: 4 additions & 0 deletions libclc/clc/include/clc/math/gentype.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
#define __CLC_CONVERT_UINTN __CLC_XCONCAT(__clc_convert_, __CLC_UINTN)
#define __CLC_CONVERT_ULONGN __CLC_XCONCAT(__clc_convert_, __CLC_ULONGN)

#define __CLC_CONVERT_BIT_INTN __CLC_XCONCAT(__clc_convert_, __CLC_BIT_INTN)

// See definitions of __CLC_S_GENTYPE/__CLC_U_GENTYPE below, which depend on the
// specific size of floating-point type. These are the signed and unsigned
// integers of the same bitwidth and element count as the GENTYPE. They match
Expand Down Expand Up @@ -329,6 +331,8 @@
#undef __CLC_CONVERT_UINTN
#undef __CLC_CONVERT_ULONGN

#undef __CLC_CONVERT_BIT_INTN

#undef __CLC_ULONGN
#undef __CLC_UINTN
#undef __CLC_USHORTN
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 @@ -41,6 +41,7 @@ math/clc_exp2.cl
math/clc_expm1.cl
math/clc_exp_helper.cl
math/clc_fabs.cl
math/clc_fdim.cl
math/clc_fma.cl
math/clc_fmax.cl
math/clc_fmin.cl
Expand Down
18 changes: 18 additions & 0 deletions libclc/clc/lib/generic/math/clc_fdim.cl
Original file line number Diff line number Diff line change
@@ -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
//
//===----------------------------------------------------------------------===//

#include <clc/clc_convert.h>
#include <clc/float/definitions.h>
#include <clc/internal/clc.h>
#include <clc/math/clc_fmax.h>
#include <clc/math/math.h>
#include <clc/relational/clc_isnan.h>
#include <clc/relational/clc_select.h>

#define __CLC_BODY <clc_fdim.inc>
#include <clc/math/gentype.inc>
15 changes: 15 additions & 0 deletions libclc/clc/lib/generic/math/clc_fdim.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// 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_fdim(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
return __clc_select(
__builtin_elementwise_max(x - y, (__CLC_GENTYPE)__CLC_FP_LIT(0.0)),
__CLC_GENTYPE_NAN,
__CLC_CONVERT_BIT_INTN(__clc_isnan(x) || __clc_isnan(y)));
}
2 changes: 1 addition & 1 deletion libclc/generic/include/clc/math/fdim.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#define __CLC_FUNCTION fdim
#define __CLC_BODY <clc/math/binary_decl_tt.inc>
#define __CLC_BODY <clc/shared/binary_decl.inc>

#include <clc/math/gentype.inc>

Expand Down
5 changes: 3 additions & 2 deletions libclc/generic/lib/math/fdim.cl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//===----------------------------------------------------------------------===//

#include <clc/clc.h>
#include <clc/math/math.h>
#include <clc/math/clc_fdim.h>

#define __CLC_BODY <fdim.inc>
#define FUNCTION fdim
#define __CLC_BODY <clc/shared/binary_def.inc>
#include <clc/math/gentype.inc>
82 changes: 0 additions & 82 deletions libclc/generic/lib/math/fdim.inc

This file was deleted.

Loading