mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-23 03:54:12 +02:00
cherrypick from ludovic courtes
2006-10-31 Paolo Bonzini <bonzini@gnu.org> Ludovic Courtes <ludo@chbouib.org> * 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. Patches applied: * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-11 Fixed a typo in `lightning/sparc/core.h'. * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-12 SPARC: Fixed `jit_immsize' (untested!). * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-13 Added a `divi' test case (does not catch the bug fixed by the previous patch). * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-14 `divi' test case: Return non-zero on failure. * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-15 `ldxi.c' (test case): Make sure we use a large pointer operand. * lcourtes@laas.fr--2005-libre/lightning--stable--1.2--patch-16 Added a `movi' test case (for `jit_movi_p' with large operands). git-archimport-id: bonzini@gnu.org--2004b/lightning--stable--1.2--patch-31
This commit is contained in:
parent
1f7feaffe2
commit
147efb8d90
14 changed files with 221 additions and 35 deletions
84
tests/divi.c
Normal file
84
tests/divi.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/******************************** -*- C -*- ****************************
|
||||
*
|
||||
* Test jit_divi_i
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/* Contributed by Ludovic Courtès. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue