-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b38ec2a
commit 470a684
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 <clcmacro.h> | ||
#include <spirv/spirv.h> | ||
|
||
#define __CLC_FUNCTION __spirv_ocl_scalbln | ||
#define __CLC_BUILTIN __ocml_scalbln | ||
|
||
float __ocml_scalbln_f32(float, int); | ||
#define __CLC_BUILTIN_F __CLC_XCONCAT(__CLC_BUILTIN, _f32) | ||
|
||
#ifdef cl_khr_fp64 | ||
#pragma OPENCL EXTENSION cl_khr_fp64 : enable | ||
double __ocml_scalbln_f64(double, int); | ||
#define __CLC_BUILTIN_D __CLC_XCONCAT(__CLC_BUILTIN, _f64) | ||
#endif // cl_khr_fp64 | ||
|
||
#ifdef cl_khr_fp16 | ||
#pragma OPENCL EXTENSION cl_khr_fp16 : enable | ||
half __ocml_scalbln_f16(half, int); | ||
#define __CLC_BUILTIN_H __CLC_XCONCAT(__CLC_BUILTIN, _f16) | ||
#endif // cl_khr_fp16 | ||
|
||
#include <math/binary_builtin.inc> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#define _USE_MATH_DEFINES | ||
|
||
#include <clcmacro.h> | ||
#include <math/math.h> | ||
#include <spirv/spirv.h> | ||
|
||
int __ocml_scalbln_f64(double, int); | ||
int __ocml_scalbln_f32(float, int); | ||
|
||
//_CLC_DEFINE_BINARY_BUILTIN(int, __spirv_ocl_scalbln, __ocml_scalbln_f32, float, int) | ||
|
||
#ifdef cl_khr_fp64 | ||
#pragma OPENCL EXTENSION cl_khr_fp64 : enable | ||
|
||
_CLC_DEFINE_BINARY_BUILTIN(int, __spirv_ocl_scalbln, __ocml_scalbln_f64, double, int) | ||
#endif | ||
|
||
#ifdef cl_khr_fp16 | ||
#pragma OPENCL EXTENSION cl_khr_fp16 : enable | ||
|
||
_CLC_OVERLOAD _CLC_DEF int __spirv_ocl_scalbln(float x, int y) { | ||
union { | ||
float f; | ||
unsigned int i; | ||
} u; | ||
u.f = x; | ||
|
||
int exponent = ((u.i >> 23) & 0xFF) - 127; | ||
|
||
if (exponent == -127 && (u.i & 0x7FFFFF) == 0) { | ||
return 0; | ||
} else if (exponent == 128) { | ||
return (int)x; | ||
} | ||
|
||
exponent += y; | ||
|
||
if (exponent > 127) { | ||
return (int)(u.i & 0x80000000 ? -INFINITY : INFINITY); | ||
} else if (exponent < -126) { | ||
return 0; | ||
} | ||
|
||
u.i = (u.i & 0x807FFFFF) | ((exponent + 127) << 23); | ||
|
||
return (int)u.f; | ||
} | ||
|
||
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, int, __spirv_ocl_scalbln, float, int); | ||
#endif | ||
|
||
#undef __CLC_BUILTIN | ||
#undef __CLC_BUILTIN_F | ||
#undef __CLC_FUNCTION |