[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Lightning] Subtract with borrow
From: |
Mike Spivey |
Subject: |
Re: [Lightning] Subtract with borrow |
Date: |
Wed, 05 Aug 2009 07:47:23 +0100 |
FWIW, here's a test case to verify the bug. It prints -3 (wring) and
not 3 (correct).
I'm not using Lightning except as a quarry for useful bits of code, so I
won't suggest a fix.
"Bad" is a relative term here, and a register allocator can avoid most
of the bad cases in most instructions by making rd = rs1 wherever
possible.
-- Mike
#include <stdio.h>
#include "lightning.h"
static jit_insn codeBuffer[1024];
typedef int (*pifi)(int, int);
int main()
{
pifi subr = (pifi) (jit_set_ip(codeBuffer).iptr);
int in1, in2;
jit_leaf(2);
in1 = jit_arg_i();
in2 = jit_arg_i();
jit_getarg_i(JIT_R0, in1);
jit_getarg_i(JIT_R1, in2);
jit_subcr_i(JIT_R2, JIT_R2, JIT_R2); /* Clear carry */
jit_subxr_i(JIT_R1, JIT_R0, JIT_R1);
jit_movr_i(JIT_RET, JIT_R1);
jit_ret();
jit_flush_code(codeBuffer, jit_get_ip().ptr);
/* call the generated code, passing 5 as an argument */
printf("result = %d\n", subr(5, 2));
return 0;
}
On Wed, 2009-08-05 at 01:10 +0200, Paolo Bonzini wrote:
> On 08/04/2009 07:19 PM, Mike Spivey wrote:
> > The i386 implementation in GIT contains the definition for
> > subtract-with-carry:
> >
> > #define jit_subxr_i(d, s1, s2) \
> > jit_opr_((d), (s1), (s2), SBBLrr((s1), (d)), SBBLrr((s2), (d)) )
> >
> > Please forgive my not compiling a test, but doesn't this treat
> > subtraction as if it is commutative? Correct code for the case where
> > s1 != d but s2 = d will be embarrassingly bad, but (if I'm right about
> > the error) bad code is better than wrong code, always!
>
> I think you're right... :-(
>
> (The code wouldn't be so bad, it just needs some push/pops).
>
> Paolo