2010-04-15 18:33:04 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define NUM_OF_ARRAY(x) (sizeof(x) / sizeof(x[0]))
|
|
|
|
|
2013-07-29 19:31:11 -07:00
|
|
|
void genVsibSub(bool isJIT, const char *name, const char *tbl[], size_t tblSize)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < tblSize; i++) {
|
|
|
|
if (isJIT) {
|
|
|
|
printf("%s (ymm7, ptr[", name);
|
|
|
|
} else {
|
|
|
|
printf("%s ymm7, [", name);
|
|
|
|
}
|
|
|
|
printf("%s", tbl[i]);
|
|
|
|
if (isJIT) {
|
|
|
|
printf("], ymm4); dump();\n");
|
|
|
|
} else {
|
|
|
|
printf("], ymm4\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-28 05:56:35 -07:00
|
|
|
void genVsib(bool isJIT)
|
|
|
|
{
|
|
|
|
if (isJIT) puts("void genVsib() {");
|
2013-07-29 19:31:11 -07:00
|
|
|
const char *vm32xTbl[] = {
|
|
|
|
"xmm0",
|
|
|
|
"xmm0 * 1",
|
|
|
|
"xmm0 + 4",
|
|
|
|
"xmm0 + eax",
|
|
|
|
"xmm0 * 4 + ecx",
|
|
|
|
"xmm3 * 8 + edi + 123",
|
|
|
|
"xmm2 * 2 + 5",
|
|
|
|
"eax + xmm0",
|
2021-06-05 01:48:07 -07:00
|
|
|
"esp + xmm2",
|
2013-07-28 05:56:35 -07:00
|
|
|
};
|
2013-07-29 19:31:11 -07:00
|
|
|
const char *vm32yTbl[] = {
|
|
|
|
"ymm0",
|
|
|
|
"ymm0 * 1",
|
|
|
|
"ymm0 + 4",
|
|
|
|
"ymm0 + eax",
|
|
|
|
"ymm0 * 4 + ecx",
|
|
|
|
"ymm3 * 8 + edi + 123",
|
|
|
|
"ymm2 * 2 + 5",
|
|
|
|
"eax + ymm0",
|
2021-06-05 01:48:07 -07:00
|
|
|
"esp + ymm2",
|
2013-07-28 05:56:35 -07:00
|
|
|
};
|
2013-07-29 19:31:11 -07:00
|
|
|
genVsibSub(isJIT, "vgatherdpd", vm32xTbl, NUM_OF_ARRAY(vm32xTbl));
|
|
|
|
genVsibSub(isJIT, "vgatherqpd", vm32yTbl, NUM_OF_ARRAY(vm32yTbl));
|
|
|
|
#ifdef XBYAK64
|
|
|
|
const char *vm32x64Tbl[] = {
|
|
|
|
"xmm0 + r11",
|
|
|
|
"r13 + xmm15",
|
|
|
|
"123 + rsi + xmm2 * 4",
|
|
|
|
};
|
|
|
|
genVsibSub(isJIT, "vgatherdpd", vm32x64Tbl, NUM_OF_ARRAY(vm32x64Tbl));
|
|
|
|
#endif
|
2013-07-28 05:56:35 -07:00
|
|
|
if (isJIT) puts("}");
|
|
|
|
}
|
|
|
|
|
2010-04-15 18:33:04 -07:00
|
|
|
void genAddress(bool isJIT, const char regTbl[][5], size_t regTblNum)
|
|
|
|
{
|
2010-06-01 00:28:14 -07:00
|
|
|
int count = 0;
|
|
|
|
int funcNum = 1;
|
|
|
|
if (isJIT) {
|
|
|
|
puts("void gen0(){");
|
|
|
|
}
|
2010-04-15 18:33:04 -07:00
|
|
|
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 };
|
2010-06-01 00:28:14 -07:00
|
|
|
for (size_t k = 0; k < NUM_OF_ARRAY(scaleTbl); k++) {
|
2010-04-15 18:33:04 -07:00
|
|
|
int scale = scaleTbl[k];
|
|
|
|
static const int dispTbl[] = { 0, 1, 1000, -1, -1000 };
|
2010-06-01 00:28:14 -07:00
|
|
|
for (size_t m = 0; m < NUM_OF_ARRAY(dispTbl); m++) {
|
2010-04-15 18:33:04 -07:00
|
|
|
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*)");
|
2022-01-27 18:57:21 -07:00
|
|
|
printf("%d", disp);
|
2010-04-15 18:33:04 -07:00
|
|
|
} else {
|
|
|
|
if (disp >= 0) {
|
|
|
|
putchar('+');
|
|
|
|
}
|
|
|
|
printf("%d", disp);
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
if (isJIT) {
|
|
|
|
printf("]); dump();\n");
|
|
|
|
} else {
|
|
|
|
printf("]\n");
|
|
|
|
}
|
2010-06-01 00:28:14 -07:00
|
|
|
if (isJIT) {
|
|
|
|
count++;
|
|
|
|
if ((count % 100) == 0) {
|
|
|
|
printf("}\n void gen%d(){\n", funcNum++);
|
|
|
|
}
|
|
|
|
}
|
2010-04-15 18:33:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-28 05:56:35 -07:00
|
|
|
if (isJIT) puts("}");
|
|
|
|
genVsib(isJIT);
|
2010-06-01 00:28:14 -07:00
|
|
|
if (isJIT) {
|
2013-07-28 05:56:35 -07:00
|
|
|
printf("void gen(){\n");
|
2010-06-01 00:28:14 -07:00
|
|
|
for (int i = 0; i < funcNum; i++) {
|
|
|
|
printf(" gen%d();\n", i);
|
|
|
|
}
|
2013-07-28 05:56:35 -07:00
|
|
|
puts("genVsib();");
|
2010-06-01 00:28:14 -07:00
|
|
|
printf("}\n");
|
|
|
|
}
|
2010-04-15 18:33:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2010-06-01 00:28:14 -07:00
|
|
|
fprintf(stderr, "32bit reg\n");
|
2010-04-15 18:33:04 -07:00
|
|
|
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
|
2010-06-01 00:28:14 -07:00
|
|
|
fprintf(stderr, "64bit reg\n");
|
2010-04-15 18:33:04 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|