• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Révision534455547021f3262fa60d32cabb626af01692a3 (tree)
l'heure2017-04-24 22:51:24
AuteurThomas Preud'homme <thomas.preudhomme@arm....>
CommiterThomas Preud'homme

Message de Log

[GAS/ARM] Fix expansion of ldr pseudo instruction

The LDR rX, =cst pseudo-instruction suffers from two issues for loading
integer constants in Thumb mode:

- movs is used if the constant and register can be encoded using that

instruction which leads to unexpected behavior due to its flag-setting
behavior

- mov.w, movw and mvn are used for r13 (sp) and r15 (pc) but these

encoding are marked as UNPREDICTABLE

This patch fixes those issues and update testing accordingly.

2017-04-24 Thomas Preud'homme <thomas.preudhomme@arm.com>

gas/
* config/tc-arm.c (move_or_literal_pool): Remove code generating MOVS.
Forbid MOV.W and MOVW if destination is SP or PC.
* testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.s: Explain
expectation of LDR not generating a MOVS for low registers and small
constants. Add tests of MOVW generation.
* testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.d: Update
expected disassembly.

Change Summary

Modification

--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,13 @@
1+2017-04-24 Thomas Preud'homme <thomas.preudhomme@arm.com>
2+
3+ * config/tc-arm.c (move_or_literal_pool): Remove code generating MOVS.
4+ Forbid MOV.W and MOVW if destination is SP or PC.
5+ * testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.s: Explain
6+ expectation of LDR not generating a MOVS for low registers and small
7+ constants. Add tests of MOVW generation.
8+ * testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.d: Update
9+ expected disassembly.
10+
111 2017-04-22 Alan Modra <amodra@gmail.com>
212
313 * testsuite/gas/ppc/vle.s: Format. Add se_rfgi and e_sc.
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -7959,17 +7959,13 @@ move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
79597959 {
79607960 if (thumb_p)
79617961 {
7962- /* This can be encoded only for a low register. */
7963- if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
7964- {
7965- /* This can be done with a mov(1) instruction. */
7966- inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7967- inst.instruction |= v;
7968- return TRUE;
7969- }
7962+ /* LDR should not use lead in a flag-setting instruction being
7963+ chosen so we do not check whether movs can be used. */
79707964
7971- if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7965+ if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
79727966 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
7967+ && inst.operands[i].reg != 13
7968+ && inst.operands[i].reg != 15)
79737969 {
79747970 /* Check if on thumb2 it can be done with a mov.w, mvn or
79757971 movw instruction. */
--- a/gas/testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.d
+++ b/gas/testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.d
@@ -6,19 +6,23 @@
66 .*: +file format .*arm.*
77
88 Disassembly of section \.text:
9-0[0-9a-f]+ <[^>]+> 2000[[:space:]]+movs[[:space:]]+r0, #0.*
10-0[0-9a-f]+ <[^>]+> 2108[[:space:]]+movs[[:space:]]+r1, #8.*
11-0[0-9a-f]+ <[^>]+> 2251[[:space:]]+movs[[:space:]]+r2, #81.*
12-0[0-9a-f]+ <[^>]+> 231f[[:space:]]+movs[[:space:]]+r3, #31.*
13-0[0-9a-f]+ <[^>]+> 242f[[:space:]]+movs[[:space:]]+r4, #47.*
14-0[0-9a-f]+ <[^>]+> 253f[[:space:]]+movs[[:space:]]+r5, #63.*
15-0[0-9a-f]+ <[^>]+> 2680[[:space:]]+movs[[:space:]]+r6, #128.*
16-0[0-9a-f]+ <[^>]+> 27ff[[:space:]]+movs[[:space:]]+r7, #255.*
9+0[0-9a-f]+ <[^>]+> f04f 0000[[:space:]]+mov\.w[[:space:]]+r0, #0.*
10+0[0-9a-f]+ <[^>]+> f04f 0108[[:space:]]+mov\.w[[:space:]]+r1, #8.*
11+0[0-9a-f]+ <[^>]+> f04f 0251[[:space:]]+mov\.w[[:space:]]+r2, #81.*
12+0[0-9a-f]+ <[^>]+> f04f 031f[[:space:]]+mov\.w[[:space:]]+r3, #31.*
13+0[0-9a-f]+ <[^>]+> f04f 042f[[:space:]]+mov\.w[[:space:]]+r4, #47.*
14+0[0-9a-f]+ <[^>]+> f04f 053f[[:space:]]+mov\.w[[:space:]]+r5, #63.*
15+0[0-9a-f]+ <[^>]+> f04f 0680[[:space:]]+mov\.w[[:space:]]+r6, #128.*
16+0[0-9a-f]+ <[^>]+> f04f 07ff[[:space:]]+mov\.w[[:space:]]+r7, #255.*
1717 0[0-9a-f]+ <[^>]+> f04f 0800[[:space:]]+mov\.w[[:space:]]+r8, #0.*
1818 0[0-9a-f]+ <[^>]+> f04f 0908[[:space:]]+mov\.w[[:space:]]+r9, #8.*
1919 0[0-9a-f]+ <[^>]+> f04f 0a51[[:space:]]+mov\.w[[:space:]]+sl, #81.*
2020 0[0-9a-f]+ <[^>]+> f04f 0b1f[[:space:]]+mov\.w[[:space:]]+fp, #31.*
2121 0[0-9a-f]+ <[^>]+> f04f 0c2f[[:space:]]+mov\.w[[:space:]]+ip, #47.*
22-0[0-9a-f]+ <[^>]+> f04f 0d3f[[:space:]]+mov\.w[[:space:]]+sp, #63.*
2322 0[0-9a-f]+ <[^>]+> f04f 0e80[[:space:]]+mov\.w[[:space:]]+lr, #128.*
24-0[0-9a-f]+ <[^>]+> f04f 0fff[[:space:]]+mov\.w[[:space:]]+pc, #255.*
23+0[0-9a-f]+ <[^>]+> f64f 78ff[[:space:]]+movw[[:space:]]+r8, #65535.*
24+0[0-9a-f]+ <[^>]+> f24f 09f0[[:space:]]+movw[[:space:]]+r9, #61680.*
25+0[0-9a-f]+ <[^>]+> f8df d004[[:space:]]+ldr\.w[[:space:]]+sp, \[pc, #4\].*
26+0[0-9a-f]+ <[^>]+> f8df f004[[:space:]]+ldr\.w[[:space:]]+pc, \[pc, #4\].*
27+0[0-9a-f]+ <[^>]+> 0000003f[[:space:]]+.word[[:space:]]+0x0000003f.*
28+0[0-9a-f]+ <[^>]+> 000000ff[[:space:]]+.word[[:space:]]+0x000000ff.*
--- a/gas/testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.s
+++ b/gas/testsuite/gas/arm/thumb2_ldr_immediate_highregs_armv6t2.s
@@ -2,8 +2,8 @@
22 .syntax unified
33 .thumb_func
44 thumb2_ldr:
5- # These can be encoded into movs since constant is small
6- # And register can be encoded in 3 bits
5+ # These must be encoded into mov.w despite constant and register being
6+ # small enough as ldr should not generate a flag-setting instruction.
77 ldr r0,=0x00
88 ldr r1,=0x08
99 ldr r2,=0x51
@@ -12,13 +12,19 @@ thumb2_ldr:
1212 ldr r5,=0x3F
1313 ldr r6,=0x80
1414 ldr r7,=0xFF
15- # These shall be encoded into mov.w
16- # Since register cannot be encoded in 3 bits
15+ # These shall be encoded into mov.w since register cannot be encoded in
16+ # 3 bits
1717 ldr r8,=0x00
1818 ldr r9,=0x08
1919 ldr r10,=0x51
2020 ldr r11,=0x1F
2121 ldr r12,=0x2F
22- ldr r13,=0x3F
2322 ldr r14,=0x80
23+ # These shall be encoded into movw since immediate cannot be encoded
24+ # with mov.w
25+ ldr r8,=0xFFFF
26+ ldr r9,=0xF0F0
27+ # These should be encoded as ldr since mov immediate is unpredictable
28+ # for sp and pc
29+ ldr r13,=0x3F
2430 ldr r15,=0xFF