Skip to content

Commit

Permalink
[libclc] Move relational functions to CLC library
Browse files Browse the repository at this point in the history
The OpenCL relational functions now call their CLC counterparts, and the
CLC relational functions are defined identically to how the OpenCL
functions were defined.

As usual, clspv and spir-v targets bypass these.

No observable changes to any libclc target (measured with llvm-diff).
  • Loading branch information
frasercrmck committed Nov 6, 2024
1 parent 5d8be4c commit 97ace17
Show file tree
Hide file tree
Showing 74 changed files with 1,563 additions and 637 deletions.
82 changes: 82 additions & 0 deletions libclc/clc/include/clc/clc_as_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef __CLC_CLC_AS_TYPE_H__
#define __CLC_CLC_AS_TYPE_H__

#define __clc_as_char(x) __builtin_astype(x, char)
#define __clc_as_uchar(x) __builtin_astype(x, uchar)
#define __clc_as_short(x) __builtin_astype(x, short)
#define __clc_as_ushort(x) __builtin_astype(x, ushort)
#define __clc_as_int(x) __builtin_astype(x, int)
#define __clc_as_uint(x) __builtin_astype(x, uint)
#define __clc_as_long(x) __builtin_astype(x, long)
#define __clc_as_ulong(x) __builtin_astype(x, ulong)
#define __clc_as_float(x) __builtin_astype(x, float)

#define __clc_as_char2(x) __builtin_astype(x, char2)
#define __clc_as_uchar2(x) __builtin_astype(x, uchar2)
#define __clc_as_short2(x) __builtin_astype(x, short2)
#define __clc_as_ushort2(x) __builtin_astype(x, ushort2)
#define __clc_as_int2(x) __builtin_astype(x, int2)
#define __clc_as_uint2(x) __builtin_astype(x, uint2)
#define __clc_as_long2(x) __builtin_astype(x, long2)
#define __clc_as_ulong2(x) __builtin_astype(x, ulong2)
#define __clc_as_float2(x) __builtin_astype(x, float2)

#define __clc_as_char3(x) __builtin_astype(x, char3)
#define __clc_as_uchar3(x) __builtin_astype(x, uchar3)
#define __clc_as_short3(x) __builtin_astype(x, short3)
#define __clc_as_ushort3(x) __builtin_astype(x, ushort3)
#define __clc_as_int3(x) __builtin_astype(x, int3)
#define __clc_as_uint3(x) __builtin_astype(x, uint3)
#define __clc_as_long3(x) __builtin_astype(x, long3)
#define __clc_as_ulong3(x) __builtin_astype(x, ulong3)
#define __clc_as_float3(x) __builtin_astype(x, float3)

#define __clc_as_char4(x) __builtin_astype(x, char4)
#define __clc_as_uchar4(x) __builtin_astype(x, uchar4)
#define __clc_as_short4(x) __builtin_astype(x, short4)
#define __clc_as_ushort4(x) __builtin_astype(x, ushort4)
#define __clc_as_int4(x) __builtin_astype(x, int4)
#define __clc_as_uint4(x) __builtin_astype(x, uint4)
#define __clc_as_long4(x) __builtin_astype(x, long4)
#define __clc_as_ulong4(x) __builtin_astype(x, ulong4)
#define __clc_as_float4(x) __builtin_astype(x, float4)

#define __clc_as_char8(x) __builtin_astype(x, char8)
#define __clc_as_uchar8(x) __builtin_astype(x, uchar8)
#define __clc_as_short8(x) __builtin_astype(x, short8)
#define __clc_as_ushort8(x) __builtin_astype(x, ushort8)
#define __clc_as_int8(x) __builtin_astype(x, int8)
#define __clc_as_uint8(x) __builtin_astype(x, uint8)
#define __clc_as_long8(x) __builtin_astype(x, long8)
#define __clc_as_ulong8(x) __builtin_astype(x, ulong8)
#define __clc_as_float8(x) __builtin_astype(x, float8)

#define __clc_as_char16(x) __builtin_astype(x, char16)
#define __clc_as_uchar16(x) __builtin_astype(x, uchar16)
#define __clc_as_short16(x) __builtin_astype(x, short16)
#define __clc_as_ushort16(x) __builtin_astype(x, ushort16)
#define __clc_as_int16(x) __builtin_astype(x, int16)
#define __clc_as_uint16(x) __builtin_astype(x, uint16)
#define __clc_as_long16(x) __builtin_astype(x, long16)
#define __clc_as_ulong16(x) __builtin_astype(x, ulong16)
#define __clc_as_float16(x) __builtin_astype(x, float16)

#ifdef cl_khr_fp64
#define __clc_as_double(x) __builtin_astype(x, double)
#define __clc_as_double2(x) __builtin_astype(x, double2)
#define __clc_as_double3(x) __builtin_astype(x, double3)
#define __clc_as_double4(x) __builtin_astype(x, double4)
#define __clc_as_double8(x) __builtin_astype(x, double8)
#define __clc_as_double16(x) __builtin_astype(x, double16)
#endif

