Commit Graph

1550 Commits

Author SHA1 Message Date
nickysn
c93c15429d + introduce tx86intreader.SetSegmentOverride(); using it everywhere adds more
checks for duplicated segment overrides (which cause a warning in TP mode and
  an error in all the other compiler modes)

git-svn-id: trunk@38384 -
2018-02-28 17:16:50 +00:00
nickysn
6f8abde786 + support [const+[ref]] in the x86 intel syntax asm reader
git-svn-id: trunk@38383 -
2018-02-28 16:24:45 +00:00
nickysn
8ffde52974 + also support [expr1]+[expr2] for adding references in the x86 intel syntax asm reader
git-svn-id: trunk@38381 -
2018-02-28 15:48:48 +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
nickysn
9c814e42c9 + support segment overrides inside references (e.g. [es:bx]) in the x86 intel
syntax inline asm reader

git-svn-id: trunk@38365 -
2018-02-27 17:29:46 +00:00
nickysn
1cf1ab8ab9 * consume the register in the reference before the check for invalid reference
syntax in the x86 intel syntax asm reader; this is preparation for support of
  segment overrides inside the reference expression (i.e. [es:bx] instead of
  es:[bx])

git-svn-id: trunk@38363 -
2018-02-27 16:35:55 +00:00
nickysn
f623038da6 + fixed a bug in the previous commit, when adding two references, the first
containing a base register, the second - an index register with a scalefactor.
  The scalefactor was ignored in this case.

git-svn-id: trunk@38354 -
2018-02-26 17:30:08 +00:00
nickysn
45fdd7655d + support concatenation of references in x86 intel syntax inline asm:
[expr1][expr2] = [expr1+expr2]
  [expr1[expr2]] = [expr1+expr2]
  This is compatible with TP7's inline asm, and perhaps also with tasm/masm/delphi.

git-svn-id: trunk@38352 -
2018-02-26 17:17:47 +00:00
florian
c5f8567ed7 * getsubreg => getsupreg
git-svn-id: trunk@38344 -
2018-02-25 15:34:14 +00:00
florian
fc6c0e8ef4 + AndShlToShl optimization
* moved topsize2memsize to cpubase

git-svn-id: trunk@38343 -
2018-02-25 15:34:12 +00:00
florian
6e811d057c * MovOpMov2Op cannot be applied for L, Q, Q as operand sizes
+ test

git-svn-id: trunk@38337 -
2018-02-25 10:19:52 +00:00
florian
98bd768521 * remove type cast of the parameter of int(...), if an instruction is available which can be used directly
git-svn-id: trunk@38335 -
2018-02-24 23:13:27 +00:00
florian
3b779278e2 + (slightly) patch by Emelyanov Roman to add support of SEH directive in FPC internal assembler with INTEL syntax, resolves #29894
git-svn-id: trunk@38331 -
2018-02-24 16:14:08 +00:00
nickysn
506d5fe30e + support bracketless references in the x86 intel syntax; ugly, but TP7 (and
perhaps also Delphi, TASM and MASM)-compatible

git-svn-id: trunk@38296 -
2018-02-20 17:18:09 +00:00
florian
e92422383a * compilation fixed
git-svn-id: trunk@38280 -
2018-02-18 09:29:36 +00:00
florian
91514da267 * factored out TX86AsmOptimizer.PostPeepholeOptCall
+ use TX86AsmOptimizer.PostPeepholeOptCall on x86-64

git-svn-id: trunk@38278 -
2018-02-17 23:25:01 +00:00
florian
1b3627add1 + peephole optimization MovMov2Mov 5
git-svn-id: trunk@38273 -
2018-02-17 21:10:51 +00:00
florian
5eb59196d5 * remove sequential moves to the same register
+ test

git-svn-id: trunk@38267 -
2018-02-17 12:45:17 +00:00
florian
99f1fe54af * check for registers removed which is not needed anymore
git-svn-id: trunk@38265 -
2018-02-17 12:45:13 +00:00
florian
f66a91499d * FPC uses meanwhile more mov instructions, so extended taicpu.is_same_reg_move to support them
git-svn-id: trunk@38264 -
2018-02-17 09:45:19 +00:00
pierre
55289c13e4 Use af_no_stabs for clang assembler which does not support stabs debug format
git-svn-id: trunk@38238 -
2018-02-14 15:09:35 +00:00
florian
381cf78ff1 * there is no vmovq for mmx registers
git-svn-id: trunk@38208 -
2018-02-11 17:50:41 +00:00
florian
31f78ea2b6 + implementation of the vectorcall calling convention by J. Gareth Moreton
+ tests

