[Beignet] [PATCH] fix builtin function "copysign"

Yang, Rong R rong.r.yang at intel.com
Wed Nov 6 23:00:56 PST 2013


LGTM, thanks.

-----Original Message-----
From: beignet-bounces at lists.freedesktop.org [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Homer Hsing
Sent: Thursday, November 07, 2013 2:32 PM
To: beignet at lists.freedesktop.org
Subject: [Beignet] [PATCH] fix builtin function "copysign"

using better algorithm

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 backend/src/ocl_stdlib.tmpl.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h index 3df893a..fdccf83 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1452,7 +1452,11 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_atanh(float x) {
   return 0.5f * native_sqrt((1 + x) / (1 - x));  }  INLINE_OVERLOADABLE float __gen_ocl_internal_copysign(float x, float y) {
-  return x * y < 0 ? -x : x;
+  union { unsigned u; float f; } ux, uy;  ux.f = x;  uy.f = y;  ux.u = 
+ (ux.u & 0x7fffffff) | (uy.u & 0x80000000u);  return ux.f;
 }
 INLINE_OVERLOADABLE float __gen_ocl_internal_erf(float x) {
   return M_2_SQRTPI_F * (x - __gen_ocl_pow(x, 3) / 3 + __gen_ocl_pow(x, 5) / 10 - __gen_ocl_pow(x, 7) / 42 + __gen_ocl_pow(x, 9) / 216);
--
1.8.3.2

_______________________________________________
Beignet mailing list
Beignet at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list