1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

57 commits

Author SHA1 Message Date
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
a8c180a926 Remove the global but not advertised jit_progname variable
* include/lightning/jit_private.h, lib/jit_disasm.c,
	lib/lightning.c: Remove the global jit_progname variable.
	It was being only used in jit_init_debug, that is called
	from init_jit, so, just pass an argument.
2014-07-27 16:48:52 -03:00
pcpa
33ee2337c7 Implement the new jit_set_data interface.
* include/lightning.h, include/lightning/jit_private.h,
	lib/lightning.c: Implement the new jit_set_data() interface,
	and the new jit_get_data() helper. Like jit_set_code(),
	jit_realize() should be called before jit_set_data().
	The most common usage should be jit_set_data(JIT_DISABLE_DATA
	| JIT_DISABLE_NOTE), to force synthesize any float/double
	constant in the stack and not generate any debug information.

	* lib/jit_note.c: Minor change to debug note generation as
	now it uses an alternate temporary data buffer during constants
	and debug generation to accommodate the possibility of the user
	setting an alternate data buffer.

	* lib/jit_hppa-fpu.c, lib/jit_s390x.c, lib/jit_s390x-cpu.c,
	lib/jit_s390x-fpu.c, lib/jit_sparc.c, lib/jit_sparc-fpu.c,
	lib/jit_x86-sse.c, lib/jit_x86-x87.c: Implement jit_set_data.

	* lib/jit_hppa-sz.c, lib/jit_sparc-sz.c, lib/jit_x86-sz.c,
	lib/jit_s390x-sz.c: Update for several instructions that now
	have a different maximum length due to jit_set_data.

	* lib/jit_mips-fpu.c: Implement jit_set_data, but missing
	validation on n32 and n64 abis (and/or big endian).

	* lib/jit_mips-sz.c: Update for changes in o32.

	* lib/jit_ppc-fpu.c: Implement jit_set_data, but missing
	validation on Darwin PPC.

	* lib/jit_ppc-sz.c: Update for changes in powerpc 32 and
	64 bit.

	* lib/jit_ia64-fpu.c: Implement untested jit_set_data.

	* TODO: Add note to list ports that were not tested for the
	new jit_set_data() feature, due to no longer having access
	to them.

	* check/nodata.c: New file implementing a simple test exercising
	several different conditions created by jit_set_data().

	* check/check.nodata.sh: New file implementing a wrapper
	over the existing *.tst files, that runs all tests without
	using a data buffer for constants; only meaningful (and
	enabled) on architectures that used to store float/double
	constants on a read only data buffer.

	* configure.ac, check/Makefile.am: Update for the new test
	cases.

	* check/lightning.c: Implement the new "-d" option that
	sets an internal flag to call jit_set_data() disable
	constants and debug, that is, using only a pure code
	buffer.
2014-03-12 14:50:31 -03:00
pcpa
79bc3d03dd Implement the new jit_set_code interface.
* include/lightning.h, include/lightning/jit_private.h,
	lib/lightning.c: Implement the new jit_set_code() interface,
	that allows instructing lightning to use an alternate code
	buffer. The new jit_realize() function should be called
	before jit_set_code(), and usually call jit_get_code()
	to query the amount of bytes expected to be required for
	the code.

	* lib/jit_size.c: Minor update to have less chances of
	miscalculating the code buffer by starting the counter
	with the size of the longest instruction instead of zero,
	as code emit fails if at any moment less than the longest
	instruction bytes are available.

	* check/setcode.c: New file implementing some basic tests
	of the new jit_set_code() interface.

	* check/Makefile.am: Update for newer test case.
2014-03-11 11:40:42 -03:00
pcpa
a9433b5a2c Implement and document the new jit_indirect call.
* include/lightning.h, lib/lightning.c: Add the new
	jit_indirect() call, that returns a special label node,
	and tells lightning that the label may be the target of
	an indirect jump.

	* doc/body.texi: Document the new jit_indirect() call, and
	add examples of different ways to create labels and branches.
2014-03-06 18:20:29 -03:00
pcpa
6e75c0352d Rewrite jit_regset_scan1 for easier optimization.
* include/lightning/jit_aarch64.h, include/lightning/jit_arm.h,
	include/lightning/jit_hppa.h, include/lightning/jit_ia64.h,
	include/lightning/jit_mips.h, include/lightning/jit_ppc.h,
	include/lightning/jit_s390x.h, include/lightning/jit_sparc.h,
	include/lightning/jit_x86.h: Change jit_regset_t to an
	unsigned type, to allow safe right shift.

	* lib/lightning.c: Rewrite jit_regset_scan1 to allow easier
	compiler optimization.
2014-02-19 14:38:14 -03:00
pcpa
a264ccee75 Add assertion to detect double patching.
This triggers the bug at the right point, otherwise, double patching
may be quite hard to track.
2013-10-16 01:13:46 -03:00
pcpa
f42a251ff1 Correct misplaced check for already visited blocks 2013-10-01 13:51:01 -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
95e3fbc8bc Add the new jit_pointer_p predicate interface.
* include/lightning.h, lib/lightning.c: Add the new
	jit_pointer_p interface, that returns a boolean value
	telling if the pointer argument is inside the jit
	code buffer. This is useful to avoid the need to add
	extra labels and calls to jit_address to figure bounds
	of code buffer, and still keep internal data private.
2013-09-14 14:43:05 -03:00
pcpa
a62f405751 Add the jit_callee_save_p interface and extra register definitions.
* check/self.c, check/self.ok: New files implementing simple
	consistency check assertions. At first validating some macros
	that use values from different sources agree.

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

	* include/lightning.h,  lib/lightning.c: Add the new
	jit_callee_save_p() call, that is intended to be used when
	writing complex code using lightning, so that one does not
	need to verify what backend is being used, or have access to
	private data, to query if a register is callee save or not;
	on several backends the scratch registers are actually callee
	save.

	* include/lightning/jit_aarch64.h, include/lightning/jit_arm.h,
	include/lightning/jit_hppa.h, include/lightning/jit_mips.h,
	include/lightning/jit_ppc.h, include/lightning/jit_sparc.h,
	include/lightning/jit_x86.h: Add an explicit definition for
	JIT_R3-JIT_Rn, JIT_V3-JIT_Vn and JIT_F6-JIT_Fn when applicable.
	This allows one to write code based on "#if defined(JIT_XN)"
	and therefore, not need to check what is the current backend
	or have access to private data structures. This is particularly
	useful when writing virtual machines with several specialized,
	global registers.

	* lib/jit_ia64.c: Properly flag the callee save general
	purpose registers as such, so that jit_callee_save_p() works
	as intended.
2013-09-10 21:41:49 -03:00
pcpa
ecf753f94f Correct build and check on NetBSD amd64.
* configure.ac: Extend FreeBSD test to also handle NetBSD.

	* lib/jit_x86-cpu.c: Correct wrongly defined offset type of
	ldxi_ui. Problem detected when building on NetBSD.

	* lib/lightning.c: Adjust code to handle NetBSD mremap,
	where arguments do not match Linux mremap.
2013-08-26 16:31:42 -03:00
pcpa
b5763c42aa Correct license to properly advertise LGPLv3 and not GPLv3. 2013-08-11 18:08:52 -03:00
pcpa
f6ee396ccb New s390x port built on the hercules emulator and fedora 16 image.
* include/lightning/jit_s390x.h, lib/jit_s390x-cpu.c,
	lib/jit_s390x-fpu.c, lib/jit_s390x.c: New files
	implementing the new s390x port.

	* configure.ac, include/lightning.h,
	include/lightning/Makefile.am,
	include/lightning/jit_private.h,
	lib/Makefile.am, lib/jit_disasm.c, lib/lightning.c:
	Minor adaptation for the new s390x backend.

	* check/float.tst: Update for the s390x result of
	truncating +Inf to integer.

	* check/qalu_mul.tst: Add extra test cases to better test
	high word of signed multiplication as the result is
	adjust from unsigned multiplication on s390x.
