Add long support for printf
authorJunyan He <junyan.he@linux.intel.com>
Thu, 18 Sep 2014 04:39:15 +0000 (12:39 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Thu, 18 Sep 2014 04:24:40 +0000 (12:24 +0800)
V2:
    Replace all the long and ulong to int64_t

Signed-off-by: Junyan He <junyan.he@linux.intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
backend/src/ir/printf.cpp
backend/src/llvm/llvm_printf_parser.cpp
kernels/test_printf.cl

index 9d60402..e99aad5 100644 (file)
@@ -149,20 +149,35 @@ namespace gbe
                     switch (slot.state->conversion_specifier) {
                       case PRINTF_CONVERSION_D:
                       case PRINTF_CONVERSION_I:
-                        PRINT_SOMETHING(int, d);
+                        if (slot.state->length_modifier == PRINTF_LM_L)
+                          PRINT_SOMETHING(uint64_t, d);
+                        else
+                          PRINT_SOMETHING(int, d);
                         break;
 
                       case PRINTF_CONVERSION_O:
-                        PRINT_SOMETHING(int, o);
+                        if (slot.state->length_modifier == PRINTF_LM_L)
+                          PRINT_SOMETHING(uint64_t, o);
+                        else
+                          PRINT_SOMETHING(int, o);
                         break;
                       case PRINTF_CONVERSION_U:
-                        PRINT_SOMETHING(int, u);
+                        if (slot.state->length_modifier == PRINTF_LM_L)
+                          PRINT_SOMETHING(uint64_t, u);
+                        else
+                          PRINT_SOMETHING(int, u);
                         break;
                       case PRINTF_CONVERSION_X:
-                        PRINT_SOMETHING(int, X);
+                        if (slot.state->length_modifier == PRINTF_LM_L)
+                          PRINT_SOMETHING(uint64_t, X);
+                        else
+                          PRINT_SOMETHING(int, X);
                         break;
                       case PRINTF_CONVERSION_x:
-                        PRINT_SOMETHING(int, x);
+                        if (slot.state->length_modifier == PRINTF_LM_L)
+                          PRINT_SOMETHING(uint64_t, x);
+                        else
+                          PRINT_SOMETHING(int, x);
                         break;
 
                       case PRINTF_CONVERSION_C:
index 00e1ef8..29684ba 100644 (file)
@@ -640,14 +640,22 @@ error:
           case PRINTF_CONVERSION_U:
           case PRINTF_CONVERSION_x:
           case PRINTF_CONVERSION_X:
-            /* If the bits change, we need to consider the signed. */
-            if (arg->getType() != Type::getInt32Ty(module->getContext())) {
-              arg = builder->CreateIntCast(arg, Type::getInt32Ty(module->getContext()), sign);
-            }
+            if (slot.state->length_modifier == PRINTF_LM_L) { /* we would rather print long. */
+              if (arg->getType() != Type::getInt64Ty(module->getContext())) {
+                arg = builder->CreateIntCast(arg, Type::getInt64Ty(module->getContext()), sign);
+              }
+              dst_type = Type::getInt64PtrTy(module->getContext(), 1);
+              sizeof_size = sizeof(int64_t);
+            } else {
+              /* If the bits change, we need to consider the signed. */
+              if (arg->getType() != Type::getInt32Ty(module->getContext())) {
+                arg = builder->CreateIntCast(arg, Type::getInt32Ty(module->getContext()), sign);
+              }
 
-            /* Int to Int, just store. */
-            dst_type = Type::getInt32PtrTy(module->getContext(), 1);
-            sizeof_size = sizeof(int);
+              /* Int to Int, just store. */
+              dst_type = Type::getInt32PtrTy(module->getContext(), 1);
+              sizeof_size = sizeof(int);
+            }
             return true;
 
           case PRINTF_CONVERSION_C:
index 84bb478..c2844f4 100644 (file)
@@ -7,6 +7,7 @@ test_printf(void)
   uint a = 'x';
   float f = 5.0f;
   int3 vec;
+  ulong cc = 1004294967296;
   vec.x = x;
   vec.y = y;
   vec.z = z;
@@ -15,6 +16,8 @@ test_printf(void)
     printf("--- Welcome to the printf test of %s ---\n", "Intel Beignet");
 
     printf("### output a char is %c\n", a);
+
+    printf("@@@ A long value is %ld\n", cc);
   }
 
   if (x % 15 == 0)