Commit Graph

389 Commits

Author SHA1 Message Date
sergei
ae627a4ba8 * tcgx86.a_op_const_reg_reg: optimize trivial cases before considering more complex ones.
git-svn-id: trunk@27892 -
2014-06-08 00:08:56 +00:00
nickysn
daf71e6d88 * fixed multiplication by 64-bit constants on x86_64, mantis #26230
git-svn-id: trunk@27822 -
2014-05-28 22:52:08 +00:00
nickysn
6e7dd647fd * Tcgx86.g_concatcopy: optimization for the case where source.segment is
specified, but equal to DS in the current memory model

git-svn-id: trunk@27720 -
2014-05-02 13:07:54 +00:00
nickysn
1eb24f9d98 + remove the segment prefix in make_simple_ref on i8086, in case it is the same
as the default segment for the reference (SS for BP-relative, DS for all
  others)

git-svn-id: trunk@27687 -
2014-04-29 23:11:10 +00:00
sergei
07e90aaa24 + Implemented IEEE 754-compliant checking for unordered results of floating-point compares on x86 targets. Mantis #9362.
git-svn-id: trunk@27581 -
2014-04-14 12:36:11 +00:00
florian
18233f2c0c * fix compilation of i8086 compiler
git-svn-id: trunk@27566 -
2014-04-13 19:28:59 +00:00
florian
d88d644925 + support for FMA intrinsic: if there is no hardware support, the compiler throws an error.
Currently it is implemented only for x86-CPUs supporting the FMA extension. While it would
  be possible to implement it in software or simulate fma(<single>,<single>,<single>) using
  double operations, it makes no sense in my opinion to do so.

git-svn-id: trunk@27564 -
2014-04-13 19:21:54 +00:00
nickysn
afcb8c3f10 * initialize DS from CS in the interrupt procedure entry code in tiny model,
because dgroup emits relocations, which results in a linker warning and broken
  code when the target format is .com file.

git-svn-id: trunk@27517 -
2014-04-10 20:02:35 +00:00
nickysn
7a873f495d * use the stack segment for SP-relative addresses in Tcgx86.g_concatcopy in
the memory models with SS<>DS (necessary, because make_simple_ref isn't called
  in the copy_string case)

git-svn-id: trunk@27479 -
2014-04-05 12:02:04 +00:00
nickysn
ee20ecfcf2 * tcgx86.make_simple_ref: in i8086 memory models with DS<>SS, add an SS: segment
override when converting SP-relative references to use a general purpose
  register

git-svn-id: trunk@27473 -
2014-04-05 08:56:40 +00:00
nickysn
b36a98ce51 + Tcgx86.g_concatcopy: added support for memory models with DS<>SS
git-svn-id: trunk@27461 -
2014-04-04 01:13:02 +00:00
nickysn
e9e4cc8bcb * Tcgx86.g_concatcopy: use boolean variables saved_ds and saved_es to keep track
whether these segment registers were saved on the stack or not

git-svn-id: trunk@27460 -
2014-04-04 00:10:36 +00:00
nickysn
096bba90da * fixed Tcgx86.g_concatcopy not using the correct push instruction size when
pushing the source segment

git-svn-id: trunk@27389 -
2014-03-30 18:09:15 +00:00
pierre
044891fd94 Avoid range check error in a_op_const_reg_reg
git-svn-id: trunk@27060 -
2014-03-09 19:49:29 +00:00
nickysn
229ebf33a8 + support getting the address of far references on i8086 in
tcgx86.a_loadaddr_ref_reg

git-svn-id: trunk@26932 -
2014-03-02 22:21:16 +00:00
florian
37b34edbc6 * do not reuse registers when calculating addresses in pic mode
git-svn-id: trunk@26743 -
2014-02-09 21:12:07 +00:00
sergei
9c1f917e3a * a_call_ref functionality cannot be implemented efficiently at code generator level, because references need specific preparations at earlier points. Moved this support to tcgcallnode and its x86 descendants, and got rid of all ifdef's around.
+ x86 targets now directly call procedure variables located in references.
- a_call_ref method removed from tcg and thlcgobj.

