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

88 commits

Author SHA1 Message Date
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
pcpa
0b89a17ca2 Add jit_ellipis and remove jit_prepare argument.
* include/lightning.h, lib/jit_arm.c, lib/jit_mips.c,
	lib/jit_ppc.c, lib/jit_x86.c, lib/lightning.c: Change jit_prepare
	to no longer receive an argument. If receiving an argument, it
	should be an ABI specifier, not a boolean if varargs or not,
	and add the new jit_ellipsis call, to specify where the
	ellipsis is in the C prototype of the function being called.
	Note that currently it is not supported to define varargs
	functions and it will be ignored if calling jit_ellipsis not
	in a prepare/finish* block, but this should be addressed.

	* check/allocai.tst, check/alu_add.tst, check/alu_and.tst,
	check/alu_com.tst, check/alu_div.tst, check/alu_lsh.tst,
	check/alu_mul.tst, check/alu_neg.tst, check/alu_or.tst,
	check/alu_rem.tst, check/alu_rsh.tst, check/alu_sub.tst,
	check/alu_xor.tst, check/alux_add.tst, check/alux_sub.tst,
	check/bp.tst, check/branch.tst, check/cvt.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/rpn.tst,
	check/lightning.c: Update for the change to jit_prepare and
	addition of jit_ellipsis.
2012-12-12 22:59:52 -02:00
pcpa
a04df966c0 Make all current test cases pass in Darwin PowerPC.
* lib/jit_ppc-cpu.c: Make movr a function that checks arguments
	so that other code can safely assume it is a noop if src and dst
	are the same register.
	  Implement rem{r,i}{,_u} as a div{,u}/mul/sub.
	  Correct ANDIS, ORIS and XORIS calls to cast the argument to
	unsigned before the shift to avoid an assertion if the argument
	had the topmost bit set.
	  Implement lshi, rshi and rshi_u as functions to test for a
	zero argument, that would otherwise trigger an assertion when
	computing the shift value.
	  Do a simple implementation of bm{s,c}{r,i} with a temporary,
	"andr" of arguments and jump based on comparison with zero.
	  Correct typo in ldxi_c.

	* lib/jit_ppc-fpu.c: Correct wrong arguments to FDIV* and STF*.

	* lib/jit_ppc.c: Correct wrong check for 6 instead of 8 integer
	arguments in registers. If calling a varargs function and
	passing a float or double argument, also either store the
	value in the stack or in integer registers, as varargs functions
	do not fetch it from float registers.
	  Add "case" for new functions and incorrectly missing ones.
	  Call libgcc's __clear_cache, that should know what to do
	if the hardware needs flushing cache before execution.

	* lib/lightning.c: Do a simple/trivial logic in jit_regset_scan1,
	that should make it easier for the compiler to optimize it, and
	that also corrects the previously wrong code for big endian, and
	that was causing problems in ppc due to not saving all callee save
	registers as it was not "finding" them in the regset due to the
	little endian assumption bug.
2012-12-11 13:14:09 -02:00
pcpa
7e3d863767 Add better ppc support code, but still not functional.
* configure.ac: Only default to using the builtin disassembler
	if on GNU/Linux. This should be temporary, due to requiring
	/proc/self/exe.
	  Correctly check $target_cpu for powerpc.

	* include/lightning/jit_ppc.h: Correctly implement jit_v_num.

	* include/lightning/jit_private.h: Declare proper prototype
	for jit_init_debug and jit_finish_debug.

	* lib/jit_ppc-cpu.c: Remove code to save/restore callee save
	float registers, as it is not required since those float
	registers are not usable currently.
	  Change prolog and epilog generation to, at least comparing
	code, match what gcc generates in "gcc -O0", but it is still
	failing in Darwin PPC, apparently due to the __clear_cache
	call not being enough, as frequently it will also fail to
	execute, and the code buffer is all zeroes.

	* lib/lightning.c: Do not fail in jit_regset_scan1 calls due
	to passing 64 as argument on computers with 64 registers.
2012-12-11 02:16:51 -02:00
pcpa
e255b76068 Add several arithmetic and branch tests cases.
* check/alu.inc, check/alu_add.ok, check/alu_add.tst,
	check/alu_and.ok, check/alu_and.tst, check/alu_com.ok,
	check/alu_com.tst, check/alu_div.ok, check/alu_div.tst,
	check/alu_lsh.ok, check/alu_lsh.tst, check/alu_mul.ok,
	check/alu_mul.tst, check/alu_neg.ok, check/alu_neg.tst,
	check/alu_or.ok, check/alu_or.tst, check/alu_rem.ok,
	check/alu_rem.tst, check/alu_rsh.ok, check/alu_rsh.tst,
	check/alu_sub.ok, check/alu_sub.tst, check/alu_xor.ok,
	check/alu_xor.tst, check/alux_add.ok, check/alux_add.tst,
	check/alux_sub.ok, check/alux_sub.tst, check/branch.ok,
	check/branch.tst: New test cases for arithmetic and branch
	tests.

	* check/Makefile.am: Update for new test cases.

	* include/lightning/jit_private.h: Make the jit_reg_free_p
	macro shared by all backends. Previously was added for the
	arm backend, but is useful in the x86_64 backend when checking
	state of "special purpose register".
	Also add the new jit_class_named register class, that must be
	or'ed with the register value if calling jit_get_reg expecting
	an specific value, because the specific register value may be
	zero, that previously was treated as no register requested.

	* lib/jit_arm-cpu.c: Correct argument order for T2_MVN.

	* lib/jit_arm-swf.c: Call the proper function for double
	divide. The "software float" implementation just calls
	libgcc functions.

	* lib/jit_arm.c: Return float/double values in the float
	register if using the hard float ABI.

	* lib/jit_x86-cpu.c: Change the can_sign_extend_int_p macro
	to not include -0x80000000L, because there is code that
	"abuses" it and thinks it can negate the immediate value
	after calling that macro.
	  Correct implementation of jit_subi that had a wrong code
	patch logic doing subtraction with reversed arguments.
	  Correct REX prefix calculation in the jit_muli implementation.
	  Correct logic to get/unget %*ax and %*dx registers in divremr
	and divremi.
	  Correct divremi that was using the symbolic, unique %*ax
	value in on place (not using the _REGNO name suffix).
	  Correct cut&paste error causing it to use "xor" instead of
	"or" in one code path of the jit_ori implementation.
	  Correct several flaws when clobbering registers and/or when
	one of the arguments was %*cx in the rotshr wrapper function
	implementing most shift operations.

	* lib/lightning.c: No longer expect that the backend be smart
	enough to know what to do when asking for a named register
	if that register is already an argument or is live. It fails
	if it is an argument, or if register is live, fails if cannot
	spill.
	  No longer incorrectly assume that eqr_{f,d} and ltgr_{f,d} are
	safe to inverse value tests in jump thread optimization.
2012-12-09 19:13:33 -02:00
pcpa
760fab8d37 Correct mips backend implementation to pass initial tests.
* include/lightning/jit_mips.h, lib/jit_mips-cpu.c,
	lib/jit_mips-fpu.c, lib/jit_mips.c: Correct float/double
	argument handling and make the mips backend pass the initial
	test cases.

	* include/lightning.h, ib/jit_print.c, lib/lightning.c:
	Add extra enum values for argument handling functions that
	could not be abstracted to the current codes, that is, when
	float values need to move from/to gpr from/to fpr. It would
	be more tempting to add such primitives, but they would have
	wordsize limitations, and it is not expected to add codes
	with one gpr argument for 64 bit and two for 32 bit.

	* lib/jit_ppc.c: Check _jit->function before calling jit_epilog()
	to avoid a runtime exception.
