[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 30/437: added ret test and clarified JIT_RET documentati
From: |
Andy Wingo |
Subject: |
[Guile-commits] 30/437: added ret test and clarified JIT_RET documentation |
Date: |
Mon, 2 Jul 2018 05:13:39 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit e2cb4af6aa9f02cf334012f97ad65a00c20f5e1c
Author: Paolo Bonzini <address@hidden>
Date: Tue Oct 31 14:45:37 2006 +0000
added ret test and clarified JIT_RET documentation
Patches applied:
* address@hidden/lightning--sparc-fixes--1.2--base-0
tag of address@hidden/lightning--stable--1.2--patch-18
* address@hidden/lightning--sparc-fixes--1.2--patch-1
tests/push-pop.c: Use more `pushr's.
* address@hidden/lightning--sparc-fixes--1.2--patch-3
Added a test for `JIT_RET' (fails on SPARC).
* address@hidden/lightning--sparc-fixes--1.2--patch-4
Fixed use of `JIT_RET': Move %o0 into %i0 after `calli' and `callr'.
* address@hidden/lightning--stable--1.2--patch-19
Merge from `sparc-fixes': Fixed `pushr' and `popr', fixed `JIT_RET'.
* address@hidden/lightning--stable--1.2--patch-20
Undoed `lightning--sparc-fixes--1.2--patch-4' (about `JIT_RET') which
was wrong.
* address@hidden/lightning--stable--1.2--patch-21
tests/ret.c: Use `jit_retval_i' to copy the function's return value.
* address@hidden/lightning--stable--1.2--patch-22
Doc: Clarified the use of `JIT_RET' and documented `jit_retval'.
git-archimport-id: address@hidden/lightning--stable--1.2--patch-32
---
doc/using.texi | 18 ++++++++++----
tests/Makefile.am | 13 +++++++---
tests/Makefile.in | 26 +++++++++++++++-----
tests/ret.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/ret.ok | 1 +
5 files changed, 117 insertions(+), 13 deletions(-)
diff --git a/doc/using.texi b/doc/using.texi
index fa6a0b4..3a8578a 100644
--- a/doc/using.texi
+++ b/doc/using.texi
@@ -104,10 +104,12 @@ which, like the x86, are poor of registers; anyway,
backends can
specify the actual number of available caller- and callee-save
registers.
-In addition, there is a special @code{RET} register which contains
-the return value. You should always remember, however, that writing
-this register could overwrite either a general-purpose register or
-an incoming parameter, depending on the architecture.
+In addition, there is a special @code{RET} register which contains the
+return value of the current function (@emph{not} the return value of
+callees---use the @code{retval} instruction for this). You should
+always remember, however, that writing this register could overwrite
+either a general-purpose register or an incoming parameter, depending
+on the architecture.
There are at least six floating-point registers, named @code{FPR0} to
@code{FPR5}. These are separate from the integer registers on
@@ -285,6 +287,7 @@ prepare i f d
pusharg c uc s us i ui l ul p f d
getarg c uc s us i ui l ul p f d
arg c uc s us i ui l ul p f d
+retval c uc s us i ui l ul p
@end example
Of these, the first two are used by the caller, while the last two
@@ -315,6 +318,13 @@ that generates other code, so they will be treated more
specifically in @ref{GNU lightning macros, , Generating code at
run-time}.
+Finally, the @code{retval} instruction fetches the return value of a
+called function in a register. The @code{retval} instruction takes a
+register argument and copies the return value of the previously called
+function in that register. A function should put its own return value
+in the @code{RET} register before returning. @xref{Fibonacci, the
+Fibonacci numbers}, for an example.
+
You should observe a few rules when using these macros. First of
all, it is not allowed to call functions with more than six arguments;
this was done to simplify and speed up the implementation on
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 763b73c..69cc039 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,7 +1,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
-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
+check_PROGRAMS = fibit incr printf printf2 rpn fib fibdelay \
+ add bp testfp funcfp rpnfp modi ldxi divi movi ret
+
+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
+
EXTRA_DIST = $(noinst_DATA) run-test
if DISASS
@@ -9,6 +14,8 @@ 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 divi movi
+TESTS = fib fibit fibdelay incr printf printf2 rpn add bp \
+ testfp funcfp rpnfp modi ldxi divi movi ret
+
TESTS_ENVIRONMENT=$(srcdir)/run-test
endif
diff --git a/tests/Makefile.in b/tests/Makefile.in
index e06f7a3..ae65e72 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -41,7 +41,7 @@ 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)
+ movi$(EXEEXT) ret$(EXEEXT)
subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -106,6 +106,10 @@ printf2_OBJECTS = printf2.$(OBJEXT)
printf2_LDADD = $(LDADD)
@address@hidden = \
@DISASS_TRUE@ $(top_builddir)/opcode/libdisass.a
+ret_SOURCES = ret.c
+ret_OBJECTS = ret.$(OBJEXT)
+ret_LDADD = $(LDADD)
address@hidden@ret_DEPENDENCIES = $(top_builddir)/opcode/libdisass.a
rpn_SOURCES = rpn.c
rpn_OBJECTS = rpn.$(OBJEXT)
rpn_LDADD = $(LDADD)
@@ -126,10 +130,11 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
$(AM_CPPFLAGS) \
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
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 \
+ ldxi.c modi.c movi.c printf.c printf2.c ret.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 ret.c rpn.c \
+ rpnfp.c testfp.c
DATA = $(noinst_DATA)
ETAGS = etags
CTAGS = ctags
@@ -235,10 +240,15 @@ 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 divi.ok movi.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 ret.ok
+
EXTRA_DIST = $(noinst_DATA) run-test
@address@hidden = $(top_builddir)/opcode/libdisass.a
address@hidden@TESTS = fib fibit fibdelay incr printf printf2 rpn add bp testfp
funcfp rpnfp modi ldxi divi movi
address@hidden@TESTS = fib fibit fibdelay incr printf printf2 rpn add bp
\
address@hidden@ testfp funcfp rpnfp modi ldxi divi movi ret
+
@address@hidden = $(srcdir)/run-test
all: all-am
@@ -315,6 +325,9 @@ printf$(EXEEXT): $(printf_OBJECTS) $(printf_DEPENDENCIES)
printf2$(EXEEXT): $(printf2_OBJECTS) $(printf2_DEPENDENCIES)
@rm -f printf2$(EXEEXT)
$(LINK) $(printf2_LDFLAGS) $(printf2_OBJECTS) $(printf2_LDADD) $(LIBS)
+ret$(EXEEXT): $(ret_OBJECTS) $(ret_DEPENDENCIES)
+ @rm -f ret$(EXEEXT)
+ $(LINK) $(ret_LDFLAGS) $(ret_OBJECTS) $(ret_LDADD) $(LIBS)
rpn$(EXEEXT): $(rpn_OBJECTS) $(rpn_DEPENDENCIES)
@rm -f rpn$(EXEEXT)
$(LINK) $(rpn_LDFLAGS) $(rpn_OBJECTS) $(rpn_LDADD) $(LIBS)
@@ -344,6 +357,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@
@AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
@AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
diff --git a/tests/ret.c b/tests/ret.c
new file mode 100644
index 0000000..f072adc
--- /dev/null
+++ b/tests/ret.c
@@ -0,0 +1,72 @@
+/******************************** -*- C -*- ****************************
+ *
+ * Test `JIT_RET'
+ *
+ ***********************************************************************/
+
+
+/* Contributed by Ludovic Court�s. */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "lightning.h"
+
+typedef int (* int_return_int_t) (int);
+
+static int
+identity (int arg)
+{
+ return arg;
+}
+
+static int_return_int_t
+generate_function_proxy (int_return_int_t func)
+{
+ static char buffer[1024];
+ int_return_int_t result;
+ int arg;
+
+ result = (int_return_int_t)(jit_set_ip (buffer).ptr);
+ jit_prolog (1);
+ arg = jit_arg_i ();
+ jit_getarg_i (JIT_R1, arg);
+
+ /* Reset `JIT_RET'. */
+ jit_movi_i (JIT_RET, -1);
+
+ /* Invoke a FUNC. */
+ jit_prepare (1);
+ jit_pusharg_i (JIT_R1);
+ (void)jit_finish (func);
+
+ /* Copy the result of FUNC from `JIT_RET' into our own result register. */
+ jit_retval_i (JIT_RET);
+
+ jit_ret ();
+ jit_flush_code (buffer, jit_get_ip ().ptr);
+
+ return result;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int_return_int_t identity_proxy;
+
+ identity_proxy = generate_function_proxy (identity);
+ if (identity_proxy (7777) != 7777)
+ {
+ printf ("failed: got %i instead of %i\n",
+ identity_proxy (7777), 7777);
+ return 1;
+ }
+ else
+ printf ("succeeded\n");
+
+ return 0;
+}
diff --git a/tests/ret.ok b/tests/ret.ok
new file mode 100644
index 0000000..774a5c0
--- /dev/null
+++ b/tests/ret.ok
@@ -0,0 +1 @@
+succeeded
- [Guile-commits] 22/437: one more tweak to fix distribution, (continued)
- [Guile-commits] 22/437: one more tweak to fix distribution, Andy Wingo, 2018/07/02
- [Guile-commits] 18/437: don't use __func__ nor __FUNCTION__ if not compiling with GNU C., Andy Wingo, 2018/07/02
- [Guile-commits] 26/437: fix i386 syntax error, Andy Wingo, 2018/07/02
- [Guile-commits] 08/437: fixes to sparc floating point, Andy Wingo, 2018/07/02
- [Guile-commits] 10/437: add more autotools-generated files, Andy Wingo, 2018/07/02
- [Guile-commits] 23/437: fix `make dist' bug and prepare for releasing 1.2a, Andy Wingo, 2018/07/02
- [Guile-commits] 27/437: Fix assertion failures in i386 movs and movz opcodes, Andy Wingo, 2018/07/02
- [Guile-commits] 21/437: clarify bundling documentation and improve autoconf macro, Andy Wingo, 2018/07/02
- [Guile-commits] 32/437: fix powerpc jit_bms, Andy Wingo, 2018/07/02
- [Guile-commits] 24/437: bump version, add ldxi test case, Andy Wingo, 2018/07/02
- [Guile-commits] 30/437: added ret test and clarified JIT_RET documentation,
Andy Wingo <=
- [Guile-commits] 20/437: fix PPC modi, Andy Wingo, 2018/07/02
- [Guile-commits] 35/437: remove pushr/popr from testsuite, Andy Wingo, 2018/07/02
- [Guile-commits] 31/437: prepare for automatic variables support, Andy Wingo, 2018/07/02
- [Guile-commits] 29/437: cherrypick from ludovic courtes, Andy Wingo, 2018/07/02
- [Guile-commits] 33/437: add jit_allocai for SPARC, Andy Wingo, 2018/07/02
- [Guile-commits] 16/437: Fix comments in config.h.in git-archimport-id: address@hidden/lightning--stable--1.2--patch-18, Andy Wingo, 2018/07/02
- [Guile-commits] 37/437: fix x86-64 builds, Andy Wingo, 2018/07/02
- [Guile-commits] 42/437: add an underscore to macros without a parameter [x86], Andy Wingo, 2018/07/02
- [Guile-commits] 36/437: update manual for jit_allocai, Andy Wingo, 2018/07/02
- [Guile-commits] 46/437: merge from ludovic, Andy Wingo, 2018/07/02