libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libjit] Why jit_value_create_nint_constant() does not truncate the


From: Peng Yu
Subject: Re: [Libjit] Why jit_value_create_nint_constant() does not truncate the data if the data is larger than the type can hold?
Date: Thu, 21 Feb 2019 10:09:24 -0600

On 2/21/19, Aleksey Demakov <address@hidden> wrote:
> The specified type has effect on code generation. When you start using the
> constant you created with some instructions then depending on the type
> libjit will use different opcodes.

If I do this, I still see the number is not truncated. Only when
change the return type `jit_type_int` to  `jit_type_ubyte` the result
is truncated to 160. But again, the truncation is not done at the
creation of the constant creation. I don't understand why this
behavior is correct. I'd expect the truncation is at the constant
creation. Otherwise, it seems to have no reason of specifying the
type.

#include <stdio.h>
#include <jit/jit.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  jit_context_t context = jit_context_create();
  jit_context_build_start(context);

  jit_type_t signature = jit_type_create_signature(jit_abi_cdecl,
jit_type_int, NULL, 0, 1);

  jit_function_t F = jit_function_create(context, signature);
  jit_type_free(signature);

  jit_value_t temp = jit_value_create_nint_constant(F, jit_type_ubyte, 100000);
  jit_insn_return(F, temp);

  jit_function_compile(F);
  jit_context_build_end(context);

  jit_int result;
  jit_function_apply(F, NULL, &result);
  printf("%d\n", (int)result);

  jit_context_destroy(context);
  return 0;
}
$ /main.exe
100000

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]