Skip to content

Commit

Permalink
Add support for vector in DataValueExt::int() (#6844)
Browse files Browse the repository at this point in the history
* Add support for vector in DataValueExt::int()

Fixes #6827

* Replace `if` with `match`

* Enable interpreter test for simd ineg

Issue #6827

* Format code with `cargo fmt`

and also improve comment
  • Loading branch information
gurry authored Aug 14, 2023
1 parent 30d086f commit 76f1cb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/runtests/simd-ineg.clif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test interpret
test run
target aarch64
target s390x
Expand Down
9 changes: 8 additions & 1 deletion cranelift/interpreter/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,14 @@ macro_rules! bitop {

impl DataValueExt for DataValue {
fn int(n: i128, ty: Type) -> ValueResult<Self> {
if ty.is_int() && !ty.is_vector() {
if ty.is_vector() {
// match ensures graceful failure since read_from_slice_ne()
// panics on anything other than 8 and 16 bytes
match ty.bytes() {
8 | 16 => Ok(DataValue::read_from_slice_ne(&n.to_ne_bytes(), ty)),
_ => Err(ValueError::InvalidType(ValueTypeClass::Vector, ty)),
}
} else if ty.is_int() {
DataValue::from_integer(n, ty).map_err(|_| ValueError::InvalidValue(ty))
} else {
Err(ValueError::InvalidType(ValueTypeClass::Integer, ty))
Expand Down

0 comments on commit 76f1cb2

Please sign in to comment.