1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-05 06:50:21 +02:00

Add code to calculate code buffer size based on devel time information.

* lib/jit_aarch64-sz.c, lib/jit_arm-sz.c, lib/jit_hppa-sz.c,
	lib/jit_ia64-sz.c, lib/jit_mips-sz.c, lib/jit_ppc-sz.c,
	lib/jit_s390x-sz.c, lib/jit_size.c, lib/jit_sparc-sz.c,
	lib/jit_x86-sz.c: New files implementing static tables
	with longest known instructions length generated to match
	a lightning instruction. These tables should make it easier
	to make it very unlikely to ever miscalculate, or by too
	much, the size of a code buffer.

	* lib/jit_size.c: New file that aids to either collect
	jit code size information, or use the information depending
	on build options.

	* size.c: New helper file that parses input for, and create
	an initial jit_$arch-sz.c file, that needs some minor edit
	for arches with multiple configurations.

	* configure.ac, Makefile.am: Add the new, devel mode only
	--enable-devel-get-jit-size configure option, that sets
	compile time flags to collect jit code size information,
	that will be used as input for the "noinst size program".

	* lib/jit_aarch64.c, lib/jit_arm.c, lib/jit_disasm.c,
	lib/jit_hppa.c, lib/jit_ia64.c, lib/jit_memory.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_s390x.c,
	lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c: Minor
	changes for the --enable-devel-get-jit-size build mode,
	as well as the "production build mode" with jit code
	size information.
This commit is contained in:
pcpa 2013-09-24 03:31:54 -03:00
parent 95e3fbc8bc
commit b768fab8b1
29 changed files with 5269 additions and 48 deletions

2
.gitignore vendored
View file

@ -13,10 +13,12 @@ config.status
config.sub
configure
install-sh
jit_*-sz.c
libtool
lightning-*.tar.*
ltmain.sh
missing
size
stamp-h1
test-driver
check/.deps

View file

@ -1,3 +1,35 @@
2013-10-24 Paulo Andrade <pcpa@gnu.org>
* lib/jit_aarch64-sz.c, lib/jit_arm-sz.c, lib/jit_hppa-sz.c,
lib/jit_ia64-sz.c, lib/jit_mips-sz.c, lib/jit_ppc-sz.c,
lib/jit_s390x-sz.c, lib/jit_size.c, lib/jit_sparc-sz.c,
lib/jit_x86-sz.c: New files implementing static tables
with longest known instructions length generated to match
a lightning instruction. These tables should make it easier
to make it very unlikely to ever miscalculate, or by too
much, the size of a code buffer.
* lib/jit_size.c: New file that aids to either collect
jit code size information, or use the information depending
on build options.
* size.c: New helper file that parses input for, and create
an initial jit_$arch-sz.c file, that needs some minor edit
for arches with multiple configurations.
* configure.ac, Makefile.am: Add the new, devel mode only
--enable-devel-get-jit-size configure option, that sets
compile time flags to collect jit code size information,
that will be used as input for the "noinst size program".
* lib/jit_aarch64.c, lib/jit_arm.c, lib/jit_disasm.c,
lib/jit_hppa.c, lib/jit_ia64.c, lib/jit_memory.c,
lib/jit_mips.c, lib/jit_ppc.c, lib/jit_s390x.c,
lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c: Minor
changes for the --enable-devel-get-jit-size build mode,
as well as the "production build mode" with jit code
size information.
2013-10-14 Paulo Andrade <pcpa@gnu.org>
* include/lightning.h, lib/lightning.c: Add the new

View file

@ -21,3 +21,22 @@ SUBDIRS = \
doc \
include \
lib
if get_jit_size
JIT_SIZE_PATH = "$(top_builddir)/jit_$(cpu)-sz.c"
AM_CPPFLAGS=-DGET_JIT_SIZE=1 -DJIT_SIZE_PATH='$(JIT_SIZE_PATH)'
AM_CFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE $(LIGHTNING_CFLAGS)
noinst_PROGRAMS = size
size_LDADD = $(top_builddir)/lib/liblightning.la -lm $(SHLIB)
size_SOURCES = size.c
get_jit_size:: $(JIT_SIZE_PATH)
$(JIT_SIZE_PATH):
make clean
make CFLAGS='-O0 -g3' check
$(top_builddir)/size
CLEANFILES = $(JIT_SIZE_PATH)
endif

View file

@ -27,13 +27,16 @@ case "$target_cpu" in
ia64)
case "$host_os" in
# Only supported mode
*hpux*) CFLAGS="$CFLAGS -mlp64" ;;
*hpux*)
LIGHTNING_CFLAGS="$LIGHTNING_CFLAGS -mlp64" ;;
*) ;;
esac ;;
*mips*)
case "$host_os" in
# Extra flags to build with gcc 3.x
*irix*) CFLAGS="$CFLAGS -D__c99 -Drestrict=" ;;
# (Hack) Flags to pass configure with gcc 3.x
# Should not set LIGHTNINT_CFLAGS
*irix*)
CFLAGS="$CFLAGS -D__c99 -Drestrict=";;
*) ;;
esac ;;
*) ;;
@ -89,6 +92,13 @@ else
DEBUG=no
fi
# This option is only useful during development.
AC_ARG_ENABLE(devel-get-jit-size,
AS_HELP_STRING([--enable-devel-get-jit-size],
[Devel mode to regenerate jit size information]),
[GET_JIT_SIZE=$enableval], [GET_JIT_SIZE=no])
AM_CONDITIONAL(get_jit_size, [test $GET_JIT_SIZE = yes])
case "$host_os" in
*bsd*) SHLIB="" ;;
*hpux*) SHLIB="-ldld" ;;
@ -213,6 +223,7 @@ if test $cpu=arm; then
AC_CHECK_LIB(m, sqrtf, ,
[AC_MSG_ERROR([sqrtf required but not available])])
fi
AC_SUBST(cpu)
AC_SUBST([LIGHTNING_CFLAGS])

