From: Junyan He Date: Thu, 18 Sep 2014 04:39:15 +0000 (+0800) Subject: Add long support for printf X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=827eb741e1870f9325b2c590253c45ecb4e7c1d3;p=contrib%2Fbeignet.git Add long support for printf V2: Replace all the long and ulong to int64_t Signed-off-by: Junyan He Reviewed-by: Zhigang Gong --- diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp index 9d60402..e99aad5 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 00e1ef8..29684ba 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 84bb478..c2844f4 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)