git-svn-id: trunk@38206 -
2018-02-11 17:50:37 +00:00
florian
092223f400 * comment links to test now
git-svn-id: trunk@38204 -
2018-02-11 16:38:33 +00:00
florian
e5ebc65cce * if si and di are allocated on i8086, using an index in references is not possible anymore
git-svn-id: trunk@38203 -
2018-02-11 15:54:37 +00:00
nickysn
ae6a4030c3 + support evaluation of recordtype*constant in the intel syntax inline asm.
The recordtype itself is evaluated to 0. This makes e.g.
  'test [di+recordtype*5], 1' work. This is TP7 compatible.

git-svn-id: trunk@38200 -
2018-02-11 03:42:45 +00:00
nickysn
f0765421eb + also set the operand size in constants like recordtype (without addressing a
record field). This makes e.g.
    test [di + recordtype], 1
  work and use the size of recordtype to determine the operand size; recordtype
  itself is evaluated to 0, so if recordtype's size is 2 bytes, the above
  instruction assembles as:
    test word ptr [di], 1
  Ugly, but TP7 compatible.

git-svn-id: trunk@38176 -
2018-02-09 17:43:31 +00:00
nickysn
7338437dcd * allow recordtype.recordfield constants to set the operand size; this makes things like
test [di + recordtype.recordfield], 1
  work, as long as the size of recordfield is a valid operand size for the target

git-svn-id: trunk@38175 -
2018-02-09 17:36:54 +00:00
nickysn
f829f70186 * use the 'size' return value of BuildConstSymbolExpression to set the operand size
git-svn-id: trunk@38174 -
2018-02-09 17:22:39 +00:00
nickysn
384715be8d + add an extra output parameter 'size' to tx86intreader.BuildConstSymbolExpression,
which allows const symbol expressions to also have a size sometimes. Why?
  Because TP7 (and perhaps Delphi) allows not specifying the size in e.g.
    test [di+recordtype.recordfield], 1
  in this case, the operand size (byte ptr, word ptr, dword ptr, qword ptr) is
  determined by the size of recordtype.recordfield; this already happens with
  variables, but in this case, this is a type.field, which is resolved to a
  constant.
  This commit only adds a dummy 'size' parameter, which is always initialized to
  0 and not used. The actual implementation of the above will follow in separate
  commits.

git-svn-id: trunk@38173 -
2018-02-09 16:52:12 +00:00
nickysn
4b339fd133 * convert the 'var' parameters of tx86intreader.BuildConstSymbolExpression to 'out'
git-svn-id: trunk@38172 -
2018-02-09 16:20:34 +00:00
nickysn
84611d716b * convert the 'var' parameters of tx86intreader.BuildRecordOffsetSize to 'out'
git-svn-id: trunk@38171 -
2018-02-09 16:15:40 +00:00
nickysn
391f85f828 + for TP7 compatibility, allow the '&', '$' and '?' characters in the x86 intel
syntax inline asm reader

git-svn-id: trunk@38167 -
2018-02-08 16:54:33 +00:00
nickysn
5f56f6ec11 * always pass a valid constsize to ConcatConstSymbol; this prevents a compiler
internal error on i8086, generated by 'DB xx' or 'DB OFFSET xx'

git-svn-id: trunk@38153 -
2018-02-07 16:17:05 +00:00
nickysn
a792a92cfb * prevent the spurious warning, generated by 'DD xx' and 'DD OFFSET xx' on i8086
git-svn-id: trunk@38152 -
2018-02-07 16:14:05 +00:00
nickysn
3ad3807b6f + accept the 'DB/DW/DD OFFSET xx' syntax
git-svn-id: trunk@38150 -
2018-02-07 16:07:59 +00:00
nickysn
3b1bd8de3f + actually set hasofs to true if 'offset' is encountered in BuildConstSymbolExpression
git-svn-id: trunk@38149 -
2018-02-07 16:03:40 +00:00
nickysn
d591e698ac + added parameter 'hasofs' to ConcatConstSymbol. Will be used to support 'dd xx'
vs 'dd offset xx' being different on i8086.

