Skip to content

Commit 428f754

Browse files
grey-eminencesys_zuul
authored andcommitted
Replace libclc cospi and sinpi implementations with svml versions
Change-Id: I786a7cf3e4e06eaf01dda09e9552712d5eb84677
1 parent 87fce2b commit 428f754

File tree

4 files changed

+153
-2
lines changed

4 files changed

+153
-2
lines changed

IGC/BiFModule/Implementation/Math/cospi.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626

2727
#include "../include/BiF_Definitions.cl"
2828
#include "../../Headers/spirv.h"
29+
#include "../SVMLReleaseOnly/svml/Math/svml_cospi.cl"
2930

3031
#include "../ExternalLibraries/libclc/trig.cl"
3132

@@ -45,7 +46,7 @@ INLINE float __builtin_spirv_OpenCL_cospi_f32( float x )
4546
}
4647
else
4748
{
48-
return libclc_cospi_f32(x);
49+
return precise_cospif(x);
4950
}
5051
}
5152

IGC/BiFModule/Implementation/Math/sinpi.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626

2727
#include "../include/BiF_Definitions.cl"
2828
#include "../../Headers/spirv.h"
29+
#include "../SVMLReleaseOnly/svml/Math/svml_sinpi.cl"
2930

3031
#include "../ExternalLibraries/libclc/trig.cl"
3132

@@ -46,7 +47,7 @@ INLINE float __builtin_spirv_OpenCL_sinpi_f32( float x )
4647
}
4748
else
4849
{
49-
return libclc_sinpi_f32(x);
50+
return precise_sinpif(x);
5051
}
5152
}
5253

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*===================== begin_copyright_notice ==================================
2+
3+
Copyright (c) 2017 Intel Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
======================= end_copyright_notice ==================================*/
26+
// SVML code
27+
/*
28+
// INTEL CORPORATION PROPRIETARY INFORMATION
29+
// This software is supplied under the terms of a license agreement or
30+
// nondisclosure agreement with Intel Corporation and may not be copied
31+
// or disclosed except in accordance with the terms of that agreement.
32+
// Copyright (C) 1996-2010 Intel Corporation. All Rights Reserved.
33+
//
34+
*/
35+
36+
static float precise_cospif( float a )
37+
{
38+
float result;
39+
40+
float sAbsX = __builtin_spirv_OpenCL_fabs_f32( a );
41+
if( sAbsX > as_float( 0x4A800000 ) ) // 2^22
42+
{
43+
float sShifter =
44+
( sAbsX < as_float( 0x4F000000 ) ) ? // 2^31
45+
as_float( 0x4FC00000 ) :
46+
0.0f;
47+
48+
a = a - (sShifter + a - sShifter);
49+
}
50+
51+
float sN = a + 0.5f + as_float( 0x4B400000 );
52+
53+
uint usN = as_uint( sN ) << 31;
54+
sN = sN - as_float( 0x4B400000 );
55+
sN = sN - 0.5f;
56+
57+
float sR = M_PI_F * (a - sN);
58+
59+
float sR2 = sR * sR;
60+
sR = as_float( as_uint( sR ) ^ usN );
61+
62+
float sP = as_float( 0x362EDEF8 );
63+
sP = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR2, as_float( 0xB94FB7FF ) );
64+
sP = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR2, as_float( 0x3C08876A ) );
65+
sP = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR2, as_float( 0xBE2AAAA6 ) );
66+
67+
sP = sP * sR2;
68+
result = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR, sR );
69+
70+
float n = __builtin_spirv_OpenCL_nan_i32(0U);
71+
result = __intel_relaxed_isinf( sAbsX ) ? n : result;
72+
73+
return result;
74+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*===================== begin_copyright_notice ==================================
2+
3+
Copyright (c) 2017 Intel Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a
6+
copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included
14+
in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
======================= end_copyright_notice ==================================*/
26+
// SVML code
27+
/*
28+
// INTEL CORPORATION PROPRIETARY INFORMATION
29+
// This software is supplied under the terms of a license agreement or
30+
// nondisclosure agreement with Intel Corporation and may not be copied
31+
// or disclosed except in accordance with the terms of that agreement.
32+
// Copyright (C) 1996-2010 Intel Corporation. All Rights Reserved.
33+
//
34+
*/
35+
36+
37+
static float precise_sinpif( float a )
38+
{
39+
float result;
40+
41+
float sAbsX = __builtin_spirv_OpenCL_fabs_f32( a );
42+
if( sAbsX > as_float( 0x4A800000 ) ) // 2^22
43+
{
44+
float sShifter =
45+
( sAbsX < as_float( 0x4F000000 ) ) ? // 2^31
46+
as_float( 0x4FC00000 ) :
47+
0.0f;
48+
49+
50+
a = a - (sShifter + a - sShifter);
51+
}
52+
53+
float sN = a + as_float( 0x4B400000 );
54+
55+
uint usN = as_uint( sN ) << 31;
56+
sN = sN - as_float( 0x4B400000 );
57+
58+
float sR = M_PI_F * (a - sN);
59+
60+
float sR2 = sR * sR;
61+
sR = as_float( as_uint( sR ) ^ usN );
62+
63+
float sP = as_float( 0x362EDEF8 );
64+
sP = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR2, as_float( 0xB94FB7FF ) );
65+
sP = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR2, as_float( 0x3C08876A ) );
66+
sP = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR2, as_float( 0xBE2AAAA6 ) );
67+
68+
sP = sP * sR2;
69+
result = __builtin_spirv_OpenCL_fma_f32_f32_f32( sP, sR, sR );
70+
71+
float n = __builtin_spirv_OpenCL_nan_i32(0U);
72+
result = __intel_relaxed_isinf( sAbsX ) ? n : result;
73+
74+
return result;
75+
}

0 commit comments

Comments
 (0)