Skip to content

Commit ecd25af

Browse files
authored
libclc: Add __clc_issubnormal (llvm#181782)
This is the missing of the FP class queries.
1 parent 8f378ea commit ecd25af

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_RELATIONAL_CLC_ISSUBNORMAL_H__
10+
#define __CLC_RELATIONAL_CLC_ISSUBNORMAL_H__
11+
12+
#include <clc/clcfunc.h>
13+
14+
#define _CLC_ISSUBNORMAL_DECL(RET_TYPE, ARG_TYPE) \
15+
_CLC_OVERLOAD _CLC_CONST _CLC_DECL RET_TYPE __clc_issubnormal(ARG_TYPE);
16+
17+
#define _CLC_VECTOR_ISSUBNORMAL_DECL(RET_TYPE, ARG_TYPE) \
18+
_CLC_ISSUBNORMAL_DECL(RET_TYPE##2, ARG_TYPE##2) \
19+
_CLC_ISSUBNORMAL_DECL(RET_TYPE##3, ARG_TYPE##3) \
20+
_CLC_ISSUBNORMAL_DECL(RET_TYPE##4, ARG_TYPE##4) \
21+
_CLC_ISSUBNORMAL_DECL(RET_TYPE##8, ARG_TYPE##8) \
22+
_CLC_ISSUBNORMAL_DECL(RET_TYPE##16, ARG_TYPE##16)
23+
24+
_CLC_ISSUBNORMAL_DECL(int, float)
25+
_CLC_VECTOR_ISSUBNORMAL_DECL(int, float)
26+
27+
#ifdef cl_khr_fp64
28+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
29+
_CLC_ISSUBNORMAL_DECL(int, double)
30+
_CLC_VECTOR_ISSUBNORMAL_DECL(long, double)
31+
#endif
32+
33+
#ifdef cl_khr_fp16
34+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
35+
_CLC_ISSUBNORMAL_DECL(int, half)
36+
_CLC_VECTOR_ISSUBNORMAL_DECL(short, half)
37+
#endif
38+
39+
#undef _CLC_ISSUBNORMAL_DECL
40+
#undef _CLC_VECTOR_ISSUBNORMAL_DECL
41+
42+
#endif // __CLC_RELATIONAL_CLC_ISSUBNORMAL_H__

libclc/clc/include/clc/relational/relational.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define fcNan (__FPCLASS_SNAN | __FPCLASS_QNAN)
4444
#define fcInf (__FPCLASS_POSINF | __FPCLASS_NEGINF)
4545
#define fcNormal (__FPCLASS_POSNORMAL | __FPCLASS_NEGNORMAL)
46+
#define fcSubnormal (__FPCLASS_POSSUBNORMAL | __FPCLASS_NEGSUBNORMAL)
4647
#define fcPosFinite \
4748
(__FPCLASS_POSNORMAL | __FPCLASS_POSSUBNORMAL | __FPCLASS_POSZERO)
4849
#define fcNegFinite \

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ relational/clc_isnan.cl
166166
relational/clc_isnormal.cl
167167
relational/clc_isnotequal.cl
168168
relational/clc_isordered.cl
169+
relational/clc_issubnormal.cl
169170
relational/clc_isunordered.cl
170171
relational/clc_select.cl
171172
relational/clc_signbit.cl
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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/internal/clc.h>
10+
#include <clc/relational/clc_issubnormal.h>
11+
#include <clc/relational/relational.h>
12+
13+
_CLC_DEFINE_ISFPCLASS(int, int, __clc_issubnormal, fcSubnormal, float)
14+
15+
#ifdef cl_khr_fp64
16+
17+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
18+
19+
// The scalar version of __clc_issubnormal(double) returns an int, but the
20+
// vector versions return a long.
21+
_CLC_DEFINE_ISFPCLASS(int, long, __clc_issubnormal, fcSubnormal, double)
22+
23+
#endif
24+
25+
#ifdef cl_khr_fp16
26+
27+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
28+
29+
// The scalar version of __clc_issubnormal(half) returns an int, but the vector
30+
// versions return a short.
31+
_CLC_DEFINE_ISFPCLASS(int, short, __clc_issubnormal, fcSubnormal, half)
32+
33+
#endif

0 commit comments

Comments
 (0)