Skip to content

Commit

Permalink
cranelift: Fix bint implementation on interpreter (#4299)
Browse files Browse the repository at this point in the history
* cranelift: Fix `bint` implementation on interpreter

The interpreter was returning -1 instead of 1 for positive values.
This also extends the bint test suite to cover all types.

* cranelift: Restrict `bint` to scalar values only
  • Loading branch information
afonso360 committed Jun 23, 2022
1 parent 51c1655 commit 87007c5
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 17 deletions.
29 changes: 21 additions & 8 deletions cranelift/codegen/meta/src/shared/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ pub(crate) fn define(
.build(),
);

let ScalarBool = &TypeVar::new(
"ScalarBool",
"A scalar boolean type",
TypeSetBuilder::new().bools(Interval::All).build(),
);

let iB = &TypeVar::new(
"iB",
"A scalar integer type",
Expand Down Expand Up @@ -3331,13 +3337,10 @@ pub(crate) fn define(

let IntTo = &TypeVar::new(
"IntTo",
"An integer type with the same number of lanes",
TypeSetBuilder::new()
.ints(Interval::All)
.simd_lanes(Interval::All)
.build(),
"A scalar integer type",
TypeSetBuilder::new().ints(Interval::All).build(),
);
let x = &Operand::new("x", Bool);
let x = &Operand::new("x", ScalarBool);
let a = &Operand::new("a", IntTo);

ig.push(
Expand All @@ -3346,15 +3349,25 @@ pub(crate) fn define(
r#"
Convert `x` to an integer.
True maps to 1 and false maps to 0. The result type must have the same
number of vector lanes as the input.
True maps to 1 and false maps to 0.
"#,
&formats.unary,
)
.operands_in(vec![x])
.operands_out(vec![a]),
);

let IntTo = &TypeVar::new(
"IntTo",
"An integer type with the same number of lanes",
TypeSetBuilder::new()
.ints(Interval::All)
.simd_lanes(Interval::All)
.build(),
);
let x = &Operand::new("x", Bool);
let a = &Operand::new("a", IntTo);

ig.push(
Inst::new(
"bmask",
Expand Down

0 comments on commit 87007c5

Please sign in to comment.