change error range of imm

This commit is contained in:
MITSUNARI Shigeo 2015-08-17 06:35:56 +09:00
parent 7a1ea1ed48
commit 762f40ffc3
2 changed files with 11 additions and 9 deletions

View file

@ -38,13 +38,12 @@ CYBOZU_TEST_AUTO(mov_const)
struct Code : Xbyak::CodeGenerator { struct Code : Xbyak::CodeGenerator {
Code() Code()
{ {
CYBOZU_TEST_NO_EXCEPTION(mov(dword[eax], -1)); CYBOZU_TEST_NO_EXCEPTION(mov(qword[eax], 0x12345678));
CYBOZU_TEST_NO_EXCEPTION(mov(dword[eax], 0x7fffffff)); CYBOZU_TEST_NO_EXCEPTION(mov(qword[eax], 0x7fffffff));
CYBOZU_TEST_NO_EXCEPTION(mov(dword[eax], -0x7fffffff)); CYBOZU_TEST_NO_EXCEPTION(mov(qword[eax], -1));
CYBOZU_TEST_NO_EXCEPTION(mov(dword[eax], 0xabcd1234)); CYBOZU_TEST_NO_EXCEPTION(mov(qword[eax], 0xffffffffffffffffull));
CYBOZU_TEST_NO_EXCEPTION(mov(dword[eax], 0xffffffff)); CYBOZU_TEST_EXCEPTION(mov(qword[eax], 0x80000000), Xbyak::Error);
CYBOZU_TEST_EXCEPTION(mov(dword[eax], 0x100000000ull), Xbyak::Error); CYBOZU_TEST_EXCEPTION(mov(qword[eax], 0xffffffff), Xbyak::Error);
CYBOZU_TEST_EXCEPTION(mov(dword[eax], -0x80000000ull), Xbyak::Error);
} }
} code; } code;
} }

View file

@ -1865,8 +1865,11 @@ public:
db(imm, size); db(imm, size);
} else if (op.isMEM()) { } else if (op.isMEM()) {
opModM(static_cast<const Address&>(op), Reg(0, Operand::REG, op.getBit()), B11000110); opModM(static_cast<const Address&>(op), Reg(0, Operand::REG, op.getBit()), B11000110);
int size = op.getBit() / 8; if (size > 4) size = 4; int size = op.getBit() / 8;
if (0xffffffff < imm && imm <= ~uint64(0x7fffffffu)) throw Error(ERR_IMM_IS_TOO_BIG); if (size == 8) {
if (!inner::IsInInt32(imm)) throw Error(ERR_IMM_IS_TOO_BIG);
size = 4;
}
db(static_cast<uint32>(imm), size); db(static_cast<uint32>(imm), size);
} else { } else {
throw Error(ERR_BAD_COMBINATION); throw Error(ERR_BAD_COMBINATION);