git-svn-id: trunk@38148 -
2018-02-07 15:23:48 +00:00
nickysn
70038f1c0b + added extra boolean out parameter 'hasofs' to
tx86intreader.BuildConstSymbolExpression; it returns whether the 'OFFSET'
  keyword has been used in the expression. This will be used for disambiguation
  between 'dd xx' and 'dd offset xx', because they should produce different
  results on i8086 (the first generates a far pointer, i.e. the same as
  'dw xx, SEG xx', the second - a 32-bit offset)

git-svn-id: trunk@38147 -
2018-02-07 15:09:54 +00:00
nickysn
629be9cee1 + add a 'constsize' parameter to ConcatConstSymbol, so it can be used to
distinguish between e.g. 16-bit and 32-bit offsets on i8086

git-svn-id: trunk@38141 -
2018-02-06 16:22:41 +00:00
florian
e6a6938787 * make fpu/mmx/xmm/ymm registers numbers instead of flags to have enough space for zmm/bnd/k registers
git-svn-id: trunk@38116 -
2018-02-04 20:29:41 +00:00
nickysn
1f0e311fdd + allow segment override prefixes to be used as a standalone opcode in the intel
syntax inline assembler; this is TP7 compatible and allows compiling ugly
  code, such as 'seges; db $67,$66; lodsw'

git-svn-id: trunk@38096 -
2018-02-01 17:31:59 +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
10ea652493 * fix for #32576
+ test case

git-svn-id: trunk@38069 -
2018-01-28 13:26:49 +00:00
florian
93353d8d79 * typo
git-svn-id: trunk@38068 -
2018-01-28 13:26:47 +00:00
svenbarth
d50848174a + add putboolean and getboolean convenience methods to tentfile
* use putboolean and getboolean where approbiate

