From 5bd422b42985bdc4d6e7cf18483822f5ade01057 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 14 Aug 2019 10:12:38 -0700 Subject: [PATCH] Add V128 type --- wasmtime-api/src/module.rs | 1 + wasmtime-api/src/types.rs | 3 +++ wasmtime-jit/src/action.rs | 6 ++++++ wasmtime-runtime/src/vmcontext.rs | 4 ++-- wasmtime-wast/src/wast.rs | 20 +++++++++++++++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/wasmtime-api/src/module.rs b/wasmtime-api/src/module.rs index 436aa8a146..4447127c77 100644 --- a/wasmtime-api/src/module.rs +++ b/wasmtime-api/src/module.rs @@ -32,6 +32,7 @@ fn into_valtype(ty: &wasmparser::Type) -> ValType { I64 => ValType::I64, F32 => ValType::F32, F64 => ValType::F64, + V128 => ValType::V128, AnyFunc => ValType::FuncRef, AnyRef => ValType::AnyRef, _ => unimplemented!("types in into_valtype"), diff --git a/wasmtime-api/src/types.rs b/wasmtime-api/src/types.rs index 972521342d..334c68a6cc 100644 --- a/wasmtime-api/src/types.rs +++ b/wasmtime-api/src/types.rs @@ -45,6 +45,7 @@ pub enum ValType { I64, F32, F64, + V128, AnyRef, /* = 128 */ FuncRef, } @@ -70,6 +71,7 @@ impl ValType { ValType::I64 => ir::types::I64, ValType::F32 => ir::types::F32, ValType::F64 => ir::types::F64, + ValType::V128 => ir::types::I8X16, _ => unimplemented!("get_cranelift_type other"), } } @@ -80,6 +82,7 @@ impl ValType { ir::types::I64 => ValType::I64, ir::types::F32 => ValType::F32, ir::types::F64 => ValType::F64, + ir::types::I8X16 => ValType::V128, _ => unimplemented!("from_cranelift_type other"), } } diff --git a/wasmtime-jit/src/action.rs b/wasmtime-jit/src/action.rs index c2753a2163..0f87f168ab 100644 --- a/wasmtime-jit/src/action.rs +++ b/wasmtime-jit/src/action.rs @@ -20,6 +20,8 @@ pub enum RuntimeValue { F32(u32), /// A runtime value with type f64. F64(u64), + /// A runtime value with type v128 + V128([u8; 16]), } impl RuntimeValue { @@ -30,6 +32,7 @@ impl RuntimeValue { RuntimeValue::I64(_) => ir::types::I64, RuntimeValue::F32(_) => ir::types::F32, RuntimeValue::F64(_) => ir::types::F64, + RuntimeValue::V128(_) => ir::types::I8X16, } } @@ -83,6 +86,7 @@ impl fmt::Display for RuntimeValue { RuntimeValue::I64(x) => write!(f, "{}: i64", x), RuntimeValue::F32(x) => write!(f, "{}: f32", x), RuntimeValue::F64(x) => write!(f, "{}: f64", x), + RuntimeValue::V128(x) => write!(f, "{:?}: v128", x.to_vec()), } } } @@ -174,6 +178,7 @@ pub fn invoke( RuntimeValue::I64(x) => ptr::write(ptr as *mut i64, *x), RuntimeValue::F32(x) => ptr::write(ptr as *mut u32, *x), RuntimeValue::F64(x) => ptr::write(ptr as *mut u64, *x), + RuntimeValue::V128(x) => ptr::write(ptr as *mut [u8; 16], *x), } } } @@ -210,6 +215,7 @@ pub fn invoke( ir::types::I64 => RuntimeValue::I64(ptr::read(ptr as *const i64)), ir::types::F32 => RuntimeValue::F32(ptr::read(ptr as *const u32)), ir::types::F64 => RuntimeValue::F64(ptr::read(ptr as *const u64)), + ir::types::I8X16 => RuntimeValue::V128(ptr::read(ptr as *const [u8; 16])), other => panic!("unsupported value type {:?}", other), } }) diff --git a/wasmtime-runtime/src/vmcontext.rs b/wasmtime-runtime/src/vmcontext.rs index 74d79f72d2..913d4c4890 100644 --- a/wasmtime-runtime/src/vmcontext.rs +++ b/wasmtime-runtime/src/vmcontext.rs @@ -252,8 +252,8 @@ mod test_vmtable_definition { #[derive(Debug, Copy, Clone)] #[repr(C, align(8))] pub struct VMGlobalDefinition { - storage: [u8; 8], - // If more elements are added here, remember to add offset_of tests below! + storage: [u8; 8], // TODO this may need to be 16 + // If more elements are added here, remember to add offset_of tests below! } #[cfg(test)] diff --git a/wasmtime-wast/src/wast.rs b/wasmtime-wast/src/wast.rs index 966b4ae4e5..71d61dacf3 100644 --- a/wasmtime-wast/src/wast.rs +++ b/wasmtime-wast/src/wast.rs @@ -15,7 +15,7 @@ fn runtime_value(v: Value) -> RuntimeValue { Value::I64(x) => RuntimeValue::I64(x), Value::F32(x) => RuntimeValue::F32(x.to_bits()), Value::F64(x) => RuntimeValue::F64(x.to_bits()), - Value::V128(_) => unimplemented!("SIMD"), + Value::V128(x) => RuntimeValue::V128(x.to_le_bytes()), } } @@ -374,6 +374,15 @@ impl WastContext { }); } } + RuntimeValue::V128(_) => { + return Err(WastFileError { + filename: filename.to_string(), + line, + error: WastError::Type(format!( + "unexpected vector type in NaN test" + )), + }); + } }; } } @@ -426,6 +435,15 @@ impl WastContext { }); } } + RuntimeValue::V128(_) => { + return Err(WastFileError { + filename: filename.to_string(), + line, + error: WastError::Type(format!( + "unexpected vector type in NaN test", + )), + }); + } }; } }