Add constant folding for OPCODE_ROTATE_LEFT
This commit is contained in:
parent
c5db959154
commit
241f410f6f
|
@ -712,7 +712,14 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder, bool& result) {
|
|||
result = true;
|
||||
}
|
||||
break;
|
||||
// TODO(benvanik): ROTATE_LEFT
|
||||
case OPCODE_ROTATE_LEFT:
|
||||
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
|
||||
v->set_from(i->src1.value);
|
||||
v->RotateLeft(i->src2.value);
|
||||
i->Remove();
|
||||
result = true;
|
||||
}
|
||||
break;
|
||||
case OPCODE_BYTE_SWAP:
|
||||
if (i->src1.value->IsConstant()) {
|
||||
v->set_from(i->src1.value);
|
||||
|
|
|
@ -843,6 +843,29 @@ void Value::Sha(Value* other) {
|
|||
}
|
||||
}
|
||||
|
||||
void Value::RotateLeft(Value* other) {
|
||||
assert_true(other->type == INT8_TYPE);
|
||||
auto rotation = other->constant.u8;
|
||||
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.u8 = rotate_left<uint8_t>(constant.u8, rotation);
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.u16 = rotate_left<uint16_t>(constant.u16, rotation);
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.u32 = rotate_left<uint32_t>(constant.u32, rotation);
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.u64 = rotate_left<uint64_t>(constant.u64, rotation);
|
||||
break;
|
||||
default:
|
||||
assert_unhandled_case(type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Extract(Value* vec, Value* index) {
|
||||
assert_true(vec->type == VEC128_TYPE);
|
||||
switch (type) {
|
||||
|
|
|
@ -519,6 +519,7 @@ class Value {
|
|||
void Shl(Value* other);
|
||||
void Shr(Value* other);
|
||||
void Sha(Value* other);
|
||||
void RotateLeft(Value* other);
|
||||
void Extract(Value* vec, Value* index);
|
||||
void Select(Value* other, Value* ctrl);
|
||||
void Splat(Value* other);
|
||||
|
|
Loading…
Reference in New Issue