fix wrong align()

This commit is contained in:
MITSUNARI Shigeo 2017-08-18 20:15:48 +09:00
parent b633c68b53
commit d512551e91
6 changed files with 42 additions and 11 deletions

View file

@ -1,5 +1,5 @@
Xbyak 5.51 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++ Xbyak 5.52 ; JIT assembler for x86(IA32), x64(AMD64, x86-64) by C++
============= =============
Abstract Abstract
@ -333,6 +333,7 @@ The header files under xbyak/ are independent of cybozulib.
History History
------------- -------------
* 2017/Aug/18 ver 5.52 fix align (thanks to MerryMage)
* 2017/Aug/17 ver 5.51 add multi-byte nop and align() uses it(thanks to inolen) * 2017/Aug/17 ver 5.51 add multi-byte nop and align() uses it(thanks to inolen)
* 2017/Aug/08 ver 5.50 add mpx(thanks to magurosan) * 2017/Aug/08 ver 5.50 add mpx(thanks to magurosan)
* 2017/Aug/08 ver 5.45 add sha(thanks to magurosan) * 2017/Aug/08 ver 5.45 add sha(thanks to magurosan)

View file

@ -1,5 +1,5 @@
C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 5.51 C++用x86(IA-32), x64(AMD64, x86-64) JITアセンブラ Xbyak 5.52
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
◎概要 ◎概要
@ -343,6 +343,7 @@ cybozulibは単体テストでのみ利用されていて、xbyak/ディレク
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
◎履歴 ◎履歴
2017/08/18 ver 5.52 align修正(thanks to MerryMage)
2017/08/17 ver 5.51 multi-byte nop追加 align()はそれを使用する(thanks to inolen) 2017/08/17 ver 5.51 multi-byte nop追加 align()はそれを使用する(thanks to inolen)
2017/08/08 ver 5.50 mpx追加(thanks to magurosan) 2017/08/08 ver 5.50 mpx追加(thanks to magurosan)
2017/08/08 ver 5.45 sha追加(thanks to magurosan) 2017/08/08 ver 5.45 sha追加(thanks to magurosan)

View file

@ -42,6 +42,7 @@ test: normalize_prefix jmp bad_address
./test_address.sh ./test_address.sh
./jmp ./jmp
./bad_address ./bad_address
./misc
ifeq ($(BIT),64) ifeq ($(BIT),64)
./test_address.sh 64 ./test_address.sh 64
./test_nm.sh 64 ./test_nm.sh 64

View file

@ -81,3 +81,25 @@ CYBOZU_TEST_AUTO(mov_const)
} }
} code; } code;
} }
CYBOZU_TEST_AUTO(align)
{
struct Code : Xbyak::CodeGenerator {
Code()
{
const size_t alignSize = 16;
for (int padding = 0; padding < 20; padding++) {
for (int i = 0; i < padding; i++) {
db(1);
}
align(alignSize);
CYBOZU_TEST_EQUAL(size_t(getCurr()) % alignSize, 0u);
}
align(alignSize);
const uint8 *p = getCurr();
// do nothing if aligned
align(alignSize);
CYBOZU_TEST_EQUAL(p, getCurr());
}
} c;
}

View file

@ -105,7 +105,7 @@ namespace Xbyak {
enum { enum {
DEFAULT_MAX_CODE_SIZE = 4096, DEFAULT_MAX_CODE_SIZE = 4096,
VERSION = 0x5510 /* 0xABCD = A.BC(D) */ VERSION = 0x5520 /* 0xABCD = A.BC(D) */
}; };
#ifndef MIE_INTEGER_TYPE_DEFINED #ifndef MIE_INTEGER_TYPE_DEFINED
@ -2391,8 +2391,17 @@ public:
#undef jnl #undef jnl
#endif #endif
void nop(size_t size = 1) /*
use single byte nop if useMultiByteNop = false
*/
void nop(size_t size = 1, bool useMultiByteNop = true)
{ {
if (!useMultiByteNop) {
for (size_t i = 0; i < size; i++) {
db(0x90);
}
return;
}
/* /*
Intel Architectures Software Developer's Manual Volume 2 Intel Architectures Software Developer's Manual Volume 2
recommended multi-byte sequence of NOP instruction recommended multi-byte sequence of NOP instruction
@ -2431,12 +2440,9 @@ public:
if (x == 1) return; if (x == 1) return;
if (x < 1 || (x & (x - 1))) throw Error(ERR_BAD_ALIGN); if (x < 1 || (x & (x - 1))) throw Error(ERR_BAD_ALIGN);
if (isAutoGrow() && x > inner::ALIGN_PAGE_SIZE) fprintf(stderr, "warning:autoGrow mode does not support %d align\n", (int)x); if (isAutoGrow() && x > inner::ALIGN_PAGE_SIZE) fprintf(stderr, "warning:autoGrow mode does not support %d align\n", (int)x);
if (useMultiByteNop) { size_t remain = size_t(getCurr()) % x;
nop(size_t(getCurr()) % x); if (remain) {
return; nop(x - remain, useMultiByteNop);
}
while (size_t(getCurr()) % x > 0) {
nop();
} }
} }
#endif #endif

View file

@ -1,4 +1,4 @@
const char *getVersionString() const { return "5.51"; } const char *getVersionString() const { return "5.52"; }
void adc(const Operand& op, uint32 imm) { opRM_I(op, imm, 0x10, 2); } void adc(const Operand& op, uint32 imm) { opRM_I(op, imm, 0x10, 2); }
void adc(const Operand& op1, const Operand& op2) { opRM_RM(op1, op2, 0x10); } void adc(const Operand& op1, const Operand& op2) { opRM_RM(op1, op2, 0x10); }
void adcx(const Reg32e& reg, const Operand& op) { opGen(reg, op, 0xF6, 0x66, isREG32_REG32orMEM, NONE, 0x38); } void adcx(const Reg32e& reg, const Operand& op) { opGen(reg, op, 0xF6, 0x66, isREG32_REG32orMEM, NONE, 0x38); }