#ifdef cl_khr_fp16
#define __clc_as_half(x) __builtin_astype(x, half)
#define __clc_as_half2(x) __builtin_astype(x, half2)
#define __clc_as_half3(x) __builtin_astype(x, half3)
#define __clc_as_half4(x) __builtin_astype(x, half4)
#define __clc_as_half8(x) __builtin_astype(x, half8)
#define __clc_as_half16(x) __builtin_astype(x, half16)
#endif

#endif // __CLC_CLC_AS_TYPE_H__
3 changes: 3 additions & 0 deletions libclc/clc/include/clc/internal/clc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
/* 6.1 Supported Data Types */
#include <clc/clctypes.h>

/* 6.2.4.2 Reinterpreting Types Using __clc_as_type() and __clc_as_typen() */
#include <clc/clc_as_type.h>

#pragma OPENCL EXTENSION all : disable

#endif // __CLC_INTERNAL_CLC_H_
31 changes: 31 additions & 0 deletions libclc/clc/include/clc/relational/clc_all.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef __CLC_RELATIONAL_CLC_ALL_H__
#define __CLC_RELATIONAL_CLC_ALL_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible all
#define __clc_all all
#else

#include <clc/clcfunc.h>

#define _CLC_ALL_DECL(TYPE) _CLC_OVERLOAD _CLC_DECL int __clc_all(TYPE v);

