gallivm: fix incorrect floor(), itrunc()
authorBrian Paul <brianp@vmware.com>
Mon, 15 Mar 2010 16:29:04 +0000 (10:29 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 15 Mar 2010 16:29:10 +0000 (10:29 -0600)
LLVMBuildFPTrunc() should be used for double->float conversion, not
float->int conversion.

There should be a better way to compute floor(), ceil(), etc that doesn't
involve float->int->float conversion.

src/gallium/auxiliary/gallivm/lp_bld_arit.c

index aa47338b323f842f407e532d697301b54bed0f6f..c39b062d10ea0898363f2b7a1a7bf317ed02c96e 100644 (file)
@@ -930,7 +930,10 @@ lp_build_floor(struct lp_build_context *bld,
    assert(type.floating);
 
    if (type.length == 1) {
    assert(type.floating);
 
    if (type.length == 1) {
-      return LLVMBuildFPTrunc(bld->builder, a, LLVMFloatType(), "");
+      LLVMValueRef res;
+      res = lp_build_ifloor(bld, a);
+      res = LLVMBuildSIToFP(bld->builder, res, LLVMFloatType(), "");
+      return res;
    }
 
    if(util_cpu_caps.has_sse4_1)
    }
 
    if(util_cpu_caps.has_sse4_1)
@@ -993,7 +996,7 @@ lp_build_itrunc(struct lp_build_context *bld,
 
    if (type.length == 1) {
       LLVMTypeRef int_type = LLVMIntType(type.width);
 
    if (type.length == 1) {
       LLVMTypeRef int_type = LLVMIntType(type.width);
-      return LLVMBuildFPTrunc(bld->builder, a, int_type, "");
+      return LLVMBuildFPToSI(bld->builder, a, int_type, "");
    }
    else {
       LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
    }
    else {
       LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);