git-svn-id: trunk@26666 -
2014-02-03 13:28:56 +00:00
sergei
0d3f36eebf - Remove references to global variable 'cg' from methods of tcg and some of its descendants.
git-svn-id: trunk@26665 -
2014-02-03 12:27:48 +00:00
florian
28a8dc42c6 * fix tcgx86.a_op_reg_reg on x86-64 and make use of it
git-svn-id: trunk@26636 -
2014-01-30 20:24:41 +00:00
florian
7d7bf1d877 + make use of SHLX/SHRX on CPUs supporting BMI2
git-svn-id: trunk@26635 -
2014-01-30 20:24:39 +00:00
florian
48ae2d215a + concatcopy variants using sse and avx, only activated if optimization for size is done because at least on an i7-4770 it has shown no benefit
git-svn-id: trunk@26588 -
2014-01-26 12:37:54 +00:00
nickysn
85dd9e5789 + added a size parameter to optimize_op_const and do a sign extension of the 'a' parameter up from the specified size, so that things like (i and $ffffffff) get optimized away the same way as (i and -1)
git-svn-id: trunk@26561 -
2014-01-22 15:00:34 +00:00
sergei
6b1f021fcf - Removed remaining optimizations that duplicate functionality of tcg.optimize_op_const.
- Don't call make_simple_ref if operation will be optimized away or replaced with another one, which calls make_simple_ref itself.

git-svn-id: trunk@26515 -
2014-01-19 01:19:01 +00:00
nickysn
1f7b14f38e * fixed the conversion of powerof2 mul/imuls to lea in tcgx86.a_op_const_reg_reg
git-svn-id: trunk@26509 -
2014-01-18 17:58:31 +00:00
nickysn
cc1faad3d2 + make use of the 3-operand form of IMUL on i386 and x86_64
git-svn-id: trunk@26508 -
2014-01-18 17:04:57 +00:00
nickysn
5d75bf4f92 * always use IMUL instead of MUL on i386, when doing a 32->32 multiplication
without overflow checking

git-svn-id: trunk@26498 -
2014-01-18 02:56:51 +00:00
nickysn
820b667e1b - rm the OP_IMUL to SHL optimization from tcgx86.a_op_const_reg and tcgx86.a_op_const_ref, because it's already done in optimize_op_const, which is called in the beginning of both methods.
git-svn-id: trunk@26491 -
2014-01-17 18:34:13 +00:00
florian
e210d5f30e + cpu_capabilites for x86_64 and i386
* take advantage of bmi2 instruction rorx

git-svn-id: trunk@26482 -
2014-01-16 21:47:28 +00:00
sergei
f2096de53a * tcg386.g_proc_exit: instead of recalculating stack size, use current_procinfo.final_localsize which was calculated in g_proc_entry.
* tcgx86.g_proc_entry: don't over-allocate stack in SEH finalizer procedures.

git-svn-id: trunk@26251 -
2013-12-19 10:32:32 +00:00
sergei
179586f589 + SEH support for Win32. Enable by cycling with OPT=-dTEST_WIN32_SEH.
Although basic things work (no regressions in test suite, also with TEST_OPT=-O2), there are some secondary issues/TODOs:
- Exception frame around PASCALMAIN is not properly removed in DLLs
- No stack traces yet
- Stack overallocated in finalizer procedures, their entry/exit code needs cleanup
- Signals unit is probably completely broken.

git-svn-id: trunk@26225 -
2013-12-12 12:43:46 +00:00
florian
4d5119bf1c * fixes several issues which cause warnings by the dfa code when using it to detect uninitialized variables
git-svn-id: trunk@26161 -
2013-12-01 17:02:08 +00:00
nickysn
7ae59a62c5 * emit a FWAIT after a floating point store, when targeting the 8087 and 80287
git-svn-id: trunk@26109 -
2013-11-19 23:11:26 +00:00
nickysn
dea947f87b * fixed tcgx86.a_op_const_ref for shl/shr/sar/rol/ror on i8086 and x86_64
git-svn-id: trunk@26018 -
2013-11-10 20:39:47 +00:00
nickysn
d0f988f7a8 * don't use LEA in the code generator on i8086, as this breaks it quite badly.
While it is possible to use 16-bit LEA on the i8086, it's probably not worth
  doing it in the code generator, because of the unpleasant register
  restrictions that 16-bit references have.

