[Beignet] [PATCH 3/4] Backend: Optimization internal math, use native
grigore.lupescu at intel.com
grigore.lupescu at intel.com
Tue Jul 26 13:24:47 UTC 2016
From: Grigore Lupescu <grigore.lupescu at intel.com>
Affected functions:
log
log2
log10
exp
exp2
Signed-off-by: Grigore Lupescu <grigore.lupescu at intel.com>
---
backend/src/libocl/tmpl/ocl_math.tmpl.cl | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index 55a4fed..c8969a1 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -3491,6 +3491,10 @@ OVERLOADABLE float log(float x) {
if (__ocl_math_fastpath_flag)
return __gen_ocl_internal_fastpath_log(x);
+ /* Use native instruction when it has enough precision */
+ if((x > 0x1.1p0) || (x <= 0))
+ return __gen_ocl_internal_fastpath_log(x);
+
return __gen_ocl_internal_log(x);
}
@@ -3498,6 +3502,10 @@ OVERLOADABLE float log2(float x) {
if (__ocl_math_fastpath_flag)
return __gen_ocl_internal_fastpath_log2(x);
+ /* Use native instruction when it has enough precision */
+ if((x > 0x1.1p0) || (x <= 0))
+ return __gen_ocl_internal_fastpath_log2(x);
+
return __gen_ocl_internal_log2(x);
}
@@ -3505,6 +3513,10 @@ OVERLOADABLE float log10(float x) {
if (__ocl_math_fastpath_flag)
return __gen_ocl_internal_fastpath_log10(x);
+ /* Use native instruction when it has enough precision */
+ if((x > 0x1.1p0) || (x <= 0))
+ return __gen_ocl_internal_fastpath_log10(x);
+
return __gen_ocl_internal_log10(x);
}
@@ -3512,11 +3524,15 @@ OVERLOADABLE float exp(float x) {
if (__ocl_math_fastpath_flag)
return __gen_ocl_internal_fastpath_exp(x);
+ /* Use native instruction when it has enough precision */
+ if (x > -0x1.6p1 && x < 0x1.6p1)
+ return __gen_ocl_internal_fastpath_exp(x);
+
return __gen_ocl_internal_exp(x);
}
OVERLOADABLE float exp2(float x) {
- /* Use native/faster instruction when it has enough precision, exp2 always */
+ /* Use native instruction when it has enough precision, exp2 always */
return native_exp2(x);
}
--
2.5.0
More information about the Beignet
mailing list