1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-03 05:20:16 +02:00
Commit graph

58 commits

Author SHA1 Message Date
pcpa
1ce1d00db8 Move multiply defined macro to a single header file. 2015-05-25 15:53:17 -03:00
pcpa
0b6cc01eea Intermediate, fully functional, rework for variadic functions
* check/cva_list.c: New file implementing a test to ensure
	the value returned by jit_va_start is a valid C va_list.

	* check/va_list.ok: New simple helper file, as now the
	va_list.tst test is enabled.

	* check/va_list.tst: Rewritten for an extensive variadic
	jit functions test.

	* check/Makefile.am: Update for the new tests.

	* lib/jit_arm-cpu.c, lib/jit_arm-swf.c, lib/jit_arm-vfp.c,
	lib/jit_arm.c: Correct broken software float in a previous
	commit. Note that the hard float abi implementation is known
	broken at this time, for special cases involving variadic
	functions, and should be corrected next.

	lib/jit_x86-cpu.c, lib/jit_x86-sz.c, lib/jit_x86.c: Correct
	the jit_va_list_t semantics to match C va_list.
2015-05-25 15:20:24 -03:00
pcpa
8cb302f337 arm: Add initial jit_va_ calls to arm
* lib/jit_arm-cpu.c, lib/jit_arm-swf.c, lib/jit_arm-vfp.c,
	lib/jit_arm.c: Add base support to jit vararg
	functions to the arm backend.
2015-05-01 14:05:00 -03:00
pcpa
d639674549 Add initial support to implement vararg jit functions
* include/lightning.h, include/lightning/jit_private.h,
	lib/jit_names.c, lib/lightning.c: Add initial support
	for the new jit_va_start, jit_va_arg, jit_va_arg_d, and
	jit_va_end interfaces. The jit_va_start call is supposed
	to return a va_list compatible pointer, but not yet
	decided if it will be "declared" stdarg compatible,
	as for now only x86 support has been added (and should
	be compatible), but issues may arise on other backends.

	* check/lightning.c: Add wrappers to call the new jit_va_*
	interfaces.

	* lib/jit_x86-cpu.c, lib/jit_x86.c: Implement the new
	jit_va_* for x86.

	* lib/jit_x86-sz.c: Add fields, but not yet fully updated,
	as this is an intermediate commit.

	* lib/jit_aarch64-sz.c, lib/jit_aarch64.c,
	lib/jit_alpha-sz.c, lib/jit_alpha.c,
	lib/jit_arm-sz.c, lib/jit_arm.c,
	lib/jit_hppa-sz.c, lib/jit_hppa.c,
	lib/jit_ia64-sz.c, lib/jit_ia64.c,
	lib/jit_mips-sz.c, lib/jit_mips.c,
	lib/jit_ppc-sz.c, lib/jit_ppc.c,
	lib/jit_s390-sz.c, lib/jit_s390.c,
	lib/jit_sparc-sz.c, lib/jit_sparc.c: Prepare for the
	new jit_va_* interfaces. Not yet implemented, and will
	cause an assertion if used.

	* check/va_list.tst: Simple early test case, that works
	on x86_64, x32, ix86, cygwin, and cygwin64.
2015-04-27 21:12:32 -03:00
pcpa
a15f261afc Update copyright date 2015-04-26 14:33:41 -03:00
pcpa
ad589fbb0a Implement jit_allocar for dynamic stack allocation
* include/lightning.h, include/lightning/jit_private.h,
	lib/jit_aarch64-cpu.c, lib/jit_aarch64.c,
	lib/jit_alpha-cpu.c, lib/jit_alpha.c,
	lib/jit_arm-cpu.c, lib/jit_arm.c,
	lib/jit_hppa-cpu.c, lib/jit_hppa.c,
	lib/jit_ia64-cpu.c, lib/jit_ia64.c,
	lib/jit_mips-cpu.c, lib/jit_mips.c,
	lib/jit_ppc-cpu.c, lib/jit_ppc.c,
	lib/jit_s390-cpu.c, lib/jit_s390.c,
	lib/jit_sparc-cpu.c, lib/jit_sparc.c,
	lib/jit_x86-cpu.c, lib/jit_x86.c: Implement the new
	jit_allocar(offs, size) interface, that receives
	two integer registers arguments, allocates space
	dynamically in the stack, returns the offset in
	the first argument, and uses the second argument
	for the size in bytes of the memory to be allocated.

	* check/allocar.ok, check/allocar.tst: New files
	implementing test cases for the new jit_allocar
	interface.

	* check/Makefile.am, check/lightning.c: Update for
	the new test case and interface.

	* doc/body.texi: Add documentation of the new
	interface.
2015-02-17 14:37:57 -02:00
Paulo Andrade
678280734e Add new --enable-devel-disassembler configure option
* configure.ac, include/lightning/jit_private.h,
	lib/jit_aarch64.c, lib/jit_alpha.c, lib/jit_arm.c,
	lib/jit_disasm.c, lib/jit_hppa.c, lib/jit_ia64.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_print.c,
	lib/jit_s390.c, lib/jit_sparc.c, lib/jit_x86.c: Add a new
	--enable-devel-disassembler option, that should be used
	during development, or lightning debug. This option
	intermixes previous jit_print and jit_disassemble
	output, making it easier to visualize what lightning
	call was used, and what code was generated.
2015-02-02 20:49:22 -02:00
Paulo Andrade
1b055bf0d8 Make more readable always true test 2015-02-01 13:04:38 -02:00
Paulo Andrade
6db38b75e9 ARM: Do not limit to 24 bit displacement jump to unknown address
* lib/jit_arm-cpu.c, lib/jit_arm.c: Only limit to 24 bit
	displacement non conditional jump in the same jit_state_t.
2015-01-31 15:59:25 -02:00
pcpa
c8b6c36971 Implement the jit_arg_register_p predicate.
* include/lightning.h, lib/jit_aarch64.c,
	lib/jit_alpha.c, lib/jit_arm-vfp.c, lib/jit_arm.c,
	lib/jit_hppa.c,	lib/jit_ia64.c, lib/jit_mips.c,
	lib/jit_ppc.c, lib/jit_s390.c, lib/jit_sparc.c,
	lib/jit_x86.c: Add the new jit_arg_register_p predicate.
	The predicate is expected to be used to know if an
	argument is in a register, what would need special
	handling if code that can overwrite non callee save
	registers is executed.

	* check/carg.c: New test case to check consistency and
	expected usage of jit_arg_register_p.

	* check/Makefile.am: Update for new test case.
2015-01-18 11:24:25 -02:00
pcpa
73e520767f Remove inconsistent, public jit_arg_reg_p macro
* include/lightning/jit_aarch64.h,
	include/lightning/jit_alpha.h,
	include/lightning/jit_arm.h,
	include/lightning/jit_hppa.h,
	include/lightning/jit_mips.h,
	 include/lightning/jit_ppc.h,
	include/lightning/jit_s390.h,
	include/lightning/jit_sparc.h,
	include/lightning/jit_x86.h,
	lib/jit_aarch64.c, lib/jit_alpha.c,
	lib/jit_arm.c, lib/jit_hppa.c,
	lib/jit_ia64.c, lib/jit_mips.c,
	lib/jit_ppc.c, lib/jit_s390.c,
	lib/jit_sparc.c, lib/jit_x86.c: Remove jit_arg_reg_p and
	jit_arg_f_reg_p from a public header, and define it only
	on port specific files where an integer offset is used
	to qualify an argument identifier. Exported code expects
	an opaque pointer (but of jit_node_t* type) to "qualify"
	an argument identifier.
	This patch, and the code review/simplification done during
	it also corrected some bugs:
	o Inconsistent jit_arg_d value of double argument after 3
	  integer arguments in arm for jit_functions; tested, C
	  functions were being properly called.
	o Inconsistent use of getarg_{f,d} and putarg*_{f,d} on
	  s390 (32-bit) that happened to not have a proper test
	  case, as it would only happen for jit functions, and
	  tested, called C functions had proper arguments.
	o Corrected a "last minute" correction that did not go
	  to the committed version, and would not compile on hppa,
	  due to bad _jit_putargi_d prototype definition.
2015-01-17 17:31:09 -02:00
Paulo Andrade
27d9b68a3f Implement jit_putarg*
* include/lightning.h, lib/jit_aarch64.c,
	lib/jit_alpha.c, lib/jit_arm.c, lib/jit_hppa.c,
	lib/jit_ia64.c, lib/jit_mips.c,	lib/jit_ppc.c,
	lib/jit_s390.c, lib/jit_sparc.c, lib/jit_x86.c:
	Implement jit_putarg*. It works as a mix of jit_getarg*
	and jit_pusharg*, in the way that the first argument is
	a register or immediate, and the second is a pointer
	returned by jit_arg*. The use of the interface is to change
	values of arguments to the current jit function.

	* check/put.ok, check/put.tst: New test cases exercising
	the new jit_putarg* interface.

	* check/Makefile.am, check/lightning.c: Update for the
	new test case and interface.
2015-01-15 14:20:07 -02:00
pcpa
5eb3c3602f ARM: Better check for constants offset overflow
* lib/jit_arm.c: Better check for need to flush constants
	before the pool being no longer reachable.