2013-07-28 14:13:39 -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
d6110f6cf3 Build and pass all tests on big endian Irix mips using the n32 abi.
* check/lightning.c, configure.ac, include/lightning.h,
	lib/lightning.c: Add tests and quirks to build/detect
	and/or work on Irix.

	* include/lightning/jit_mips.h, lib/jit_mips-cpu.c,
	lib/jit_mips-fpu.c, lib/jit_mips.c: Adapt code to run
	in big endian mips, using the n32 abi.
2013-06-22 19:44:00 -03:00
pcpa
e82e5be448 Build and pass all test cases on a multiprocessor HP-UX.
* configure.ac, check/Makefile.am, doc/Makefile.am: Do not
	explicitly link to -ldl, but instead autodetect the library
	with dlopen, dlsym, etc.

	* check/lightning.c: Add workaround to apparently buggy
	getopt in HP-UX that sets optind to the wrong index, and
	use RTLD_NEXT on HP-UX instead of RTLD_DEFAULT to dlsym
	global symbols.

	* include/lightning.h: Rework definitions of wordsize and
	byte order to detect proper values on HP-UX.

	* lib/lightning.c: Minor correction to use MAP_ANONYMOUS
	instead of MAP_ANON on HP-UX.

	* lib/jit_hppa.c: Float arguments must be passed on integer
	registers on HP-UX, not only for varargs functions.
	  Add code to properly clear instruction cache. This was
	not required on Debian hppa port, but may have been working
	by accident.

	* lib/jit_hppa-cpu.c: Follow pattern of HP-UX binaries and
	use bve,n instead of bv,n to return from functions.

	* lib/jit_hppa-fpu.c: For some reason "fst? frX,rX,(rY)" did
	not work on the tested computer	(HP-UX B.11.23 U 9000/785 HP-UX)
	so the code was changed, at first for __hpux only to add the
	base and offset register and use the instruction with an
	immediate (zero) offset.
2013-06-09 18:31:50 -03:00
pcpa
ce6ab1f09e Prepare for the first alpha release of lightning 2.0. 2013-06-05 20:18:54 -03:00
pcpa
3356b9d93a Add functional hppa port. All tests pass.
* include/lightning/jit_hppa.h, lib/jit_hppa-cpu.c,
	lib/jit_hppa-fpu.c, lib/jit_hppa.c: New files implementing
	the hppa port. Built on Debian Linux PA-RISC 2.0, 32 bit.

	* check/float.tst: Add preprocessor for hppa expected
	values when converting NaN and +-Inf to an integer.

	* check/ldst.inc: Ensure double load/store tests use an
	8 byte aligned address by default.

	* lib/lightning.c: Correct a bug found during tests in
	the new port, where qmul* and qdiv* were not properly
	setting one of the result registers as modified in the
	function, what would be a problem if the only "write"
	usage were the qmul* or qdiv*.

	* check/varargs.tst, check/varargs.ok: Add one extra
	interleaved integer/double test to validate proper code
	generation in the extra case.

	* check/lightning.c, configure.ac, include/lightning.h,
	include/lightning/Makefile.am,
	include/lightning/jit_private.h, lib/Makefile.am,
	lib/jit_disasm.c: Update for the hppa port.
