[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Lightning] Re: lightning x86 FP patch
From: |
Paolo Bonzini |
Subject: |
[Lightning] Re: lightning x86 FP patch |
Date: |
Wed, 02 Jan 2008 12:52:48 +0100 |
User-agent: |
Thunderbird 2.0.0.9 (Macintosh/20071031) |
I think the `opr' on the sixth line should be `op':
: (rd) == (s2) ? jit_fxch((s2), op((rd) == 0 ? (s1) : (rd), 0)) \
because the argument order is not reversed.
There is a bug, but your patch would break other cases. This is the
right patch to fix it:
--- orig/lightning/i386/fp-32.h
+++ mod/lightning/i386/fp-32.h
@@ -63,7 +63,9 @@
((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)
I've added a testcase too.
Thanks!
Paolo
2008-01-02 Paolo Bonzini <address@hidden>
* lightning/i386/fp-32.h: Fix sub(a,b,a) with a ~= JIT_FPR0.
* lightning/tests/3to2.c: New.
* lightning/tests/3to2.ok: New.
--- orig/lightning/i386/fp-32.h
+++ mod/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)
--- orig/tests/Makefile.am
+++ mod/tests/Makefile.am
@@ -2,12 +2,12 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(top_
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
+ push-pop 3to2
TESTS_ENVIRONMENT=$(srcdir)/run-test
endif
--- /dev/null
+++ mod/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 <stdio.h>
+#include <stdlib.h>
+#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;
+}
+
+int
+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
--- /dev/null
+++ mod/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
- [Lightning] Re: lightning x86 FP patch,
Paolo Bonzini <=