[Beignet] [PATCH] Add long support for printf

Zhigang Gong zhigang.gong at linux.intel.com
Wed Sep 17 19:26:07 PDT 2014


Please refer the following commit and don't use ulong at the host side directly.

commit cd8604c12ba92cfd52f2b6564f316616cb3a9a62
Author: Yang Rong <rong.r.yang at intel.com>
Date:   Mon Sep 1 13:05:05 2014 +0800

    Two minor fix.

    1. Some systems don't define ulong type, use unsigned long instead of..


On Wed, Sep 17, 2014 at 11:04:04PM +0800, junyan.he at inbox.com wrote:
> From: Junyan He <junyan.he at linux.intel.com>
> 
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
>  backend/src/ir/printf.cpp               |   25 ++++++++++++++++++++-----
>  backend/src/llvm/llvm_printf_parser.cpp |   22 +++++++++++++++-------
>  kernels/test_printf.cl                  |    3 +++
>  3 files changed, 38 insertions(+), 12 deletions(-)
> 
> diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
> index 9d60402..fc7e2fe 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(long, 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(long, 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(long, 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(long, 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(long, 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..42cc878 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(ulong);
> +            } 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)
> -- 
> 1.7.9.5
> 
> 
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list