Skip to content

Commit 93ae907

Browse files
authored
Implement vsplit in cranelift interpreter (bytecodealliance#5462)
* Add vsplit testfile * Add vsplit implementation
1 parent 22439f7 commit 93ae907

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
test interpret
2+
3+
function %vsplit_i32x4_hi(i32x4) -> i32x2 {
4+
block0(v0: i32x4):
5+
v1, v2 = vsplit.i32x4 v0
6+
return v1
7+
}
8+
; run: %vsplit_i32x4_hi([1 2 3 4]) == [1 2]
9+
10+
function %vsplit_i32x4_lo(i32x4) -> i32x2 {
11+
block0(v0: i32x4):
12+
v1, v2 = vsplit.i32x4 v0
13+
return v2
14+
}
15+
; run: %vsplit_i32x4_lo([1 2 3 4]) == [3 4]
16+
17+
18+
19+
function %vsplit_scalar_i64x2_hi(i64x2) -> i64 {
20+
block0(v0: i64x2):
21+
v1, v2 = vsplit.i64x2 v0
22+
return v1
23+
}
24+
; run: %vsplit_scalar_i64x2_hi([1 2]) == 1
25+
26+
function %vsplit_scalar_i64x2_lo(i64x2) -> i64 {
27+
block0(v0: i64x2):
28+
v1, v2 = vsplit.i64x2 v0
29+
return v2
30+
}
31+
; run: %vsplit_scalar_i64x2_lo([3 4]) == 4

cranelift/interpreter/src/step.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,15 @@ where
985985
}
986986
assign(Value::int(result, ctrl_ty)?)
987987
}
988-
Opcode::Vsplit => unimplemented!("Vsplit"),
988+
Opcode::Vsplit => {
989+
let new_type = ctrl_ty.half_vector().unwrap();
990+
let vector = extractlanes(&arg(0)?, ctrl_ty)?;
991+
let (high, low) = vector.split_at((ctrl_ty.lane_count() / 2) as usize);
992+
assign_multiple(&[
993+
vectorizelanes(high, new_type)?,
994+
vectorizelanes(low, new_type)?,
995+
])
996+
}
989997
Opcode::Vconcat => unimplemented!("Vconcat"),
990998
Opcode::Vselect => assign(vselect(&arg(0)?, &arg(1)?, &arg(2)?, ctrl_ty)?),
991999
Opcode::VanyTrue => {

0 commit comments

Comments
 (0)