The general algorithm is that reducing the x to area [-0.5,0.5] then calculate results.
Signed-off-by: Yi Sun <yi....@intel.com> diff --git a/utests/utest_math_gen.py b/utests/utest_math_gen.py index 20ae3f1..9ea495f 100755 --- a/utests/utest_math_gen.py +++ b/utests/utest_math_gen.py @@ -470,8 +470,41 @@ static float rsqrt(float x) sinpi_input_type = ['float','float2','float4','float8','float16'] sinpi_output_type = ['float','float2','float4','float8','float16'] sinpi_cpu_func=''' +static float reduce1( float x ) +{ + SF fx, fy; + fx.f = fy.f = x; + int n; + + fy.spliter.exponent = fx.spliter.exponent - 1; + n = (int)fy.f; + + fx.f = fx.f - 2.0 * n; + + return fx.f; +} + static float sinpi(float x){ - return sin(M_PI*x); + float r = 0.0; + if ( x > 1 || x < -1) r = reduce1(x); + + // reduce to [-0.5, 0.5] + if(r < -0.5) + r = -1 - r; + else if (r > 0.5) + r = 1 - r; + + if (r > 0.25 && r <= 0.5) + return cos(r * M_PI); + else if (r >= 0 && r <= 0.25) + return sin(r * M_PI); + else if (r >= -0.25 && r < 0) + return -sin(r * -M_PI); + else if (r >= -0.5 && r < -0.25) + return -cos(r * -M_PI); + + // Error return + return 0xffffffff; } ''' sinpiUtests = func('sinpi','sinpi',[sinpi_input_type],sinpi_output_type,[sinpi_input_values],'4 * FLT_ULP',sinpi_cpu_func) -- 1.8.5.3 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet