diff --git a/ChangeLog b/ChangeLog index ed0427aa4..63ea188f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-01-02 Paolo Bonzini + + * lightning/i386/fp-32.h: Fix sub(a,b,a) with a ~= JIT_FPR0. + * lightning/tests/3to2.c: New. + * lightning/tests/3to2.ok: New. + 2007-11-07 Paolo Bonzini * opcode/Makefile.am: Fix AM_CPPFLAGS. diff --git a/lightning/i386/fp-32.h b/lightning/i386/fp-32.h index 7f2a44173..362c95510 100644 --- a/lightning/i386/fp-32.h +++ b/lightning/i386/fp-32.h @@ -63,7 +63,7 @@ ((s2) == 0 ? opr(0, (rd)) \ : (s2) == (s1) ? jit_fxch((rd), op(0, 0)) \ : jit_fxch((rd), op((s2), 0))) \ - : (rd) == (s2) ? jit_fxch((s2), opr((rd) == 0 ? (s1) : (rd), 0)) \ + : (rd) == (s2) ? jit_fxch((s2), opr((s1), 0)) \ : (FLDr (s1), op((s2)+1, 0), FSTPr((rd)+1))) #define jit_addr_d(rd,s1,s2) jit_fp_binary((rd),(s1),(s2),FADDrr,FADDrr) diff --git a/opcode/Makefile.in b/opcode/Makefile.in index 722a6e30a..5110633e4 100644 --- a/opcode/Makefile.in +++ b/opcode/Makefile.in @@ -173,7 +173,7 @@ target_os = @target_os@ target_vendor = @target_vendor@ EXTRA_LIBRARIES = libdisass.a noinst_LIBRARIES = @LIBDISASS@ -AM_CPPFLAGS = -I$(top_srcdir) +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lightning/$(cpu) libdisass_a_SOURCES = dis-buf.c i386-dis.c ppc-dis.c ppc-opc.c sparc-dis.c \ sparc-opc.c disass.c diff --git a/tests/3to2.c b/tests/3to2.c new file mode 100644 index 000000000..b829d8492 --- /dev/null +++ b/tests/3to2.c @@ -0,0 +1,135 @@ +/******************************** -*- C -*- **************************** + * + * Test ternary->binary op conversion + * + ***********************************************************************/ + + +/*********************************************************************** + * + * Copyright 2008 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 +#include +#include "lightning.h" + +#ifdef JIT_FPR +static jit_insn codeBuffer[1024]; + +double +test_double (int a, int b, int c) +{ + double x; + int ofs; + + jit_set_ip (codeBuffer); + jit_leaf (2); + ofs = jit_arg_d (); + jit_getarg_d (b, ofs); + ofs = jit_arg_d (); + jit_getarg_d (c, ofs); + jit_subr_d (a,b,c); + jit_movr_d (JIT_FPRET, a); + jit_ret (); + + jit_flush_code ((char *) codeBuffer, jit_get_ip ().ptr); + +#ifdef LIGHTNING_DISASSEMBLE + disassemble (stderr, (char *) codeBuffer, jit_get_ip ().ptr); +#endif + +#ifndef LIGHTNING_CROSS + x = ((double (*) (double, double)) codeBuffer) (3.0, 2.0); + printf ("%g %g\n", ((b == c) ? 0.0 : 1.0), x); +#endif + + return x; +} + +double +test_int (int a, int b, int c) +{ + int x; + int ofs; + + jit_set_ip (codeBuffer); + jit_leaf (2); + ofs = jit_arg_i (); + jit_getarg_i (b, ofs); + ofs = jit_arg_i (); + jit_getarg_i (c, ofs); + jit_subr_i (a,b,c); + jit_movr_i (JIT_RET, a); + jit_ret (); + + jit_flush_code ((char *) codeBuffer, jit_get_ip ().ptr); + +#ifdef LIGHTNING_DISASSEMBLE + disassemble (stderr, (char *) codeBuffer, jit_get_ip ().ptr); +#endif + +#ifndef LIGHTNING_CROSS + x = ((int (*) (int, int)) codeBuffer) (3, 2); + printf ("%d %d\n", ((b == c) ? 0 : 1), x); +#endif + + return x; +} + +int +main () +{ + test_double (JIT_FPR0, JIT_FPR0, JIT_FPR0); + test_double (JIT_FPR0, JIT_FPR0, JIT_FPR1); + test_double (JIT_FPR0, JIT_FPR1, JIT_FPR0); + test_double (JIT_FPR0, JIT_FPR1, JIT_FPR2); + + test_double (JIT_FPR3, JIT_FPR3, JIT_FPR3); + test_double (JIT_FPR3, JIT_FPR3, JIT_FPR1); + test_double (JIT_FPR3, JIT_FPR1, JIT_FPR3); + test_double (JIT_FPR3, JIT_FPR1, JIT_FPR2); + + test_int (JIT_R0, JIT_R0, JIT_R0); + test_int (JIT_R0, JIT_R0, JIT_R1); + test_int (JIT_R0, JIT_R1, JIT_R0); + test_int (JIT_R0, JIT_R1, JIT_R2); + + test_int (JIT_V0, JIT_V0, JIT_V0); + test_int (JIT_V0, JIT_V0, JIT_R1); + test_int (JIT_V0, JIT_R1, JIT_V0); + test_int (JIT_V0, JIT_R1, JIT_R2); + + return 0; +} +#else +int +main() +{ + return (77); +} +#endif diff --git a/tests/3to2.ok b/tests/3to2.ok new file mode 100644 index 000000000..8eec0b665 --- /dev/null +++ b/tests/3to2.ok @@ -0,0 +1,16 @@ +0 0 +1 1 +1 1 +1 1 +0 0 +1 1 +1 1 +1 1 +0 0 +1 1 +1 1 +1 1 +0 0 +1 1 +1 1 +1 1 diff --git a/tests/Makefile.am b/tests/Makefile.am index 47cf1db17..0df0a039c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,12 +2,12 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/lightning/$(cpu) check_PROGRAMS = fibit incr printf printf2 rpn fib fibdelay \ add bp testfp funcfp rpnfp modi ldxi divi movi ret \ - allocai push-pop sete + allocai push-pop sete 3to2 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 sete.ok + allocai.ok push-pop.ok sete.ok 3to2.ok EXTRA_DIST = $(noinst_DATA) run-test @@ -18,7 +18,7 @@ endif if REGRESSION_TESTING TESTS = fib fibit fibdelay incr printf printf2 rpn add bp \ testfp funcfp rpnfp modi ldxi divi movi ret allocai \ - push-pop sete + push-pop sete 3to2 TESTS_ENVIRONMENT=$(srcdir)/run-test endif diff --git a/tests/Makefile.in b/tests/Makefile.in index 846766bc3..a8f04f165 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -42,7 +42,7 @@ check_PROGRAMS = fibit$(EXEEXT) incr$(EXEEXT) printf$(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) \ - sete$(EXEEXT) + sete$(EXEEXT) 3to2$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -53,6 +53,10 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = +3to2_SOURCES = 3to2.c +3to2_OBJECTS = 3to2.$(OBJEXT) +3to2_LDADD = $(LDADD) +@DISASS_TRUE@3to2_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a add_SOURCES = add.c add_OBJECTS = add.$(OBJEXT) add_LDADD = $(LDADD) @@ -144,12 +148,12 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) 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 sete.c testfp.c -DIST_SOURCES = add.c allocai.c bp.c divi.c fib.c fibdelay.c fibit.c \ +SOURCES = 3to2.c 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 sete.c testfp.c +DIST_SOURCES = 3to2.c 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 sete.c testfp.c DATA = $(noinst_DATA) ETAGS = etags CTAGS = ctags @@ -258,13 +262,13 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) -I$(top_srcdir)/lightning/$(cpu) 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 sete.ok + allocai.ok push-pop.ok sete.ok 3to2.ok EXTRA_DIST = $(noinst_DATA) run-test @DISASS_TRUE@LDADD = $(top_builddir)/opcode/libdisass.a @REGRESSION_TESTING_TRUE@TESTS = fib fibit fibdelay incr printf printf2 rpn add bp \ @REGRESSION_TESTING_TRUE@ testfp funcfp rpnfp modi ldxi divi movi ret allocai \ -@REGRESSION_TESTING_TRUE@ push-pop sete +@REGRESSION_TESTING_TRUE@ push-pop sete 3to2 @REGRESSION_TESTING_TRUE@TESTS_ENVIRONMENT = $(srcdir)/run-test all: all-am @@ -303,6 +307,9 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps) clean-checkPROGRAMS: -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS) +3to2$(EXEEXT): $(3to2_OBJECTS) $(3to2_DEPENDENCIES) + @rm -f 3to2$(EXEEXT) + $(LINK) $(3to2_LDFLAGS) $(3to2_OBJECTS) $(3to2_LDADD) $(LIBS) add$(EXEEXT): $(add_OBJECTS) $(add_DEPENDENCIES) @rm -f add$(EXEEXT) $(LINK) $(add_LDFLAGS) $(add_OBJECTS) $(add_LDADD) $(LIBS) @@ -370,6 +377,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/3to2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/allocai.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bp.Po@am__quote@