Commit Graph

84 Commits

Author SHA1 Message Date
J. Gareth "Curious Kit" Moreton
63a2395e2c * x86: Made a check for BMI2 more explicit in the integer division code generator 2022-09-09 21:02:29 +00:00
J. Gareth "Curious Kit" Moreton
645fe8a0c3 * x86: EDX is now deallocated before MULX instructions in the "magic div" algorithm so it can be used as the destination 2022-09-05 20:30:10 +00:00
J. Gareth "Curious Kit" Moreton
3f24bd3886 * x86: Improved unsigned integer division for when BMI2 is available. 2022-08-26 18:04:32 +00:00
J. Gareth "Curious Kit" Moreton
079905654d * x86: 64-bit integer division reciprocal algorithm uses IMUL
with an immediate for the modulus version where possible
2022-08-26 18:04:32 +00:00
J. Gareth "Curious Kit" Moreton
6f24c8b4ef * x86: Code generation fixes where FLAGS
register is not properly allocated.
2022-04-27 20:46:32 +00:00
J. Gareth "Curious Kit" Moreton
3ce6c478cc Bug fixes to magic division and vectorcall code that trigger -CriotR checks 2021-11-16 20:39:57 +00:00
J. Gareth "Curious Kit" Moreton
671c674d65 Expanding division to 64-bit and tests 2021-11-08 21:46:12 +00:00
florian
fc41306c45 * fix alignment issues with -<single/double> when using SSE 2021-09-19 17:44:16 +02:00
florian
5bcc530707 * handle -<mm reg.> more cleverly if SSE is used 2021-09-18 22:11:03 +02:00
florian
9bd785c06b * fix handling of -0.0 in sse/avx code, resolves #39357 2021-09-13 22:47:26 +02:00
pierre
85fa313e59 Use uvalue field to get unsigned and avoid range check or overflow errors
git-svn-id: trunk@48977 -
2021-03-15 13:24:27 +00:00
yury
64c586b86d * Removed/ifdefed lots of unused variables.
git-svn-id: trunk@48384 -
2021-01-24 12:24:01 +00:00
florian
ecc3ce64ea * x86: some fixes to enable 8 and 16 bit operations
git-svn-id: trunk@48166 -
2021-01-16 22:46:25 +00:00
florian
80f87edffd * x86-64: correctly translate and with large constants in mod optimizations, resolves #38164
git-svn-id: trunk@47805 -
2020-12-17 22:09:23 +00:00
florian
9af9f140a5 * do an unsigned division if one operand is unsigned an the other
one a constant in its range, resolves #38180

git-svn-id: trunk@47797 -
2020-12-16 21:55:05 +00:00
florian
637976e83f * patch by Marģers to unify internal error numbers, resolves #37888
git-svn-id: trunk@47103 -
2020-10-13 19:59:01 +00:00
florian
99d3651da9 * generate simplified code for unary minus when sse/avx is used
git-svn-id: trunk@47082 -
2020-10-10 21:08:16 +00:00
florian
cf153b0854 * use (V)XORPS/D for unary minus
git-svn-id: trunk@47074 -
2020-10-10 13:50:34 +00:00
florian
28f25b2df0 * reworked usage of tcgnotnode.handle_locjump
git-svn-id: trunk@46275 -
2020-08-05 21:15:32 +00:00
florian
f6e6b807d5 + optimize <signed> mod <power of 2> for x86-64 as well
git-svn-id: trunk@45854 -
2020-07-25 16:42:19 +00:00
Jonas Maebe
281b3ad276 * fix case completeness and unreachable code warnings in compiler that would
be introduced by the next commit

