diff --git a/ChangeLog b/ChangeLog index 760acf4b4..2633f387e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-10-31 Paolo Bonzini + Ludovic Courtes + + * tests/divi.c, tests/divi.ok, tests/movi.c, tests/movi.ok: New. + * tests/ldxi.c: Ensure large pointer is generated. + * tests/Makefile.am: Point to new tests. + * lightning.h: Include funcs-common.h before funcs.h. + * lightning/sparc/core.h: Fix bugs in modi/divi. + 2006-10-30 Paolo Bonzini * lightning/Makefile.am: Use "ln -sf". diff --git a/Makefile.in b/Makefile.in index 18d2d75b2..45883fd5d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -43,7 +43,7 @@ DIST_COMMON = README $(am__configure_deps) $(dist_aclocal_DATA) \ $(include_HEADERS) $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(srcdir)/config.h.in $(srcdir)/lightningize.in \ $(top_srcdir)/configure AUTHORS COPYING COPYING.DOC \ - COPYING.LESSER ChangeLog INSTALL NEWS THANKS TODO \ + COPYING.LESSER ChangeLog INSTALL NEWS THANKS \ build-aux/config.guess build-aux/config.sub build-aux/depcomp \ build-aux/install-sh build-aux/mdate-sh build-aux/missing \ build-aux/texinfo.tex diff --git a/THANKS b/THANKS index 76715415f..72057c89a 100644 --- a/THANKS +++ b/THANKS @@ -1,8 +1,9 @@ Thanks to all the following people for their help in improving GNU lightning: -Tom Tromey -Laurent Michel Eli Barzilay -Jens Troeger +Ludovic Courtes +Laurent Michel Basile Starynkevitch +Jens Troeger +Tom Tromey diff --git a/doc/version.texi b/doc/version.texi index 25aa291bb..86b0b309e 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 21 June 2005 -@set UPDATED-MONTH June 2005 +@set UPDATED 25 October 2006 +@set UPDATED-MONTH October 2006 @set EDITION 1.2b @set VERSION 1.2b diff --git a/lightning.h b/lightning.h index 973f66721..398626c80 100644 --- a/lightning.h +++ b/lightning.h @@ -46,8 +46,8 @@ extern "C" { #include #include -#include #include +#include #include #include diff --git a/lightning/funcs-common.h b/lightning/funcs-common.h index f7976e619..dda5e4dc2 100644 --- a/lightning/funcs-common.h +++ b/lightning/funcs-common.h @@ -46,9 +46,4 @@ jit_fail(const char *msg, const char *file, int line, const char *function) } -#ifndef jit_start_pfx -#define jit_start_pfx() ( (jit_insn*)0x4) -#define jit_end_pfx() ( (jit_insn*)0x0) -#endif - #endif /* __lightning_funcs_common_h */ diff --git a/lightning/sparc/core.h b/lightning/sparc/core.h index bc1c90993..2795a4a4a 100644 --- a/lightning/sparc/core.h +++ b/lightning/sparc/core.h @@ -1,13 +1,13 @@ /******************************** -*- C -*- **************************** * - * Platform-independent layer (Sparc version) + * Platform-independent layer (SPARC version) * ***********************************************************************/ /*********************************************************************** * - * Copyright 2000, 2001, 2002 Free Software Foundation, Inc. + * Copyright 2000, 2001, 2002, 2006 Free Software Foundation, Inc. * Written by Paolo Bonzini. * * This file is part of GNU lightning. @@ -98,17 +98,17 @@ struct jit_local_state { jit_mul (JIT_BIG, JIT_BIG, s2), \ jit_subr_i (d, s1, JIT_BIG)) -#define jit_modi(jit_divi, jit_muli, jit_divr, jit_mulr, d, rs, is) \ - (_siP(13,(imm)) \ - ? (jit_divi (JIT_BIG, rs, is), \ - jit_muli (JIT_BIG, JIT_BIG, is), \ - jit_subr_i (d, rs, JIT_BIG)) \ - : (SETir ((is), JIT_BIG2), \ +#define jit_modi(jit_divi, jit_muli, jit_divr, jit_mulr, d, rs, is) \ + (_siP(13,(is)) \ + ? (jit_divi (JIT_BIG, rs, is), \ + jit_muli (JIT_BIG, JIT_BIG, is), \ + jit_subr_i (d, rs, JIT_BIG)) \ + : (SETir ((is), JIT_BIG2), \ jit_modr (jit_divr, jit_mulr, d, rs, JIT_BIG2))) /* How many instruction are needed to put imm in a register. */ #define jit_immsize(imm) (!(imm) ? 0 : \ - (!_siP((imm), 13) && ((imm) & 0x3ff) ? 2 : 1)) + (!_siP(13,(imm)) && ((imm) & 0x3ff) ? 2 : 1)) /* branch instructions return the address of the *delay* instruction -- this diff --git a/tests/Makefile.am b/tests/Makefile.am index de3990261..763b73c58 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ 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 -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 +check_PROGRAMS = fibit incr printf printf2 rpn fib fibdelay add bp testfp funcfp rpnfp modi ldxi divi movi +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 EXTRA_DIST = $(noinst_DATA) run-test if DISASS @@ -9,6 +9,6 @@ LDADD = $(top_builddir)/opcode/libdisass.a endif if REGRESSION_TESTING -TESTS = fib fibit fibdelay incr printf printf2 rpn add bp testfp funcfp rpnfp modi ldxi +TESTS = fib fibit fibdelay incr printf printf2 rpn add bp testfp funcfp rpnfp modi ldxi divi movi TESTS_ENVIRONMENT=$(srcdir)/run-test endif diff --git a/tests/Makefile.in b/tests/Makefile.in index dda527dfe..e06f7a386 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -40,7 +40,8 @@ target_triplet = @target@ check_PROGRAMS = fibit$(EXEEXT) incr$(EXEEXT) printf$(EXEEXT) \ printf2$(EXEEXT) rpn$(EXEEXT) fib$(EXEEXT) fibdelay$(EXEEXT) \ add$(EXEEXT) bp$(EXEEXT) testfp$(EXEEXT) funcfp$(EXEEXT) \ - rpnfp$(EXEEXT) modi$(EXEEXT) ldxi$(EXEEXT) + rpnfp$(EXEEXT) modi$(EXEEXT) ldxi$(EXEEXT) divi$(EXEEXT) \ + movi$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -59,6 +60,10 @@ bp_SOURCES = bp.c bp_OBJECTS = bp.$(OBJEXT) bp_LDADD = $(LDADD) @DISASS_TRUE@bp_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a +divi_SOURCES = divi.c +divi_OBJECTS = divi.$(OBJEXT) +divi_LDADD = $(LDADD) +@DISASS_TRUE@divi_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a fib_SOURCES = fib.c fib_OBJECTS = fib.$(OBJEXT) fib_LDADD = $(LDADD) @@ -88,6 +93,10 @@ modi_SOURCES = modi.c modi_OBJECTS = modi.$(OBJEXT) modi_LDADD = $(LDADD) @DISASS_TRUE@modi_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a +movi_SOURCES = movi.c +movi_OBJECTS = movi.$(OBJEXT) +movi_LDADD = $(LDADD) +@DISASS_TRUE@movi_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a printf_SOURCES = printf.c printf_OBJECTS = printf.$(OBJEXT) printf_LDADD = $(LDADD) @@ -116,10 +125,11 @@ 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 bp.c fib.c fibdelay.c fibit.c funcfp.c incr.c ldxi.c \ - modi.c printf.c printf2.c rpn.c rpnfp.c testfp.c -DIST_SOURCES = add.c bp.c fib.c fibdelay.c fibit.c funcfp.c incr.c \ - ldxi.c modi.c printf.c printf2.c rpn.c rpnfp.c testfp.c +SOURCES = add.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 rpn.c rpnfp.c testfp.c +DIST_SOURCES = add.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 rpn.c rpnfp.c \ + testfp.c DATA = $(noinst_DATA) ETAGS = etags CTAGS = ctags @@ -225,10 +235,10 @@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ 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 +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 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 testfp funcfp rpnfp modi ldxi +@REGRESSION_TESTING_TRUE@TESTS = fib fibit fibdelay incr printf printf2 rpn add bp testfp funcfp rpnfp modi ldxi divi movi @REGRESSION_TESTING_TRUE@TESTS_ENVIRONMENT = $(srcdir)/run-test all: all-am @@ -272,6 +282,9 @@ add$(EXEEXT): $(add_OBJECTS) $(add_DEPENDENCIES) bp$(EXEEXT): $(bp_OBJECTS) $(bp_DEPENDENCIES) @rm -f bp$(EXEEXT) $(LINK) $(bp_LDFLAGS) $(bp_OBJECTS) $(bp_LDADD) $(LIBS) +divi$(EXEEXT): $(divi_OBJECTS) $(divi_DEPENDENCIES) + @rm -f divi$(EXEEXT) + $(LINK) $(divi_LDFLAGS) $(divi_OBJECTS) $(divi_LDADD) $(LIBS) fib$(EXEEXT): $(fib_OBJECTS) $(fib_DEPENDENCIES) @rm -f fib$(EXEEXT) $(LINK) $(fib_LDFLAGS) $(fib_OBJECTS) $(fib_LDADD) $(LIBS) @@ -293,6 +306,9 @@ ldxi$(EXEEXT): $(ldxi_OBJECTS) $(ldxi_DEPENDENCIES) modi$(EXEEXT): $(modi_OBJECTS) $(modi_DEPENDENCIES) @rm -f modi$(EXEEXT) $(LINK) $(modi_LDFLAGS) $(modi_OBJECTS) $(modi_LDADD) $(LIBS) +movi$(EXEEXT): $(movi_OBJECTS) $(movi_DEPENDENCIES) + @rm -f movi$(EXEEXT) + $(LINK) $(movi_LDFLAGS) $(movi_OBJECTS) $(movi_LDADD) $(LIBS) printf$(EXEEXT): $(printf_OBJECTS) $(printf_DEPENDENCIES) @rm -f printf$(EXEEXT) $(LINK) $(printf_LDFLAGS) $(printf_OBJECTS) $(printf_LDADD) $(LIBS) @@ -317,6 +333,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/add.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bp.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/divi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fib.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fibdelay.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fibit.Po@am__quote@ @@ -324,6 +341,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/incr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldxi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/modi.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/movi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/printf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/printf2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpn.Po@am__quote@ diff --git a/tests/divi.c b/tests/divi.c new file mode 100644 index 000000000..02e7d1564 --- /dev/null +++ b/tests/divi.c @@ -0,0 +1,84 @@ +/******************************** -*- C -*- **************************** + * + * Test jit_divi_i + * + ***********************************************************************/ + + +/* Contributed by Ludovic Courtès. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include "lightning.h" + +typedef int (* divider_t) (int); + +static divider_t +generate_divider (int operand, unsigned int *size) +{ + static char buffer[1024]; + divider_t result; + int arg; + + result = (divider_t)(jit_set_ip (buffer).iptr); + jit_leaf (1); + arg = jit_arg_i (); + jit_getarg_i (JIT_R1, arg); + + jit_divi_i (JIT_R2, JIT_R1, operand); + jit_movr_i (JIT_RET, JIT_R2); + + jit_ret (); + jit_flush_code (buffer, jit_get_ip ().ptr); + + *size = (char *)jit_get_ip ().ptr - buffer; + + return result; +} + +static int +test_divider (int divisor, const int *operands, unsigned operand_count) +{ + int failed = 0; + unsigned int op, size; + divider_t div = generate_divider (divisor, &size); + + for (op = 0; op < operand_count; op++) + { + int result, expected; + + result = div (operands[op]); + expected = operands[op] / divisor; + printf ("%i/%i = %i (expected %i)\n", operands[op], divisor, + result, expected); + + if (result != expected) + failed = 1; + } + + return (!failed); +} + + + +int +main (int argc, char *argv[]) +{ + static const int small_ops[] = { 40, 64, 80 }; + static const int large_ops[] = { 98304, 65536, 163840 }; + + /* Test a small immediate operand. */ + if (!test_divider (8, small_ops, sizeof (small_ops) / sizeof (int))) + return 1; + + /* Test a large immediate operand (requires more instructions on RISC + processors). */ + if (!test_divider (32768, large_ops, sizeof (large_ops) / sizeof (int))) + return 1; + + return 0; +} diff --git a/tests/divi.ok b/tests/divi.ok new file mode 100644 index 000000000..c23cbd224 --- /dev/null +++ b/tests/divi.ok @@ -0,0 +1,6 @@ +40/8 = 5 (expected 5) +64/8 = 8 (expected 8) +80/8 = 10 (expected 10) +98304/32768 = 3 (expected 3) +65536/32768 = 2 (expected 2) +163840/32768 = 5 (expected 5) diff --git a/tests/ldxi.c b/tests/ldxi.c index 92fe4e0fa..753b1c951 100644 --- a/tests/ldxi.c +++ b/tests/ldxi.c @@ -20,7 +20,7 @@ typedef char (* loader_t) (int); /* Check `ldxi' with a big operand (OPERAND is assumed to be ``big'', e.g., more than one octet-long on PowerPC). */ static loader_t -generate_ldxi_big_operand (void *operand) +generate_ldxi_big_operand (const void *operand) { static char buffer[1024]; loader_t result; @@ -47,14 +47,23 @@ int main (int argc, char *argv[]) { static const char the_array[] = "GNU Lightning"; + char the_on_stack_array[] = "GNU Lightning"; unsigned i; - loader_t array_loader = generate_ldxi_big_operand ((void *)the_array); + loader_t array_loader; + const char *large_pointer; + + if (the_array > the_on_stack_array) + large_pointer = the_array; + else + large_pointer = the_on_stack_array; + + array_loader = generate_ldxi_big_operand (large_pointer); for (i = 0; i < sizeof (the_array) - 1; i++) { printf ("array[%i] = %c, array_loader (%i) = %c\n", - i, the_array[i], i, array_loader (i)); - if (the_array[i] != array_loader (i)) + i, large_pointer[i], i, array_loader (i)); + if (large_pointer[i] != array_loader (i)) return 1; } diff --git a/tests/movi.c b/tests/movi.c new file mode 100644 index 000000000..e7439cab6 --- /dev/null +++ b/tests/movi.c @@ -0,0 +1,63 @@ +/******************************** -*- C -*- **************************** + * + * Test jit_movi_p + * + ***********************************************************************/ + + +/* Contributed by Ludovic Courtès. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include "lightning.h" + +typedef void * (* mover_t) (void); + +static mover_t +generate_movi (const void *operand) +{ + static char buffer[1024]; + mover_t result; + + /* printf ("si?=%i ui?=%i\n", _siP (16, operand), _uiP (16, operand)); */ + + result = (mover_t)(jit_set_ip (buffer).iptr); + jit_leaf (1); + + jit_movi_p (JIT_R0, operand); + jit_movr_p (JIT_RET, JIT_R0); + + jit_ret (); + jit_flush_code (buffer, jit_get_ip ().ptr); + + return result; +} + + +int +main (int argc, char *argv[]) +{ + static const char the_array[] = "GNU Lightning"; + mover_t get_array; + const void *large_pointer; + + if (the_array > (char *)&get_array) + large_pointer = the_array; + else + large_pointer = &get_array; + + /* On RISC machines, moving a large immediate may require several + instructions (e.g., `sethi' followed by `ori' on SPARC). */ + get_array = generate_movi (large_pointer); + + if (get_array () == large_pointer) + printf ("`jit_movi_p' succeeded\n"); + else + printf ("`jit_movi_p' failed\n"); + + return (get_array () != large_pointer); +} diff --git a/tests/movi.ok b/tests/movi.ok new file mode 100644 index 000000000..180c39f56 --- /dev/null +++ b/tests/movi.ok @@ -0,0 +1 @@ +`jit_movi_p' succeeded