git-svn-id: trunk@25989 -
2013-11-07 17:00:58 +00:00
florian
7fc1d70e49 * do reg2=reg1*const by lea if possible
git-svn-id: trunk@25908 -
2013-11-01 19:01:36 +00:00
florian
3c58cad96b * make use of lea if possible
git-svn-id: trunk@25898 -
2013-11-01 19:01:11 +00:00
nickysn
67fdcb02f2 * in tcgx86.make_simple_ref, on the i8086, emit 'mov es, reg', instead of
'push reg/pop es', since that is a lot faster on 8088..80386

git-svn-id: trunk@25700 -
2013-10-06 19:52:38 +00:00
nickysn
6be9627e74 * use all kinds of copy and not just copy_string in Tcgx86.g_concatcopy, when
segments are specified on the i8086

git-svn-id: trunk@25698 -
2013-10-06 19:04:13 +00:00
nickysn
bd0585274e * tsettings.enablecld converted to a targetswitch ts_cld
git-svn-id: trunk@25592 -
2013-09-28 13:41:58 +00:00
nickysn
52fcc0a407 + added a new x86-specific compiler option 'enablecld', which controls whether
the compiler should emit a CLD before using the x86 string instructions.

git-svn-id: trunk@25590 -
2013-09-28 11:54:02 +00:00
Jonas Maebe
3b9b6a0cd7 * explicitly define the asmsymbols for Darwin call stubs as local
git-svn-id: trunk@25264 -
2013-08-16 10:07:46 +00:00
sergei
e1550e1aed * Restore registers in correct order (for push/pop it *does* matter), fixes crashes caused by r25224.
git-svn-id: trunk@25228 -
2013-08-08 05:35:51 +00:00
sergei
5c4abfa75a + Implemented saving/restoring registers using PUSH/POP instructions on i386 targets with non-fixed stack. Provides some advantage in code size (e.g. the compiler becomes about 20KBytes smaller).
* This should be applicable to i8086 targets as well (but needs testing), by copying changes from i386/cgcpu.pas to i8086/cgcpu.pas and removing "$ifdef i386" lines in cgx86.pas.

git-svn-id: trunk@25224 -
2013-08-07 09:59:07 +00:00
sergei
a21a20d559 + i8086-specific version of g_stackpointer_alloc.
git-svn-id: trunk@25219 -
2013-08-06 08:11:39 +00:00
sergei
1f72143eef * In preparation for fixing Mantis #24791: Copy related code from tcgx86.g_proc_entry to tcgx86_64.g_proc_entry, and remove win64-specific stuff from tcgx86 version.
git-svn-id: trunk@25218 -
2013-08-06 07:34:50 +00:00
florian
507edb16de * use add/sub instead of inc/dec on modern CPUs when optimizing for speed
git-svn-id: trunk@25057 -
2013-07-07 19:50:13 +00:00
nickysn
7e70a5f763 * i8086 fix after r25010: i8086 doesn't support lea sp,[sp-XXX]
git-svn-id: trunk@25012 -
2013-06-29 12:21:15 +00:00
florian
94cf650d9a * use lea to adjust stack pointer, this is equal or faster on all modern CPUs than add/sub
git-svn-id: trunk@25010 -
2013-06-28 17:06:57 +00:00
florian
466eb4c684 * use MOVAPS/MOVAPD for reg -> reg moves to reduce data dependencies
git-svn-id: trunk@24967 -
2013-06-24 20:55:04 +00:00
florian
e81d2d1f3b * basic avx support for floating point operations (use -Cfavx to activate)
git-svn-id: trunk@24896 -
2013-06-14 20:03:01 +00:00
nickysn
62316da236 * a_call_reg moved to a_call_reg_near
git-svn-id: trunk@24855 -
2013-06-09 22:09:39 +00:00
nickysn
604b7c9deb + added cg.a_call_ref_near and a_call_ref_far
git-svn-id: trunk@24853 -
2013-06-09 20:22:47 +00:00
nickysn
ec497ae11e + the regular tcgx86.a_call_name and .a_call_name_static moved to .a_call_name_near and .a_call_name_static_near, because a_call_name and a_call_name_static are going to be overriden in tcg8086
git-svn-id: trunk@24827 -
2013-06-09 10:42:39 +00:00
nickysn
ec76b2cf40 * refactored the segment-in-integer-register reference support, so it's handled in make_simple_ref, instead of all over the place in the code generator
git-svn-id: trunk@24752 -
2013-06-01 22:18:09 +00:00
nickysn
c9c882c30a * always use 16-bit pushes for pushing/popping the segment registers on i8086 in Tcgx86.g_concatcopy
git-svn-id: trunk@24735 -
2013-06-01 17:49:49 +00:00
nickysn
e243b6b869 * never use the 66h prefix when pushing/popping segment registers on i8086, as the stack is aligned on 2 bytes there
git-svn-id: trunk@24729 -
2013-06-01 16:03:14 +00:00
nickysn
c2e3fb5918 + emit proper interrupt procedure entry/exit code on i8086
git-svn-id: trunk@24728 -
2013-06-01 15:50:11 +00:00
nickysn
0a8e008a0d + the ES register made volatile on i8086 as per the 16-bit x86 calling conventions
git-svn-id: trunk@24462 -
2013-05-07 14:27:21 +00:00
nickysn
e4f3dd1264 * do not emit shl/shr with a const different than 1 on 8086
git-svn-id: trunk@24382 -
2013-04-29 23:02:09 +00:00
nickysn
fbc41991f9 * i8086 fixes in tcgx86.a_op_reg_reg for 16-bit OP_SHR,OP_SHL,OP_SAR,OP_ROL,OP_ROR
git-svn-id: branches/i8086@23881 -
2013-03-17 00:05:05 +00:00
florian
edd4c1ce4b * proper fix to avoid sp relative adressing as r23867 tries
git-svn-id: branches/i8086@23868 -
2013-03-16 16:51:31 +00:00
florian
b321f867c6 + trgintcpu.add_cpu_interferences for i8086 so references are properly build
* empty make_simple_ref code path for i8086