2014-12-26 00:38:54 -02:00
pcpa
88aa2fcad2 Implement new, typed, jit_htonr* interfaces
* include/lightning.h: Split jit_htonr in the new 3 interfaces
	jit_htonr_us, jit_htonr_ui and jit_htonr_ul, the later only
	available on 64 bit. The plain/untyped jit_htonr macro call
	maps to the wordsize one.
	* lib/jit_aarch64-cpu.c,  lib/jit_aarch64-sz.c, lib/jit_aarch64.c,
	lib/jit_alpha-cpu.c, lib/jit_alpha-sz.c, lib/jit_alpha.c,
	lib/jit_arm-cpu.c, lib/jit_arm-sz.c, lib/jit_arm.c,
	lib/jit_hppa-cpu.c, lib/jit_hppa-sz.c, lib/jit_hppa.c,
	lib/jit_ia64-cpu.c, lib/jit_ia64-sz.c, lib/jit_ia64.c,
	lib/jit_mips-cpu.c, lib/jit_mips-sz.c, lib/jit_mips.c,
	lib/jit_ppc-cpu.c, lib/jit_ppc-sz.c, lib/jit_ppc.c,
	lib/jit_s390x-cpu.c, lib/jit_s390x-sz.c, lib/jit_s390x.c,
	lib/jit_sparc-cpu.c, lib/jit_sparc-sz.c, lib/jit_sparc.c,
	lib/jit_x86-cpu.c, lib/jit_x86-sz.c, lib/jit_x86.c:
	Update backends for the new jit_htonr*.
	* check/lightning.c, lib/jit_names.c, lib/lightning.c:
	Update for the new jit_htonr* interfaces.
	* check/Makefile.am: Update for new test cases.
	* check/hton.ok, check/hton.tst: New test cases.
2014-12-25 23:06:24 -02:00
Paulo Andrade
1cb0e18c7b ARM: Flush cache page by page
* lib/jit_arm.c: Call __clear_cache for every page.
	This should only be required for older boards or
	toolchain setup, but has been reported to be required
	for lightning at some point.
2014-12-21 21:21:54 -02:00
Paulo Andrade
f63d064a10 ARM: Correct constants offset check
* lib/jit_arm.c: Correct check to guard overflow of index
	of constants from program counter.
2014-12-21 21:21:54 -02:00
pcpa
7b449aa063 Implement jit_flush
* include/lightning/jit_private.h, lib/jit_aarch64.c,
	lib/jit_alpha.c, lib/jit_arm.c, lib/jit_hppa.c,
	lib/jit_ia64.c, lib/jit_mips.c, lib/jit_ppc.c,
	lib/jit_s390x.c, lib/jit_sparc.c, lib/jit_x86.c:
	Implement a private jit_flush call, that flushes
	the cache, if applicable, aligning down to the
	previous and up to the next page boundary.
2014-11-08 19:34:23 -02:00
pcpa
44519452d9 Add assertion to check for register allocation leaks
* lib/jit_aarch64.c, lib/jit_alpha.c, lib/jit_arm.c,
	lib/jit_hppa.c, lib/jit_ia64.c, lib/jit_mips.c, lib/jit_ppc.c,
	lib/jit_s390x.c, lib/jit_sparc.c, lib/jit_x86.c: Add an
	assertion to all code generation "drivers" to ensure
	_jitc->regarg is empty or in an expected state, after
	translation of a lightning instruction to native code.
	This change was a brute force test to find out other cases
	of a temporary not being release (like was happening with
	_bmsi and _bmci on x86), but no other case was found,
	after running make check, with assertions enabled, on all
	backends.