git-svn-id: trunk@37972 -
2018-01-14 21:36:02 +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
1a69c49e81 * fix range check errors by explicit casts
git-svn-id: trunk@37945 -
2018-01-11 21:00:18 +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
Jonas Maebe
f1ace2b74d - reverted r36870, Darwin's assembler uses a different way to specify
32/64 bit (like it was before; fixes mantis #32954)

git-svn-id: trunk@37914 -
2018-01-05 19:48:19 +00:00
Jonas Maebe
1b66995754 * factored out check to determine whether a variable can be subscripted in
inline assembly, and fixed check after r35959 (mantis #32318)
   o can also subscript parameters passed by value on the stack
   o can also subscript local variables, the parameters passed by reference
     that are subsequently copied into a local

git-svn-id: trunk@37886 -
2018-01-01 14:29:21 +00:00
nickysn
c464f7fa56 * fixed the SEG inline asm directive when used with 32-bit registers on the i8086 target
git-svn-id: trunk@37613 -
2017-11-22 15:04:30 +00:00
Károly Balogh
e6aed467b5 renamed script unit to cscript to avoid namespace conflict with univint package on Darwin. this makes it possible to build the textmode IDE on Darwin
git-svn-id: trunk@37598 -
2017-11-17 11:27:19 +00:00
florian
674398c5a5 * i8086 compilation fixed after r37572
git-svn-id: trunk@37573 -
2017-11-11 13:25:02 +00:00
florian
73fda1ccb6 * factored out OptPass1Sub
+ make use of OptPass1Sub on x86_64 and i8086 as well

git-svn-id: trunk@37572 -
2017-11-10 20:55:22 +00:00
nickysn
ae92973196 + added support for the retw, retnw, retfw, retd, retnd, retfd, retq, retnq and
retfq x86 instructions. These are variants of the ret instruction with the
  return offset size set explicitly, e.g. retfw is a 16-bit far ret (i.e. pops
  a 16-bit offset and a 16-bit segment), retfd is a 32-bit far ret (pops a
  32-bit offset, followed by a 16-bit segment), etc.

git-svn-id: trunk@37571 -
2017-11-10 16:53:29 +00:00
pierre
176cec14c9 Fix value of NR_DR6 and NR_DR7
git-svn-id: trunk@37564 -
2017-11-07 07:29:54 +00:00
florian
1556599ad5 * symbols with bind type AB_EXTERNAL_INDIRECT need to be declared as EXTERN for masm/nasm etc.
git-svn-id: trunk@37553 -
2017-11-04 19:10:17 +00:00
florian
4da4b768ec * factored out PostPeepholeOptTest
+ use PostPeepholeOptTest on x86-64

git-svn-id: trunk@37551 -
2017-11-04 19:10:14 +00:00
florian
3097eaf8ee * made PostPeepholeOptMov a function
git-svn-id: trunk@37550 -
2017-11-04 19:10:12 +00:00
florian
a7ea7fb569 * factored out PostPeepholeOptCmp
+ use PostPeepholeOptCmp for x86_64

git-svn-id: trunk@37549 -
2017-11-04 19:10:09 +00:00
nickysn
e5dad9c98c + set oper.haslabelref in several other places, where a reference, containing a
label is created in the intel syntax x86 assembler. This fixes tfarcal3.pp and
  tfarcal4.pp after r37538

git-svn-id: trunk@37541 -
2017-11-01 14:31:16 +00:00
nickysn
9649154368 * fixed the token2str const array for intel syntax x86 asm
git-svn-id: trunk@37540 -
2017-11-01 13:36:16 +00:00
nickysn
9450beb99c * fixed bug in intel syntax i8086 inline asm, when certain 'jmp/call [v]'
instructions got erroneously converted to 'jmp/call v', if 'v' is an external
  far variable that points to certain things (like a local label, exported via
  public)

git-svn-id: trunk@37538 -
2017-10-31 16:49:38 +00:00
nickysn
29558a74cd + support exporting labels from asm blocks in intel syntax asm blocks via the
'public' directive

git-svn-id: trunk@37530 -
2017-10-30 16:44:13 +00:00
nickysn
8a0d8f025b * fixed another i8086 inline asm 32-bit constant bug (e.g. in 'or eax, 80000001h')
git-svn-id: trunk@37521 -
2017-10-25 19:38:37 +00:00
nickysn
325e66287c * fix for inline asm of instructions with 32-bit constant operands on i8086
git-svn-id: trunk@37519 -
2017-10-25 18:03:22 +00:00
nickysn
2af5c9d508 * changed type used for section alignment from byte/shortint to longint, so the
internal object writer and the internal linker support object files with
  sections with alignment >=256

git-svn-id: trunk@37518 -
2017-10-25 15:47:29 +00:00
nickysn
8cc230ef1a - don't switch index into base in the gas assembly writer. This optimization
(and others) are performed in optimize_ref().

git-svn-id: trunk@37517 -
2017-10-25 13:42:18 +00:00
nickysn
d7e4b50068 + also optimize x86_64 references by switching [rbp+reg64] to [reg64+rbp],
[r13+reg64] to [reg64+r13] and [r13d+reg32] to [reg32+r13d]

git-svn-id: trunk@37516 -
2017-10-24 16:18:43 +00:00
nickysn
5ae32a0ec5 + always do the x86_64 reference optimizations as if SS=DS, because the CPU
basically ignores these segments in long mode

git-svn-id: trunk@37515 -
2017-10-24 15:38:59 +00:00
nickysn
e58bad8eef + check for the 'pop cs' instruction in the x86 inline assembler and print a
warning (on the i8086 target) or an error (on i386 and x86_64) when this
  instruction is used (because it only works on 8086 and 8088 CPUs)

git-svn-id: trunk@37514 -
2017-10-24 15:07:20 +00:00
nickysn
0d1f7910d7 + also apply optimize_ref() on references of inline asm instructions
git-svn-id: trunk@37512 -
2017-10-23 22:28:08 +00:00
nickysn
875339993f * strip segment overrides, for segments, which should be equal in the current
model to the default segment of the reference in optimize_ref, when
  inlineasm=false

git-svn-id: trunk@37511 -
2017-10-23 15:51:33 +00:00
nickysn
80226e3af4 + added an optimization pass, that optimizes x86 references
git-svn-id: trunk@37494 -
2017-10-20 15:55:55 +00:00
nickysn
67a0e9bdae + added x86 helper function get_default_segment_of_ref, which returns the
default segment base for the ref, in case there's no segment override
* in the internal assembler, use get_default_segment_of_ref to strip redundant
  prefixes, instead of always assuming all refs are DS-based

git-svn-id: trunk@37486 -
2017-10-18 14:24:58 +00:00
nickysn
e8bbc4eef9 + support the xlat x86 instruction syntax with a memory operand. This allows
specifying the address size (e.g. xlat byte ptr [bx] or xlat byte ptr [ebx])

git-svn-id: trunk@37478 -
2017-10-17 16:40:06 +00:00
nickysn
9cebeeffa9 + check for address size mismatch in intel syntax assembler as well
git-svn-id: trunk@37475 -
2017-10-16 16:19:15 +00:00
nickysn
353efcb163 * fixed rdi register name in error message
git-svn-id: trunk@37474 -
2017-10-16 16:14:18 +00:00
nickysn
cece021bd1 + check whether the address sizes match for x86 string instructions with two
memory operands, when using the at&t syntax inline assembler

git-svn-id: trunk@37473 -
2017-10-16 16:01:38 +00:00
nickysn
4cb1a96ec1 * use get_ref_address_size in the nasm writer, when handling the parameterized
string instructions

git-svn-id: trunk@37471 -
2017-10-16 14:21:03 +00:00
nickysn
6f2e64ff90 + added function get_ref_address_size
git-svn-id: trunk@37470 -
2017-10-16 14:13:03 +00:00
nickysn
b0653a6313 + added functions is_32_bit_ref and is_64_bit_ref, similar to is_16_bit_ref
* taicpu.needaddrprefix now uses is_32_bit_ref on x86_64
* is_16/32/64_bit_ref made part of the aasmcpu unit interface, so they can be
  used elsewhere (e.g. in the inline assembler readers)

git-svn-id: trunk@37469 -
2017-10-16 14:05:06 +00:00
nickysn
2b6e5d817e * changed the parameter of is_16_bit_ref to be a treference, instead of toper
git-svn-id: trunk@37463 -
2017-10-16 00:30:26 +00:00
nickysn
acfa199b09 * in the nasm writer, only output a segment prefix for the [si] operand, in
case there's a segment operand, different that DS (the default source
  segment) for parameterized x86 string instructions

git-svn-id: trunk@37459 -
2017-10-14 16:58:15 +00:00
nickysn
a8232ac477 + added warning if source or destination for x86 string instructions isn't
specified to be (%esi) or (%edi), when using at&t syntax assembler (this is
  not considered an error by intel syntax assemblers, so we're not adding a
  warning there, for now)

git-svn-id: trunk@37458 -
2017-10-14 15:27:00 +00:00
nickysn
dd9b5eb2aa + added the 'Cannot override ES' message in the at&t assembler reader as well
git-svn-id: trunk@37456 -
2017-10-14 00:48:46 +00:00
nickysn
1ee36b5b9b + added error message in the intel assembler reader, when an attempt is made to
override the ES segment in an x86 string instruction (because it cannot be
  overriden)

git-svn-id: trunk@37454 -
2017-10-13 14:56:38 +00:00
nickysn
baf492c7a5 + another helper function: x86_parameterized_string_op_param_count
* when generating x86 code for parameterized string instructions with the
  internal object writer, don't rely on the destination operand being [(r/e)di]
  when determining the segment prefix, because when using intel syntax, source
  and destination can be anything (only the operand size, the address size and
  the source segment is taken into account)

git-svn-id: trunk@37452 -
2017-10-12 16:07:15 +00:00
nickysn
4c75b15afe * shortened the names of the is_x86_string_instruction_op,
is_x86_parameterless_string_instruction_op and
  is_x86_parameterized_string_instruction_op by removing 'instruction' from
  their names

git-svn-id: trunk@37451 -
2017-10-12 15:20:22 +00:00
nickysn
e3ca2a3043 + added helper functions get_x86_string_op_si_param and get_x86_string_op_di_param
* use get_x86_string_op_si_param in the nasm writer

git-svn-id: trunk@37450 -
2017-10-12 15:12:40 +00:00
nickysn
5a5cd65559 + added helper functions x86_param2paramless_string_op and
get_x86_string_op_size
* refactored the AT&T inline asm handling of x86 parameterized string ops, so it
  uses the new helper functions

git-svn-id: trunk@37449 -
2017-10-12 14:25:32 +00:00
nickysn
2f28768d2d * simplify some code, by using is_x86_parameterized_string_instruction_op
git-svn-id: trunk@37448 -
2017-10-12 13:26:07 +00:00
nickysn
98c4986b6d + added x86 helper functions is_x86_string_instruction_op,
is_x86_parameterless_string_instruction_op and
  is_x86_parameterized_string_instruction_op

git-svn-id: trunk@37447 -
2017-10-12 13:18:38 +00:00
nickysn
0fb79946a5 + added support for the parameterized versions of the x86 string instructions
(movs, cmps, scas, lods, stos, ins, outs) in the inline asm of the i8086, i386
  and x86_64 targets. Both intel and at&t syntax is supported.
* NEC V20/V30 instruction 'ins' (available only on the i8086 target, because it
  is incompatible with 386+ instructions) renamed 'nec_ins', to avoid conflict
  with the 186+ 'ins' instruction.

git-svn-id: trunk@37446 -
2017-10-12 00:07:02 +00:00