git-svn-id: trunk@42046 -
2019-05-12 14:29:03 +00:00
yury
4357caaad8 * Removed unused local vars.
git-svn-id: trunk@40183 -
2018-11-02 18:44:29 +00:00
florian
2385c47c28 * compilation on x86-64 fixed
git-svn-id: trunk@38370 -
2018-02-27 21:54:12 +00:00
florian
8c5606b41d + support mmx shifting
git-svn-id: trunk@38367 -
2018-02-27 21:40:12 +00:00
florian
810acd82b2 * patch by J. Gareth Moreton that makes some improvements to the Peephole Optimizer for x86 and x86-64 code, as well as some cleanup with formatting, code syntax consistency, and debug messages.
- xorq %reg,%reg (identical registers) is now changed to xorl %reg,%reg if doing so removes the REX prefix.
  - movw %bx,%ax; andl $0xffff,%eax, for example, is now changed to movzwl %bx,%eax as long as a conditional operation doesn't follow 'and' (checks to see if the CPU flags are in use).
  - movzbq and movzwq get optimised to movzbl and movzwl respectively if doing so removes the REX prefix.
  - Removal of optimisation code that zero-extends from 32-bit to 64-bit, because there isn't actually a valid combination of opcodes for MOVZX that allows that (for registers,
    just use  MOV). This is not the case with MOVSX.
  - movq is now optimised to movl even if the CPU flags are in use (this stops mov %reg,0 from being optimised to xor %reg,%reg if doing so breaks an algorithm that relies on them).
  - Fixed typo in peephole message regarding movq to movl (it said movd instead).
  - Made the peephole debug messages more consistent in formatting, some of which now have more detail.
* small fixes of the patch

git-svn-id: trunk@38070 -
2018-01-28 14:41:54 +00:00
florian
5c4b1737c4 * in the generate_code normally imaginary registers are used, so just resize the register to 8 bit, the register allocator takes care of the rest
git-svn-id: trunk@37964 -
2018-01-13 22:05:38 +00:00
florian
4a98fcb9d3 * patch by J. Gareth Moreton: reorganises the produced machine code for large unsigned divisions, resolves #32984
git-svn-id: trunk@37950 -
2018-01-12 22:03:52 +00:00
florian
52aa40c3b0 * remove explicit cast to int64 to avoid an internalerror 200706094, resolves #33004
git-svn-id: trunk@37946 -
2018-01-11 21:02:39 +00:00
florian
724b822b54 * patch based on a proposal by J. Gareth Moreton to reduce register usage
git-svn-id: trunk@37941 -
2018-01-09 21:32:18 +00:00
florian
11a3d8762a * patch by J. Gareth Moreton:
- Moved the part that emits the CMOV command outside of the if-else block, because it's the same in both branches and was just duplicated code.
  - Moved a comment about powers of 2 to be right before the correct if-else block.
  - Added a couple of comments to explain what the algorithm is doing to obtain the remainder.
  - Added missing "writeln('ok');" (since 'tmoddiv3.pp' has it) and program header to 'tmoddiv4.pp'.
  - Changed program name from "testfile2" to "tmoddiv3" in 'tmoddiv3.pp'.

git-svn-id: trunk@37939 -
2018-01-09 20:04:49 +00:00
florian
81b2cf5d65 * slightly modified patch by J. Gareth Moreton: Optimization for 'mod' on i386/x86-64, resolves #32945
git-svn-id: trunk@37922 -
2018-01-06 14:58:28 +00:00
nickysn
ddba821561 * GetNextReg(), used by 16-bit and 8-bit code generators (i8086 and avr) moved
from cpubase unit to a method in the tcg class. The reason for doing that is
  that this is now a standard part of the 16-bit and 8-bit code generators and
  moving to the tcg class allows doing extra checks (not done yet, but for
  example, in the future, we can keep track of whether there was an extra
  register allocated with getintregister and halt with an internalerror in case
  GetNextReg() is called for registers, which weren't allocated as a part of a
  sequence, therefore catching a certain class of 8-bit and 16-bit code
  generator bugs at compile time, instead of generating wrong code).
- removed GetLastReg() from avr's cpubase unit, because it isn't used for
  anything. It might be added to the tcg class, in case it's ever needed, but
  for now I've left it out.
* GetOffsetReg() and GetOffsetReg64() were also moved to the tcg unit.

git-svn-id: trunk@37180 -
2017-09-11 14:53:06 +00:00
nickysn
6634141bf4 + generate better code for division by negative power of 2 constants in the x86
(i386 and x86_64) code generator (same as the division by a positive power of
  2, followed by a NEG instruction, to invert the sign of the result; previously
  the code generator generated an IMUL instruction with a magic constant,
  followed by shift; the new code sequence should be both shorter and faster)

