lightning
[Top][All Lists]
Advanced

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

[Lightning] Re: lightning and i386


From: Paolo Bonzini
Subject: [Lightning] Re: lightning and i386
Date: Mon, 13 Aug 2007 09:58:57 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

Paolo Bonzini wrote:
The sete line's causing the problem I'm seeing (I don't know if that's responsible for all the incorrect results, but returning the equality of two numbers is something many paths in my bytecode take.) It's also present in 1.2c amd64.

I can fix this soon.

Well, I could, but I cannot reproduce the bug.  I get "sete %bl" correctly.

The attached patch adds a testcase for sete. You could try it and see if it fails. (It also improves slightly the encoding of boolean operations, saving 3 bytes).

Paolo
* looking for address@hidden/lightning--stable--1.2--patch-55 to compare with
* comparing to address@hidden/lightning--stable--1.2--patch-55
A  tests/sete.c
A  tests/sete.ok
M  tests/Makefile.in
M  lightning/i386/core-64.h
M  tests/Makefile.am
M  lightning/i386/core-i386.h

* modified files

--- orig/lightning/i386/core-64.h
+++ mod/lightning/i386/core-64.h
@@ -84,7 +84,7 @@ struct jit_local_state {
 
 #define jit_bra_l(rs, is, op) (_s32P((long)(is)) \
                                ? _jit_bra_l(rs, is, op) \
-                               : (jit_movi_l(JIT_REXTMP, is), 
jit_bra_qr(JIT_REXTMP, rs, op)))
+                               : (MOVQir(is, JIT_REXTMP), 
jit_bra_qr(JIT_REXTMP, rs, op)))
 
 /* When CMP with 0 can be replaced with TEST */
 #define jit_bra_l0(rs, is, op, op0)                                    \


--- orig/lightning/i386/core-i386.h
+++ mod/lightning/i386/core-i386.h
@@ -69,22 +69,22 @@
         (rs == forced) ? op : (jit_pushr_i(forced), MOVLrr(rs, forced), op, 
jit_popr_i(forced)))
 
 /* For LT, LE, ... */
-#define jit_replace8(d, op)                                            \
+#define jit_replace8(d, cmp, op)                                       \
        (jit_check8(d)                                                  \
-         ? (MOVLir(0, d), op(d))                                       \
-         : (jit_pushr_i(_EAX), MOVLir(0, _EAX), op(_EAX), MOVLrr(_EAX, (d)), 
jit_popr_i(_EAX)))
+         ? (XORLrr(d, d), (cmp), op(_rN(d) | _AL))                             
\
+         : (jit_pushr_i(_EAX), XORLrr(_EAX, _EAX), (cmp), op(_AL), 
MOVLrr(_EAX, (d)), jit_popr_i(_EAX)))
 
 #define jit_bool_r(d, s1, s2, op)                                      \
-       (CMPLrr(s2, s1), jit_replace8(d, op))
+       (jit_replace8(d, CMPLrr(s2, s1), op))
 
 #define jit_bool_i(d, rs, is, op)                                      \
-       (CMPLir(is, rs), jit_replace8(d, op))
+       (jit_replace8(d, CMPLir(is, rs), op))
 
 /* When CMP with 0 can be replaced with TEST */
 #define jit_bool_i0(d, rs, is, op, op0)                                        
\
        ((is) != 0                                                      \
-         ? (CMPLir(is, rs), jit_replace8(d, op))                       \
-         : (TESTLrr(rs, rs), jit_replace8(d, op0)))
+         ? (jit_replace8(d, CMPLir(is, rs), op))                       \
+         : (jit_replace8(d, TESTLrr(rs, rs), op0)))
 
 /* For BLT, BLE, ... */
 #define jit_bra_r(s1, s2, op)          (CMPLrr(s2, s1), op, _jit.x.pc)