2014-10-26 18:25:41 -02:00
pcpa
960280decd Implement the jit_rsb* interface.
* check/alu_rsb.ok, check/alu_rsb.tst: New files implementing
	tests for jit_rsb*.

	* check/Makefile.am, check/lightning.c, include/lightning.h,
	lib/jit_aarch64-cpu.c, lib/jit_aarch64-fpu.c, lib/jit_aarch64-sz.c,
	lib/jit_aarch64.c, lib/jit_alpha-cpu.c, lib/jit_alpha-fpu.c,
	lib/jit_alpha-sz.c, lib/jit_alpha.c, lib/jit_arm-cpu.c,
	lib/jit_arm-swf.c, lib/jit_arm-sz.c, lib/jit_arm-vfp.c,
	lib/jit_arm.c, lib/jit_hppa-cpu.c, lib/jit_hppa-fpu.c,
	lib/jit_hppa-sz.c, lib/jit_hppa.c, lib/jit_ia64-cpu.c,
	lib/jit_ia64-fpu.c, lib/jit_ia64-sz.c, lib/jit_ia64.c,
	lib/jit_mips-cpu.c, lib/jit_mips-fpu.c, lib/jit_mips-sz.c,
	lib/jit_mips.c, lib/jit_names.c, lib/jit_ppc-cpu.c,
	lib/jit_ppc-fpu.c, lib/jit_ppc-sz.c, lib/jit_ppc.c,
	lib/jit_s390x-cpu.c, lib/jit_s390x-fpu.c, lib/jit_s390x-sz.c,
	lib/jit_s390x.c, lib/jit_sparc-cpu.c, lib/jit_sparc-fpu.c,
	lib/jit_sparc-sz.c, lib/jit_sparc.c, lib/jit_x86-cpu.c,
	lib/jit_x86-sse.c, lib/jit_x86-sz.c, lib/jit_x86-x87.c,
	lib/jit_x86.c, lib/lightning.c: Implement jit_rsb*. This
	was a missing lightning 1.x interface, that on most
	backends is synthesized, but on a few backends (hppa and ia64),
	it can generate better code as on those there is, or the
	only instruction with an immediate is in "rsb" format
	(left operand).
2014-10-18 11:31:18 -03:00
pcpa
afae5407f6 Implement the jit_align interface
* lib/jit_aarch64-cpu.c, lib/jit_alpha-cpu.c, lib/jit_arm-cpu.c,
	lib/jit_hppa-cpu.c, lib/jit_mips-cpu.c, lib/jit_ppc-cpu.c,
	lib/jit_sparc-cpu.c: Implement or correct the internal
	nop(count) call that receives an argument that tells the
	modulo bytes to align the code for the next instruction.

	* include/lightning.h, lib/lightning.c, lib/jit_aarch64.c,
	lib/jit_alpha.c, lib/jit_arm.c, lib/jit_hppa.c, lib/jit_ia64.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_s390x.c, lib/jit_sparc.c,
	lib/jit_x86.c: Implement the new jit_align() call that receive
	an argument, that tells the modulo, in bytes, to align the
	next instruction. In most backends the only value that makes
	a difference is a value that matches sizeof(void*), as all
	other values usually are already automatically aligned in
	labels, but not guaranteed to be aligned at word size bytes.

	* check/align.ok, check/align.tst: New files, implementing
	a simple test for the new jit_align() interface.

	* check/Makefile.am, check/lightning.c, lib/jit_aarch64-sz.c,
	lib/jit_alpha-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_print.c, lib/jit_s390x-sz.c, lib/jit_sparc-sz.c,
	lib/jit_x86-sz.c: Update for the new jit_code_align code and
	the jit_align() interface.
2014-10-14 17:05:25 -03:00
pcpa
839341a498 Implement jit_frame and jit_tramp interfaces
* include/lightning.h, include/lightning/jit_private.h,
	lib/jit_aarch64-cpu.c, lib/jit_alpha-cpu.c, lib/jit_arm-cpu.c,
	lib/jit_hppa-cpu.c, lib/jit_ia64-cpu.c, lib/jit_mips-cpu.c,
	lib/jit_ppc-cpu.c, lib/jit_s390x-cpu.c, lib/jit_sparc-cpu.c,
	lib/jit_x86-cpu.c, lib/lightning.c: Implement the new
	jit_frame and jit_tramp interfaces, that allow writing
	trampoline like calls, where a single dispatcher jit buffer
	is written, and later other jit buffers are created, with
	the same stack frame layout as the dispatcher. This is the
	logic that GNU Smalltalk used in lightning 1.x, and is required
	to make a sane port for lighting 2.x.

	* jit_ia64-cpu.c: Implement support for jit_frame and jit_tramp,
	and also correct wrong encoding for B4 instructions, that
	implement jmpr, as well as correct reverse logic in _jmpr,
	that was moving the branch register to the jump register,
	and not vice-versa.
	Also, if a stack frame is to be assumed, always assume it may
	call a function with up to 8 arguments, regardless of the
	hint frame argument.

	* lib/jit_arm.c: Add a new must_align_p() interface to ensure
	function prologs are always aligned. This condition was
	previously always true, somewhat by accident, but with
	jit_tramp it is not guaranteed.

	* jit_ia64-cpu.c: lib/jit_ppc.c: Add minor special handling
	required to implement jit_tramp, where a function descriptor
	should not be added before a prolog, as jit_tramp means omit
	prolog.

	* check/lightning.c: Update test driver for the new interfaces.

	* check/Makefile.am, check/tramp.tst, check/tramp.ok: Add
	a simple test and example of the jit_frame and jit_tramp
	usage implementing a simple Fibonacci function using a
	simulation of an interpreter stack and how it would handle
	state in language specific variables.

	* doc/body.texi: Add documentation for jit_frame and
	jit_tramp.
