Shift instructions

View: New views
4 Messages — Rating Filter:   Alert me  

Shift instructions

by Mike Spivey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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;
     
     jit_prolog(1);
     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_ret();
     
     jit_flush_code(codeBuffer, jit_get_ip().ptr);
     
     printf("fun(-16) = %d\n", fun(-16));
     return 0;
}


_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning

Re: Shift instructions

by Mike Spivey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I spoke five minutes too soon:

diff --git a/lightning/i386/core.h b/lightning/i386/core.h
index 86aee39..2f017f9 100644
--- a/lightning/i386/core.h
+++ b/lightning/i386/core.h
@@ -63,7 +63,7 @@
  ((rd == forced) ? JITSORRY("Register conflict for " # op) : \
  (rs == forced) ? op : \
  jit_save (forced) \
-  ? (jit_pushr_i(forced), jit_movr_l(rs, forced), op, \
+  ? (jit_pushr_i(forced), jit_movr_l(forced, rs), op, \
      jit_popr_i(forced)) \
   : (jit_movr_l(rs, forced), op))

Best wishes,

-- Mike

Mike Spivey wrote:

> 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
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Lightning mailing list
> Lightning@...
> http://lists.gnu.org/mailman/listinfo/lightning


_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning

Re: Shift instructions

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

I'll take a look.

Paolo


_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning

Re: Shift instructions

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike Spivey wrote:
> I spoke five minutes too soon:

... and I spoke five minutes too late. :-)

Thanks.

Paolo


_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning