[dart2wasm] Add intrinsics for bitwise operations on booleans.

Change-Id: Ic09545535c954d72615ca035ed1b133fada5d733
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275080
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
This commit is contained in:
Jackson Gardner 2022-12-13 23:07:40 +00:00 committed by Commit Queue
parent c15f248840
commit 1306a4c284
3 changed files with 41 additions and 0 deletions

View file

@ -26,6 +26,13 @@ class Intrinsifier {
static final Map<w.ValueType, Map<w.ValueType, Map<String, CodeGenCallback>>>
binaryOperatorMap = {
boolType: {
boolType: {
'|': (b) => b.i32_or(),
'^': (b) => b.i32_xor(),
'&': (b) => b.i32_and(),
}
},
intType: {
intType: {
'+': (b) => b.i64_add(),

View file

@ -50,6 +50,23 @@ void test() {
Expect.equals(0x00000000000000F0, 0xF00000000000000F << 4);
Expect.equals(0xF00000000, 15 << 32);
// Test bitwise operations on booleans
// This avoids frontend optimizations
final trueValue = int.parse("1") == 1;
final falseValue = int.parse("2") == 1;
Expect.equals(trueValue, trueValue & trueValue);
Expect.equals(falseValue, trueValue & falseValue);
Expect.equals(falseValue, falseValue & trueValue);
Expect.equals(falseValue, falseValue & falseValue);
Expect.equals(trueValue, trueValue | trueValue);
Expect.equals(trueValue, trueValue | falseValue);
Expect.equals(trueValue, falseValue | trueValue);
Expect.equals(falseValue, falseValue | falseValue);
Expect.equals(falseValue, trueValue ^ trueValue);
Expect.equals(trueValue, trueValue ^ falseValue);
Expect.equals(trueValue, falseValue ^ trueValue);
Expect.equals(falseValue, falseValue ^ falseValue);
testNegativeValueShifts();
testPositiveValueShifts();
testNoMaskingOfShiftCount();

View file

@ -52,6 +52,23 @@ void test() {
Expect.equals(0x00000000000000F0, 0xF00000000000000F << 4);
Expect.equals(0xF00000000, 15 << 32);
// Test bitwise operations on booleans
// This avoids frontend optimizations
final trueValue = int.parse("1") == 1;
final falseValue = int.parse("2") == 1;
Expect.equals(trueValue, trueValue & trueValue);
Expect.equals(falseValue, trueValue & falseValue);
Expect.equals(falseValue, falseValue & trueValue);
Expect.equals(falseValue, falseValue & falseValue);
Expect.equals(trueValue, trueValue | trueValue);
Expect.equals(trueValue, trueValue | falseValue);
Expect.equals(trueValue, falseValue | trueValue);
Expect.equals(falseValue, falseValue | falseValue);
Expect.equals(falseValue, trueValue ^ trueValue);
Expect.equals(trueValue, trueValue ^ falseValue);
Expect.equals(trueValue, falseValue ^ trueValue);
Expect.equals(falseValue, falseValue ^ falseValue);
testNegativeValueShifts();
testPositiveValueShifts();
testNoMaskingOfShiftCount();