2014-10-14 17:04:40 -03:00
pcpa
20a2f1f9c5 Allow jit_jmpi on an immediate constant address.
* lib/jit_aarch64.c, lib/jit_alpha.c, lib/jit_arm.c,
	lib/jit_hppa.c, lib/jit_ia64.c, lib/jit_mips.c,
	lib/jit_ppc.c, lib/jit_s390x.c, lib/jit_sparc.c,
	lib/jit_x86.c, lib/lightning.c: Allow jit_jmpi on a
	target that is not a node. This may lead to hard to
	debug code generation, but is a required feature for
	certain generators, like the ones that used lightning
	1.2x. Note that previously, but not really well
	documented, it was instructed to use:
	jit_movi(rn, addr); jit_jmpr(rn);
	but now, plain:
	jit_patch_abs(jit_jmpi(), addr);
	should also work.
2014-10-14 17:04:13 -03:00
pcpa
0d9ac79a12 Do not pass null for free, memcpy and memmove
* lib/jit_memory.c: Do not call free on NULL pointers.

	* include/lightning/jit_private.h, lib/jit_note.c,
	lib/lightning.c: Add a wrapper to memcpy and memmove
	to not actually call those functions with a zero size
	argument, and likely also a null src or dst.
2014-07-29 10:29:49 -03:00
pcpa
354146b4ca ARM: Do not leave early init_jit if /proc is not mounted.
* lib/jit_arm.c: Do not get confused with default settings
	if /proc is not mounted on Linux specific code path.
2014-04-22 14:39:10 -03:00
pcpa
6fa5123855 ARM: Minor changes that should allow building on non gnu-linux/gcc.
* configure.ac, lib/jit_arm-swf.c, lib/jit_arm.c: Add
	changes that should at least allow building lightning
	on Apple iOS7.
2013-11-27 15:05:27 -02:00
pcpa
0ad5e08ee5 ARM: Correct build when disassembler is disabled. 2013-09-27 13:19:49 -03:00
pcpa
b768fab8b1 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.
2013-09-24 03:31:54 -03:00
pcpa
5a2df005c5 Correct wrong example and mt unsafe code in the arm backend.
* doc/body.texi: Correct reversed arguments in example of
	usage in a (possibly) multi threaded, multiple jit_state_t
	environments.

	* include/lightning/jit_arm.h, include/lightning/jit_private.h,
	lib/jit_arm-cpu.c, lib/jit_arm.c: Make a previously, non
	documented, global state private to the related jit_state_t
	generating code.
2013-09-12 00:24:19 -03:00
pcpa
b8770059dc Correct wrong test and update of arm thumb offset information.
* lib/jit_arm-cpu.c, lib/jit_arm.c: Correct wrong test and update
	of the thumb offset information, when checking if needing to
	patch a jump from arm to thumb mode. The problem would happen when
	remapping the code buffer, and the new address being lower than
	the previous one.
2013-08-29 17:08:05 -03:00
pcpa
b5763c42aa Correct license to properly advertise LGPLv3 and not GPLv3. 2013-08-11 18:08:52 -03:00
pcpa
89a0b7a10b New aarch64 port built on the Foundation v8 emulator.
* include/lightning/jit_aarch64.h, lib/jit_aarch64-cpu.c,
	lib/jit_aarch64-fpu.c, lib/jit_aarch64.c: New files
	implementing the new aarch64 port, as a new architecture,
	not as an expansion of the existing armv[4-7] port.

	* check/lightning.c: Add aarch64 support and a small
	change to recognize character constants as immediate
	values.

	* check/float.tst: Add aarch64 preprocessor conditionals
	to select proper expected value when converting [+-]Inf
	and NaN to integer.

	* include/lightning/jit_arm.h, lib/jit_arm.c: Minor changes
	to better match the new aarch64 files.

	* configure.ac, include/lightning.h,
	include/lightning/Makefile.am, include/lightning/jit_private.h,
	lib/Makefile.am, lib/lightning.c: Minor adjustments
	for the aarch64 port.
