gallivm: convert floats to doubles
authorZack Rusin <zackr@vmware.com>
Thu, 1 Apr 2010 01:30:37 +0000 (21:30 -0400)
committerZack Rusin <zackr@vmware.com>
Thu, 1 Apr 2010 01:30:37 +0000 (21:30 -0400)
printf can't handle floats, convert them to doubles so that we can
actually print floats.

src/gallium/auxiliary/gallivm/lp_bld_printf.c

index 78c9ec778b6f11948cf2ba7774a5a30a5efc506d..e4fa2c264c3f24a9dc4b32901caceff8be6a685d 100644 (file)
@@ -104,8 +104,15 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
    params[0] = LLVMBuildGEP(builder, fmtarg, index, 2, "");
 
    va_start(arglist, fmt);
-   for (i = 1; i <= argcount; i++)
-      params[i] = va_arg(arglist, LLVMValueRef);
+   for (i = 1; i <= argcount; i++) {
+      LLVMValueRef val = va_arg(arglist, LLVMValueRef);
+      LLVMTypeRef type = LLVMTypeOf(val);
+      /* printf wants doubles, so lets convert so that
+       * we can actually print them */
+      if (LLVMGetTypeKind(type) == LLVMFloatTypeKind)
+         val = LLVMBuildFPExt(builder, val, LLVMDoubleType(), "");
+      params[i] = val;
+   }
    va_end(arglist);
 
    return LLVMBuildCall(builder, func_printf, params, argcount + 1, "");