2013-06-01 01:53:33 -03:00
pcpa
6ef03b0e04 Finish Itanium port, correcting remaining failing test cases.
* check/varargs.tst: Correct misplaced .align directive
	that was causing the double buffer to not be aligned at
	8 bytes.
	* lib/jit_ia64-cpu.c:
	  Properly implement abi for excess arguments passed on
	stack.
	  Simplify load/store with immediate displacement argument
	with zero value.
	  Simplify some calls to "subi" changing to "addi" with
	a negative argument.
	  Remove some #if 0'ed code, that could be useful in
	special conditions, but the most useful one would be
	to "optimize" "static" jit functions, but for the sake
	of simplicity, jit functions are implemented in a way
	that can be passed back to C code as C function pointers.
	  Add an attribute to prototypes of several unused functions.
	These functions are defined for the sake of implementing all
	Itanium documented instructions, but a significant amount of
	them is not used by lightning.
	* lib/jit_ia64-fpu.c: Simplify load/store with zero immediate
	displacement and add unused attribute for functions not used
	by lightning, but required to provide macros implementing all
	Itanium documented instructions.
	* lib/jit_ia64.c: Update for the properly implemented abi
	for stack arguments.
	* lib/lightning.c: Mark an unused function as such.
2013-04-27 22:31:29 -03:00
pcpa
caeb6d6e11 Implement fpr register arguments and minor extra fixes.
* include/lightning.h: Add new backend specific movr_w_d,
	movr_d_w and movi_d_w codes as helpers to ia64 varargs
	functions arguments.

	* lib/jit_ia64-cpu.c:
	  Correct wrong encoding of A5 small integers.
	  Correct define of "mux" instruction modifiers.
	  Correct ordering of arguments and predicates of cmp_xy
	implementation with immediate arguments; like most other
	codes with an immediate, the immediate is the second, not
	the third argument.

	* lib/jit_ia64-fpu.c: Actual implementation of the code
	to move to/from gpr to/from fpr, to implement varargs abi.

	* lib/jit_ia64.c: Make fpr argument registers not allocatable
	as temporaries, no need for the extra checks when there are
	plenty registers.

	* lib/jit_print.c, lib/lightning.c: Minor updates for the
	new movr_w_d, movr_d_w and movi_d_w codes.
2013-04-27 01:41:46 -03:00
pcpa
89f1e2f608 Properly split instruction groups for predicate registers.
* include/lightning/jit_ia64.h, include/lightning/jit_private.h,
	lib/jit_ia64-cpu.c, lib/jit_ia64-fpu.c, lib/jit_ia64.c,
	lib/lightning.c: Rework code to detect need of a "stop" to
	also handle predicates, as if a predicate is written, it
	cannot be read in the same instruction group.
	  Use a single jit_regset_t variable for all registers when
	checking need for a stop (increment value by 128 for
	float registers).
	  Correct wrong "subi" implementation, as the code executed
	is r0=im-r1, not r0=r1-im.
	  Use standard lightning 6 fpr registers, and rework to
	use callee save float registers, that may be spill/reloaded
	in prolog/epilog. This is required because some jit
	instructions implementations need to call functions; currently
	integer div/mod and float sqrt, what may change the value of
	scratch float registers.
	  Rework point of "sync" of branches that need to return a
	patch'able address, because the need for a "stop" before a
	predicate read causes all branches to be the instruction
	in slot 0, as there is no template to "stop" and branch
	in the same instruction "bundle".
2013-04-26 06:02:29 -03:00
pcpa
c2e4eb621d Add basic Itanium port infrastructure.
* include/lightning/jit_ia64.h, lib/jit_ia64-cpu.c,
	lib/jit_ia64-fpu.c, lib/jit_ia64.c: New files implementing
	the basic infrastructure of an Itanium port. The code
	compiles and can generate jit for basic hello world like
	functions.

	* check/lightning.c, configure.ac, include/lightning.h,
	include/lightning/Makefile.am, include/lightning/jit_private.h,
	lib/Makefile.am, lib/lightning.c: Update for the Itanium
	port.

	* lib/jit_mips-cpu.c, lib/jit_mips.c: Correct typo and
	make the jit_carry register local to the jit_state_t.
	This matches code reviewed in the Itanium port, that
	should use the same base logic to handle carry/borrow.
