Handle use of SIMD vector globals and locals

This commit is contained in:
Andrew Brown
2019-09-06 11:43:11 -07:00
parent 7e6913e362
commit 6cbc6e8bfb
3 changed files with 10 additions and 1 deletions

View File

@@ -179,6 +179,10 @@ fn declare_locals<FE: FuncEnvironment + ?Sized>(
I64 => builder.ins().iconst(ir::types::I64, 0), I64 => builder.ins().iconst(ir::types::I64, 0),
F32 => builder.ins().f32const(ir::immediates::Ieee32::with_bits(0)), F32 => builder.ins().f32const(ir::immediates::Ieee32::with_bits(0)),
F64 => builder.ins().f64const(ir::immediates::Ieee64::with_bits(0)), F64 => builder.ins().f64const(ir::immediates::Ieee64::with_bits(0)),
V128 => {
let constant_handle = builder.func.dfg.constants.insert([0; 16].to_vec());
builder.ins().vconst(ir::types::I8X16, constant_handle)
}
AnyRef => builder.ins().null(environ.reference_type()), AnyRef => builder.ins().null(environ.reference_type()),
ty => wasm_unsupported!("unsupported local type {:?}", ty), ty => wasm_unsupported!("unsupported local type {:?}", ty),
}; };

View File

@@ -14,6 +14,7 @@ use crate::translation_utils::{
}; };
use crate::{wasm_unsupported, HashMap}; use crate::{wasm_unsupported, HashMap};
use core::convert::TryFrom; use core::convert::TryFrom;
use cranelift_codegen::ir::immediates::Uimm128;
use cranelift_codegen::ir::{self, AbiParam, Signature}; use cranelift_codegen::ir::{self, AbiParam, Signature};
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use std::vec::Vec; use std::vec::Vec;
@@ -201,6 +202,9 @@ pub fn parse_global_section(
Operator::I64Const { value } => GlobalInit::I64Const(value), Operator::I64Const { value } => GlobalInit::I64Const(value),
Operator::F32Const { value } => GlobalInit::F32Const(value.bits()), Operator::F32Const { value } => GlobalInit::F32Const(value.bits()),
Operator::F64Const { value } => GlobalInit::F64Const(value.bits()), Operator::F64Const { value } => GlobalInit::F64Const(value.bits()),
Operator::V128Const { value } => {
GlobalInit::V128Const(Uimm128::from(value.bytes().to_vec().as_slice()))
}
Operator::GetGlobal { global_index } => { Operator::GetGlobal { global_index } => {
GlobalInit::GetGlobal(GlobalIndex::from_u32(global_index)) GlobalInit::GetGlobal(GlobalIndex::from_u32(global_index))
} }

View File

@@ -4,6 +4,7 @@ use crate::wasm_unsupported;
use core::u32; use core::u32;
use cranelift_codegen::entity::entity_impl; use cranelift_codegen::entity::entity_impl;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_codegen::ir::immediates::Uimm128;
#[cfg(feature = "enable-serde")] #[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use wasmparser; use wasmparser;
@@ -77,7 +78,7 @@ pub enum GlobalInit {
/// An `f64.const`. /// An `f64.const`.
F64Const(u64), F64Const(u64),
/// A `vconst`. /// A `vconst`.
V128Const([u8; 16]), V128Const(Uimm128),
/// A `get_global` of another global. /// A `get_global` of another global.
GetGlobal(GlobalIndex), GetGlobal(GlobalIndex),
///< The global is imported from, and thus initialized by, a different module. ///< The global is imported from, and thus initialized by, a different module.