Skip to content

Commit fb7dd61

Browse files
authored
Winch: Implement float rounding instructions for x64 with AVX (#10243)
1 parent 3156541 commit fb7dd61

File tree

14 files changed

+472
-17
lines changed

14 files changed

+472
-17
lines changed

crates/wast-util/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,12 @@ impl WastTest {
419419
// simd-related failures
420420
"memory64/simd.wast",
421421
"misc_testsuite/simd/canonicalize-nan.wast",
422-
"misc_testsuite/simd/issue_3327_bnot_lowering.wast",
423422
"spec_testsuite/simd_f32x4.wast",
424423
"spec_testsuite/simd_f32x4_arith.wast",
425424
"spec_testsuite/simd_f32x4_pmin_pmax.wast",
426-
"spec_testsuite/simd_f32x4_rounding.wast",
427425
"spec_testsuite/simd_f64x2.wast",
428426
"spec_testsuite/simd_f64x2_arith.wast",
429427
"spec_testsuite/simd_f64x2_pmin_pmax.wast",
430-
"spec_testsuite/simd_f64x2_rounding.wast",
431428
"spec_testsuite/simd_load.wast",
432429
"spec_testsuite/simd_load_zero.wast",
433430
"spec_testsuite/simd_splat.wast",
@@ -446,6 +443,7 @@ impl WastTest {
446443
"misc_testsuite/issue6562.wast",
447444
"misc_testsuite/simd/almost-extmul.wast",
448445
"misc_testsuite/simd/cvt-from-uint.wast",
446+
"misc_testsuite/simd/issue_3327_bnot_lowering.wast",
449447
"misc_testsuite/simd/issue6725-no-egraph-panic.wast",
450448
"misc_testsuite/simd/replace-lane-preserve.wast",
451449
"misc_testsuite/simd/spillslot-size-fuzzbug.wast",
@@ -455,7 +453,9 @@ impl WastTest {
455453
"spec_testsuite/simd_boolean.wast",
456454
"spec_testsuite/simd_conversions.wast",
457455
"spec_testsuite/simd_f32x4_cmp.wast",
456+
"spec_testsuite/simd_f32x4_rounding.wast",
458457
"spec_testsuite/simd_f64x2_cmp.wast",
458+
"spec_testsuite/simd_f64x2_rounding.wast",
459459
"spec_testsuite/simd_i16x8_cmp.wast",
460460
"spec_testsuite/simd_i32x4_cmp.wast",
461461
"spec_testsuite/simd_i64x2_arith2.wast",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f32x4.ceil (v128.const f32x4 0 1 2 3))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundps $2, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: cmpb $0, (%rdi)
39+
;; 59: addb %al, (%rax)
40+
;; 5b: addb %al, (%rax)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f32x4.floor (v128.const f32x4 0 1 2 3))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundps $1, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: cmpb $0, (%rdi)
39+
;; 59: addb %al, (%rax)
40+
;; 5b: addb %al, (%rax)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f32x4.nearest (v128.const f32x4 0 1 2 3))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundps $0, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: cmpb $0, (%rdi)
39+
;; 59: addb %al, (%rax)
40+
;; 5b: addb %al, (%rax)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f32x4.trunc (v128.const f32x4 0 1 2 3))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundps $3, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: cmpb $0, (%rdi)
39+
;; 59: addb %al, (%rax)
40+
;; 5b: addb %al, (%rax)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f64x2.ceil (v128.const f64x2 0 1))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundpd $2, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: addb %al, (%rax)
39+
;; 58: addb %al, (%rax)
40+
;; 5a: addb %al, (%rax)
41+
;; 5c: addb %al, (%rax)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f64x2.floor (v128.const f64x2 0 1))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundpd $1, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: addb %al, (%rax)
39+
;; 58: addb %al, (%rax)
40+
;; 5a: addb %al, (%rax)
41+
;; 5c: addb %al, (%rax)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f64x2.nearest (v128.const f64x2 0 1))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundpd $0, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: addb %al, (%rax)
39+
;; 58: addb %al, (%rax)
40+
;; 5a: addb %al, (%rax)
41+
;; 5c: addb %al, (%rax)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(func (result v128)
7+
(f64x2.trunc (v128.const f64x2 0 1))
8+
)
9+
)
10+
;; wasm[0]::function[0]:
11+
;; pushq %rbp
12+
;; movq %rsp, %rbp
13+
;; movq 8(%rdi), %r11
14+
;; movq 0x10(%r11), %r11
15+
;; addq $0x10, %r11
16+
;; cmpq %rsp, %r11
17+
;; ja 0x40
18+
;; 1c: movq %rdi, %r14
19+
;; subq $0x10, %rsp
20+
;; movq %rdi, 8(%rsp)
21+
;; movq %rsi, (%rsp)
22+
;; movdqu 0x1c(%rip), %xmm0
23+
;; vroundpd $3, %xmm0, %xmm0
24+
;; addq $0x10, %rsp
25+
;; popq %rbp
26+
;; retq
27+
;; 40: ud2
28+
;; 42: addb %al, (%rax)
29+
;; 44: addb %al, (%rax)
30+
;; 46: addb %al, (%rax)
31+
;; 48: addb %al, (%rax)
32+
;; 4a: addb %al, (%rax)
33+
;; 4c: addb %al, (%rax)
34+
;; 4e: addb %al, (%rax)
35+
;; 50: addb %al, (%rax)
36+
;; 52: addb %al, (%rax)
37+
;; 54: addb %al, (%rax)
38+
;; 56: addb %al, (%rax)
39+
;; 58: addb %al, (%rax)
40+
;; 5a: addb %al, (%rax)
41+
;; 5c: addb %al, (%rax)

winch/codegen/src/isa/aarch64/masm.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ impl Masm for MacroAssembler {
11931193
bail!(CodeGenError::unimplemented_masm_instruction())
11941194
}
11951195

1196-
fn v128_trunc_sat(
1196+
fn v128_trunc(
11971197
&mut self,
11981198
_context: &mut CodeGenContext<Emission>,
11991199
_kind: V128TruncKind,
@@ -1255,6 +1255,18 @@ impl Masm for MacroAssembler {
12551255
) -> Result<()> {
12561256
bail!(CodeGenError::unimplemented_masm_instruction())
12571257
}
1258+
1259+
fn v128_ceil(&mut self, _src: Reg, _dst: WritableReg, _size: OperandSize) -> Result<()> {
1260+
bail!(CodeGenError::unimplemented_masm_instruction())
1261+
}
1262+
1263+
fn v128_floor(&mut self, _src: Reg, _dst: WritableReg, _size: OperandSize) -> Result<()> {
1264+
bail!(CodeGenError::unimplemented_masm_instruction())
1265+
}
1266+
1267+
fn v128_nearest(&mut self, _src: Reg, _dst: WritableReg, _size: OperandSize) -> Result<()> {
1268+
bail!(CodeGenError::unimplemented_masm_instruction())
1269+
}
12581270
}
12591271

12601272
impl MacroAssembler {

0 commit comments

Comments
 (0)