2013-07-16 20:09:02 -03:00
pcpa
ce6ab1f09e Prepare for the first alpha release of lightning 2.0. 2013-06-05 20:18:54 -03:00
pcpa
7bdd22bd99 Make it simpler to add support for more than 64 registers.
* include/lightning/jit_private.h, lib/jit_arm.c,
	lib/jit_mips-cpu.c, lib/jit_mips.c, lib/jit_ppc-cpu.c,
	lib/jit_ppc.c, lib/jit_print.c, lib/jit_sparc-cpu.c,
	lib/jit_sparc.c, lib/jit_x86-cpu.c, lib/jit_x86.c,
	lib/lightning.c: Change all jit_regset macros to take
	a pointer argument, to avoid structure copies when
	adding a port to an architecture with more than 64
	registers.
2013-04-10 15:07:01 -03:00
pcpa
066db584c9 Ensure the end argument of __clear_cache is page aligned.
* lib/jit_arm.c, lib/jit_ppc.c: Do not rely on __clear_cache
	aligning to the next page boundary the end argument. It may
	actually truncate it.
2013-04-08 18:00:36 -03:00
pcpa
51c96f9e19 Do not start over jit generation if can safely grow buffer size.
* include/lightning/jit_private.h, lib/jit_arm.c, lib/jit_memory.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_sparc.c, lib/jit_x86.c,
	lib/lightning.c: Do not start over jit generation if can grow
	the code buffer with mremap without moving the base pointer.
2013-03-29 12:53:40 -03:00
pcpa
c39def9dce Add a simple memory management wrapper.
* lib/jit_memory.c: Implement a simple memory allocation wrapper
	to allow overriding calls to malloc/calloc/realloc/free, as well
	as ensuring all memory containing pointers is zero or points to
	allocated memory.

	* include/lightning.h, include/lightning/jit_private.h: Definitions
	for the memory allocation wrapper.

	* lib/Makefile.am: Update for new jit_memory.c file.

	* lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips.c, lib/jit_note.c,
	lib/jit_ppc.c, lib/jit_sparc.c, lib/jit_x86.c, lib/lightning.c:
	Use the new memory allocation wrapper code.
2013-03-29 12:10:36 -03:00
pcpa
7ef8060fb2 Adapt PowerPC port to work in Darwin 32 bit and Linux 64 bit.
* include/lightning.h: Add check for __powerpc__ defined
	in Linux, while Darwin defines __ppc__.

	* include/lightning/jit_ppc.h: Adjust register definitions
	for Darwin 32 bit and Linux 64 bit ppc usage and/or ABI.

	* include/lightning/jit_private.h: Add proper check for
	Linux __powerpc__ and an data definition for an workaround
	to properly handle code that starts with a jump to a "main"
	label.

	* lib/jit_disasm.c: Add extra disassembler initialization
	for __powerpc64__.

	* lib/jit_ppc-cpu.c: Add extra macros and functions, and
	correct/adapt previous ones to handle powerpc64.

	* lib/jit_ppc-fpu.c: Adapt for 64 bit wordsize. Basically
	add conversion from/to int32/int64 and proper handling of
	load/store offsets too large for 32 bit.

	* lib/jit_ppc.c: Add calls to 64 bit codes and adaptation
	for the PowerPC 64 bit Linux ABI.

	* lib/jit_arm.c, lib/jit_mips.c, lib/jit_sparc, lib/jit_x86.c,
	lib/lightning.c: Correct off by one error when restarting jit
	of a function due to finding too late that needs to spill/reload
	some register. Problem was found by accident on a very special
	condition during PowerPC 64 code adaptation.
2013-03-10 15:36:25 -03:00
pcpa
9afca85921 Rework to better describe what is used only during jit generation.
* include/lightning/jit_private.h, lib/jit_arm-cpu.c,
	lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips-cpu.c,
	lib/jit_mips.c, lib/jit_note.c, lib/jit_ppc-cpu.c,
	lib/jit_ppc.c, lib/jit_print.c, lib/jit_sparc-cpu.c,
	lib/jit_sparc.c, lib/jit_x86-cpu.c, lib/jit_x86.c,
	lib/lightning.c: Add an extra structure for data storage
	during jit generation, and release it after generating
	jit, to reduce a bit memory usage, and also to make it
	easier to understand what data is available during
	jit runtime.
2013-03-06 16:49:26 -03:00
pcpa
12c35b7e83 Correct regression with float arguments in arm hardp
* lib/jit_arm.c: Correct jit_pushargi_f in the arm hardfp abi.
	Most of the logic uses even numbered register numbers, so that
	a float and a double can be used in the same register, but
	the abi requires packing the float arguments, so jit_pushargi_f
	needs to allocate a temporary register to modify only the
	proper register argument (or be very smart to push two
	immediate arguments if applicable).