2013-04-25 21:56:32 -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
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
be9068f2ee Correct wrong shift value for 32 bit 2013-03-22 19:48:44 -03:00
pcpa
f341d91e2b Remove non optional gmp dependency.
* configure.ac, include/lightning/jit_private.h, lib/lightning.c:
	Remove dependency on gmp. Only a simple bitmap was required, and
	that was not enough reason to force linking to gmp and possible
	complications caused by it.
2013-03-22 18:28:42 -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
f39eee6694 Make code and data buffer readonly.
* lib/lightning.c: Make data and code buffer readonly.
2013-03-06 16:36:38 -03:00
pcpa
e304bc8bf9 Pass all but the (not yet implemented) qmul and qdiv tests in sparc
* check/float.tst: Add sparc to list of known NaN and +-Inf
	to integer conversion.

	* check/lightning.c: Define __sparc__ to preprocessor in
	the sparc backend.

	* include/lightning/jit_private.h: Correct wrong definition
	of emit_stxi_d, that has lived for a long time, but would
	cause problems whenever needing to spill/reload a float
	register.

	* include/lightning/jit_sparc.h: Can only use %g2,%g3,%g4
	for scratch variables, as other "global" registers are
	reserved for the system, e.g. libc.
	  Reorder float register naming to make it easier to
	access odd float registers, so that generating code for
	pusharg and getarg is easier for the IR.

	* lib/jit_mips-cpu.c, lib/jit_ppc-cpu.c: Update to match
	new code in jit_sparc-cpu.c. It must call jit_get_reg
	with jit_class_nospill if using the register to move
	an unconditional branch address to it, as the reload
	will not happen (actually could happen in the delay
	slot...)

	* lib/jit_sparc-cpu.c: Correct wrong macro definition for
	ldxr_s.
	  Properly implement div* and implement rem. Div* needs
	to use the y register, and rem* needs to be synthesized.
	  Correct b?sub* macro definitions.

	* lib/jit_sparc-fpu.c: Correct reversed float to/from double
	conversion.
	  Correct wrong jit_get_reg call asking for a gpr and then
	using the fpr with that number.
	  Correct wrong branch displacement computation for
	conditional branches.

	* lib/jit_sparc.c: Correct getarg_d and pushargi_d implementation.
	  Add rem* entries to the switch converting IR to machine code.

	* lib/lightning.c: Correct a problem detected when adding
	the jit_class_nospill flag to jit_get_reg, that was caused
	when having a branch to an "epilog" node, what would cause
	the code to think all registers in unknown state were live,
	while in truth, all registers in unknown state in the
	"just after return" point are actually dead.
2013-02-19 01:06:18 -03:00
pcpa
610a569300 Add framework for sparc port.
* include/lightning/jit_sparc.h, lib/jit_sparc-cpu.c,
	lib/jit_sparc-fpu.c, lib/jit_sparc.c: New files implementing
	the basic framework of the sparc port.

	* configure.ac, include/lightning.h, include/lightning/Makefile.am,
	include/lightning/jit_private.h, lib/jit_disasm.c: Update
	for the sparc port framework.

	* lib/jit_mips.c: Correct reversed retr/reti logic.

	* lib/jit_ppc.c: Correct misspelled __LITTLE_ENDIAN.

	* lib/lightning.c: Always do byte hashing in hash_data, because
	the logic to "compress" strings causes large pointers to not
	be guaranteed aligned at 4 byte boundaries.
	  Update for the sparc port framework.
