File: align-via-padding.s

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (76 lines) | stat: -rw-r--r-- 2,311 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# RUN: llvm-mc -mcpu=skylake -filetype=obj -triple x86_64-pc-linux-gnu %s -x86-pad-max-prefix-size=5 -x86-pad-for-align=1 | llvm-objdump -d - | FileCheck %s

# This test file highlights the interactions between prefix padding and
# relaxation padding.

  .file "test.c"
  .text
  .section  .text
  # We can both relax and prefix for padding purposes, but the moment, we
  # can't prefix without first having relaxed.
  # CHECK: .text
  # CHECK:  0: eb 1f                         jmp
  # CHECK:  2: eb 1d                         jmp
  # CHECK:  4: eb 1b                         jmp
  # CHECK:  6: eb 19                         jmp
  # CHECK:  8: eb 17                         jmp
  # CHECK:  a: 2e 2e 2e 2e 2e e9 0d 00 00 00 jmp
  # CHECK: 14: 2e 2e 2e 2e 2e e9 03 00 00 00 jmp
  # CHECK: 1e: 66 90                         nop
  # CHECK: 20: cc                            int3
  .p2align 4
  jmp foo
  jmp foo
  jmp foo
  jmp foo
  jmp foo
  jmp foo
  jmp foo
  .p2align 5
  int3
foo:
  ret

  # Canonical toy loop to show benefit - we can align the loop header with
  # fewer nops by relaxing the branch, even though we don't need to
  # CHECK: <loop_preheader>:
  # CHECK: 45: 48 85 c0                       testq %rax, %rax
  # CHECK: 48: 2e 2e 2e 2e 0f 8e 1e 00 00 00  jle 0x70 <loop_exit>
  # CHECK: 52: 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00    	nopw	%cs:(%rax,%rax)
  # CHECK: <loop_header>:
  # CHECK: 60: 48 83 e8 01                    subq $1, %rax
  # CHECK: 64: 48 85 c0                       testq %rax, %rax
  # CHECK: 67: 7e 07                          jle 0x70 <loop_exit>
  # CHECK: 69: 2e 2e e9 f0 ff ff ff           jmp
  # CHECK: <loop_exit>:
  # CHECK: 70: c3                             retq
  .p2align 5
  .skip 5
loop_preheader:
  testq %rax, %rax
  jle loop_exit
  .p2align 5
loop_header:
  subq $1, %rax
  testq %rax, %rax
  jle loop_exit
  jmp loop_header
  .p2align 4
loop_exit:
  ret

  # Correctness cornercase - can't prefix pad jmp without having relaxed it
  # first as doing so would make the relative offset too large
  # CHECK: fd: cc                             int3
  # CHECK: fe: eb 80                          jmp 0x80 <loop_exit+0x10>
  # CHECK: 100: cc                           	int3
.p2align 5
.L1:
.rept 126
  int3
.endr
  jmp .L1
.rept 30
  int3
.endr
.p2align 5