2013-02-11 17:39:06 -02:00
pcpa
60c1c545fc Implement the "live" code to explicitly tell a register is live.
*include/lightning.h, lib/lightning.c: Add the new jit_live code
	to explicitly mark a register as live. It is required to avoid
	assuming functions always return a value in the gpr and fpr return
	register, and to avoid the need of some very specialized codes
	that vary too much from backend to backend, to instruct the
	optimization code the return register is live.

	* lib/jit_arm.c, lib/jit_mips.c, lib/jit_ppc.c, lib/jit_print.c,
	lib/jit_x86.c: Update for the new jit_live code.

	* check/ret.ok, check/ret.tst: New files implementing a simple
	test case that would previously fail at least in ix86/x86_64.

	* check/Makefile.am: Update for new "ret" test case.
2013-02-05 14:14:25 -02:00
pcpa
d91b25d1be Implement the qmul and qdiv instructions.
2013-02-04 Paulo Andrade <pcpa@gnu.org>

	* include/lightning.h, include/lightning/jit_private.h,
	lib/jit_arm-cpu.c, lib/jit_arm.c, lib/jit_mips-cpu.c,
	lib/jit_mips.c, lib/jit_ppc-cpu.c, lib/jit_ppc.c,
	lib/jit_x86-cpu.c, lib/jit_x86.c, lib/lightning.c:
	Implement the new qmul and qdiv instructions that return signed
	and unsigned lo/hi multiplication result and div/rem division result.
	These should be useful for jit translation of code that needs to
	know if a multiplication overflows (no branch opcode added) or if
	a division is exact (easy check if remainder is zero).

	* check/lightning.c, lib/jit_print.c, check/Makefile.am,
	check/all.tst: Update for the new qmul and qdiv instructions.

	* check/qalu.inc, check/qalu_div.ok, check/qalu_div.tst,
	check/qalu_mul.ok, check/qalu_mul.tst: New files implementing
	simple test cases for qmul and qdiv.
2013-02-04 18:54:37 -02:00
pcpa
44d4fa5444 Add heuristic code to estimate space and resize if required jit buffer. 2013-01-29 16:37:43 -02:00
pcpa
9e86ef12cf Add the new jit_name call to mark function boundaries
* check/3to2.tst, check/add.tst, check/allocai.tst, check/bp.tst,
	check/call.tst, check/ccall.c, check/clobber.tst, check/divi.tst,
	check/fib.tst, check/ldsti.tst, check/ldstr-c.tst, check/ldstr.tst,
	check/ldstxi-c.tst, check/ldstxi.tst, check/ldstxr-c.tst,
	check/ldstxr.tst, check/lightning.c, check/rpn.tst, check/stack.tst,
	check/varargs.tst, include/lightning.h,
	include/lightning/jit_private.h, lib/jit_arm.c, lib/jit_disasm.c,
	lib/jit_mips.c, lib/jit_note.c, lib/jit_ppc.c, lib/jit_print.c,
	lib/jit_x86.c, lib/lightning.c:	Extend the "jit_note" abstraction
	with the new "jit_name" call, that receives a string argument, and
	should usually be called to mark boundaries of functions of code
	generating jit (that is, it is not expected that the language
	generating jit map its functions to jit functions).
2013-01-18 18:05:57 -02:00
pcpa
a34410eee2 Add filename and line number annotation abstraction.
* lib/jit_note.c: New file implementing a simple string+integer
	annotation, that should be used to map filename and line number
	to offsets in the generated jit.

	* include/lightning.h, lib/lightning.c: Update for the new
	note code.
	  Add an extra mandatory argument to init_jit, that is used
	as argument to bfd_openr.
	  Change from generic void* to char* the argument to jit_note
	and add an extra integer argument, to map to filename and
	line number.

	* check/ccall.c, check/lightning.c, include/lightning/jit_private.h,
	lib/jit_arm.c, lib/jit_disasm.c, lib/jit_mips.c, lib/jit_ppc.c,
	lib/jit_print.c, lib/jit_x86.c: lib/Makefile.am: Update for the
	new annotation code.

	* configure.ac, check/Makefile.am: Update to work with latest
	automake.
