[Beignet] [PATCH] libocl: refine length() implementation.
Ruiling Song
ruiling.song at intel.com
Wed Jan 28 22:25:39 PST 2015
Just try to reduce if-branching.
And the (m<1) condition check seems no use, so I remove it.
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
backend/src/libocl/src/ocl_geometric.cl | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/backend/src/libocl/src/ocl_geometric.cl b/backend/src/libocl/src/ocl_geometric.cl
index cd09968..07f1419 100644
--- a/backend/src/libocl/src/ocl_geometric.cl
+++ b/backend/src/libocl/src/ocl_geometric.cl
@@ -38,13 +38,9 @@ OVERLOADABLE float dot(float4 p0, float4 p1) {
OVERLOADABLE float length(float x) { return __gen_ocl_fabs(x); }
#define BODY \
- if(m == 0) \
- return 0; \
- if(isinf(m)) \
- return INFINITY; \
- if(m < 1) \
- m = 1; \
- x /= m; \
+ m = m==0.0f ? 1.0f : m; \
+ m = isinf(m) ? 1.0f : m; \
+ x = x/m; \
return m * sqrt(dot(x,x));
OVERLOADABLE float length(float2 x) {
float m = max(__gen_ocl_fabs(x.s0), __gen_ocl_fabs(x.s1));
--
1.7.10.4
More information about the Beignet
mailing list