[Top][All Lists]

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

[Lightning] Shift instructions

From: Mike Spivey
Subject: [Lightning] Shift instructions
Date: Thu, 19 Feb 2009 19:10:02 +0000
User-agent: Thunderbird (X11/20090105)

Dear Paolo and all,

Attached is a program that attempts to compute (-16) << 2.  The result
should be -64, but -16 is printed on i386.

I've tried a number of combinations, but haven't quite tracked down the
problem yet:

* Use JIT_R1 instead of JIT_V0 throughout --> fixed.

* Insert jit_movi_i(JIT_R1, 3); before the shift instruction (but leave
instruction referring to JIT_V0) --> result is -128.

* Use a jit_mulr_i instruction instead of the shift --> correct result.

* Use jit_lshi_i instead of jit_lshr_i --> correct result.

So it looks like the problem concerns putting the shift amount into the
ECX register before the actual shift instruction.

I am sorry to be always the bearer of bad tidings, but there it is!  Can
anything be done?

Best wishes,

-- Mike

#include <stdio.h>
#include "lightning.h"
static jit_insn codeBuffer[1024];
typedef int (*pifi)(int);    /* Pointer to Int Function of Int */
int main()
     pifi fun = (pifi) (jit_set_ip(codeBuffer).iptr);
     int in;
     in = jit_arg_i();
     jit_getarg_i(JIT_V2, in);

     jit_movi_i(JIT_V0, 2);
     jit_lshr_i(JIT_V1, JIT_V2, JIT_V0);
     jit_movr_i(JIT_RET, JIT_V1);
     jit_flush_code(codeBuffer, jit_get_ip().ptr);
     printf("fun(-16) = %d\n", fun(-16));
     return 0;

reply via email to

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