git-svn-id: branches/i8086@23782 -
2013-03-10 18:51:42 +00:00
nickysn
95b15d15bd another nested ifdef cleaned up
git-svn-id: branches/i8086@23741 -
2013-03-09 11:35:42 +00:00
nickysn
981f0a5c6c nested ifdefs converted to series of elseif + some other ifdefs cleaned up
git-svn-id: branches/i8086@23740 -
2013-03-09 11:25:25 +00:00
nickysn
5f7d432ff9 i8086 fixes in Tcgx86.g_concatcopy and TCGSize2OpSize
git-svn-id: branches/i8086@23720 -
2013-03-08 00:13:02 +00:00
Jonas Maebe
5d628b29bb * set the subregsize of OS_M64 SSE registers to R_SUBQ so we can
differentiate between 64 bit and 128 bit (R_SUBMMWHOLE) SSE vector regs,
    and support spilling/assembling for R_SUBQ SSE registers (8 bytes)
    (mantis #23962)

    We currently never use the full 128 bit of an SSE register, and
    spilling for those hasn't been implemented yet either (R_SUBMMWHOLE
    SSE regs are spilled into a 4-byte temp currently -> can overwrite data)

git-svn-id: trunk@23700 -
2013-03-06 12:42:46 +00:00
yury
e13e2e1697 * Turn off special handling of interrupt calling convention for i386-android.
git-svn-id: branches/targetandroid@23492 -
2013-01-22 14:43:42 +00:00
yury
0960ee2034 * Add missing checks for android target.
git-svn-id: branches/targetandroid@23477 -
2013-01-21 12:08:25 +00:00
sergei
7530fb3352 * tcgx86.make_simple_ref: handle references to absolute addresses (these are quite rare on x86_64, but still worth to handle correctly).
* If possible, use reference base instead of index, this yields shorter instructions.
* Added comment about offset limits for rip-relative addressing.
- Removed code related to taking threadvar address on win32, it is incorrect because Windows TLS is not directly accessible via segment registers (fs:0x2c points to array of pointers to TLS storages of each module, so at least double indirection is needed).

git-svn-id: trunk@23342 -
2013-01-07 16:00:12 +00:00
florian
d7e0f07aab + UseAVX check
git-svn-id: trunk@22642 -
2012-10-14 14:04:31 +00:00
florian
283ff05127 * merged avx support in inline assembler developed by Torsten Grundke
git-svn-id: trunk@22568 -
2012-10-06 19:47:18 +00:00
florian
8818b58e5d * Bsf/Bsr on x86 handle now correctly 0 as argument, resolves #22783
* generic Bsf implementations handle now correctly 0 as argument
* test extended