View file

@ -432,8 +432,14 @@ struct jit_compiler {
} prolog;
jit_bool_t jump;
#endif
/* global flag for code buffer heuristic size computation */
#if GET_JIT_SIZE
/* Temporary storage to calculate instructions length */
jit_word_t size;
/* Global flag for code buffer heuristic size computation */
jit_word_t mult;
/* Pointer to code to prevent miscalculation if reallocating buffer */
jit_uint8_t *cptr;
#endif
};
#define _jitc _jit->comp
@ -557,13 +563,26 @@ extern void jit_alloc(jit_pointer_t*, jit_word_t);
extern void jit_realloc(jit_pointer_t*, jit_word_t, jit_word_t);
void jit_free(jit_pointer_t*);
#if HAVE_MREMAP
# define jit_remap() _jit_remap(_jit)
extern jit_bool_t _jit_remap(jit_state_t*);
extern void jit_init_size(void);
extern void jit_finish_size(void);
#if GET_JIT_SIZE
# define jit_size_prepare() _jit_size_prepare(_jit)
extern void
_jit_size_prepare(jit_state_t*);
# define jit_size_collect(node) _jit_size_collect(_jit, node)
extern void
_jit_size_collect(jit_state_t*, jit_node_t*);
#else
# define jit_remap() 0
# define jit_get_size() _jit_get_size(_jit)
extern jit_word_t
_jit_get_size(jit_state_t*);
#endif
extern jit_word_t
jit_get_max_instr(void);
/*
* Externs
*/

View file

@ -17,41 +17,56 @@
AM_CFLAGS = -I$(top_srcdir)/include -D_GNU_SOURCE $(LIGHTNING_CFLAGS)
liblightning_LTLIBRARIES = liblightning.la
if get_jit_size
JIT_SIZE_PATH = "$(top_builddir)/jit_$(cpu)-sz.c"
AM_CPPFLAGS=-DGET_JIT_SIZE=1 -DJIT_SIZE_PATH='$(JIT_SIZE_PATH)'
endif
liblightningdir = $(libdir)
liblightning_la_SOURCES = \
jit_disasm.c \
jit_memory.c \
jit_note.c \
jit_print.c \
jit_size.c \
lightning.c
EXTRA_DIST = \
jit_aarch64.c \
jit_aarch64-cpu.c \
jit_aarch64-fpu.c \
jit_aarch64-sz.c \
jit_arm.c \
jit_arm-cpu.c \
jit_arm-swf.c \
jit_arm-vfp.c \
jit_arm-sz.c \
jit_hppa.c \
jit_hppa-cpu.c \
jit_hppa-fpu.c \
jit_hppa-sz.c \
jit_ia64.c \
jit_ia64-cpu.c \
jit_ia64-fpu.c \
jit_ia64-sz.c \
jit_mips.c \
jit_mips-cpu.c \
jit_mips-fpu.c \
jit_mips-sz.c \
jit_ppc.c \
jit_ppc-cpu.c \
jit_ppc-fpu.c \
jit_ppc-sz.c \
jit_s390x.c \
jit_s390x-cpu.c \
jit_s390x-fpu.c \
jit_s390x-sz.c \
jit_sparc.c \
jit_sparc-cpu.c \
jit_sparc-fpu.c \
jit_sparc-sz.c \
jit_x86.c \
jit_x86-cpu.c \
jit_x86-sse.c \
jit_x86-x87.c
jit_x86-x87.c \
jit_x86-sz.c

350
lib/jit_aarch64-sz.c Normal file
View file

@ -0,0 +1,350 @@
#if __WORDSIZE == 64
#define JIT_INSTR_MAX 64
0,
0,
0,
0,
0,
0,
0,
64,
0,
4,
12,
4,
12,
4,
8,
4,
16,
4,
12,
4,
8,
4,
12,
12,
20,
12,
20,
4,
12,
4,
12,
20,
16,
20,
16,
12,
20,
12,
20,
4,
12,
4,
12,
4,
12,
4,
4,
4,
4,
4,
4,
4,
4,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
4,
16,
4,
4,
4,
4,
4,
4,
4,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
8,
8,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
12,
4,
12,
4,
12,
4,
12,
4,
4,
4,
4,
4,
4,
4,
4,
8,
8,
8,
8,
8,
8,
8,
8,
8,
24,
8,
8,
8,
8,
8,
8,
8,
8,
8,
24,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
0,
20,
4,
20,
64,
0,
4,
12,
4,
12,
4,
12,
4,
12,
4,
4,
4,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
8,
4,
4,
4,
4,
8,
8,
16,
8,
8,
8,
16,
8,
8,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
0,
4,
12,
4,
12,
4,
12,
4,
12,
4,
4,
4,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
8,
4,
4,
4,
4,
12,
8,
16,
8,
8,
8,
16,
8,
8,
8,
16,
8,
16,
8,
20,
8,
16,
8,
16,
8,
16,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
16,
24,
8,
16,
8,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#endif /* __WORDSIZE */

View file

@ -711,7 +711,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

704
lib/jit_arm-sz.c Normal file
View file

