Simplify some code based on newly implemented instructions
This commit is contained in:
parent
e9115eb647
commit
ae98a2f570
30
Cargo.lock
generated
30
Cargo.lock
generated
@ -63,7 +63,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
[[package]]
|
||||
name = "cranelift-bforest"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"cranelift-entity",
|
||||
]
|
||||
@ -71,7 +71,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-codegen"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bumpalo",
|
||||
@ -91,7 +91,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-codegen-meta"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"cranelift-codegen-shared",
|
||||
]
|
||||
@ -99,12 +99,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-codegen-shared"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
|
||||
[[package]]
|
||||
name = "cranelift-egraph"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"cranelift-entity",
|
||||
"fxhash",
|
||||
@ -117,12 +117,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-entity"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
|
||||
[[package]]
|
||||
name = "cranelift-frontend"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"cranelift-codegen",
|
||||
"log",
|
||||
@ -133,12 +133,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-isle"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
|
||||
[[package]]
|
||||
name = "cranelift-jit"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cranelift-codegen",
|
||||
@ -156,7 +156,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-module"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cranelift-codegen",
|
||||
@ -165,7 +165,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-native"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"cranelift-codegen",
|
||||
"libc",
|
||||
@ -175,7 +175,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "cranelift-object"
|
||||
version = "0.90.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cranelift-codegen",
|
||||
@ -310,9 +310,9 @@ checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
|
||||
|
||||
[[package]]
|
||||
name = "regalloc2"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69025b4a161879ba90719837c06621c3d73cffa147a000aeacf458f6a9572485"
|
||||
checksum = "91b2eab54204ea0117fe9a060537e0b07a4e72f7c7d182361ecc346cab2240e5"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"log",
|
||||
@ -391,7 +391,7 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
[[package]]
|
||||
name = "wasmtime-jit-icache-coherence"
|
||||
version = "2.0.0"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#e8f3d03bbe17151530601bac82af912869f09080"
|
||||
source = "git+https://github.com/bytecodealliance/wasmtime.git#033758daaf3e7f0af4348e0d996f26de5c6ba4fc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
|
@ -575,12 +575,6 @@ fn codegen_stmt<'tcx>(
|
||||
_ => unreachable!("un op Not for {:?}", layout.ty),
|
||||
},
|
||||
UnOp::Neg => match layout.ty.kind() {
|
||||
ty::Int(IntTy::I128) => {
|
||||
// FIXME remove this case once ineg.i128 works
|
||||
let zero =
|
||||
CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size));
|
||||
crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand)
|
||||
}
|
||||
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
|
||||
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
|
||||
_ => unreachable!("un op Neg for {:?}", layout.ty),
|
||||
|
@ -197,10 +197,7 @@ fn bool_to_zero_or_max_uint<'tcx>(
|
||||
ty => ty,
|
||||
};
|
||||
|
||||
let val = if int_ty == types::I8 { val } else { fx.bcx.ins().uextend(int_ty, val) };
|
||||
|
||||
// FIXME use bmask instead
|
||||
let mut res = fx.bcx.ins().ineg(val);
|
||||
let mut res = fx.bcx.ins().bmask(int_ty, val);
|
||||
|
||||
if ty.is_float() {
|
||||
res = fx.bcx.ins().bitcast(ty, res);
|
||||
@ -636,85 +633,21 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
ret.write_cvalue(fx, res);
|
||||
}
|
||||
sym::bswap => {
|
||||
// FIXME(CraneStation/cranelift#794) add bswap instruction to cranelift
|
||||
fn swap(bcx: &mut FunctionBuilder<'_>, v: Value) -> Value {
|
||||
match bcx.func.dfg.value_type(v) {
|
||||
types::I8 => v,
|
||||
|
||||
// https://code.woboq.org/gcc/include/bits/byteswap.h.html
|
||||
types::I16 => {
|
||||
let tmp1 = bcx.ins().ishl_imm(v, 8);
|
||||
let n1 = bcx.ins().band_imm(tmp1, 0xFF00);
|
||||
|
||||
let tmp2 = bcx.ins().ushr_imm(v, 8);
|
||||
let n2 = bcx.ins().band_imm(tmp2, 0x00FF);
|
||||
|
||||
bcx.ins().bor(n1, n2)
|
||||
}
|
||||
types::I32 => {
|
||||
let tmp1 = bcx.ins().ishl_imm(v, 24);
|
||||
let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000);
|
||||
|
||||
let tmp2 = bcx.ins().ishl_imm(v, 8);
|
||||
let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000);
|
||||
|
||||
let tmp3 = bcx.ins().ushr_imm(v, 8);
|
||||
let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00);
|
||||
|
||||
let tmp4 = bcx.ins().ushr_imm(v, 24);
|
||||
let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF);
|
||||
|
||||
let or_tmp1 = bcx.ins().bor(n1, n2);
|
||||
let or_tmp2 = bcx.ins().bor(n3, n4);
|
||||
bcx.ins().bor(or_tmp1, or_tmp2)
|
||||
}
|
||||
types::I64 => {
|
||||
let tmp1 = bcx.ins().ishl_imm(v, 56);
|
||||
let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000_0000_0000u64 as i64);
|
||||
|
||||
let tmp2 = bcx.ins().ishl_imm(v, 40);
|
||||
let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000_0000_0000u64 as i64);
|
||||
|
||||
let tmp3 = bcx.ins().ishl_imm(v, 24);
|
||||
let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00_0000_0000u64 as i64);
|
||||
|
||||
let tmp4 = bcx.ins().ishl_imm(v, 8);
|
||||
let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF_0000_0000u64 as i64);
|
||||
|
||||
let tmp5 = bcx.ins().ushr_imm(v, 8);
|
||||
let n5 = bcx.ins().band_imm(tmp5, 0x0000_0000_FF00_0000u64 as i64);
|
||||
|
||||
let tmp6 = bcx.ins().ushr_imm(v, 24);
|
||||
let n6 = bcx.ins().band_imm(tmp6, 0x0000_0000_00FF_0000u64 as i64);
|
||||
|
||||
let tmp7 = bcx.ins().ushr_imm(v, 40);
|
||||
let n7 = bcx.ins().band_imm(tmp7, 0x0000_0000_0000_FF00u64 as i64);
|
||||
|
||||
let tmp8 = bcx.ins().ushr_imm(v, 56);
|
||||
let n8 = bcx.ins().band_imm(tmp8, 0x0000_0000_0000_00FFu64 as i64);
|
||||
|
||||
let or_tmp1 = bcx.ins().bor(n1, n2);
|
||||
let or_tmp2 = bcx.ins().bor(n3, n4);
|
||||
let or_tmp3 = bcx.ins().bor(n5, n6);
|
||||
let or_tmp4 = bcx.ins().bor(n7, n8);
|
||||
|
||||
let or_tmp5 = bcx.ins().bor(or_tmp1, or_tmp2);
|
||||
let or_tmp6 = bcx.ins().bor(or_tmp3, or_tmp4);
|
||||
bcx.ins().bor(or_tmp5, or_tmp6)
|
||||
}
|
||||
types::I128 => {
|
||||
let (lo, hi) = bcx.ins().isplit(v);
|
||||
let lo = swap(bcx, lo);
|
||||
let hi = swap(bcx, hi);
|
||||
bcx.ins().iconcat(hi, lo)
|
||||
}
|
||||
ty => unreachable!("bswap {}", ty),
|
||||
}
|
||||
}
|
||||
intrinsic_args!(fx, args => (arg); intrinsic);
|
||||
let val = arg.load_scalar(fx);
|
||||
|
||||
let res = CValue::by_val(swap(&mut fx.bcx, val), arg.layout());
|
||||
let res = match fx.bcx.func.dfg.value_type(val) {
|
||||
types::I8 => val,
|
||||
types::I128 => {
|
||||
// FIXME(bytecodealliance/wasmtime#1092) bswap.i128 is not yet implemented
|
||||
let (lsb, msb) = fx.bcx.ins().isplit(val);
|
||||
let lsb_swap = fx.bcx.ins().bswap(lsb);
|
||||
let msb_swap = fx.bcx.ins().bswap(msb);
|
||||
fx.bcx.ins().iconcat(msb_swap, lsb_swap)
|
||||
}
|
||||
_ => fx.bcx.ins().bswap(val),
|
||||
};
|
||||
let res = CValue::by_val(res, arg.layout());
|
||||
ret.write_cvalue(fx, res);
|
||||
}
|
||||
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user