git-svn-id: trunk@22327 -
2012-09-05 13:51:45 +00:00
Jonas Maebe
b1dc518ac4 * removed systems_need_16_byte_stack_alignment and use target_info.stackalign instead
git-svn-id: trunk@22279 -
2012-09-02 14:32:21 +00:00
Jonas Maebe
952ac1ffa6 * only use indirect symbol loads for (weak)external and private_external
symbols on darwin/ppc and darwin/i386, and also for common symbols on
    darwin/ppc, as they're not required for other kinds of symbols on those
    platforms (gcc doesn't use them either with -O1 and higher; it does use
    them always for darwin/ppc64 except for local symbols, and hence so do we)

git-svn-id: trunk@22271 -
2012-08-30 21:30:38 +00:00
Jonas Maebe
35c70a6c96 * copy the darwin got register to a new register when using it, so it
cannot get modified

git-svn-id: trunk@22240 -
2012-08-25 15:12:34 +00:00
Jonas Maebe
0a1157da38 * fixed memory leaks in the compiler introduced in r21862 by marking and
releasing temporarily created function result locations

git-svn-id: trunk@21953 -
2012-07-23 13:49:29 +00:00
Jonas Maebe
408f459f5a * the code generator bugs referred to in r21921 weren't completely fixed yet
after all, although for some reason the problems only showed up with the
    external assembler on x86-64 platforms other than Darwin. Now we never use
    GOT entries on x86-64 anymore for local symbols, regardless of their nature,
    and instead use plain RIP-relative addressing for them.

