Skip to content

Commit 103d562

Browse files
committed
winch: convert multiplications
This does not include any special "small immediate resizing" rules for Winch, so the Winch disassembly tests gain a few bytes (e.g., some immediates that _could_ fit in 8 bits are emitted as the full 32 bits).
1 parent 0771ae7 commit 103d562

File tree

22 files changed

+183
-153
lines changed

22 files changed

+183
-153
lines changed

cranelift/codegen/src/isa/x64/inst/external.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ impl From<PairedGpr> for asm::GprMem<PairedGpr, Gpr> {
112112
}
113113
}
114114

115+
// For Winch ergonomics.
116+
impl From<WritableGpr> for asm::Gpr<WritableGpr> {
117+
fn from(gpr: WritableGpr) -> Self {
118+
Self::new(gpr)
119+
}
120+
}
121+
115122
impl asm::AsReg for PairedGpr {
116123
fn enc(&self) -> u8 {
117124
let PairedGpr { read, write } = self;

tests/disas/winch/x64/call_indirect/call_indirect.wat

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
;; movq 0x10(%r11), %r11
3838
;; addq $0x30, %r11
3939
;; cmpq %rsp, %r11
40-
;; ja 0x227
40+
;; ja 0x22d
4141
;; 1c: movq %rdi, %r14
4242
;; subq $0x20, %rsp
4343
;; movq %rdi, 0x18(%rsp)
@@ -50,7 +50,7 @@
5050
;; testl %eax, %eax
5151
;; je 0x56
5252
;; 4c: movl $1, %eax
53-
;; jmp 0x21e
53+
;; jmp 0x224
5454
;; 56: movl 0xc(%rsp), %eax
5555
;; subl $2, %eax
5656
;; subq $4, %rsp
@@ -59,7 +59,7 @@
5959
;; movq %r14, %rdx
6060
;; movq 0x40(%rdx), %rbx
6161
;; cmpq %rbx, %rcx
62-
;; jae 0x229
62+
;; jae 0x22f
6363
;; 7f: movq %rcx, %r11
6464
;; imulq $8, %r11, %r11
6565
;; movq 0x38(%rdx), %rdx
@@ -69,27 +69,27 @@
6969
;; cmovaeq %rsi, %rdx
7070
;; movq (%rdx), %rax
7171
;; testq %rax, %rax
72-
;; jne 0xdc
73-
;; a2: subq $4, %rsp
72+
;; jne 0xdf
73+
;; a5: subq $4, %rsp
7474
;; movl %ecx, (%rsp)
7575
;; subq $8, %rsp
7676
;; movq %r14, %rdi
7777
;; movl $0, %esi
7878
;; movl 8(%rsp), %edx
79-
;; callq 0x32e
79+
;; callq 0x334
8080
;; addq $8, %rsp
8181
;; addq $4, %rsp
8282
;; movq 0x1c(%rsp), %r14
83-
;; jmp 0xe3
84-
;; dc: andq $0xfffffffffffffffe, %rax
83+
;; jmp 0xe6
84+
;; df: andq $0xfffffffffffffffe, %rax
8585
;; testq %rax, %rax
86-
;; je 0x22b
87-
;; ec: movq 0x30(%r14), %r11
86+
;; je 0x231
87+
;; ef: movq 0x30(%r14), %r11
8888
;; movl (%r11), %ecx
8989
;; movl 0x10(%rax), %edx
9090
;; cmpl %edx, %ecx
91-
;; jne 0x22d
92-
;; fe: pushq %rax
91+
;; jne 0x233
92+
;; 101: pushq %rax
9393
;; popq %rcx
9494
;; movq 0x18(%rcx), %r8
9595
;; movq 8(%rcx), %rbx
@@ -111,8 +111,8 @@
111111
;; movq %r14, %rdx
112112
;; movq 0x40(%rdx), %rbx
113113
;; cmpq %rbx, %rcx
114-
;; jae 0x22f
115-
;; 161: movq %rcx, %r11
114+
;; jae 0x235
115+
;; 164: movq %rcx, %r11
116116
;; imulq $8, %r11, %r11
117117
;; movq 0x38(%rdx), %rdx
118118
;; movq %rdx, %rsi
@@ -121,27 +121,27 @@
121121
;; cmovaeq %rsi, %rdx
122122
;; movq (%rdx), %rax
123123
;; testq %rax, %rax
124-
;; jne 0x1be
125-
;; 184: subq $4, %rsp
124+
;; jne 0x1c4
125+
;; 18a: subq $4, %rsp
126126
;; movl %ecx, (%rsp)
127127
;; subq $4, %rsp
128128
;; movq %r14, %rdi
129129
;; movl $0, %esi
130130
;; movl 4(%rsp), %edx
131-
;; callq 0x32e
131+
;; callq 0x334
132132
;; addq $4, %rsp
133133
;; addq $4, %rsp
134134
;; movq 0x20(%rsp), %r14
135-
;; jmp 0x1c5
136-
;; 1be: andq $0xfffffffffffffffe, %rax
135+
;; jmp 0x1cb
136+
;; 1c4: andq $0xfffffffffffffffe, %rax
137137
;; testq %rax, %rax
138-
;; je 0x231
139-
;; 1ce: movq 0x30(%r14), %r11
138+
;; je 0x237
139+
;; 1d4: movq 0x30(%r14), %r11
140140
;; movl (%r11), %ecx
141141
;; movl 0x10(%rax), %edx
142142
;; cmpl %edx, %ecx
143-
;; jne 0x233
144-
;; 1e0: pushq %rax
143+
;; jne 0x239
144+
;; 1e6: pushq %rax
145145
;; popq %rcx
146146
;; movq 0x18(%rcx), %r8
147147
;; movq 8(%rcx), %rbx
@@ -160,10 +160,10 @@
160160
;; addq $0x20, %rsp
161161
;; popq %rbp
162162
;; retq
163-
;; 227: ud2
164-
;; 229: ud2
165-
;; 22b: ud2
166163
;; 22d: ud2
167164
;; 22f: ud2
168165
;; 231: ud2
169166
;; 233: ud2
167+
;; 235: ud2
168+
;; 237: ud2
169+
;; 239: ud2

tests/disas/winch/x64/call_indirect/local_arg.wat

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
;; movq 0x10(%r11), %r11
4343
;; addq $0x30, %r11
4444
;; cmpq %rsp, %r11
45-
;; ja 0x154
45+
;; ja 0x157
4646
;; 5c: movq %rdi, %r14
4747
;; subq $0x20, %rsp
4848
;; movq %rdi, 0x18(%rsp)
@@ -55,7 +55,7 @@
5555
;; movq %r14, %rdx
5656
;; movq 0x40(%rdx), %rbx
5757
;; cmpq %rbx, %rcx
58-
;; jae 0x156
58+
;; jae 0x159
5959
;; 9e: movq %rcx, %r11
6060
;; imulq $8, %r11, %r11
6161
;; movq 0x38(%rdx), %rdx
@@ -65,27 +65,27 @@
6565
;; cmovaeq %rsi, %rdx
6666
;; movq (%rdx), %rax
6767
;; testq %rax, %rax
68-
;; jne 0xfb
69-
;; c1: subq $4, %rsp
68+
;; jne 0xfe
69+
;; c4: subq $4, %rsp
7070
;; movl %ecx, (%rsp)
7171
;; subq $8, %rsp
7272
;; movq %r14, %rdi
7373
;; movl $0, %esi
7474
;; movl 8(%rsp), %edx
75-
;; callq 0x312
75+
;; callq 0x315
7676
;; addq $8, %rsp
7777
;; addq $4, %rsp
7878
;; movq 0x1c(%rsp), %r14
79-
;; jmp 0x102
80-
;; fb: andq $0xfffffffffffffffe, %rax
79+
;; jmp 0x105
80+
;; fe: andq $0xfffffffffffffffe, %rax
8181
;; testq %rax, %rax
82-
;; je 0x158
83-
;; 10b: movq 0x30(%r14), %r11
82+
;; je 0x15b
83+
;; 10e: movq 0x30(%r14), %r11
8484
;; movl (%r11), %ecx
8585
;; movl 0x10(%rax), %edx
8686
;; cmpl %edx, %ecx
87-
;; jne 0x15a
88-
;; 11d: movq 0x18(%rax), %rbx
87+
;; jne 0x15d
88+
;; 120: movq 0x18(%rax), %rbx
8989
;; movq 8(%rax), %rcx
9090
;; subq $0xc, %rsp
9191
;; movq %rbx, %rdi
@@ -98,7 +98,7 @@
9898
;; addq $0x20, %rsp
9999
;; popq %rbp
100100
;; retq
101-
;; 154: ud2
102-
;; 156: ud2
103-
;; 158: ud2
104-
;; 15a: ud2
101+
;; 157: ud2
102+
;; 159: ud2
103+
;; 15b: ud2
104+
;; 15d: ud2

tests/disas/winch/x64/i32_mul/const.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
;; movq 0x10(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x40
18+
;; ja 0x43
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
@@ -25,4 +25,4 @@
2525
;; addq $0x10, %rsp
2626
;; popq %rbp
2727
;; retq
28-
;; 40: ud2
28+
;; 43: ud2

tests/disas/winch/x64/i32_mul/max.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
;; movq 0x10(%r11), %r11
1515
;; addq $0x10, %r11
1616
;; cmpq %rsp, %r11
17-
;; ja 0x40
17+
;; ja 0x43
1818
;; 1c: movq %rdi, %r14
1919
;; subq $0x10, %rsp
2020
;; movq %rdi, 8(%rsp)
2121
;; movq %rsi, (%rsp)
2222
;; movl $0x7fffffff, %eax
23-
;; imull $-1, %eax, %eax
23+
;; imull $0xffffffff, %eax, %eax
2424
;; addq $0x10, %rsp
2525
;; popq %rbp
2626
;; retq
27-
;; 40: ud2
27+
;; 43: ud2

tests/disas/winch/x64/i32_mul/max_one.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
;; movq 0x10(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x40
18+
;; ja 0x43
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
2222
;; movq %rsi, (%rsp)
2323
;; movl $0x80000000, %eax
24-
;; imull $-1, %eax, %eax
24+
;; imull $0xffffffff, %eax, %eax
2525
;; addq $0x10, %rsp
2626
;; popq %rbp
2727
;; retq
28-
;; 40: ud2
28+
;; 43: ud2

tests/disas/winch/x64/i32_mul/mixed.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
;; movq 0x10(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x40
18+
;; ja 0x43
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
@@ -25,4 +25,4 @@
2525
;; addq $0x10, %rsp
2626
;; popq %rbp
2727
;; retq
28-
;; 40: ud2
28+
;; 43: ud2

tests/disas/winch/x64/i32_mul/signed.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
;; movq 0x10(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x40
18+
;; ja 0x43
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
2222
;; movq %rsi, (%rsp)
2323
;; movl $0xffffffff, %eax
24-
;; imull $-1, %eax, %eax
24+
;; imull $0xffffffff, %eax, %eax
2525
;; addq $0x10, %rsp
2626
;; popq %rbp
2727
;; retq
28-
;; 40: ud2
28+
;; 43: ud2

tests/disas/winch/x64/i32_mul/unsigned_with_zero.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
;; movq 0x10(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x40
18+
;; ja 0x43
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
@@ -25,4 +25,4 @@
2525
;; addq $0x10, %rsp
2626
;; popq %rbp
2727
;; retq
28-
;; 40: ud2
28+
;; 43: ud2

tests/disas/winch/x64/i64_mul/const.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
;; movq 0x10(%r11), %r11
1616
;; addq $0x10, %r11
1717
;; cmpq %rsp, %r11
18-
;; ja 0x43
18+
;; ja 0x46
1919
;; 1c: movq %rdi, %r14
2020
;; subq $0x10, %rsp
2121
;; movq %rdi, 8(%rsp)
@@ -25,4 +25,4 @@
2525
;; addq $0x10, %rsp
2626
;; popq %rbp
2727
;; retq
28-
;; 43: ud2
28+
;; 46: ud2

0 commit comments

Comments
 (0)