@ -0,0 +1,704 @@
#if __WORDSIZE == 32
#if defined(__ARM_PCS_VFP)
#define JIT_INSTR_MAX 44
0,
0,
0,
0,
0,
0,
0,
26,
0,
4,
8,
4,
8,
4,
4,
4,
8,
4,
8,
4,
4,
4,
8,
4,
12,
4,
8,
32,
44,
24,
28,
18,
22,
18,
22,
24,
28,
24,
28,
4,
4,
4,
8,
4,
8,
4,
4,
4,
4,
4,
4,
4,
4,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
4,
8,
4,
4,
4,
4,
0,
0,
4,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
0,
0,
0,
0,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
0,
0,
0,
0,
4,
12,
4,
12,
4,
12,
0,
0,
4,
4,
4,
4,
4,
4,
0,
0,
8,
8,
8,
8,
8,
8,
8,
8,
8,
16,
8,
8,
8,
8,
8,
8,
8,
8,
8,
16,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
0,
4,
4,
12,
16,
0,
4,
8,
4,
8,
4,
8,
4,
8,
4,
4,
4,
18,
30,
20,
32,
18,
30,
18,
30,
18,
30,
18,
30,
18,
30,
18,
30,
24,
36,
18,
30,
18,
30,
24,
36,
18,
30,
18,
30,
8,
0,
8,
4,
4,
12,
4,
12,
8,
4,
4,
12,
8,
4,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
16,
28,
16,
28,
20,
32,
16,
28,
12,
24,
20,
32,
12,
24,
12,
24,
0,
4,
20,
4,
20,
4,
20,
4,
20,
4,
4,
4,
18,
34,
20,
36,
18,
34,
18,
34,
18,
34,
18,
34,
18,
34,
18,
34,
24,
40,
18,
34,
18,
34,
24,
40,
18,
34,
18,
34,
8,
0,
8,
4,
4,
16,
4,
12,
8,
4,
4,
12,
8,
4,
12,
28,
12,
28,
12,
28,
12,
28,
12,
28,
12,
28,
16,
32,
16,
32,
20,
36,
16,
32,
12,
28,
20,
36,
12,
28,
12,
28,
0,
0,
0,
0,
0,
4,
8,
0,
0,
0,
0,
#endif /* __ARM_PCS_VFP */
#endif /* __WORDSIZE */
#if __WORDSIZE == 32
#if !defined(__ARM_PCS_VFP)
#define JIT_INSTR_MAX 74
0,
0,
0,
0,
0,
0,
0,
18,
0,
4,
8,
4,
8,
4,
4,
4,
8,
4,
8,
4,
4,
4,
8,
4,
12,
4,
8,
32,
44,
24,
28,
18,
22,
18,
22,
24,
28,
24,
28,
4,
4,
4,
8,
4,
8,
4,
4,
4,
4,
4,
4,
4,
4,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
14,
4,
8,
4,
4,
4,
4,
0,
0,
4,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
0,
0,
0,
0,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
0,
0,
0,
0,
4,
12,
4,
12,
4,
12,
0,
0,
4,
4,
4,
4,
4,
4,
0,
0,
8,
8,
8,
8,
8,
8,
8,
8,
8,
16,
8,
8,
8,
8,
8,
8,
8,
8,
8,
16,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
0,
4,
4,
12,
12,
0,
22,
22,
22,
22,
22,
22,
22,
22,
12,
12,
18,
20,
30,
20,
32,
20,
30,
20,
30,
20,
30,
24,
30,
50,
58,
50,
58,
50,
58,
50,
58,
50,
58,
54,
62,
24,
30,
50,
58,
16,
0,
32,
22,
8,
12,
8,
16,
8,
8,
8,
16,
8,
8,
24,
24,
24,
28,
24,
44,
24,
28,
24,
28,
24,
28,
24,
28,
24,
28,
52,
60,
24,
28,
24,
28,
52,
60,
24,
28,
24,
28,
0,
34,
36,
34,
36,
34,
36,
34,
36,
20,
20,
26,
28,
34,
28,
36,
28,
34,
28,
34,
28,
34,
32,
34,
66,
70,
66,
70,
66,
70,
66,
70,
66,
70,
70,
74,
32,
34,
66,
70,
20,
0,
36,
22,
16,
20,
16,
24,
20,
16,
16,
24,
20,
16,
32,
34,
32,
34,
32,
50,
32,
34,
32,
34,
32,
34,
32,
34,
32,
34,
68,
72,
32,
34,
32,
34,
68,
72,
32,
34,
32,
34,
4,
8,
0,
6,
8,
12,
12,
0,
0,
0,
0,
#endif /* __ARM_PCS_VFP */
#endif /* __WORDSIZE */

View file

@ -1026,7 +1026,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

View file