#define _CLC_VECTOR_ALL_DECL(TYPE) \
_CLC_ALL_DECL(TYPE) \
_CLC_ALL_DECL(TYPE##2) \
_CLC_ALL_DECL(TYPE##3) \
_CLC_ALL_DECL(TYPE##4) \
_CLC_ALL_DECL(TYPE##8) \
_CLC_ALL_DECL(TYPE##16)

_CLC_VECTOR_ALL_DECL(char)
_CLC_VECTOR_ALL_DECL(short)
_CLC_VECTOR_ALL_DECL(int)
_CLC_VECTOR_ALL_DECL(long)

#undef _CLC_ALL_DECL
#undef _CLC_VECTOR_ALL_DECL

#endif

#endif // __CLC_RELATIONAL_CLC_ALL_H__
31 changes: 31 additions & 0 deletions libclc/clc/include/clc/relational/clc_any.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef __CLC_RELATIONAL_CLC_ANY_H__
#define __CLC_RELATIONAL_CLC_ANY_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible any
#define __clc_any any
#else

#include <clc/clcfunc.h>

#define _CLC_ANY_DECL(TYPE) _CLC_OVERLOAD _CLC_DECL int __clc_any(TYPE v);

#define _CLC_VECTOR_ANY_DECL(TYPE) \
_CLC_ANY_DECL(TYPE) \
_CLC_ANY_DECL(TYPE##2) \
_CLC_ANY_DECL(TYPE##3) \
_CLC_ANY_DECL(TYPE##4) \
_CLC_ANY_DECL(TYPE##8) \
_CLC_ANY_DECL(TYPE##16)

_CLC_VECTOR_ANY_DECL(char)
_CLC_VECTOR_ANY_DECL(short)
_CLC_VECTOR_ANY_DECL(int)
_CLC_VECTOR_ANY_DECL(long)

#undef _CLC_ANY_DECL
#undef _CLC_VECTOR_ANY_DECL

#endif

#endif // __CLC_RELATIONAL_CLC_ANY_H__
33 changes: 33 additions & 0 deletions libclc/clc/include/clc/relational/clc_bitselect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2015 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __CLC_RELATIONAL_CLC_BITSELECT_H__
#define __CLC_RELATIONAL_CLC_BITSELECT_H__

#define __CLC_BODY <clc/relational/clc_bitselect.inc>
#include <clc/math/gentype.inc>
#define __CLC_BODY <clc/relational/clc_bitselect.inc>
#include <clc/integer/gentype.inc>

#undef __CLC_BODY

#endif // __CLC_RELATIONAL_CLC_BITSELECT_H__
25 changes: 25 additions & 0 deletions libclc/clc/include/clc/relational/clc_bitselect.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2015 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_bitselect(__CLC_GENTYPE x,
__CLC_GENTYPE y,
__CLC_GENTYPE z);
41 changes: 41 additions & 0 deletions libclc/clc/include/clc/relational/clc_isequal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef __CLC_RELATIONAL_CLC_ISEQUAL_H__
#define __CLC_RELATIONAL_CLC_ISEQUAL_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible isequal
#define __clc_isequal isequal
#else

#include <clc/clcfunc.h>

#define _CLC_ISEQUAL_DECL(TYPE, RETTYPE) \
_CLC_OVERLOAD _CLC_DECL RETTYPE __clc_isequal(TYPE x, TYPE y);

#define _CLC_VECTOR_ISEQUAL_DECL(TYPE, RETTYPE) \
_CLC_ISEQUAL_DECL(TYPE##2, RETTYPE##2) \
_CLC_ISEQUAL_DECL(TYPE##3, RETTYPE##3) \
_CLC_ISEQUAL_DECL(TYPE##4, RETTYPE##4) \
_CLC_ISEQUAL_DECL(TYPE##8, RETTYPE##8) \
_CLC_ISEQUAL_DECL(TYPE##16, RETTYPE##16)

_CLC_ISEQUAL_DECL(float, int)
_CLC_VECTOR_ISEQUAL_DECL(float, int)

#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
_CLC_ISEQUAL_DECL(double, int)
_CLC_VECTOR_ISEQUAL_DECL(double, long)
#endif

#ifdef cl_khr_fp16
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
_CLC_ISEQUAL_DECL(half, int)
_CLC_VECTOR_ISEQUAL_DECL(half, short)
#endif

#undef _CLC_ISEQUAL_DECL
#undef _CLC_VECTOR_ISEQUAL_DECL

#endif

#endif // __CLC_RELATIONAL_CLC_ISEQUAL_H__
19 changes: 19 additions & 0 deletions libclc/clc/include/clc/relational/clc_isfinite.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __CLC_RELATIONAL_CLC_ISFINITE_H__
#define __CLC_RELATIONAL_CLC_ISFINITE_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible isfinite
#define __clc_isfinite isfinite
#else

#define __CLC_FUNCTION __clc_isfinite
#define __CLC_BODY <clc/relational/unary_decl.inc>

#include <clc/relational/floatn.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif

#endif // __CLC_RELATIONAL_CLC_ISFINITE_H__
19 changes: 19 additions & 0 deletions libclc/clc/include/clc/relational/clc_isgreater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __CLC_RELATIONAL_CLC_ISGREATER_H__
#define __CLC_RELATIONAL_CLC_ISGREATER_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible isgreater
#define __clc_isgreater isgreater
#else

#define __CLC_FUNCTION __clc_isgreater
#define __CLC_BODY <clc/relational/binary_decl.inc>

#include <clc/relational/floatn.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif

#endif // __CLC_RELATIONAL_CLC_ISGREATER_H__
19 changes: 19 additions & 0 deletions libclc/clc/include/clc/relational/clc_isgreaterequal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __CLC_RELATIONAL_CLC_ISGREATEREQUAL_H__
#define __CLC_RELATIONAL_CLC_ISGREATEREQUAL_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible isgreaterequal
#define __clc_isgreaterequal isgreaterequal
#else

#define __CLC_FUNCTION __clc_isgreaterequal
#define __CLC_BODY <clc/relational/binary_decl.inc>

#include <clc/relational/floatn.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif

#endif // __CLC_RELATIONAL_CLC_ISGREATEREQUAL_H__
41 changes: 41 additions & 0 deletions libclc/clc/include/clc/relational/clc_isinf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef __CLC_RELATIONAL_CLC_ISINF_H__
#define __CLC_RELATIONAL_CLC_ISINF_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible isinf
#define __clc_isinf isinf
#else

#include <clc/clcfunc.h>

#define _CLC_ISINF_DECL(RET_TYPE, ARG_TYPE) \
_CLC_OVERLOAD _CLC_DECL RET_TYPE __clc_isinf(ARG_TYPE);

#define _CLC_VECTOR_ISINF_DECL(RET_TYPE, ARG_TYPE) \
_CLC_ISINF_DECL(RET_TYPE##2, ARG_TYPE##2) \
_CLC_ISINF_DECL(RET_TYPE##3, ARG_TYPE##3) \
_CLC_ISINF_DECL(RET_TYPE##4, ARG_TYPE##4) \
_CLC_ISINF_DECL(RET_TYPE##8, ARG_TYPE##8) \
_CLC_ISINF_DECL(RET_TYPE##16, ARG_TYPE##16)

_CLC_ISINF_DECL(int, float)
_CLC_VECTOR_ISINF_DECL(int, float)

#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
_CLC_ISINF_DECL(int, double)
_CLC_VECTOR_ISINF_DECL(long, double)
#endif

#ifdef cl_khr_fp16
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
_CLC_ISINF_DECL(int, half)
_CLC_VECTOR_ISINF_DECL(short, half)
#endif

#undef _CLC_ISINF_DECL
#undef _CLC_VECTOR_ISINF_DECL

#endif

#endif // __CLC_RELATIONAL_CLC_ISINF_H__
19 changes: 19 additions & 0 deletions libclc/clc/include/clc/relational/clc_isless.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __CLC_RELATIONAL_CLC_ISLESS_H__
#define __CLC_RELATIONAL_CLC_ISLESS_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible isless
#define __clc_isless isless
#else

#define __CLC_FUNCTION __clc_isless
#define __CLC_BODY <clc/relational/binary_decl.inc>

#include <clc/relational/floatn.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif

#endif // __CLC_RELATIONAL_CLC_ISLESS_H__
Loading

0 comments on commit 97ace17

Please sign in to comment.