[Beignet] [PATCH 3/4] replace log with llvm intrinsic.

xionghu.luo at intel.com xionghu.luo at intel.com
Thu Jan 29 22:15:20 PST 2015


From: Luo Xionghu <xionghu.luo at intel.com>

translate native log to llvm.log2 for fast path.

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 backend/src/libocl/tmpl/ocl_math.tmpl.cl   | 2 +-
 backend/src/llvm/llvm_gen_backend.cpp      | 4 ++--
 backend/src/llvm/llvm_gen_ocl_function.hxx | 1 -
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/backend/src/libocl/tmpl/ocl_math.tmpl.cl b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
index fc0343c..64f702c 100644
--- a/backend/src/libocl/tmpl/ocl_math.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_math.tmpl.cl
@@ -28,7 +28,7 @@ CONST float __gen_ocl_sin(float x) __asm("llvm.sin" ".f32");
 CONST float __gen_ocl_cos(float x) __asm("llvm.cos" ".f32");
 CONST float __gen_ocl_sqrt(float x) __asm("llvm.sqrt" ".f32");
 PURE CONST float __gen_ocl_rsqrt(float x);
-PURE CONST float __gen_ocl_log(float x);
+CONST float __gen_ocl_log(float x) __asm("llvm.log2" ".f32");
 PURE CONST float __gen_ocl_exp(float x);
 PURE CONST float __gen_ocl_pow(float x, float y);
 PURE CONST float __gen_ocl_rcp(float x);
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 06a9a1b..f49a4c6 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -2801,6 +2801,7 @@ error:
           case Intrinsic::trunc:
           case Intrinsic::sin:
           case Intrinsic::cos:
+          case Intrinsic::log2:
             this->newRegister(&I);
           break;
           default:
@@ -2854,7 +2855,6 @@ error:
       case GEN_OCL_FBH:
       case GEN_OCL_FBL:
       case GEN_OCL_CBIT:
-      case GEN_OCL_LOG:
       case GEN_OCL_EXP:
       case GEN_OCL_POW:
       case GEN_OCL_RCP:
@@ -3272,6 +3272,7 @@ error:
           case Intrinsic::trunc: this->emitUnaryCallInst(I,CS,ir::OP_RNDZ); break;
           case Intrinsic::sin: this->emitUnaryCallInst(I,CS,ir::OP_SIN); break;
           case Intrinsic::cos: this->emitUnaryCallInst(I,CS,ir::OP_COS); break;
+          case Intrinsic::log2: this->emitUnaryCallInst(I,CS,ir::OP_LOG); break;
           default: NOT_IMPLEMENTED;
         }
       } else {
@@ -3340,7 +3341,6 @@ error:
             ctx.REGION(dst, src, x.getIntegerValue());
             break;
           }
-          case GEN_OCL_LOG: this->emitUnaryCallInst(I,CS,ir::OP_LOG); break;
           case GEN_OCL_EXP: this->emitUnaryCallInst(I,CS,ir::OP_EXP); break;
           case GEN_OCL_RSQ: this->emitUnaryCallInst(I,CS,ir::OP_RSQ); break;
           case GEN_OCL_RCP: this->emitUnaryCallInst(I,CS,ir::OP_RCP); break;
diff --git a/backend/src/llvm/llvm_gen_ocl_function.hxx b/backend/src/llvm/llvm_gen_ocl_function.hxx
index ae14d9f..d68cb72 100644
--- a/backend/src/llvm/llvm_gen_ocl_function.hxx
+++ b/backend/src/llvm/llvm_gen_ocl_function.hxx
@@ -21,7 +21,6 @@ DECL_LLVM_GEN_FUNCTION(GET_WORK_DIM, __gen_ocl_get_work_dim)
 // Math function
 DECL_LLVM_GEN_FUNCTION(FABS, __gen_ocl_fabs)
 DECL_LLVM_GEN_FUNCTION(RSQ, __gen_ocl_rsqrt)
-DECL_LLVM_GEN_FUNCTION(LOG, __gen_ocl_log)
 DECL_LLVM_GEN_FUNCTION(EXP, __gen_ocl_exp)
 DECL_LLVM_GEN_FUNCTION(POW, __gen_ocl_pow)
 DECL_LLVM_GEN_FUNCTION(RCP, __gen_ocl_rcp)
-- 
1.9.1



More information about the Beignet mailing list