2013-01-11 15:29:35 -02:00
pcpa
4fe47942eb Rework {get,push}arg{,i,r}_{f,d} to a more descriptive name and usage. 2013-01-09 17:14:51 -02:00
pcpa
9d2566ee0a Add the new ccall test case to test interleaved C and jit function calls
* check/cccall.c, check/ccall.ok: New test case to validate
	interleaved calls from/to C code and jit.

	* check/Makefile.am: Update for the new ccall test case.

	* include/lightning.h, lib/lightning.c: Add the new jit_address
	call that returns the real/final address of a "note" in the
	generated jit. It requires a jit_node_t as returned by the
	jit_note call, and is only valid after calling jit_emit.
	  Add an intermediate solution to properly handle arm
	soft and softfp modes that move a double to an integer register
	pair. Currently it just adds extra tests for the condition,
	but the proper solution should be to have extra lightning
	codes for these conditions, codes which should be only used
	by the backends that need it, and merged with the existing
	jit_pusharg*_{f,d}.

	* include/lightning/jit_private.h: Add new jit_state_t flag
	to know it finished jit_emit, so that calls to jit_address
	are valid.

	* lib/jit_mips.c: Correct abi implementation so that the
	new ccall test case pass. Major problem was using
	_jit->function.self.arg{i,f} as boolean values, but that
	would cause lightning.c:patch_registers() to incorrectly
	assume only one register was used as argument when calling
	jit_regarg_p(); _jit->function.self.arg{i,f} must be the
	number of registers used as arguments (in all backends).

	* lib/jit_x86.c: Add workaround, by marking %rax as used,
	to a special condition, when running out of registers and the
	allocator trying to spill and reload %rax, but %rax was used
	as a pointer to a function, what would cause the reload to
	destroy the return value. This condition can be better
	generalized, but the current solution is good enough.

	* include/lightning/jit_ppc.h, lib/jit_ppc-cpu.c, lib/jit_ppc.c:
	Rewrite logic to handle arguments, as the original code was
	written based on a SysV pdf about the generic powerpc ABI,
	what did "invent" a new abi for the previous test cases, but
	failed in the new ccall test in Darwin PPC. Now it properly
	handles 13 float registers for arguments, as well as proper
	computation of stack offsets when running out of registers
	for arguments.
2013-01-05 16:14:59 -02:00
pcpa
2e6c680d70 Change type of return of jit_arg* and argument to jit_getarg*
* check/lightning.c, include/lightning.h, lib/jit_arm.c,
	lib/jit_mips.c, lib/jit_ppc.c, lib/jit_print.c,	lib/jit_x86.c,
	lib/lightning.c: Change return value of jit_arg{,_f,_d} to
	a jit_node_t* object, that should be used as argument to
	jit_getarg_{c,uc,s,us,i,ui,l,f,d}. This just requires changing
	from jit_int32_t to jit_pointer_t (or jit_node_t*) the "handle"
	for the getarg calls, with the benefit that it makes it easy
	to implement patching of the stack address of non register
	arguments, this way allowing to implement variable size stack
	frames if applicable; useful if there are too many registers and
	jit functions uses only a few callee save registers.
2012-12-28 10:35:14 -02:00
pcpa
1287a2d448 Correct extra regressions found by the call.tst test case.
* lib/jit_arm.c, lib/jit_mips-cpu.c, lib/jit_mips.c: Correct
	regressions when patching jit_calli for a forward function.

	* lib/jit_ppc-cpu.c: Correct wrong arguments to ANDI opcode
	in jit_getarg_u{c,s} implementation.
2012-12-28 10:28:50 -02:00
pcpa
adc854f1a7 Correct regressions with --with-float={soft,softfp} in the arm backend
* lib/jit_arm.c: Correct use of wrong argument offset
	variable in armv7l or float/double argument for varargs
	function in armv7hl.
	  Correct jit_getarg* logic in software float mode to
	match expected behavior in other backends, that is, if
	a function is not called, it is safe to use a few lightning
	calls before a next jit_getarg* call, as done in the test
	case check/stack.tst. The proper solution should be to
	extend the parser in lib/lightning.c to check if there is
	some float operation that will call some (libgcc?) function,
	but software float arm should be a very uncommon backend for
	lightning, so, just load the already in place arguments
	saved to stack, assuming the register argument was clobbered
	(what should not be the case most times...).
2012-12-22 16:28:02 -02:00
pcpa
a74318a1d7 Add new test case to check stack integrity on complex stack frames.
* check/stack.ok, check/stack.tst: New files to test data
	integrity on a deep chain of stack frames.

	* lib/jit_arm.c, lib/jit_arm-cpu.c, lib/jit_mips.c,
	lib/jit_mips-cpu.c, lib/jit_ppc.c, lib/jit_ppc-cpu.c,
	lib/jit_x86.c, lib/jit_x86-cpu.c: Calculate _jit->function->stack
	in the emit stage, otherwise it will calculate it wrong if
	need to jit_allocai space to spill registers.

	* lib/lightning.c: Correct wrong offset when updating the
	"current" jit function pointer in the code that may need to
	allocate stack space to spill registers.

	* check/lightning.c: Correct off by one data space check.

	* check/Makefile.am: Update for new test case.
2012-12-19 18:07:12 -02:00