Commit Graph

181 Commits

Author SHA1 Message Date
masta
92c47148cc Optimize 8/16 OP_NOT on ARM
This now generates:

mvn r0, r0, lsl #24/#16
mov r0, r0, lsr/asr #24/#16

The lsr/asr might be folded into a following instruction, making the
whole operation 1 cycle instead of 2-3 with the previous solution.

git-svn-id: trunk@21658 -
2012-06-20 12:39:09 +00:00
masta
0f3441a9c2 Split OP_ADD, OP_SUB, OP_AND and OP_ORR into multiple instructions if that can avoid constant construction or even loading from a pool.
OP_ADD, OP_SUB, OP_ORR will be split into two intructions if possible when a load/const
construction is required.

OP_AND is a bit different, because we can't just split it up, but we try
to find a two instruction BIC-equivalent to it.

Till now code like

a:= a and $FFFF;

produced code like

mov r0, $FF00
orr r0, r0, $FF
and r1, r1, r0

With this addition we produce code like:

bic r0, r0, $FF00
bic r0, r0, $FF

Saving us at least a cycle and in some cases also a load from the
constant-pool.

This uses the new split_into_shifter_const function.

git-svn-id: trunk@21647 -
2012-06-18 16:59:29 +00:00
masta
f11fbe527e Improve loading of ARM constant values
*  use split_into_shifter_const to reduce the MOV/ORR combination to a
   single check and allow a broader rang of combinations.
*  Introduce MVN/BIC combination to load values which have more 1 than 0
   bits set (like small negative values)

git-svn-id: trunk@21646 -
2012-06-18 16:59:24 +00:00
florian
45c70ec81c * patch by Nico Erfurth: Support the usage of BIC instead of AND on ARM
BIC clears the specified bits, while AND keeps them. The usage of BIC
allows a broader range of shifterconsts to be used on the ARM cpu, often
saving a cycle.

Previously code like:
Data:=Data and $FFFFFF00

would result in

mvn r1, #255
and r0, r0, r1

This patch changes this to

bic r0, r0, #255

git-svn-id: trunk@21510 -
2012-06-06 19:45:26 +00:00
florian
4ea1d22c5a * patch by Nico Erfruth: Support BX for function returns on armv5+
BX is supported from ARMv4T onwards, but i don't have a armv4t device to
test it.

Using BX instead of mov pc,lr allows for a better pipeline utilization
by enabling the CPUs branch predictor to work properly.

git-svn-id: trunk@21505 -
2012-06-06 19:42:26 +00:00
florian
c75486db89 * patch by Nico Erfurth:
Reorder unaligned Load sequence on ARM

The old version produced code like that:

ldrb rDEST, [rBASE]
ldrb rTemp, [rBASE, #1]
orr  rDEST, rDEST, rTEMP lsl #8 (2 stall cycles)
ldrb rTemp, [rBASE, #2]
orr  rDEST, rDEST, rTEMP lsl #16 (2 stall cycles)
ldrb rTemp, [rBASE, #3]
orr  rDEST, rDEST, rTEMP lsl #24 (2 stall cycles)

This creates a lot of stall-cycles on ARM Implementations with load
delay slots like Marvel Kirkwood or Intel XScale. With the usual up to 2
stall-cycles this code requires a total of 13 cycles (7 instructions + 6 stall
cycles) in best case.

The new code uses a second temp register to avoid the stall cycles.

ldrb rDEST, [rBASE]
ldrb rTemp1, [rBASE, #1]
ldrb rTemp2, [rBASE, #2]
orr  rDEST, rDEST, rTEMP1 lsl #8
ldrb rTemp1, [rBASE, #3]
orr  rDEST, rDEST, rTEMP2 lsl #16
orr  rDEST, rDEST, rTEMP1 lsl #24 (1 stall cycle)

The rescheduling and second register bring the total cycles down to 8.
If a later rescheduling should happen for the last orr it even can go
down to 7.

git-svn-id: trunk@21363 -
2012-05-22 19:09:20 +00:00
florian
5f0bcd9248 * patch by Nico Erfurth:
Optimize ARM OP_MUL/OP_IMUL for x*ispowerof2(const+1) cases

Calculations like a*7 can be optimized to a*8-a with the usage of RSB and left
shifts which can be done in a single cycle.

git-svn-id: trunk@21351 -
2012-05-20 20:50:04 +00:00
Jonas Maebe
bba4b02eb2 * use r7 instead of r11 as frame pointer on Darwin/iOS, and make sure r7
always points to the previous r7 on the stack (with the saved return
    address coming right after it) so that the debugger and crashreporter
    can use it for backtraces as specified in the ABI
   o changed NR_FRAME_POINTER_REG and RS_FRAME_POINTER_REG from a symbolic
     into a typed constant, and added a new method to tprocinfo that can
     be used to initialze it (so it can be inited to r7/r11 depending on
     the target platform)
  * allow using r9 on Darwin, it was only used by the system on iOS up to
    2.x, which we no longer support
  * prefer using r9 and r12 before r4..r11 on Darwin, because they are
    volatile and hence do not have to be saved

git-svn-id: trunk@20661 -
2012-03-29 20:54:33 +00:00
Jonas Maebe
6ba8dc7146 + support for the ARM hard float EABI on Linux (patch by Peter Green):
o new eabihf (hard float) abi
   o vfpv3_d16 variant of VFP (default variant used by EABI assemblers: VFPv3
     with only 16 double registers instead of 32) and pass it to GNU as
   o make the odd numbered single precision floating point VFP registers
     available for explicit allocation for use by the calling convention
  * fixed copy/paste error in stdname of S30 register
  -> use -dFPC_ARMHF to create an ARM eabi hard float compiler
  (mantis #21554)

git-svn-id: trunk@20660 -
2012-03-29 20:50:09 +00:00
florian
841d67ec81 * don't waste an extra register when copying 4 bytes
git-svn-id: trunk@20475 -
2012-03-05 19:12:00 +00:00
pierre
42c98f3cd5 Override abstract method to abvoid warning at compilation time
git-svn-id: trunk@19578 -
2011-11-03 10:08:12 +00:00
florian
ce61891ca3 * offset used by A_LDF,A_STF,A_FLDS,A_FLDD,A_FSTS,A_FSTD must be dividable by 4
git-svn-id: trunk@19270 -
2011-09-28 19:01:09 +00:00
Jonas Maebe
2b11fd2bef * cpus that only understand Thumb-2 don't support "blx <imm>"
git-svn-id: trunk@19238 -
2011-09-25 20:44:39 +00:00
florian
5fa184c952 + patch by Jeppe Johansen to make use of the div/udiv instruction on arm7m, resolves #20022
* explicitly make symbol addressing PC relative

git-svn-id: trunk@19221 -
2011-09-24 21:41:01 +00:00
Jonas Maebe
852ae48cb7 * also use blx instead of bl for direct calls on ARMv5+, since the target
may be thumb(2) (mantis #19896)
  * don't conditionalize "blx <imm target>", because that's not a valid
    encoding

git-svn-id: trunk@18984 -
2011-09-05 20:33:15 +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
77f2d6cc0d * introduce usage of TCGInt in the code generator units
git-svn-id: trunk@17459 -
2011-05-14 17:58:23 +00:00
svenbarth
35b47e491c Rebase to revision 17306
git-svn-id: branches/svenbarth/classhelpers@17314 -
2011-04-13 10:04:14 +00:00
florian
8bff2a0de4 * patch by Jeppe Johansen to fix thumb2 epilog generation, resolves #18392
git-svn-id: trunk@17252 -
2011-04-05 19:25:20 +00:00
svenbarth
96116a6c3a Several adjustments because virtual methods in helpers are just normal methods and a VMT isn't generated for them either.
* $CPU/cgcpu.pas: disable the generation of VMT loading code
* dbgstabs.pas, dbgdwarf.pas: treat virtual methods of helpers as normal methods
* ncgcal.pas: don't register virtual helper methods for WPO 
* ncgrtti.pas: write virtual helper methods as normal methods to RTTI
* nobj.pas: correctly handle final and override cases in helpers
* pdecvar.pas: property getters
* rautils.pas: no VMT offset in records

git-svn-id: branches/svenbarth/classhelpers@17150 -
2011-03-20 10:41:45 +00:00
svenbarth
80e6498921 Rebase to revision 17096
git-svn-id: branches/svenbarth/classhelpers@17099 -
2011-03-09 16:29:47 +00:00
Jonas Maebe
b8e9fd5c00 * use blx also for ARMv5, since it works on non-T variants and is required
for correct operation on T-variants (patch by Dejan Boras, mantis #18819)

git-svn-id: trunk@17001 -
2011-02-25 19:46:35 +00:00
Jonas Maebe
780e75bfac o patch by Jeppe Johansen to fix mantis #17472:
* generate add.w instead of add for thumb-2 in case one of the registers
      is > r8
    * add register interferences for the "add" instruction so the register
      allocator can detect invalid instruction forms (even for assembler code)
    * fixed error in thumb2.inc detected by the previous change

git-svn-id: trunk@16633 -
2010-12-24 15:54:39 +00:00
paul
b317139006 compiler: fix compilation problems caused by tprocdef._class -> tprocdef.struct rename which was found by make fullcycle
git-svn-id: branches/paul/extended_records@16530 -
2010-12-10 06:50:58 +00:00
Jonas Maebe
c44d79f3ba * fix the value of the frame pointer for Thumb-2 after r14317
(patch by Jeppe Johansen, mantis #18025)

git-svn-id: trunk@16416 -
2010-11-24 10:07:49 +00:00
Jonas Maebe
f13f6627c4 * moved use_fixed_stack from cgutils to a method in paramgr so it can
be used outside the code generator
  * renamed tabstractprocdef.requiredargarea into callerargareasize,
    and also added calleeargareasize field; added init_paraloc_info(side)
    method to init the parameter locations and init those size fields and
    replaced all "if not procdef.has_paraloc_info then ..." blocks with
    procdef.init_paraloc_info(callersize)"
  * moved detection of stack tainting parameters from psub to
    symdef/tabstractprocdef
  + added tcallparanode.contains_stack_tainting_call(), which detects
    whether a parameter contains a call that makes use of stack paramters
  * record for each parameter whether or not any following parameter
    contains a call with stack parameters; if not, in case the current
    parameter itself is a stack parameter immediately place it in its
    final location also for use_fixed_stack platforms rather than
    first putting it in a temporary location (part of mantis #17442)
  * on use_fixed_stack platforms, always first evaluate parameters
    containing a stack tainting call, since those force any preceding
    stack parameters of the current call to be stored in a temp location
    and copied to the final location afterwards

git-svn-id: trunk@16050 -
2010-09-26 21:24:14 +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
283018a3bf * changed tprocdef.funcretloc[] from a tlocation into a tcgpara so it can
represent complex locations (required for full x86-64 ABI support,
    which is not yet implemented) -> lots of special result handling
    code has been removed and replaced by the parameter handling
    routines
  + added support for composite parameters (and hence function
    results) to tcg.a_load_ref_cgpara() (so it can be used for
    handling, e.g., 64 bit parameters on 32 bit platforms)
  * the above fixed writing past the end of allocated memory when
    handling records returned in registers on x86-64 whose size is
    not a multiple of 8 bytes (mantis #16357)
  - removed the x86-64 and PPC specific versions of a_load_ref_cgpara(),
    as they are now handled correctly by the generic version
  * moved the responsibility of allocating tcgpara cpu registers
    (using paramanager.allocparaloc()) from the callers of
    cg.a_load*_cgpara() to the cg.a_load*_cgpara() methods
    themselves (so the register allocation can be done efficiently
    when dealing with function results)
  * for the above, renamed paramanager.alloc/freeparaloc() to
    paramanager.alloc/freecgpara(), and use paramanager.allocparaloc()
    to allocate individual pcgparalocations instead
  * fixed the register size of SSE2 function result registers for
    x86-64 (when used for floating point), which results in removing
    a few superfluous "movs? %xmm0,%xmm0" instructions
  * fixed compilation of paramanagers of avr, m68k and mips after r13695
    and also updated them for these new changes

git-svn-id: trunk@15350 -
2010-05-30 21:12:57 +00:00
Jonas Maebe
9bc15a5f61 * renamed a_param_* to a_load_*_cgpara
git-svn-id: trunk@15305 -
2010-05-22 09:07:21 +00:00
Jonas Maebe
fbebd87593 * use BLX instead of "mov r14, r15; mov r15, reg" for a_call_reg on ARMv6
and above, so this also works when calling thumb code (should actually
    also be done for ARMv5T, but we don't have a monicker for that yet)
  * use BX instead of "mov r15, r14" for simple returns from subroutines
    on ARMv6+ to support returning to thumb code from ARM code (idem)

git-svn-id: trunk@14332 -
2009-12-04 22:38:50 +00:00
Jonas Maebe
d1538ab023 o added ARM VPFv2/VFPv3 support:
+ RTL support:
      o VFP exceptions are disabled by default on Darwin,
        because they cause kernel panics on iPhoneOS 2.2.1 at least
      o all denormals are truncated to 0 on Darwin, because disabling
        that also causes kernel panics on iPhoneOS 2.2.1 (probably
        because otherwise denormals can also cause exceptions)
    * set softfloat rounding mode correctly for non-wince/darwin/vfp
      targets
    + compiler support: only half the number of single precision
      registers is available due to limitations of the register
      allocator
    + added a number of comments about why the stackframe on ARM is
      set up the way it is by the compiler
    + added regtype and subregtype info to regsets, because they're
      also used for VFP registers (+ support in assembler reader)
    + various generic support routines for dealing with floating point
      values located in integer registers that have to be transferred to
      mm registers (needed for VFP)
    * renamed use_sse() to use_vectorfpu() and also use it for
      ARM/vfp support
    o only superficially tested for Linux (compiler compiled with -Cpvfpv6
      -Cfvfpv2 works on a Cortex-A8, no testsuite run performed -- at least
      the fpu exception handler still needs to be implemented), Darwin has
      been tested more thoroughly
  + added ARMv6 cpu type and made it default for Darwin/ARM
  + ARMv6+ implementations of atomic operations using ldrex/strex
  * don't use r9 on Darwin/ARM, as it's reserved under certain
    circumstances (don't know yet which ones)
  * changed C-test object files for ARM/Darwin to ARMv6 versions
  * check in assembler reader that regsets are not empty, because
    instructions with a regset operand have undefined behaviour in that
    case
  * fixed resultdef of tarmtypeconvnode.first_int_to_real in case of
    int64->single type conversion
  * fixed constant pool locations in case 64 bit constants are generated,
    and/or when vfp instructions with limited reach are present

  WARNING: when using VFP on an ARMv6 or later cpu, you *must* compile all
    code with -Cparmv6 (or higher), or you will get crashes. The reason is
    that storing/restoring multiple VFP registers must happen using
    different instructions on pre/post-ARMv6.

git-svn-id: trunk@14317 -
2009-12-03 22:46:30 +00:00
florian
0c8546f94c * more MIPS code of David Zhang integrated
git-svn-id: trunk@14228 -
2009-11-20 14:46:45 +00:00
Jonas Maebe
3a774ce66a * fixed alignment for (non-)lazy symbol sections
* converted lazy symbol directive in arm/cgcpu.pas to section, forgotten
    in r14128 (fixes mantis #15047)

git-svn-id: trunk@14135 -
2009-11-10 10:43:15 +00:00
florian
515774b864 * merged armthum branch
-- Zusammenführen der Unterschiede zwischen Projektarchiv-URLs in ».«:
U    rtl/arm/setjump.inc
A    rtl/arm/thumb2.inc
U    rtl/arm/divide.inc
A    rtl/embedded/arm/stm32f103.pp
U    rtl/inc/system.inc
U    compiler/alpha/cgcpu.pas
U    compiler/sparc/cgcpu.pas
U    compiler/i386/cgcpu.pas
U    compiler/ncgld.pas
U    compiler/powerpc/cgcpu.pas
U    compiler/avr/cgcpu.pas
U    compiler/aggas.pas
U    compiler/powerpc64/cgcpu.pas
U    compiler/x86_64/cgcpu.pas
U    compiler/cgobj.pas
U    compiler/psystem.pas
U    compiler/aasmtai.pas
U    compiler/m68k/cgcpu.pas
U    compiler/ncgutil.pas
U    compiler/rautils.pas
U    compiler/arm/raarmgas.pas
U    compiler/arm/armatts.inc
U    compiler/arm/cgcpu.pas
U    compiler/arm/armins.dat
U    compiler/arm/rgcpu.pas
U    compiler/arm/cpubase.pas
U    compiler/arm/agarmgas.pas
U    compiler/arm/cpuinfo.pas
U    compiler/arm/armop.inc
U    compiler/arm/narmadd.pas
U    compiler/arm/aoptcpu.pas
U    compiler/arm/armatt.inc
U    compiler/arm/aasmcpu.pas
U    compiler/systems/t_embed.pas
U    compiler/psub.pas
U    compiler/options.pas

git-svn-id: trunk@13801 -
2009-10-04 09:03:44 +00:00
Jonas Maebe
a6f20cdba9 * align the stack pointer to alignment.localalignmax, fixes crashes on
ARM EABI systems because of a missing 8 byte alignment (mantis
    #11595, #13391 and #13454)

git-svn-id: trunk@13030 -
2009-04-24 12:35:26 +00:00
Jonas Maebe
7d459cf12a * the compiler now explicitly keeps track of the minimally guaranteed
alignment for each memory reference (mantis #12137, and
    test/packages/fcl-registry/tregistry1.pp on sparc). This also
    enables better code generation for packed records in many cases.
  o several changes were made to the compiler to minimise the chances
    of accidentally forgetting to set the alignment of memory references
    in the future:
    - reference_reset*() now has an extra alignment parameter
    - location_reset() can now only be used for non LOC_(C)REFERENCE,
      use location_reset_ref() for those (split the tloc enum so the
      compiler can catch errors using range checking)

git-svn-id: trunk@12719 -
2009-02-08 13:00:24 +00:00
Jonas Maebe
a23630260b + "weakexternal" support for imported procedures and variables.
the syntax is exactly the same as for "external", except for
    the keyword. It is currently only active for Darwin targets.
    It should also work at least for Linux targets, but only with
    the GNU assembler (which is why it is not activated there)
  + test for this functionality

git-svn-id: trunk@12009 -
2008-11-01 18:38:32 +00:00
Jonas Maebe
5347e536c2 + support for generating non-pic darwin/arm call stubs
+ write the header for non-pic darwin/arm call stubs properly in aggas
  * r9 is not available for general use on darwin/arm according to the llvm
    code generator

git-svn-id: trunk@11862 -
2008-10-04 14:07:52 +00:00
yury
4cabbe0e39 * Fixed compiler cycling with enabled range and overflow checking.
git-svn-id: trunk@11489 -
2008-07-29 21:11:03 +00:00
florian
fe7cba52dc + support of inlined ror/rol on arm
git-svn-id: trunk@11473 -
2008-07-28 15:48:38 +00:00
florian
1afb1aa9cc + ror/rol functions
+ internal compiler support for ror/rol on i386

git-svn-id: trunk@11466 -
2008-07-27 17:12:32 +00:00
yury
a6eb251cee * Define dummy tcgarm.g_stackpointer_alloc to fix abstract warning.
* Suppressed unreachable code warnings.
* Now ARM compiler compiles without warnings and notes.

git-svn-id: trunk@11456 -
2008-07-23 13:22:36 +00:00
yury
a039dd6942 * Fixed warnings about hiding inherited method.
git-svn-id: trunk@11449 -
2008-07-23 11:51:19 +00:00
yury
6c6bf452ca * Fixed level 2 comment warnings.
git-svn-id: trunk@11441 -
2008-07-23 10:08:48 +00:00
florian
67ef9f20ae * test for previous commit
* fixed wrapper generation for bigger offsets as well

git-svn-id: trunk@11059 -
2008-05-23 16:16:34 +00:00
florian
ea46cb4218 * take care of the maximum constant size when creating interface wrappers, resolves #10831
git-svn-id: trunk@11058 -
2008-05-23 16:02:17 +00:00
yury
60ecb64346 * Fixed loading of single floating point values from memory to register for ARM hardfloat.
git-svn-id: trunk@10826 -
2008-04-27 20:47:52 +00:00
yury
b9431c876e * More complete fix for bug #10515. Thanks to Jonas for suggestion.
* Fixed warnings in tcnvint6.pp

git-svn-id: trunk@10765 -
2008-04-23 08:22:27 +00:00
yury
88597d23c5 * Fixed tcgarm.a_load_ref_reg to load word values from location with alignment 2 using unaligned load.
git-svn-id: trunk@10754 -
2008-04-22 08:46:19 +00:00
yury
9222540e84 * Small optimization.
git-svn-id: trunk@10692 -
2008-04-18 11:46:39 +00:00