[Beignet] [Patch for Release_v0.9.x 2/6] GBE: fix bug in pow/pown.

Zhigang Gong zhigang.gong at intel.com
Tue Nov 4 21:14:41 PST 2014


pow/pown ignore the sign of their first argument (e.g. pow(-2,3) gives
8 instead of -8)

This patch is from:
https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=Fix-pow-erf-tgamma.patch;att=3;bug=768090

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/builtin_vector_proto.def |  3 +--
 backend/src/ocl_stdlib.tmpl.h        | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/backend/src/builtin_vector_proto.def b/backend/src/builtin_vector_proto.def
index 18d23ca..811ab6c 100644
--- a/backend/src/builtin_vector_proto.def
+++ b/backend/src/builtin_vector_proto.def
@@ -94,8 +94,7 @@ floatn pown (floatn x, intn y)
 float pown (float x, int y)
 doublen pown (doublen x, intn y)
 double pown (double x, int y)
-#XXX we define powr as pow
-#gentype powr (gentype x, gentype y)
+gentype powr (gentype x, gentype y)
 gentype remainder (gentype x, gentype y)
 floatn remquo (floatn x, floatn y, __global intn *quo)
 floatn remquo (floatn x, floatn y, __local intn *quo)
diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h
index f648a8c..d6900ee 100755
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -3190,7 +3190,6 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_exp10(float x){
 #define atan2pi __gen_ocl_internal_atan2pi
 #define atanpi __gen_ocl_internal_atanpi
 #define atanh __gen_ocl_internal_atanh
-#define pow powr
 #define cbrt __gen_ocl_internal_cbrt
 #define rint __gen_ocl_internal_rint
 #define copysign __gen_ocl_internal_copysign
@@ -3729,11 +3728,25 @@ INLINE_OVERLOADABLE float remquo(float x, float y, private int *quo) { BODY; }
 #undef BODY
 INLINE_OVERLOADABLE float native_divide(float x, float y) { return x/y; }
 INLINE_OVERLOADABLE float pown(float x, int n) {
-  if (x == 0 && n == 0)
-    return 1;
+  if (x == 0.f && n == 0)
+    return 1.f;
+  if (x < 0.f && (n&1) )
+    return -powr(-x, n);
   return powr(x, n);
 }
 
+INLINE_OVERLOADABLE float pow(float x, float y) {
+  int n;
+  if (x == 0.f && y == 0.f)
+    return 1.f;
+  if (x >= 0.f)
+    return powr(x, y);
+  n = y;
+  if ((float)n == y)//is exact integer
+    return pown(x, n);
+  return NAN;
+}
+
 INLINE_OVERLOADABLE float internal_rootn(float x, int n, const bool isFastpath)
 {
   float ax,re;
-- 
1.8.3.2



More information about the Beignet mailing list