git-svn-id: trunk@37003 -
2017-08-21 11:35:20 +00:00
nickysn
19087d04da * replace several emit_const_reg calls that generate SHR or SAR instructions
with calls to cg.a_op_const_reg in the x86 div code generator, so that the
  same code can be used in the future for i8086 as well (SHR and SAR by
  constants other than 1 are 186+, so on 8086 they have to go through the CL
  register, which is handled correctly in cg.a_op_const_reg)

git-svn-id: trunk@36815 -
2017-07-31 16:02:52 +00:00
nickysn
9e8cc127b0 * improved the code, generated for signed division by 2 on i386 and x86_64 by
replacing the sequence
    sar reg, 31 (or 63)
    and reg, 1
  with:
    shr reg, 31 (or 63)

git-svn-id: trunk@36800 -
2017-07-27 16:02:30 +00:00
nickysn
bb7cd4866d * corrected comment in x86 division code - it said "signed", when it actually meant "negative"
git-svn-id: trunk@36799 -
2017-07-27 15:04:56 +00:00
nickysn
b6c3329f20 + also check for negative powers of 2 in the mod by power-of-2 constant x86 optimization, since the sign of the divisor is ignored by the 'mod' operation
git-svn-id: trunk@36797 -
2017-07-26 16:10:41 +00:00
nickysn
7c306f18e3 + perform unsigned modulus by power of 2 constant by using an AND instruction (instead of DIV) on x86
git-svn-id: trunk@36756 -
2017-07-21 15:58:26 +00:00
florian
b1dff29cbf * removed unused units
git-svn-id: trunk@36165 -
2017-05-09 19:53:14 +00:00
Jonas Maebe
a25ebbba3e + added volatility information to all memory references
o separate information for reading and writing, because e.g. in a
     try-block, only the writes to local variables and parameters are
     volatile (they have to be committed immediately in case the next
     instruction causes an exception)
   o for now, only references to absolute memory addresses are marked
     as volatile
   o the volatily information is (should be) properly maintained throughout
     all code generators for all archictures with this patch
   o no optimizers or other compiler infrastructure uses the volatility
     information yet
   o this functionality is not (yet) exposed at the language level, it
     is only for internal code generator use right now

git-svn-id: trunk@34996 -
2016-11-27 18:17:37 +00:00
florian
49f63d67b2 * correctly check left.location instead of left.expectloc when generating
code for not nodes, resolves #30208

git-svn-id: trunk@33906 -
2016-06-04 15:54:17 +00:00
florian
77b4709e7a + i386 compiler tracks now flag usage if needed, so the mov $0,reg -> xor reg,reg transformation can be enabled
git-svn-id: trunk@33545 -
2016-04-22 19:44:26 +00:00
yury
374148b966 * fixed compilation of 8086 compiler.
git-svn-id: trunk@31746 -
2015-09-17 16:30:02 +00:00
yury
47b316d0e2 * Removed unused vars for x86-64 compiler.
git-svn-id: trunk@31744 -
2015-09-17 15:26:31 +00:00
Jonas Maebe
687bb15299 * renamed getdatalabel() to getglobaldatalabel
git-svn-id: branches/hlcgllvm@30336 -
2015-03-27 21:25:34 +00:00
florian
29d4037a9c * make integer division instruction (div/idiv) on x86 dependent on the
resulttype of the div node set by the type checking pass, this is 
  also how the generic code generator handles it, resolves #27173

git-svn-id: trunk@29382 -
2015-01-04 13:08:57 +00:00
Károly Balogh
07ad2a04ac * fix warnings when compiling the compiler with DFA optimizer enabled on i386
git-svn-id: trunk@28497 -
2014-08-20 12:28:44 +00:00
sergei
05ecd3cec1 * One more fix of operand size, likely harmless because shift amount is taken modulo bit-width anyway.
git-svn-id: trunk@27955 -
2014-06-14 13:31:48 +00:00
sergei
be6d6d90d7 + Division-by-constant optimization for x86_64 (merged i386 code adapted for different operand sizes, so the result should be suitable for i386 as well).
git-svn-id: trunk@27945 -
2014-06-13 12:32:45 +00:00
sergei
b594eee70b * Moved x86_64 mod/div code to x86, with minimal changes to ensure it compiles on i386/i8086. Merging optimized division-by-const code from i386 is pending...
git-svn-id: trunk@27930 -
2014-06-11 01:42:46 +00:00