@ -225,6 +225,7 @@ disasm_print_address(bfd_vma addr, struct disassemble_info *info)
(*info->fprintf_func)(info->stream, "0x%s", buffer);
# define _jit disasm_jit
# undef jit_pointer_p
# define jit_pointer_p(u) \
((u) >= _jit->code.ptr && (u) < _jit->pc.uc)
if (jit_pointer_p((jit_uint8_t *)(jit_word_t)addr)) {

350
lib/jit_hppa-sz.c Normal file
View file

@ -0,0 +1,350 @@
#if __WORDSIZE == 32
#define JIT_INSTR_MAX 64
0,
0,
0,
0,
0,
0,
0,
64,
0,
4,
12,
4,
12,
4,
8,
4,
12,
4,
12,
4,
8,
28,
36,
40,
44,
32,
40,
36,
40,
36,
40,
40,
40,
40,
40,
36,
40,
36,
40,
4,
12,
4,
12,
4,
12,
12,
4,
12,
4,
12,
4,
4,
4,
8,
8,
8,
8,
8,
8,
8,
8,
8,
12,
8,
8,
8,
8,
8,
8,
8,
8,
8,
8,
4,
8,
4,
4,
4,
4,
0,
0,
4,
8,
12,
4,
8,
8,
12,
4,
8,
4,
8,
0,
0,
0,
0,
8,
8,
4,
4,
8,
8,
4,
4,
4,
4,
0,
0,
0,
0,
4,
8,
4,
8,
4,
8,
0,
0,
8,
4,
8,
4,
8,
4,
0,
0,
8,
8,
8,
8,
8,
12,
8,
8,
8,
16,
8,
8,
8,
8,
8,
8,
8,
8,
8,
16,
12,
16,
12,
16,
8,
8,
8,
8,
8,
8,
8,
8,
12,
16,
16,
20,
12,
16,
16,
20,
0,
12,
40,
44,
64,
0,
4,
16,
4,
16,
4,
16,
4,
16,
4,
4,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
12,
0,
12,
4,
4,
12,
4,
12,
4,
4,
4,
12,
8,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
0,
4,
16,
4,
16,
4,
16,
4,
16,
4,
4,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
12,
0,
12,
4,
4,
12,
4,
12,
4,
4,
4,
12,
8,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#endif /* __WORDSIZE */

View file

@ -716,7 +716,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

350
lib/jit_ia64-sz.c Normal file
View file

@ -0,0 +1,350 @@
#if __WORDSIZE == 64
#define JIT_INSTR_MAX 144
0,
0,
0,
0,
16,
16,
48,
128,
0,
16,
32,
48,
48,
64,
64,
16,
32,
48,
48,
64,
64,
32,
48,
96,
80,
96,
80,
64,
80,
64,
80,
128,
112,
128,
112,
64,
80,
64,
80,
16,
32,
16,
32,
16,
32,
16,
16,
16,
16,
16,
16,
16,
0,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
32,
16,
16,
16,
16,
16,
16,
0,
16,
32,
0,
16,
16,
32,
0,
16,
16,
32,
0,
16,
16,
16,
32,
48,
16,
32,
32,
48,
16,
32,
32,
48,
16,
32,
16,
32,
16,
32,
0,
32,
16,
32,
0,
32,
16,
16,
32,
16,
16,
16,
32,
16,
16,
16,
16,
32,
32,
32,
32,
16,
64,
64,
32,
48,
32,
16,
16,
16,
16,
16,
64,
64,
32,
32,
32,
32,
112,
112,
64,
64,
112,
112,
64,
64,
112,
112,
64,
64,
112,
112,
64,
64,
0,
48,
32,
64,
144,
0,
0,
32,
16,
16,
0,
16,
144,
144,
16,
16,
80,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
48,
80,
16,
48,
16,
48,
48,
80,
16,
48,
16,
48,
32,
32,
32,
16,
16,
48,
16,
16,
0,
32,
16,
16,
16,
16,
32,
64,
48,
64,
64,
96,
48,
64,
32,
64,
48,
64,
48,
64,
48,
64,
112,
144,
48,
64,
48,
64,
96,
128,
48,
64,
32,
64,
0,
0,
32,
16,
16,
0,
16,
128,
144,
16,
16,
80,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
16,
48,
48,
80,
16,
48,
16,
48,
48,
80,
16,
48,
16,
48,
32,
32,
32,
16,
16,
48,
16,
16,
0,
32,
16,
16,
16,
16,
32,
64,
48,
64,
64,
96,
48,
80,
32,
64,
48,
64,
48,
64,
48,
64,
112,
144,
48,
64,
48,
64,
96,
128,
48,
64,
32,
64,
0,
0,
0,
0,
0,
0,
0,
16,
32,
0,
0,
#endif /* __WORDSIZE */

View file

@ -736,7 +736,6 @@ _jit_retval_d(jit_state_t *_jit, jit_int32_t r0)
jit_pointer_t
_emit_code(jit_state_t *_jit)
{
jit_uint8_t *end;
jit_node_t *node;
jit_node_t *temp;
jit_word_t word;
@ -850,11 +849,13 @@ _emit_code(jit_state_t *_jit)
patch(word, node); \
} \
break
#if GET_JIT_SIZE
/* default of 64 bytes is too low for some possible
* quite long code generation sequences, e.g. qdivi */
end = _jit->code.ptr + _jit->code.length - 4096;
_jitc->code.end = _jit->code.ptr + _jit->code.length - 4096;
#endif
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

View file

@ -86,29 +86,6 @@ jit_free(jit_pointer_t *ptr)
*ptr = NULL;
}
#if HAVE_MREMAP
jit_bool_t
_jit_remap(jit_state_t *_jit)
{
jit_uint8_t *code;
jit_word_t length;
length = _jitc->pool.length * 1024 * (_jitc->mult + 1);
code = mremap(_jit->code.ptr, _jit->code.length, length, 0, NULL);
if (code != MAP_FAILED) {
assert(code == _jit->code.ptr);
++_jitc->mult;
_jit->code.length = length;
_jitc->code.end = _jit->code.ptr + _jit->code.length - 64;
return (1);
}
return (0);
}
#endif
static void *
jit_default_alloc_func(size_t size)
{

704
lib/jit_mips-sz.c Normal file
View file

@ -0,0 +1,704 @@
#if __WORDSIZE == 32
#if defined(_ABIN32)
#define JIT_INSTR_MAX 44
0,
0,
0,
0,
0,
0,
0,
44,
0,
4,
12,
12,
20,
28,
28,
4,
12,
12,
20,
28,
28,
8,
16,
12,
20,
12,
20,
8,
16,
8,
16,
12,
16,
12,
16,
8,
16,
8,
16,
4,
12,
4,
12,
4,
12,
4,
4,
4,
4,
4,
4,
4,
8,
4,
4,
4,
4,
8,
12,
8,
12,
12,
12,
8,
12,
8,
12,
4,
8,
4,
8,
8,
8,
4,
8,
8,
4,
8,
4,
0,
0,
4,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
0,
0,
0,
0,
8,
4,
8,
4,
8,
4,
8,
4,
8,
4,
0,
0,
0,
0,
4,
12,
4,
12,
4,
12,
0,
0,
8,
4,
8,
4,
8,
4,
0,
0,
12,
12,
12,
12,
12,
16,
12,
16,
8,
16,
12,
12,
12,
12,
12,
16,
12,
16,
8,
16,
12,
12,
12,
12,
28,
28,
16,
20,
28,
28,
16,
20,
28,
28,
16,
20,
28,
28,
16,
20,
0,
8,
12,
16,
44,
0,
4,
16,
4,
16,
4,
16,
4,
16,
4,
4,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
8,
0,
8,
4,
4,
12,
4,
12,
8,
4,
4,
12,
8,
4,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
0,
4,
16,
4,
16,
4,
16,
4,
16,
4,
4,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
8,
0,
8,
4,
4,
12,
4,
12,
8,
4,
4,
12,
8,
4,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
0,
0,
0,
0,
0,
0,
0,
4,
12,
0,
0,
#endif /* _ABIN32 */
#endif /* __WORDSIZE */
#if __WORDSIZE == 32
#if !defined(_ABIN32)
#define JIT_INSTR_MAX 96
0,
0,
0,
0,
0,
0,
0,
96,
0,
4,
12,
12,
20,
28,
28,
4,
12,
12,
20,
28,
28,
8,
16,
12,
20,
12,
20,
8,
16,
8,
16,
12,
16,
12,
16,
8,
16,
8,
16,
4,
12,
4,
12,
4,
12,
4,
4,
4,
4,
4,
4,
4,
8,
4,
4,
4,
4,
8,
12,
8,
12,
12,
12,
8,
12,
8,
12,
4,
8,
4,
8,
8,
8,
4,
8,
8,
4,
8,
4,
0,
0,
56,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
0,
0,
0,
0,
8,
4,
8,
4,
8,
4,
8,
4,
8,
4,
0,
0,
0,
0,
4,
12,
4,
12,
4,
12,
0,
0,
8,
4,
8,
4,
8,
4,
0,
0,
12,
12,
12,
12,
12,
16,
12,
16,
8,
16,
12,
12,
12,
12,
12,
16,
12,
16,
8,
16,
12,
12,
12,
12,
28,
28,
16,
20,
28,
28,
16,
20,
28,
28,
16,
20,
28,
28,
16,
20,
0,
8,
12,
16,
96,
0,
4,
16,
4,
16,
4,
16,
4,
16,
4,
4,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
8,
0,
8,
4,
4,
12,
4,
12,
8,
4,
4,
12,
8,
4,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
0,
4,
20,
4,
20,
4,
20,
4,
20,
4,
4,
4,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
16,
40,
8,
0,
8,
4,
4,
24,
8,
16,
12,
8,
8,
16,
12,
8,
12,
28,
12,
28,
12,
28,
12,
28,
12,
28,
12,
36,
12,
36,
12,
36,
12,
36,
12,
36,
12,
36,
12,
28,
12,
28,
12,
36,
4,
8,
0,
0,
4,
8,
8,
0,
0,
0,
0,
#endif /* _ABIN32 */
#endif /* __WORDSIZE */

View file

@ -972,7 +972,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

1056
lib/jit_ppc-sz.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -869,7 +869,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

350
lib/jit_s390x-sz.c Normal file
View file

@ -0,0 +1,350 @@
#if __WORDSIZE == 64
#define JIT_INSTR_MAX 68
0,
0,
0,
0,
0,
0,
2,
38,
0,
8,
24,
8,
20,
8,
12,
12,
24,
12,
20,
12,
12,
8,
24,
60,
68,
16,
32,
12,
28,
16,
32,
16,
20,
20,
24,
12,
28,
16,
32,
8,
20,
8,
20,
8,
24,
6,
10,
6,
10,
6,
10,
4,
12,
20,
24,
20,
24,
20,
24,
20,
24,
20,
24,
20,
24,
20,
24,
20,
24,
20,
24,
20,
24,
4,
16,
4,
4,
4,
4,
4,
4,
4,
6,
18,
6,
18,
6,
18,
6,
18,
6,
18,
6,
18,
6,
18,
14,
6,
14,
6,
14,
6,
14,
6,
14,
6,
14,
6,
14,
6,
4,
16,
4,
16,
4,
16,
6,
18,
12,
4,
12,
4,
12,
6,
14,
6,
10,
14,
10,
14,
10,
14,
10,
14,
10,
26,
10,
14,
10,
14,
10,
14,
10,
14,
10,
26,
18,
18,
18,
18,
10,
14,
10,
14,
10,
14,
10,
14,
10,
14,
10,
14,
10,
14,
10,
14,
0,
18,
2,
18,
36,
0,
6,
16,
8,
16,
6,
16,
8,
16,
4,
4,
4,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
20,
30,
16,
26,
16,
26,
20,
30,
16,
26,
16,
26,
4,
4,
4,
4,
2,
10,
4,
16,
12,
4,
4,
16,
12,
4,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
18,
28,
10,
20,
10,
20,
18,
28,
10,
20,
10,
20,
0,
6,
16,
8,
16,
6,
16,
8,
16,
4,
4,
4,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
16,
26,
20,
30,
16,
26,
16,
26,
20,
30,
16,
26,
16,
26,
4,
4,
4,
4,
2,
10,
4,
16,
12,
4,
4,
16,
12,
4,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
10,
20,
18,
28,
10,
20,
10,
20,
18,
28,
10,
20,
10,
20,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#endif /* __WORDSIZE */

View file

@ -701,7 +701,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

128
lib/jit_size.c Normal file
View file

@ -0,0 +1,128 @@
/*
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* 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.
*
* Authors:
* Paulo Cesar Pereira de Andrade
*/
#include <lightning.h>
#include <lightning/jit_private.h>
#if GET_JIT_SIZE
# include <stdio.h>
#endif
/*
* Initialization
*/
static jit_int16_t _szs[jit_code_x86_retval_d + 1] = {
#if GET_JIT_SIZE
# define JIT_INSTR_MAX 256
#else
# if defined(__i386__) || defined(__x86_64__)
# include "jit_x86-sz.c"
# elif defined(__mips__)
# include "jit_mips-sz.c"
# elif defined(__arm__)
# include "jit_arm-sz.c"
# elif defined(__ppc__) || defined(__powerpc__)
# include "jit_ppc-sz.c"
# elif defined(__sparc__)
# include "jit_sparc-sz.c"
# elif defined(__ia64__)
# include "jit_ia64-sz.c"
# elif defined(__hppa__)
# include "jit_hppa-sz.c"
# elif defined(__aarch64__)
# include "jit_aarch64-sz.c"
# elif defined(__s390x__)
# include "jit_s390x-sz.c"
# endif
#endif
};
/*
* Implementation
*/
void
jit_init_size(void)
{
#if DEBUG
# if !GET_JIT_SIZE
jit_word_t offset;
for (offset = 0; offset < jit_size(_szs); offset++)
if (_szs[offset] != 0)
return;
/* Ensure data was collected */
abort();
# endif
#endif
}
#if GET_JIT_SIZE
void
_jit_size_prepare(jit_state_t *_jit)
{
_jitc->cptr = _jit->code.ptr;
_jitc->size = _jit->pc.w;
}
void
_jit_size_collect(jit_state_t *_jit, jit_node_t *node)
{
jit_word_t length;
if (_jitc->cptr == _jit->code.ptr) {
length = _jit->pc.w - _jitc->size;
if (_szs[node->code] < length)
_szs[node->code] = length;
}
}
#else
jit_word_t
_jit_get_size(jit_state_t *_jit)
{
jit_word_t size;
jit_node_t *node;
for (size = 0, node = _jitc->head; node; node = node->next)
size += _szs[node->code];
return ((size + 4095) & -4096);
}
#endif
jit_word_t
jit_get_max_instr(void)
{
return (JIT_INSTR_MAX);
}
void
jit_finish_size(void)
{
#if GET_JIT_SIZE
FILE *fp;
jit_word_t offset;
/* Define a single path */
fp = fopen(JIT_SIZE_PATH, "a");
assert(fp);
for (offset = 0; offset < jit_size(_szs); offset++)
fprintf(fp, "%d %d\n", offset, _szs[offset]);
fclose(fp);
#endif
}

350
lib/jit_sparc-sz.c Normal file
View file

@ -0,0 +1,350 @@
#if __WORDSIZE == 32
#define JIT_INSTR_MAX 28
0,
0,
0,
0,
0,
0,
0,
16,
0,
4,
12,
4,
12,
4,
4,
4,
12,
4,
12,
4,
4,
4,
12,
8,
16,
8,
16,
12,
20,
8,
16,
28,
24,
24,
20,
20,
28,
16,
24,
4,
12,
4,
12,
4,
12,
4,
4,
4,
4,
4,
4,
4,
4,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
4,
8,
8,
4,
8,
8,
0,
0,
4,
4,
12,
4,
12,
4,
12,
4,
12,
4,
12,
0,
0,
0,
0,
4,
4,
4,
4,
4,
4,
4,
4,
4,
4,
0,
0,
0,
0,
4,
12,
4,
12,
4,
12,
0,
0,
4,
4,
4,
4,
4,
4,
0,
0,
12,
12,
12,
12,
12,
12,
12,
12,
12,
20,
12,
12,
12,
12,
12,
12,
12,
12,
12,
20,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
12,
0,
16,
8,
16,
24,
0,
4,
16,
4,
16,
4,
16,
4,
16,
4,
4,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
12,
0,
12,
4,
4,
12,
4,
12,
4,
4,
4,
12,
4,
4,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
0,
4,
16,
4,
16,
4,
16,
4,
16,
8,
8,
4,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
16,
28,
12,
0,
16,
4,
8,
12,
4,
12,
4,
4,
4,
12,
4,
4,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
12,
24,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#endif /* __WORDSIZE */

View file

@ -702,7 +702,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

700
lib/jit_x86-sz.c Normal file
View file

@ -0,0 +1,700 @@
#if __WORDSIZE == 32
#define JIT_INSTR_MAX 26
0,
0,
0,
0,
0,
0,
3,
26,
0,
3,
6,
4,
6,
4,
5,
4,
6,
6,
6,
6,
5,
5,
7,
20,
23,
20,
23,
21,
24,
22,
25,
23,
24,
24,
25,
21,
24,
22,
25,
4,
7,
4,
8,
4,
8,
16,
7,
16,
5,
16,
5,
4,
4,
15,
16,
15,
16,
15,
16,
15,
16,
15,
16,
15,
16,
15,
16,
15,
16,
15,
16,
15,
16,
2,
5,
11,
11,
3,
3,
0,
0,
4,
3,
7,
3,
7,
3,
7,
3,
7,
2,
6,
0,
0,
0,
0,
4,
4,
4,
4,
4,
4,
4,
4,
3,
6,
0,
0,
0,
0,
10,
14,
3,
7,
2,
6,
0,
0,
11,
11,
4,
4,
3,
6,
0,
0,
8,
9,
8,
9,
8,
12,
8,
9,
8,
12,
8,
9,
8,
9,
8,
9,
8,
9,
8,
12,
8,
12,
8,
12,
8,
9,
8,
9,
8,
9,
8,
9,
8,
9,
8,
9,
8,
9,
8,
9,
0,
5,
2,
5,
24,
0,
8,
16,
12,
16,
8,
16,
12,
16,
12,
12,
6,
13,
21,
13,
21,
15,
22,
13,
21,
13,
21,
18,
25,
13,
21,
13,
21,
13,
20,
13,
21,
13,
21,
13,
20,
13,
20,
13,
20,
7,
0,
7,
4,
10,
8,
4,
8,
5,
5,
6,
10,
7,
7,
10,
18,
10,
18,
12,
20,
10,
18,
10,
18,
13,
21,
10,
18,
10,
18,
10,
18,
10,
18,
10,
18,
10,
18,
10,
17,
10,
18,
0,
8,
16,
12,
16,
8,
16,
12,
16,
18,
13,
6,
13,
21,
13,
21,
15,
23,
13,
21,
13,
21,
18,
26,
13,
21,
13,
21,
13,
21,
13,
21,
13,
21,
13,
21,
13,
21,
13,
21,
7,
0,
7,
4,
10,
8,
4,
8,
5,
8,
6,
10,
7,
7,
10,
18,
10,
18,
12,
20,
10,
18,
10,
18,
13,
21,
10,
18,
10,
18,
10,
18,
10,
18,
10,
18,
10,
18,
10,
18,
10,
18,
0,
0,
0,
0,
0,
0,
0,
0,
0,
14,
10,
#endif /* __WORDSIZE */
#if __WORDSIZE == 64
#define JIT_INSTR_MAX 43
0,
0,
0,
0,
0,
0,
7,
43,
0,
5,
13,
6,
13,
6,
7,
6,
13,
9,
13,
9,
7,
7,
14,
20,
30,
20,
30,
22,
29,
23,
30,
25,
32,
26,
33,
22,
29,
23,
30,
6,
13,
6,
13,
6,
13,
9,
8,
9,
7,
9,
7,
6,
6,
13,
14,
13,
14,
13,
14,
13,
14,
13,
14,
13,
14,
13,
14,
13,
14,
13,
14,
13,
14,
3,
10,
4,
4,
4,
4,
3,
3,
6,
5,
9,
5,
9,
5,
9,
5,
9,
4,
8,
4,
8,
4,
8,
6,
5,
6,
5,
6,
5,
6,
5,
5,
7,
5,
4,
5,
7,
4,
8,
5,
9,
4,
8,
4,
8,
5,
4,
6,
5,
5,
6,
5,
7,
9,
10,
9,
10,
9,
13,
9,
10,
9,
19,
9,
10,
9,
10,
9,
10,
9,
10,
9,
19,
9,
13,
9,
13,
9,
10,
9,
10,
9,
10,
9,
10,
9,
10,
9,
10,
9,
10,
9,
10,
0,
5,
3,
13,
37,
0,
10,
20,
15,
20,
10,
20,
15,
20,
14,
15,
5,
11,
26,
11,
26,
13,
28,
11,
26,
11,
26,
16,
31,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
5,
5,
5,
5,
5,
15,
6,
10,
7,
6,
6,
10,
7,
7,
10,
20,
10,
25,
12,
27,
10,
25,
10,
25,
13,
28,
10,
25,
10,
25,
10,
25,
10,
25,
10,
25,
10,
25,
10,
25,
10,
25,
0,
10,
25,
15,
25,
10,
25,
15,
25,
21,
16,
5,
12,
27,
12,
27,
14,
29,
12,
27,
12,
27,
17,
32,
12,
27,
12,
27,
12,
27,
12,
27,
12,
27,
12,
27,
12,
27,
12,
27,
5,
5,
5,
5,
5,
15,
6,
10,
7,
6,
6,
10,
7,
7,
11,
26,
11,
26,
13,
28,
11,
26,
11,
26,
14,
29,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
11,
26,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#endif /* __WORDSIZE */

View file

@ -1127,7 +1127,7 @@ _emit_code(jit_state_t *_jit)
} \
break
for (node = _jitc->head; node; node = node->next) {
if (_jit->pc.uc >= _jitc->code.end && !jit_remap())
if (_jit->pc.uc >= _jitc->code.end)
return (NULL);
value = jit_classify(node->code);

View file

@ -180,12 +180,14 @@ init_jit(char *progname)
jit_progname = progname;
jit_get_cpu();
jit_init_debug();
jit_init_size();
}
void
finish_jit(void)
{
jit_finish_debug();
jit_finish_size();
}
jit_int32_t
@ -1644,6 +1646,9 @@ _jit_reglive(jit_state_t *_jit, jit_node_t *node)
void
_jit_regarg_set(jit_state_t *_jit, jit_node_t *node, jit_int32_t value)
{
#if GET_JIT_SIZE
jit_size_prepare();
#endif
if (value & jit_cc_a0_reg) {
if (value & jit_cc_a0_rlh) {
jit_regset_setbit(&_jitc->regarg, jit_regno(node->u.q.l));
@ -1661,6 +1666,9 @@ _jit_regarg_set(jit_state_t *_jit, jit_node_t *node, jit_int32_t value)
void
_jit_regarg_clr(jit_state_t *_jit, jit_node_t *node, jit_int32_t value)
{
#if GET_JIT_SIZE
jit_size_collect(node);
#endif
if (value & jit_cc_a0_reg) {
if (value & jit_cc_a0_rlh) {
jit_regset_clrbit(&_jitc->regarg, jit_regno(node->u.q.l));
@ -1690,12 +1698,15 @@ _jit_emit(jit_state_t *_jit)
jit_epilog();
jit_optimize();
/* Heuristic to guess code buffer size */
_jitc->mult = 4;
_jitc->emit = 1;
#if GET_JIT_SIZE
/* Heuristic to guess code buffer size */
_jitc->mult = 4;
_jit->code.length = _jitc->pool.length * 1024 * _jitc->mult;
#else
_jit->code.length = jit_get_size();
#endif
#if defined(__sgi)
mmap_fd = open("/dev/zero", O_RDWR);
@ -1704,7 +1715,8 @@ _jit_emit(jit_state_t *_jit)
PROT_EXEC | PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, mmap_fd, 0);
assert(_jit->code.ptr != MAP_FAILED);
_jitc->code.end = _jit->code.ptr + _jit->code.length - 64;
_jitc->code.end = _jit->code.ptr + _jit->code.length -
jit_get_max_instr();
_jit->pc.uc = _jit->code.ptr;
for (;;) {
@ -1715,8 +1727,13 @@ _jit_emit(jit_state_t *_jit)
node->code == jit_code_epilog))
node->flag &= ~jit_flag_patch;
}
#if GET_JIT_SIZE
++_jitc->mult;
length = _jitc->pool.length * 1024 * _jitc->mult;
#else
/* Should only happen on very special cases */
length = _jit->code.length + 4096;
#endif
#if !HAVE_MREMAP
munmap(_jit->code.ptr, _jit->code.length);
@ -1738,7 +1755,8 @@ _jit_emit(jit_state_t *_jit)
assert(_jit->code.ptr != MAP_FAILED);
_jit->code.length = length;
_jitc->code.end = _jit->code.ptr + _jit->code.length - 64;
_jitc->code.end = _jit->code.ptr + _jit->code.length -
jit_get_max_instr();
_jit->pc.uc = _jit->code.ptr;
_jitc->patches.offset = 0;
}

84
size.c Normal file
View file

@ -0,0 +1,84 @@
/*
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* 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.
*
* Authors:
* Paulo Cesar Pereira de Andrade
*/
#include <lightning.h>
#include <lightning/jit_private.h>
#include <stdio.h>
jit_int16_t _szs[jit_code_x86_retval_d + 1];
int
main(int argc, char *argv[])
{
FILE *fp;
jit_word_t offset;
int code, size, max;
if ((fp = fopen(JIT_SIZE_PATH, "r")) == NULL)
exit(-1);
while (fscanf(fp, "%d %d\n", &code, &size) == 2) {
if (_szs[code] < size)
_szs[code] = size;
}
fclose(fp);
max = 0;
for (offset = 0; offset <= jit_code_x86_retval_d; offset++)
if (max < _szs[offset])
max = _szs[offset];
if ((fp = fopen(JIT_SIZE_PATH, "w")) == NULL)
exit(-1);
fprintf(fp, "#if __WORDSIZE == %d\n", __WORDSIZE);
#if defined(__arm__)
# if defined(__ARM_PCS_VFP)
fprintf(fp, "#if defined(__ARM_PCS_VFP)\n");
# else
fprintf(fp, "#if !defined(__ARM_PCS_VFP)\n");
# endif
#elif defined(__mips__)
# if defined(_ABIN32)
fprintf(fp, "#if defined(_ABIN32)\n");
# else
fprintf(fp, "#if !defined(_ABIN32)\n");
# endif
#elif defined(__ppc__)
fprintf(fp, "#if defined(__ppc__)\n");
#elif defined(__powerpc__)
fprintf(fp, "#if defined(__powerpc__)\n");
#endif
fprintf(fp, "#define JIT_INSTR_MAX %d\n", max);
for (offset = 0; offset <= jit_code_x86_retval_d; offset++)
fprintf(fp, " %d,\n", _szs[offset]);
#if defined(__arm__)
fprintf(fp, "#undef /* __ARM_PCS_VFP */\n");
#elif defined(__mips__)
fprintf(fp, "#endif /* _ABIN32 */\n");
#elif defined(__ppc__)
fprintf(fp, "#endif /* __ppc__ */\n");
#elif defined(__powerpc__)
fprintf(fp, "#endif /* __powerpc__ */\n");
#endif
fprintf(fp, "#endif /* __WORDSIZE */\n");
fclose(fp);
return (0);
}