[Beignet] [PATCH 2/2] utests: Refine cases for sinpi.

Song, Ruiling ruiling.song at intel.com
Fri Mar 7 00:59:05 PST 2014


What about add more test data?
I tried -0.5, seems that it cannot get correct result, please check your algorithm.
You can try more input data like:
-0.5, 0.5, -0.49, 0.49, 0.51, -0.51, -0.1, 0.1

-----Original Message-----
From: Sun, Yi 
Sent: Wednesday, March 05, 2014 1:59 PM
To: beignet at lists.freedesktop.org
Cc: Song, Ruiling; Sun, Yi
Subject: [Beignet][PATCH 2/2] utests: Refine cases for sinpi.

The general algorithm is that reducing the x to area [-0.5,0.5] then calculate results.

Signed-off-by: Yi Sun <yi.sun at 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



More information about the Beignet mailing list