From 5ea118e8a93fb8204a537bccd5e5a9f1b98128b0 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 28 Jul 2010 23:28:30 +0200 Subject: [PATCH] add ldst test 2010-07-28 Paolo Bonzini * tests/Makefile.am: Add ldst test. * tests/Makefile.in: Regenerate. * tests/ldst.c: New. * tests/ldst.ok: New. --- ChangeLog | 7 +++ tests/Makefile.am | 6 +- tests/Makefile.in | 19 +++++-- tests/ldst.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++ tests/ldst.ok | 0 5 files changed, 164 insertions(+), 8 deletions(-) create mode 100644 tests/ldst.c create mode 100644 tests/ldst.ok diff --git a/ChangeLog b/ChangeLog index 9c7f4b962..550d75d6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-07-28 Paolo Bonzini + + * tests/Makefile.am: Add ldst test. + * tests/Makefile.in: Regenerate. + * tests/ldst.c: New. + * tests/ldst.ok: New. + 2010-07-28 Paolo Bonzini * THANKS: Add Paulo Cesar Pereira de Andrade. diff --git a/tests/Makefile.am b/tests/Makefile.am index 0df0a039c..1d27834c7 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 3to2 + allocai push-pop sete 3to2 ldst 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 3to2.ok + allocai.ok push-pop.ok sete.ok 3to2.ok ldst.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 3to2 + push-pop sete 3to2 ldst TESTS_ENVIRONMENT=$(srcdir)/run-test endif diff --git a/tests/Makefile.in b/tests/Makefile.in index a1be53c96..8918679f5 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -40,7 +40,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) 3to2$(EXEEXT) + sete$(EXEEXT) 3to2$(EXEEXT) ldst$(EXEEXT) @REGRESSION_TESTING_TRUE@TESTS = fib$(EXEEXT) fibit$(EXEEXT) \ @REGRESSION_TESTING_TRUE@ fibdelay$(EXEEXT) incr$(EXEEXT) \ @REGRESSION_TESTING_TRUE@ printf$(EXEEXT) printf2$(EXEEXT) \ @@ -50,7 +50,8 @@ check_PROGRAMS = fibit$(EXEEXT) incr$(EXEEXT) printf$(EXEEXT) \ @REGRESSION_TESTING_TRUE@ ldxi$(EXEEXT) divi$(EXEEXT) \ @REGRESSION_TESTING_TRUE@ movi$(EXEEXT) ret$(EXEEXT) \ @REGRESSION_TESTING_TRUE@ allocai$(EXEEXT) push-pop$(EXEEXT) \ -@REGRESSION_TESTING_TRUE@ sete$(EXEEXT) 3to2$(EXEEXT) +@REGRESSION_TESTING_TRUE@ sete$(EXEEXT) 3to2$(EXEEXT) \ +@REGRESSION_TESTING_TRUE@ ldst$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -104,6 +105,10 @@ incr_SOURCES = incr.c incr_OBJECTS = incr.$(OBJEXT) incr_LDADD = $(LDADD) @DISASS_TRUE@incr_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a +ldst_SOURCES = ldst.c +ldst_OBJECTS = ldst.$(OBJEXT) +ldst_LDADD = $(LDADD) +@DISASS_TRUE@ldst_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a ldxi_SOURCES = ldxi.c ldxi_OBJECTS = ldxi.$(OBJEXT) ldxi_LDADD = $(LDADD) @@ -159,10 +164,10 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ 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 \ + funcfp.c incr.c ldst.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 \ + fibit.c funcfp.c incr.c ldst.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 @@ -276,7 +281,7 @@ 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 3to2.ok + allocai.ok push-pop.ok sete.ok 3to2.ok ldst.ok EXTRA_DIST = $(noinst_DATA) run-test @DISASS_TRUE@LDADD = $(top_builddir)/opcode/libdisass.a @@ -348,6 +353,9 @@ funcfp$(EXEEXT): $(funcfp_OBJECTS) $(funcfp_DEPENDENCIES) incr$(EXEEXT): $(incr_OBJECTS) $(incr_DEPENDENCIES) @rm -f incr$(EXEEXT) $(LINK) $(incr_OBJECTS) $(incr_LDADD) $(LIBS) +ldst$(EXEEXT): $(ldst_OBJECTS) $(ldst_DEPENDENCIES) + @rm -f ldst$(EXEEXT) + $(LINK) $(ldst_OBJECTS) $(ldst_LDADD) $(LIBS) ldxi$(EXEEXT): $(ldxi_OBJECTS) $(ldxi_DEPENDENCIES) @rm -f ldxi$(EXEEXT) $(LINK) $(ldxi_OBJECTS) $(ldxi_LDADD) $(LIBS) @@ -398,6 +406,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fibit.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/funcfp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/incr.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldst.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@ diff --git a/tests/ldst.c b/tests/ldst.c new file mode 100644 index 000000000..311310254 --- /dev/null +++ b/tests/ldst.c @@ -0,0 +1,140 @@ +/* Written by Paulo Cesar Pereira de Andrade, pcpa@mandriva.com.br */ + +#include +#include +#include +#include + +#define CHECK_FLOAT 1 + +typedef struct types { + char c; + unsigned char uc; + short s; + unsigned short us; + int i; + unsigned int ui; + long l; + unsigned long ul; + float f; + double d; + void *p; +} types_t; + +typedef void (*pvv_t)(void); + +pvv_t pvv; +types_t t0, t1; +jit_insn code[4096]; + +#define warn(format, ...) \ + fprintf(stderr, "%s:%d: " format "\n", __func__, (int) __LINE__ ,#__VA_ARGS__) + +#if __WORDSIZE == 64 +# define LONG_VALUE 0x7fffffffffffffff +#else +# define LONG_VALUE 0x7fffffff +#endif +void +check1(void) +{ + if (t0.c != t1.c) warn("0x%x 0x%x", t0.c, t1.c); + if (t0.uc != t1.uc) warn("0x%x 0x%x", t0.uc, t1.uc); + if (t0.s != t1.s) warn("0x%x 0x%x", t0.s, t1.s); + if (t0.us != t1.us) warn("0x%x 0x%x", t0.us, t1.us); + if (t0.i != t1.i) warn("0x%x 0x%x", t0.i, t1.i); + if (t0.ui != t1.ui) warn("0x%x 0x%x", t0.ui, t1.ui); + if (t0.l != t1.l) warn("0x%lx 0x%lx", t0.l, t1.l); + if (t0.ul != t1.ul) warn("0x%lx 0x%lx", t0.ul, t1.ul); +#if CHECK_FLOAT + if (t0.f != t1.f) warn("%f %f", t0.f, t1.f); + if (t0.d != t1.d) warn("%f %f", t0.d, t1.d); +#endif + if (t0.p != t1.p) warn("0x%p 0x%p", t0.p, t1.p); +} +check0(void) +{ + if (t0.c != 0x7f) warn("0x%x", t0.c); + if (t0.uc != 0x7f) warn("0x%x", t0.uc); + if (t0.s != 0x7fff) warn("0x%x", t0.s); + if (t0.us != 0x7fff) warn("0x%x", t0.us); + if (t0.i != 0x7fffffff) warn("0x%x", t0.i); + if (t0.ui != 0x7fffffff) warn("0x%x", t0.ui); + if (t0.l != LONG_VALUE) warn("0x%lx", t0.l); + if (t0.ul != LONG_VALUE) warn("0x%lx", t0.ul); +#if CHECK_FLOAT + if (t0.f != 0.5f) warn("%f", t0.f); + if (t0.d != 1.5) warn("%f", t0.d); + +#endif + if (t0.p != (void*)0xdeadbeef) warn("0x%p", t0.p); +} +void +test(V0, V1, R0, F0) +{ + jit_movi_p ( V0, &t0); + jit_movi_p ( V1, &t1); + jit_movi_i ( R0, 0x7f); + jit_stxi_c (offsetof(types_t, c), V0, R0); + jit_stxi_uc(offsetof(types_t, uc), V0, R0); + jit_movi_i ( R0, 0x7fff); + jit_stxi_s(offsetof(types_t, s), V0, R0); + jit_stxi_us(offsetof(types_t, us), V0, R0); + jit_movi_i ( R0, 0x7fffffff); + jit_stxi_i (offsetof(types_t, i), V0, R0); + jit_stxi_ui(offsetof(types_t, ui), V0, R0); + jit_movi_l ( R0, LONG_VALUE); + jit_stxi_l (offsetof(types_t, l), V0, R0); + jit_stxi_ul(offsetof(types_t, ul), V0, R0); +#if CHECK_FLOAT + jit_movi_f ( F0, 0.5f); + jit_stxi_f (offsetof(types_t, f), V0, F0); + jit_movi_d ( F0, 1.5); + jit_stxi_d (offsetof(types_t, d), V0, F0); +#endif + jit_movi_p ( R0, 0xdeadbeef); + jit_stxi_p (offsetof(types_t, p), V0, R0); + jit_calli (check0); + + jit_ldxi_c ( R0, V0, offsetof(types_t, c)); + jit_stxi_c (offsetof(types_t, c), V1, R0); + jit_ldxi_uc( R0, V0, offsetof(types_t, uc)); + jit_stxi_uc(offsetof(types_t, uc), V1, R0); + jit_ldxi_s ( R0, V0, offsetof(types_t, s)); + jit_stxi_s (offsetof(types_t, s), V1, R0); + jit_ldxi_us( R0, V0, offsetof(types_t, us)); + jit_stxi_us(offsetof(types_t, us), V1, R0); + jit_ldxi_i ( R0, V0, offsetof(types_t, i)); + jit_stxi_i (offsetof(types_t, i), V1, R0); + jit_ldxi_ui( R0, V0, offsetof(types_t, ui)); + jit_stxi_ui(offsetof(types_t, ui), V1, R0); + jit_ldxi_l ( R0, V0, offsetof(types_t, l)); + jit_stxi_l (offsetof(types_t, l), V1, R0); + jit_ldxi_ul( R0, V0, offsetof(types_t, ul)); + jit_stxi_ul(offsetof(types_t, ul), V1, R0); +#if CHECK_FLOAT + jit_ldxi_f ( F0, V0, offsetof(types_t, f)); + jit_stxi_f (offsetof(types_t, f), V1, F0); + jit_ldxi_d ( F0, V0, offsetof(types_t, d)); + jit_stxi_d (offsetof(types_t, d), V1, F0); +#endif + jit_ldxi_p ( R0, V0, offsetof(types_t, p)); + jit_stxi_p (offsetof(types_t, p), V1, R0); + jit_calli (check1); +} + +int +main(int argc, char *argv[]) +{ + jit_set_ip(code); + jit_prolog(0); + test(JIT_V0, JIT_V1, JIT_R0, JIT_FPR0); + jit_ret(); + + jit_flush_code(code, jit_get_ip().ptr); + + pvv = (pvv_t)code; + (*pvv)(); + + return (0); +} diff --git a/tests/ldst.ok b/tests/ldst.ok new file mode 100644 index 000000000..e69de29bb