[Mesa-dev] [PATCH 1/2] gallivm: Fix lp_build_print_value of small integers

Brian Paul brianp at vmware.com
Thu Dec 6 06:56:50 PST 2012


OK, by "small integers" you mean 8 and 16-bit ints.  At first I 
thought you meant 1, 2, 3, etc.


On 12/06/2012 06:20 AM, jfonseca at vmware.com wrote:
> From: José Fonseca<jfonseca at vmware.com>
>
> They need to be converted to native integers to prevent garbagge in

"garbage"


> higher order bits from being printed.
> ---
>   src/gallium/auxiliary/gallivm/lp_bld_printf.c |   13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
> index 0de6a08..7a6bbd9 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
> @@ -125,8 +125,19 @@ lp_build_print_value(struct gallivm_state *gallivm,
>         params[2] = value;
>      } else {
>         for (i = 0; i<  length; ++i) {
> +         LLVMValueRef param;
>            util_strncat(format, type_fmt, sizeof(format) - strlen(format) - 1);
> -         params[2 + i] = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
> +         param = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
> +         if (type_kind == LLVMIntegerTypeKind&&
> +             LLVMGetIntTypeWidth(type_ref)<  sizeof(int) * 8) {
> +            LLVMTypeRef int_type = LLVMIntTypeInContext(gallivm->context, sizeof(int) * 8);
> +            if (LLVMGetIntTypeWidth(type_ref) == 8) {

                   /* print 8-bit ints as unsigned */

> +               param = LLVMBuildZExt(builder, param, int_type, "");
> +            } else {

                   /* print 16-bit ints as signed */

> +               param = LLVMBuildSExt(builder, param, int_type, "");
> +            }
> +         }
> +         params[2 + i] = param;
>         }
>      }
>

Looks good otherwise.  Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list