git-svn-id: trunk@21924 -
2012-07-17 14:36:37 +00:00
Jonas Maebe
bb28a7cd08 * decrease the fpu stack position counter after explicitly inserted
fist(t)pq instructions (mantis #22331)
  * also internalerror in case the internal fpu stack position counter
    becomes larger than 7, so we don't have to wait for the entire
    byte to overflow before we detect a problem

git-svn-id: trunk@21734 -
2012-06-29 09:52:35 +00:00
Jonas Maebe
260958eb45 * changed last parameter of g_indirect_sym_load() to a set and also
pass on whether the symbol refers to code or data (important for
    AIX weak symbols; note that AIX does not support undefined weak
    external symbols, and FPC does not yet support weakly defining
    non-external symbols, so this functionality isn't really used yet)

git-svn-id: trunk@20802 -
2012-04-11 18:02:03 +00:00
sergei
cbad0abab5 + Platform-specific exception support for x86_64-win64. Enable by cycling with OPT=-dTEST_WIN64_SEH.
git-svn-id: trunk@20098 -
2012-01-16 23:13:31 +00:00
florian
c4a5499d2a * handle flag to reg./ref. conversion correctly for boolean64
git-svn-id: trunk@19914 -
2011-12-29 17:28:35 +00:00
florian
a59a37dddd * handle assignments of qword bools with LOC_FLAGS correctly, resolves #20874
git-svn-id: trunk@19912 -
2011-12-29 16:48:46 +00:00
florian
60cccdcdbd * improve heuristics for copy_move vs. copy_string when optimizing for size, #20664
git-svn-id: trunk@19758 -
2011-12-04 21:18:56 +00:00
sergei
ce3f850a68 * x86_64, use rip-relative references when taking address of local code labels, fixes test/library/tlib1a.pp for Linux and FreeBSD and passing exception address to FPC_RAISEEXCEPTION on Darwin.
git-svn-id: trunk@19616 -
2011-11-09 05:12:59 +00:00
sergei
4c21beb48e win64 unwinding, misc fixes:
* Insert seh_endprologue directive after the last prologue instruction, not before it
* Omit seh_stackalloc for zero bytes
* (For now) ignore SEH directives in NASM and MASM writers, instead of failing with internal error.

git-svn-id: trunk@19246 -
2011-09-26 13:55:21 +00:00
sergei
b997094755 + Generate unwind bytecode for function prologues on win64.
* For now placed actual processing of unwind info under {$ifdef TEST_WIN64_UNWIND}, because in the current state it doesn't add much value.

git-svn-id: trunk@19200 -
2011-09-23 21:22:25 +00:00
florian
13ac5d185f * fix add_move_instruction for sse moves
git-svn-id: trunk@18789 -
2011-08-20 12:30:47 +00:00
florian
26850e3425 * fix full cycle after adding new boolean types
git-svn-id: branches/pasboolxx@17847 -
2011-06-27 20:11:08 +00:00
florian
d35d1ed357 + initial support for pascal booleans with sizes 2, 4 and 8
git-svn-id: branches/pasboolxx@17836 -
2011-06-26 15:02:37 +00:00
florian
2005f6869b * cycling with $R+ fixed
git-svn-id: trunk@17600 -
2011-05-28 21:18:35 +00:00
florian
77f2d6cc0d * introduce usage of TCGInt in the code generator units
git-svn-id: trunk@17459 -
2011-05-14 17:58:23 +00:00
Jonas Maebe
b49b3ecc61 * one more fix that should have been part of r16717: also generate
addr_pic_no_got references for linux in a_loadaddr_ref_reg()

git-svn-id: trunk@16728 -
2011-01-07 19:17:47 +00:00
Jonas Maebe
0da9d36116 * fixed internal assembler for x86-64 so that it correctly handles
relocations for addr_pic_no_got references (do not go via the GOT)
  * fixed code generator so that it generates addr_pic_no_got references
    also for platforms that use the internal assembler (this will break linking
    of some tests that check static data > 2GB on Linux/x86-64, but they were
    already broken before as well because we don't use the "huge" x86-64
    execution model)
  * fixed x86-64 Linux syscall code to not expect GOT-based relocations for
    the system unit's errno variable (it's an implementation-only variable)

git-svn-id: trunk@16717 -
2011-01-06 09:28:25 +00:00
florian
5dae691c96 * implementation of bit scan intrinsics by Richard Vida, resolves #17592
git-svn-id: trunk@16174 -
2010-10-16 15:03:30 +00:00
Jonas Maebe
8b0301409a + i386/iphonesim target for the new iPhoneSimulator in Xcode 3.2.4 and
later: the same as i386/darwin, except
      a) uses the non-fragile Objective-C ABI/runtime
      b) does not require stubs for direct calls/jumps (not required for
         i386/darwin under 10.6 and later either, but still generated
         there for backwards compatibility)
      c) only the same packages are enabled as for ARM/Darwin
      d) MacOSAll is compiled specifically for the iPhoneSimulator SDK
    This target also defines the symbol "darwin" apart from the target
    name "iphonesim" for source code compatibility reasons.

git-svn-id: trunk@16065 -
2010-09-29 21:56:47 +00:00
Jonas Maebe
356026f849 * use new_section() instead of tai_section.create() everywhere
- sort of reverted r14134, which is no longer required after the above
    change (new_section() inserts the alignment itself)
  * made the tai_section.create() constructor private so it cannot be
    called directly anymore

git-svn-id: trunk@15482 -
2010-06-26 10:50:14 +00:00
Jonas Maebe
3c8b23cda4 * fixed cg.a_loadmm_reg_ref() and cg.a_loadfpu_reg_ref() in case they are
used to store a record function result in an MM/FPUREGISTER to memory
    (the register size will be OS_F32/OS_F64, while the memory size will
     be OS_32/OS_64 -> convert the latter to the former)
  * extended tcalext6 to also test this scenario

git-svn-id: trunk@15385 -
2010-06-04 22:31:35 +00:00
Jonas Maebe
9e785ea553 + several internalerrors in case things go wrong
+ support for OS_M64 in several places

git-svn-id: trunk@15366 -
2010-06-03 19:09:27 +00:00
pierre
7c08e5cb57 * Fix solaris problem after commit rev 14971
git-svn-id: trunk@14974 -
2010-03-05 13:46:36 +00:00
Jonas Maebe
a7dca09535 * only refer to local symbols without GOT redirection on darwin/x86_64,
because on linux/x86_64
     a) the resulting code crashes when using the internal assembler
     b) refuses to link when using the external assembler
   (and hence I don't know whether it's safe to do on other non-darwin
    platforms either) -- fixes mantis #15889

git-svn-id: trunk@14971 -
2010-03-04 20:23:45 +00:00