diff options
author | MITSUNARI Shigeo <[email protected]> | 2010-04-16 10:33:04 +0900 |
---|---|---|
committer | MITSUNARI Shigeo <[email protected]> | 2010-04-16 10:33:04 +0900 |
commit | cbb4ca2178c6bd391b48c130afececfdddc66836 (patch) | |
tree | 46c9cfe83e040443af60585e212d071f0f127ebc /test/address.cpp | |
download | xbyak-cbb4ca2178c6bd391b48c130afececfdddc66836.tar.gz xbyak-cbb4ca2178c6bd391b48c130afececfdddc66836.zip |
first commit
Diffstat (limited to 'test/address.cpp')
-rw-r--r-- | test/address.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/address.cpp b/test/address.cpp new file mode 100644 index 0000000..0cef961 --- /dev/null +++ b/test/address.cpp @@ -0,0 +1,78 @@ +#include <stdio.h> +#include <string.h> + +#define NUM_OF_ARRAY(x) (sizeof(x) / sizeof(x[0])) + +void genAddress(bool isJIT, const char regTbl[][5], size_t regTblNum) +{ + for (size_t i = 0; i < regTblNum + 1; i++) { + const char *base = regTbl[i]; + for (size_t j = 0; j < regTblNum + 1; j++) { + if (j == 4) continue; /* esp is not index register */ + const char *index = regTbl[j]; + static const int scaleTbl[] = { 0, 1, 2, 4, 8 }; + for (int k = 0; k < NUM_OF_ARRAY(scaleTbl); k++) { + int scale = scaleTbl[k]; + static const int dispTbl[] = { 0, 1, 1000, -1, -1000 }; + for (int m = 0; m < NUM_OF_ARRAY(dispTbl); m++) { + int disp = dispTbl[m]; + bool isFirst = true; + if (isJIT) { + printf("mov (ecx, ptr["); + } else { + printf("mov ecx, ["); + } + if (i < regTblNum) { + printf("%s", base); + isFirst = false; + } + if (j < regTblNum) { + if (!isFirst) putchar('+'); + printf("%s", index); + if (scale) printf("*%d", scale); + isFirst = false; + } + if (isFirst) { + if (isJIT) printf("(void*)"); + printf("0x%08X", disp); + } else { + if (disp >= 0) { + putchar('+'); + } + printf("%d", disp); + isFirst = false; + } + if (isJIT) { + printf("]); dump();\n"); + } else { + printf("]\n"); + } + } + } + } + } +} + +int main(int argc, char *argv[]) +{ + argc--, argv++; + bool phase = argc > 0 && strcmp(*argv, "1") == 0; + bool isJIT = (argc > 1); + fprintf(stderr, "phase:%c %s\n", phase ? '1' : '2', isJIT ? "jit" : "asm"); + if (phase) { + static const char reg32Tbl[][5] = { + "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", +#ifdef XBYAK64 + "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d", +#endif + }; + genAddress(isJIT, reg32Tbl, NUM_OF_ARRAY(reg32Tbl)); + } else { +#ifdef XBYAK64 + static const char reg64Tbl[][5] = { + "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + }; + genAddress(isJIT, reg64Tbl, NUM_OF_ARRAY(reg64Tbl)); +#endif + } +} |