2013-02-18 01:18:54 -03:00
pcpa
8f020fe044 Add code to release all memory used by the jit state.
* include/lightning.h, lib/lightning.c: Implement the new
	jit_clear_state and jit_destroy_state calls. jit_clear_state
	releases all memory not required during jit_execution; that
	is, leaves only the mmap'ed data and code buffers allocated.
	jit_destroy_state releases the mmap'ed buffers as well as
	the jit_state_t object itself, that holds pointers to the
	code and data buffers, as well as annotation pointers (for
	disassembly or backtrace) in the data buffer.

	* lib/jit_note.c: Correct invalid vector offset access.

	* check/ccall.c, check/lightning.c, doc/ifib.c, doc/incr.c,
	doc/printf.c, doc/rfib.c, doc/rpn.c: Use the new jit_clear_state
	and jit_destroy_state calls, to demonstrate the new code to
	release all jit memory.

	* doc/body.texi: Add basic documentation and usage description
	of jit_clear_state and jit_destroy_state.
2013-02-11 15:51:55 -02:00
pcpa
6039794ec3 Store all annotation information in the read only data buffer.
* include/lightning/jit_private.h, lib/jit_note.c, lib/lightning.c:
	  Store all annotation information in the mmap'ed area reserved for
	read only data. This adds code to not allocate memory for jit_note_t
	objects, and to	relocate jit_line_t objects and its contents after
	calculating annotation information. The jit_line_t objects are
	relocated because it is not possible to always calculate before
	hand data layout because note information may be extended or
	redundant entries removed, as well as allowed to be added in
	non sequential order.
	  A bug was also corrected in _jit_set_note, that was causing it
	to allocate new jit_line_t objects when not needed. It was still
	working correctly, but allocating way more memory than required.
2013-02-11 15:50:59 -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
39afbe1c40 Correct off by one label/note name and add align argument to jit_data
2013-01-14 Paulo Andrade <pcpa@gnu.org>

	* include/lightning.h, lib/lightning.c: Add an extra align
	argument to the jit_data call (that should be made private),
	so that it should not align strings at 8 bytes.
	  Correct the jit_note call to include the null ending byte
	when adding label/note names to the "jit data section".
2013-01-14 14:43:54 -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
d7f94379ed Test and correct test cases in all current backends. 2013-01-02 17:53:51 -02:00
pcpa
537c85be27 Correct wrong and confusing reverse float comparison logic
* lib/lightning.c: Correct both, wrong and confusing logic
	to compute the reverse of a jump. Now it properly matches
	C semantics for "eq" (==) and "ne" (!=) and correct computation
	of reverse of "uneq" as "gt".

	* check/branch.tst: Update "ne" float branch check that
	previously happened to be wrongly tested with a NaN argument.
2012-12-29 18:55:11 -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
38770ecbaa Correct bogus logic caused by wrong optimizations.
* lib/lightning.c: Partially rewrite/revert code to compute
	initial	register live state at the start of a basic block.
	The original logic was corrupted when adding optimizations
	to do as few computations as possible in jit_update. The
	reglive field must be always a known set of live registers
	at the start of a basic block. The value that was incorrect
	was the regmask field, that must be the set of registers
	that are in unknown state, because they are not known live,
	neither set (or possibly not set) in the basic block, and
	*must* store the state at the start of the basic block.
2012-12-21 21:00:32 -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
pcpa
03559bb8cc Make it clear stdarg like abstraction is not supported.
* include/lightning.h, include/lightning/jit_private.h,
	lib/jit_arm.c, lib/jit_mips.c, lib/jit_ppc.c, lib/jit_x86.c,
	lib/lightning.c: Make jit_ellipsis implementation not
	backend specific. It is not intended to handle va_list
	like objects at runtime, as jit_arg* and jit_getarg*
	return constant values resolved at parse time, so, effectively
	it is not possible to create printf like jit functions, as
	there is no va_start, va_arg, va_end, etc, abstraction. This
	limitation should be kept for the sake of making new ports
	easier.
2012-12-14 15:21:39 -02:00
pcpa
074056499f Remove most type casts and compile test tool silently with -Wall 2012-12-14 14:15:25 -02:00