Skip to content

Commit 001f427

Browse files
committed
spirv fmin/fmax
1 parent 414c6cf commit 001f427

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

libclc/clc/lib/spirv/SOURCES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
math/clc_fmax.cl
2+
math/clc_fmin.cl
13
math/clc_runtime_has_hw_fma32.cl
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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/clcmacro.h>
10+
#include <clc/internal/clc.h>
11+
#include <clc/relational/clc_isnan.h>
12+
13+
#define __FLOAT_ONLY
14+
#define __CLC_MIN_VECSIZE 1
15+
#define FUNCTION __clc_fmax
16+
#define __IMPL_FUNCTION __builtin_fmaxf
17+
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc>
18+
#include <clc/math/gentype.inc>
19+
#undef __CLC_MIN_VECSIZE
20+
#undef FUNCTION
21+
#undef __IMPL_FUNCTION
22+
23+
#ifdef cl_khr_fp64
24+
25+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
26+
27+
#define __DOUBLE_ONLY
28+
#define __CLC_MIN_VECSIZE 1
29+
#define FUNCTION __clc_fmax
30+
#define __IMPL_FUNCTION __builtin_fmax
31+
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc>
32+
#include <clc/math/gentype.inc>
33+
#undef __CLC_MIN_VECSIZE
34+
#undef FUNCTION
35+
#undef __IMPL_FUNCTION
36+
37+
#endif
38+
39+
#ifdef cl_khr_fp16
40+
41+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
42+
43+
_CLC_DEF _CLC_OVERLOAD half __clc_fmax(half x, half y) {
44+
if (__clc_isnan(x))
45+
return y;
46+
if (__clc_isnan(y))
47+
return x;
48+
return (x < y) ? y : x;
49+
}
50+
51+
#define __HALF_ONLY
52+
#define __CLC_SUPPORTED_VECSIZE_OR_1 2
53+
#define FUNCTION __clc_fmax
54+
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc>
55+
#include <clc/math/gentype.inc>
56+
#undef FUNCTION
57+
58+
#endif
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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/clcmacro.h>
10+
#include <clc/internal/clc.h>
11+
#include <clc/relational/clc_isnan.h>
12+
13+
#define __FLOAT_ONLY
14+
#define __CLC_MIN_VECSIZE 1
15+
#define FUNCTION __clc_fmin
16+
#define __IMPL_FUNCTION __builtin_fminf
17+
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc>
18+
#include <clc/math/gentype.inc>
19+
#undef __CLC_MIN_VECSIZE
20+
#undef FUNCTION
21+
#undef __IMPL_FUNCTION
22+
23+
#ifdef cl_khr_fp64
24+
25+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
26+
27+
#define __DOUBLE_ONLY
28+
#define __CLC_MIN_VECSIZE 1
29+
#define FUNCTION __clc_fmin
30+
#define __IMPL_FUNCTION __builtin_fmin
31+
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc>
32+
#include <clc/math/gentype.inc>
33+
#undef __CLC_MIN_VECSIZE
34+
#undef FUNCTION
35+
#undef __IMPL_FUNCTION
36+
37+
#endif
38+
39+
#ifdef cl_khr_fp16
40+
41+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
42+
43+
_CLC_DEF _CLC_OVERLOAD half __clc_fmin(half x, half y) {
44+
if (__clc_isnan(x))
45+
return y;
46+
if (__clc_isnan(y))
47+
return x;
48+
return (y < x) ? y : x;
49+
}
50+
51+
#define __HALF_ONLY
52+
#define __CLC_SUPPORTED_VECSIZE_OR_1 2
53+
#define FUNCTION __clc_fmin
54+
#define __CLC_BODY <clc/shared/binary_def_scalarize.inc>
55+
#include <clc/math/gentype.inc>
56+
57+
#endif

0 commit comments

Comments
 (0)