Browse Source
Merge pull request #2214 from bjorn3/fix_128bit_switch
Fix Switch for 128bit integers
pull/2229/head
Chris Fallin
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
20 additions and
3 deletions
-
cranelift/codegen/meta/src/cdsl/typevar.rs
-
cranelift/codegen/meta/src/shared/legalize.rs
-
cranelift/frontend/src/switch.rs
|
|
@ -302,7 +302,7 @@ impl TypeVar { |
|
|
|
pub fn to_rust_code(&self) -> String { |
|
|
|
match &self.base { |
|
|
|
Some(base) => format!( |
|
|
|
"{}.{}()", |
|
|
|
"{}.{}().unwrap()", |
|
|
|
base.type_var.to_rust_code(), |
|
|
|
base.derived_func.name() |
|
|
|
), |
|
|
|
|
|
@ -402,6 +402,17 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
let zero = Literal::constant(&imm.imm64, 0); |
|
|
|
narrow.legalize( |
|
|
|
def!(a = iadd_imm.I128(x, c)), |
|
|
|
vec![ |
|
|
|
def!(yh = iconst.I64(zero)), |
|
|
|
def!(yl = iconst.I64(c)), |
|
|
|
def!(y = iconcat.I64(yh, yl)), |
|
|
|
def!(a = iadd(x, y)), |
|
|
|
], |
|
|
|
); |
|
|
|
|
|
|
|
// Widen instructions with one input operand.
|
|
|
|
for &op in &[bnot, popcnt] { |
|
|
|
for &int_ty in &[I8, I16] { |
|
|
|
|
|
@ -276,6 +276,11 @@ impl Switch { |
|
|
|
bx.switch_to_block(new_block); |
|
|
|
|
|
|
|
// Cast to u32, as br_table is not implemented for integers bigger than 32bits.
|
|
|
|
let discr = if bx.func.dfg.value_type(discr) == types::I128 { |
|
|
|
bx.ins().isplit(discr).0 |
|
|
|
} else { |
|
|
|
discr |
|
|
|
}; |
|
|
|
bx.ins().ireduce(types::I32, discr) |
|
|
|
} else { |
|
|
|
discr |
|
|
@ -648,8 +653,9 @@ block4: |
|
|
|
jump block5 |
|
|
|
|
|
|
|
block5: |
|
|
|
v2 = ireduce.i32 v0 |
|
|
|
br_table v2, block3, jt0" |
|
|
|
v2, v3 = isplit.i128 v0 |
|
|
|
v4 = ireduce.i32 v2 |
|
|
|
br_table v4, block3, jt0" |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|