[wasm] add rotate opcodes

BUG=

Review URL: https://codereview.chromium.org/1755013003

Cr-Commit-Position: refs/heads/master@{#34455}
This commit is contained in:
weiliang.lin 2016-03-02 21:10:15 -08:00 committed by Commit bot
parent c7c9567376
commit 9d0cf920bd
9 changed files with 68 additions and 1 deletions

View File

@ -449,6 +449,11 @@ Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left,
case wasm::kExprI32ShrS:
op = m->Word32Sar();
break;
case wasm::kExprI32Ror:
op = m->Word32Ror();
break;
case wasm::kExprI32Rol:
return BuildI32Rol(left, right);
case wasm::kExprI32Eq:
op = m->Word32Equal();
break;
@ -621,6 +626,11 @@ Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left,
case wasm::kExprI64ShrS:
op = m->Word64Sar();
break;
case wasm::kExprI64Ror:
op = m->Word64Ror();
break;
case wasm::kExprI64Rol:
return BuildI64Rol(left, right);
#endif
case wasm::kExprF32CopySign:
@ -1823,6 +1833,31 @@ Node* WasmGraphBuilder::FromJS(Node* node, Node* context,
return num;
}
Node* WasmGraphBuilder::BuildI32Rol(Node* left, Node* right) {
// Implement Rol by Ror since TurboFan does not have Rol opcode.
// TODO(weiliang): support Word32Rol opcode in TurboFan.
Int32Matcher m(right);
if (m.HasValue()) {
return Binop(wasm::kExprI32Ror, left,
jsgraph()->Int32Constant(32 - m.Value()));
} else {
return Binop(wasm::kExprI32Ror, left,
Binop(wasm::kExprI32Sub, jsgraph()->Int32Constant(32), right));
}
}
Node* WasmGraphBuilder::BuildI64Rol(Node* left, Node* right) {
// Implement Rol by Ror since TurboFan does not have Rol opcode.
// TODO(weiliang): support Word64Rol opcode in TurboFan.
Int64Matcher m(right);
if (m.HasValue()) {
return Binop(wasm::kExprI64Ror, left,
jsgraph()->Int64Constant(64 - m.Value()));
} else {
return Binop(wasm::kExprI64Ror, left,
Binop(wasm::kExprI64Sub, jsgraph()->Int64Constant(64), right));
}
}
Node* WasmGraphBuilder::Invert(Node* node) {
return Unop(wasm::kExprI32Eqz, node);

View File

@ -190,6 +190,8 @@ class WasmGraphBuilder {
Node* BuildF64Floor(Node* input);
Node* BuildF64Ceil(Node* input);
Node* BuildF64NearestInt(Node* input);
Node* BuildI32Rol(Node* left, Node* right);
Node* BuildI64Rol(Node* left, Node* right);
Node* BuildF64Acos(Node* input);
Node* BuildF64Asin(Node* input);

View File

@ -144,6 +144,8 @@
#define WASM_I32_SHL(x, y) kExprI32Shl, x, y
#define WASM_I32_SHR(x, y) kExprI32ShrU, x, y
#define WASM_I32_SAR(x, y) kExprI32ShrS, x, y
#define WASM_I32_ROR(x, y) kExprI32Ror, x, y
#define WASM_I32_ROL(x, y) kExprI32Rol, x, y
#define WASM_I32_EQ(x, y) kExprI32Eq, x, y
#define WASM_I32_NE(x, y) kExprI32Ne, x, y
#define WASM_I32_LTS(x, y) kExprI32LtS, x, y
@ -174,6 +176,8 @@
#define WASM_I64_SHL(x, y) kExprI64Shl, x, y
#define WASM_I64_SHR(x, y) kExprI64ShrU, x, y
#define WASM_I64_SAR(x, y) kExprI64ShrS, x, y
#define WASM_I64_ROR(x, y) kExprI64Ror, x, y
#define WASM_I64_ROL(x, y) kExprI64Rol, x, y
#define WASM_I64_EQ(x, y) kExprI64Eq, x, y
#define WASM_I64_NE(x, y) kExprI64Ne, x, y
#define WASM_I64_LTS(x, y) kExprI64LtS, x, y

View File

@ -104,6 +104,8 @@ bool WasmOpcodes::IsSupported(WasmOpcode opcode) {
case kExprI64Shl:
case kExprI64ShrU:
case kExprI64ShrS:
case kExprI64Ror:
case kExprI64Rol:
case kExprI64Eq:
case kExprI64Ne:
case kExprI64LtS:

View File

@ -252,7 +252,11 @@ std::ostream& operator<<(std::ostream& os, const FunctionSig& function);
V(F64ConvertF32, 0xb2, d_f) \
V(F64ReinterpretI64, 0xb3, d_l) \
V(I32ReinterpretF32, 0xb4, i_f) \
V(I64ReinterpretF64, 0xb5, l_d)
V(I64ReinterpretF64, 0xb5, l_d) \
V(I32Ror, 0xb6, i_ii) \
V(I32Rol, 0xb7, i_ii) \
V(I64Ror, 0xb8, l_ll) \
V(I64Rol, 0xb9, l_ll)
// For compatibility with Asm.js.
#define FOREACH_ASMJS_COMPAT_OPCODE(V) \

View File

@ -217,6 +217,10 @@ TEST(Run_WasmInt32Binops) {
TestInt32Binop(kExprI32Shl, 0xA0000000, 0xA, 28);
TestInt32Binop(kExprI32ShrU, 0x07000010, 0x70000100, 4);
TestInt32Binop(kExprI32ShrS, 0xFF000000, 0x80000000, 7);
TestInt32Binop(kExprI32Ror, 0x01000000, 0x80000000, 7);
TestInt32Binop(kExprI32Ror, 0x01000000, 0x80000000, 39);
TestInt32Binop(kExprI32Rol, 0x00000040, 0x80000000, 7);
TestInt32Binop(kExprI32Rol, 0x00000040, 0x80000000, 39);
TestInt32Binop(kExprI32Eq, 1, -99, -99);
TestInt32Binop(kExprI32Ne, 0, -97, -97);
@ -382,6 +386,10 @@ TEST(Run_WasmInt64Binops) {
TestInt64Binop(kExprI64Shl, 0xA0000000, 0xA, 28);
TestInt64Binop(kExprI64ShrU, 0x0700001000123456LL, 0x7000010001234567LL, 4);
TestInt64Binop(kExprI64ShrS, 0xFF00000000000000LL, 0x8000000000000000LL, 7);
TestInt64Binop(kExprI64Ror, 0x0100000000000000LL, 0x8000000000000000LL, 7);
TestInt64Binop(kExprI64Ror, 0x0100000000000000LL, 0x8000000000000000LL, 71);
TestInt64Binop(kExprI64Rol, 0x0000000000000040LL, 0x8000000000000000LL, 7);
TestInt64Binop(kExprI64Rol, 0x0000000000000040LL, 0x8000000000000000LL, 71);
TestInt64Cmp(kExprI64Eq, 1, -9999, -9999);
TestInt64Cmp(kExprI64Ne, 1, -9199, -9999);
TestInt64Cmp(kExprI64LtS, 1, -4, 4);

View File

@ -244,6 +244,10 @@ var kExprF64ConvertF32 = 0xb2;
var kExprF64ReinterpretI64 = 0xb3;
var kExprI32ReinterpretF32 = 0xb4;
var kExprI64ReinterpretF64 = 0xb5;
var kExprI32Ror = 0xb6;
var kExprI32Rol = 0xb7;
var kExprI64Ror = 0xb8;
var kExprI64Rol = 0xb9;
var kTrapUnreachable = 0;
var kTrapMemOutOfBounds = 1;

View File

@ -870,6 +870,8 @@ TEST_F(AstDecoderTest, MacrosInt32) {
VERIFY(WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22)));
VERIFY(WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23)));
VERIFY(WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24)));
VERIFY(WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24)));
VERIFY(WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24)));
VERIFY(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25)));
VERIFY(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25)));
@ -907,6 +909,8 @@ TEST_F(AstDecoderTest, MacrosInt64) {
VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64(22)));
VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64(23)));
VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64(24)));
VERIFY_L_LL(WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64(24)));
VERIFY_L_LL(WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64(24)));
VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64(26)));
VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64(27)));

View File

@ -173,6 +173,8 @@ TEST_F(WasmMacroGenTest, Int32Ops) {
EXPECT_SIZE(5, WASM_I32_SHL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_SHR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_SAR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_ROR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_ROL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_EQ(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I32_LTS(WASM_ZERO, WASM_ZERO));
@ -205,6 +207,8 @@ TEST_F(WasmMacroGenTest, Int64Ops) {
EXPECT_SIZE(5, WASM_I64_SHL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_SHR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_SAR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_ROR(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_ROL(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_EQ(WASM_ZERO, WASM_ZERO));
EXPECT_SIZE(5, WASM_I64_LTS(WASM_ZERO, WASM_ZERO));