From d0d493b41755f22432397bdb109ad1a5eae47841 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 13 Aug 2007 08:00:13 +0000 Subject: [PATCH] improve set* encoding for i386, add testcase 2007-08-12 Paolo Bonzini * lightning/i386/core-i386.h: Improve encoding of set* instructions. * lightning/i386/core-64.h: Fix jit_bra_l. * tests/sete.c: New. * tests/sete.ok: New. git-archimport-id: bonzini@gnu.org--2004b/lightning--stable--1.2--patch-56 git-archimport-id: bonzini@gnu.org--2004b/lightning--stable--1.2--patch-60 --- ChangeLog | 7 ++++ lightning/i386/core-64.h | 2 +- lightning/i386/core-i386.h | 14 ++++---- tests/Makefile.am | 6 ++-- tests/Makefile.in | 19 ++++++++--- tests/sete.c | 67 ++++++++++++++++++++++++++++++++++++++ tests/sete.ok | 2 ++ 7 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 tests/sete.c create mode 100644 tests/sete.ok diff --git a/ChangeLog b/ChangeLog index 6faf6aabe..15c02f963 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-08-12 Paolo Bonzini + + * lightning/i386/core-i386.h: Improve encoding of set* instructions. + * lightning/i386/core-64.h: Fix jit_bra_l. + * tests/sete.c: New. + * tests/sete.ok: New. + 2007-06-29 Paolo Bonzini * tests/bp.c: Upgrade to GPL/LGPLv3. diff --git a/lightning/i386/core-64.h b/lightning/i386/core-64.h index 7baa94398..03d105311 100644 --- a/lightning/i386/core-64.h +++ b/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) \ diff --git a/lightning/i386/core-i386.h b/lightning/i386/core-i386.h index be10dc454..754cdff73 100644 --- a/lightning/i386/core-i386.h +++ b/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) diff --git a/tests/Makefile.am b/tests/Makefile.am index c9cac9e89..47cf1db17 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 + 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 @@ -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 + push-pop sete TESTS_ENVIRONMENT=$(srcdir)/run-test endif diff --git a/tests/Makefile.in b/tests/Makefile.in index eda7bcae6..846766bc3 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -41,7 +41,8 @@ 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) 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) @DISASS_TRUE@rpnfp_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a +sete_SOURCES = sete.c +sete_OBJECTS = sete.$(OBJEXT) +sete_LDADD = $(LDADD) +@DISASS_TRUE@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,13 +258,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 + allocai.ok push-pop.ok sete.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 +@REGRESSION_TESTING_TRUE@ push-pop sete @REGRESSION_TESTING_TRUE@TESTS_ENVIRONMENT = $(srcdir)/run-test all: all-am @@ -352,6 +357,9 @@ rpn$(EXEEXT): $(rpn_OBJECTS) $(rpn_DEPENDENCIES) 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@ @am__quote@./$(DEPDIR)/ret.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpn.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rpnfp.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sete.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testfp.Po@am__quote@ .c.o: diff --git a/tests/sete.c b/tests/sete.c new file mode 100644 index 000000000..6442bd5c8 --- /dev/null +++ b/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 +#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; +} diff --git a/tests/sete.ok b/tests/sete.ok new file mode 100644 index 000000000..aa736b442 --- /dev/null +++ b/tests/sete.ok @@ -0,0 +1,2 @@ +5 == 4? no +5 == 5? yes