summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2014-09-18 12:39:15 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-09-18 12:24:40 +0800
commit827eb741e1870f9325b2c590253c45ecb4e7c1d3 (patch)
tree47f6e503635d0af95062413a154173a51a36fe9f
parenteebdde1fe000fde48f3e1370619d07a1defb2d97 (diff)
Add long support for printf
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>
-rw-r--r--backend/src/ir/printf.cpp25
-rw-r--r--backend/src/llvm/llvm_printf_parser.cpp22
-rw-r--r--kernels/test_printf.cl3
3 files changed, 38 insertions, 12 deletions
diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
index 9d604021..e99aad59 100644
--- a/backend/src/ir/printf.cpp
+++ b/backend/src/ir/printf.cpp
@@ -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:
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
index 00e1ef85..29684ba9 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -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:
diff --git a/kernels/test_printf.cl b/kernels/test_printf.cl
index 84bb4785..c2844f45 100644
--- a/kernels/test_printf.cl
+++ b/kernels/test_printf.cl
@@ -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)