2012-12-04 12:39:10 -02:00
pcpa
712877a5a4 Correct implementation problems on ix86.
* check/all.tst, check/lightning.c: Only declare or use 64 bit
	interfaces on 64 bit builds.

	* check/fib.tst: Use simpler logic to not need preprocessor
	conditionals for 32 or 64 bit.

	* include/lightning.h: Only declare 64 bit macros on a 64 bit
	build. Code using lightning must know about wordsize and the
	jit generation limitations, also, this way it generates a
	compile time failure, not a runtime assertion.

	* include/lightning/jit_x86.h: Correct typo in macro name.

	* 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: Correct wrong code to get
	current jit function pointer.

	* lib/lightning.c: Move call to the simplify() optimization
	to after register liveness is known. Previous code did work
	by accident but now with proper test cases the problem was
	noticed.

	* lib/jit_disasm.c: Always cast bfd_vma to long long when
	passing it as printf argument.
2012-12-03 09:40:08 -02:00
pcpa
7a1c455237 Big merge with new lightning semantics aiming for lightning 2.0.
2012-12-02 Paulo Andrade <pcpa@gnu.org>

	* tests/Makefile.am, tests/3to2.c, tests/3to2.ok, tests/add.c,
	tests/add.ok, tests/allocai.c, tests/allocai.ok, tests/bp.c,
	tests/bp.ok, tests/divi.c, tests/divi.ok, tests/fib.c, tests/fib.ok,
	tests/fibdelay.c, tests/fibdelay.ok, tests/fibit.c, tests/fibit.ok,
	tests/funcfp.c, tests/funcfp.ok, tests/incr.c, tests/incr.ok,
	tests/ldst.c, tests/ldst.ok, tests/ldxi.c, tests/ldxi.ok,
	tests/modi.c, tests/modi.ok, tests/movi.c, tests/movi.ok,
	tests/printf.c, tests/printf.ok, tests/printf2.c, tests/printf2.ok,
	tests/ret.c, tests/ret.ok, tests/rpn.c, tests/rpn.ok, tests/rpnfp.c,
	tests/rpnfp.ok, tests/sete.c, tests/sete.ok, tests/testfp.c,
	tests/testfp.ok, tests-run-test: Removed previous test suite, in
	favor of a newer one in the check subdirectory.

	* check/3to2.ok, check/3to2.tst, check/add.ok, check/add.tst,
	check/allocai.ok, check/allocai.tst, check/bp.ok, check/bp.tst,
	check/divi.ok, check/divi.tst, check/fib.ok, check/fib.tst:
	New sample input for the new test program, loosely matching
	several of the previous test cases.

	* check/Makefile.am: New test suite makefile.

	* check/check.sh, check/run-test: New wrapper files for the
	new test suite.

	* check/lightning.c: New file. The main driver of the new test
	suite, that compiles to a parser of a very simple assembly like
	language, generates jit and executes it.

	* check/all.tst: New file. A generic debug and sample test file
	with a directive to prevent it from being executed, and useful to
	read disassembly of all possible instructions, using a fixed set
	of registers.

	* include/Makefile.am, include/lightning.h,
	include/lightning/Makefile.am, include/lightning/jit_arm.h,
	include/lightning/jit_mips.h, include/lightning/jit_ppc.h,
	include/lightning/jit_private.h, include/lightning/jit_x86.h,
	lib/Makefile.am, lib/jit_disasm.c, lib/jit_print.c,
	lib/jit_x86-cpu.c, lib/jit_x86-sse.c, lib/jit_x86-x87.c,
	lib/jit_x86.c, lib/lightning.c: New files. These files are
	written from scratch, only by <pcpa@gnu.org>, and have now
	copyright assignment to the FSF. This is the core of the new
	lightning rework. Previously it was integrated in code with
	a garbage collector and several custom types like vectors and
	hash tables, so this first code merge with lightning converts
	that code into a library extracting only the jit bits, and at
	first only for x86_64 GNU/Linux.

	* lightning.h, m4/lightning.m4: Removed. These are no longer
	required in the new lightning code.

	.gitignore, Makefile.am, configure.ac: Update for the new
	lightning code.
2012-12-02 19:44:36 -02:00