--- orig/tests/Makefile.am
+++ mod/tests/Makefile.am
@@ -2,12 +2,12 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(top_
 
 check_PROGRAMS = fibit incr printf printf2 rpn fib fibdelay    \
        add bp testfp funcfp rpnfp modi ldxi divi movi ret      \
-       allocai push-pop
+       allocai push-pop sete
 
 noinst_DATA = fibit.ok incr.ok printf.ok printf2.ok rpn.ok     \
        fib.ok fibdelay.ok testfp.ok funcfp.ok rpnfp.ok add.ok  \
        bp.ok modi.ok ldxi.ok divi.ok movi.ok ret.ok            \
-       allocai.ok push-pop.ok
+       allocai.ok push-pop.ok sete.ok
 
 EXTRA_DIST = $(noinst_DATA) run-test
 


--- orig/tests/Makefile.in
+++ mod/tests/Makefile.in
@@ -41,7 +41,8 @@ check_PROGRAMS = fibit$(EXEEXT) incr$(EX
        printf2$(EXEEXT) rpn$(EXEEXT) fib$(EXEEXT) fibdelay$(EXEEXT) \
        add$(EXEEXT) bp$(EXEEXT) testfp$(EXEEXT) funcfp$(EXEEXT) \
        rpnfp$(EXEEXT) modi$(EXEEXT) ldxi$(EXEEXT) divi$(EXEEXT) \
-       movi$(EXEEXT) ret$(EXEEXT) allocai$(EXEEXT) push-pop$(EXEEXT)
+       movi$(EXEEXT) ret$(EXEEXT) allocai$(EXEEXT) push-pop$(EXEEXT) \
+       sete$(EXEEXT)
 subdir = tests
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -128,6 +129,10 @@ rpnfp_SOURCES = rpnfp.c
 rpnfp_OBJECTS = rpnfp.$(OBJEXT)
 rpnfp_LDADD = $(LDADD)
 @address@hidden = $(top_builddir)/opcode/libdisass.a
+sete_SOURCES = sete.c
+sete_OBJECTS = sete.$(OBJEXT)
+sete_LDADD = $(LDADD)
address@hidden@sete_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a
 testfp_SOURCES = testfp.c
 testfp_OBJECTS = testfp.$(OBJEXT)
 testfp_LDADD = $(LDADD)
@@ -141,10 +146,10 @@ CCLD = $(CC)
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = add.c allocai.c bp.c divi.c fib.c fibdelay.c fibit.c \
        funcfp.c incr.c ldxi.c modi.c movi.c printf.c printf2.c \
-       push-pop.c ret.c rpn.c rpnfp.c testfp.c
+       push-pop.c ret.c rpn.c rpnfp.c sete.c testfp.c
 DIST_SOURCES = add.c allocai.c bp.c divi.c fib.c fibdelay.c fibit.c \
        funcfp.c incr.c ldxi.c modi.c movi.c printf.c printf2.c \
-       push-pop.c ret.c rpn.c rpnfp.c testfp.c
+       push-pop.c ret.c rpn.c rpnfp.c sete.c testfp.c
 DATA = $(noinst_DATA)
 ETAGS = etags
 CTAGS = ctags
@@ -253,7 +258,7 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(top_
 noinst_DATA = fibit.ok incr.ok printf.ok printf2.ok rpn.ok     \
        fib.ok fibdelay.ok testfp.ok funcfp.ok rpnfp.ok add.ok  \
        bp.ok modi.ok ldxi.ok divi.ok movi.ok ret.ok            \
-       allocai.ok push-pop.ok
+       allocai.ok push-pop.ok sete.ok
 
 EXTRA_DIST = $(noinst_DATA) run-test
 @address@hidden = $(top_builddir)/opcode/libdisass.a
@@ -352,6 +357,9 @@ rpn$(EXEEXT): $(rpn_OBJECTS) $(rpn_DEPEN
 rpnfp$(EXEEXT): $(rpnfp_OBJECTS) $(rpnfp_DEPENDENCIES) 
        @rm -f rpnfp$(EXEEXT)
        $(LINK) $(rpnfp_LDFLAGS) $(rpnfp_OBJECTS) $(rpnfp_LDADD) $(LIBS)
+sete$(EXEEXT): $(sete_OBJECTS) $(sete_DEPENDENCIES) 
+       @rm -f sete$(EXEEXT)
+       $(LINK) $(sete_LDFLAGS) $(sete_OBJECTS) $(sete_LDADD) $(LIBS)
 testfp$(EXEEXT): $(testfp_OBJECTS) $(testfp_DEPENDENCIES) 
        @rm -f testfp$(EXEEXT)
        $(LINK) $(testfp_LDFLAGS) $(testfp_OBJECTS) $(testfp_LDADD) $(LIBS)
@@ -380,6 +388,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 
 .c.o:



* added files

--- /dev/null
+++ mod/tests/sete.c
@@ -0,0 +1,67 @@
+/******************************** -*- C -*- ****************************
+ *
+ *     Sample call for using arguments in GNU lightning
+ *
+ ***********************************************************************/
+
+
+/***********************************************************************
+ *
+ * Copyright 2000 Free Software Foundation, Inc.
+ * Written by Paolo Bonzini.
+ *
+ * This file is part of GNU lightning.
+ *
+ * GNU lightning is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU lightning is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with GNU lightning; see the file COPYING.LESSER; if not, write to the
+ * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ ***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include "lightning.h"
+
+static char codeBuffer[1024];
+
+typedef int (*pifii)(int, int);        /* Pointer to Int Function of Int, Int 
*/
+
+int main()
+{
+  pifii myFunction= (pifii) (jit_set_ip(codeBuffer).iptr);
+  int  arg;                            /* offset of the argument */
+
+  jit_leaf(2);
+  arg = jit_arg_i();
+  jit_getarg_i(JIT_R0, arg);
+  arg = jit_arg_i();
+  jit_getarg_i(JIT_R1, arg);
+  jit_eqr_i(JIT_V0, JIT_R0, JIT_R1);
+  jit_movr_i(JIT_RET, JIT_V0);
+  jit_ret(); 
+  jit_flush_code(codeBuffer, jit_get_ip().ptr);
+
+  /* call the generated code, passing its size as argument */
+#ifdef LIGHTNING_DISASSEMBLE
+  disassemble(stderr, codeBuffer, jit_get_ip().ptr);
+#endif
+#ifndef LIGHTNING_CROSS
+  printf("%d == %d? %s\n", 5, 4, myFunction(5, 4) ? "yes" : "no");
+  printf("%d == %d? %s\n", 5, 5, myFunction(5, 5) ? "yes" : "no");
+#endif
+  return 0;
+}
--- /dev/null
+++ mod/tests/sete.ok
@@ -0,0 +1,2 @@
+5 == 4? no
+5 == 5? yes


reply via email to

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