Merge commit '0a097849af1bcd979ff4b430a03971f16822cbcb' as 'external/xbyak'

This commit is contained in:
Simone Coco
2025-12-23 16:51:03 +01:00
148 changed files with 33794 additions and 0 deletions

44
external/xbyak/gen/Makefile vendored Normal file
View File

@@ -0,0 +1,44 @@
TARGET=../xbyak/xbyak_mnemonic.h
BIN=sortline gen_code gen_avx512
CFLAGS=-I../ -I ./ -Wall -Wextra -Wno-missing-field-initializers $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
all: $(TARGET) ../CMakeLists.txt ../meson.build ../readme.md ../readme.txt
avx_type_def.h: ../xbyak/xbyak.h
sed -n '/@@@begin of avx_type_def.h/,/@@@end of avx_type_def.h/p' $< > $@
avx_type.hpp: avx_type_def.h
sortline: sortline.cpp
$(CXX) $(CFLAGS) $< -o $@
gen_code: gen_code.cpp avx_type.hpp
$(CXX) $(CFLAGS) $< -o $@
gen_avx512: gen_avx512.cpp avx_type.hpp
$(CXX) $(CFLAGS) $< -o $@
$(TARGET): $(BIN)
./gen_code | ./sortline > $@
echo "#ifdef XBYAK_ENABLE_OMITTED_OPERAND" >> $@
./gen_code omit | ./sortline >> $@
echo "#endif" >>$@
./gen_code fixed >> $@
echo "#ifndef XBYAK_DISABLE_AVX512" >> $@
./gen_avx512 | ./sortline >> $@
echo "#ifdef XBYAK64" >> $@
./gen_avx512 64 | ./sortline >> $@
echo "#endif" >> $@
echo "#endif" >> $@
VER=$(shell head -n 1 ../xbyak/xbyak_mnemonic.h|grep -o "[0-9.]*")
../CMakeLists.txt: $(TARGET)
sed -i -e 's/CXX VERSION [0-9.]*/CXX VERSION $(VER)/' $@
../meson.build: $(TARGET)
sed -i -e "s/version: '[0-9.]*',/version: '$(VER)',/" $@
../readme.md: $(TARGET)
sed -l 2 -i -e "s/# Xbyak [0-9.]*/# Xbyak $(VER)/" $@
../readme.txt: $(TARGET)
sed -l 2 -i -e "s/Xbyak [0-9.]*/Xbyak $(VER)/" $@
clean:
$(RM) $(BIN) $(TARGET) avx_type_def.h

60
external/xbyak/gen/avx_type.hpp vendored Normal file
View File

@@ -0,0 +1,60 @@
#include <assert.h>
#include "avx_type_def.h"
const int NONE = 256; // same as Xbyak::CodeGenerator::NONE
std::string type2String(uint64_t type)
{
if (type == 0) return "T_NONE";
std::string str;
int low = type & T_NX_MASK;
if (0 < low && low < 7) {
const char *tbl[8] = {
"T_N1", "T_N2", "T_N4", "T_N8", "T_N16", "T_N32"
};
assert(low < int(sizeof(tbl) / sizeof(tbl[0])));
str = tbl[low - 1];
}
if (type & T_N_VL) str += "|T_N_VL";
if (type & T_APX) str += "|T_APX";
if ((type & T_NX_MASK) == T_DUP) str += "|T_DUP";
if (type & T_66) str += "|T_66";
if (type & T_F3) str += "|T_F3";
if (type & T_F2) str += "|T_F2";
if (type & T_MAP5) str += "|T_MAP5";
if (type & T_0F) str += "|T_0F";
if (type & T_MAP6) str += "|T_MAP6";
if (type & T_0F38) str += "|T_0F38";
if (type & T_0F3A) str += "|T_0F3A";
if (type & T_L1) str += "|T_L1";
if (type & T_W0) str += "|T_W0";
if (type & T_W1) str += "|T_W1";
if (type & T_EW1) str += "|T_EW1";
if (type & T_YMM) str += "|T_YMM";
if (type & T_EVEX) str += "|T_EVEX";
if (type & T_ER_X) str += "|T_ER_X";
if (type & T_ER_Y) str += "|T_ER_Y";
if (type & T_ER_Z) str += "|T_ER_Z";
if (type & T_ER_R) str += "|T_ER_R";
if (type & T_SAE_X) str += "|T_SAE_X";
if (type & T_SAE_Y) str += "|T_SAE_Y";
if (type & T_SAE_Z) str += "|T_SAE_Z";
if (type & T_MUST_EVEX) str += "|T_MUST_EVEX";
switch (type & T_B16) { // T_B16 = T_B32 | T_B64
case T_B16: str += "|T_B16"; break;
case T_B32: str += "|T_B32"; break;
case T_B64: str += "|T_B64"; break;
default: break;
}
if (type & T_M_K) str += "|T_M_K";
if (type & T_VSIB) str += "|T_VSIB";
if (type & T_MEM_EVEX) str += "|T_MEM_EVEX";
if (type & T_NF) str += "|T_NF";
if (type & T_CODE1_IF1) str += "|T_CODE1_IF1";
if (type & T_ND1) str += "|T_ND1";
if (type & T_ZU) str += "|T_ZU";
if (str[0] == '|') str = str.substr(1);
return str;
}

52
external/xbyak/gen/avx_type_def.h vendored Normal file
View File

@@ -0,0 +1,52 @@
// @@@begin of avx_type_def.h
static const uint64_t T_NONE = 0ull;
// low 3 bit
static const uint64_t T_N1 = 1ull;
static const uint64_t T_N2 = 2ull;
static const uint64_t T_N4 = 3ull;
static const uint64_t T_N8 = 4ull;
static const uint64_t T_N16 = 5ull;
static const uint64_t T_N32 = 6ull;
static const uint64_t T_NX_MASK = 7ull;
static const uint64_t T_DUP = T_NX_MASK;//1 << 4, // N = (8, 32, 64)
static const uint64_t T_N_VL = 1ull << 3; // N * (1, 2, 4) for VL
static const uint64_t T_APX = 1ull << 4;
static const uint64_t T_66 = 1ull << 5; // pp = 1
static const uint64_t T_F3 = 1ull << 6; // pp = 2
static const uint64_t T_ER_R = 1ull << 7; // reg{er}
static const uint64_t T_0F = 1ull << 8;
static const uint64_t T_0F38 = 1ull << 9;
static const uint64_t T_0F3A = 1ull << 10;
static const uint64_t T_MAP5 = 1ull << 11;
static const uint64_t T_L1 = 1ull << 12;
static const uint64_t T_W0 = 1ull << 13; // T_EW0 = T_W0
static const uint64_t T_W1 = 1ull << 14; // for VEX
static const uint64_t T_EW1 = 1ull << 16; // for EVEX
static const uint64_t T_YMM = 1ull << 17; // support YMM, ZMM
static const uint64_t T_EVEX = 1ull << 18;
static const uint64_t T_ER_X = 1ull << 19; // xmm{er}
static const uint64_t T_ER_Y = 1ull << 20; // ymm{er}
static const uint64_t T_ER_Z = 1ull << 21; // zmm{er}
static const uint64_t T_SAE_X = 1ull << 22; // xmm{sae}
static const uint64_t T_SAE_Y = 1ull << 23; // ymm{sae}
static const uint64_t T_SAE_Z = 1ull << 24; // zmm{sae}
static const uint64_t T_MUST_EVEX = 1ull << 25; // contains T_EVEX
static const uint64_t T_B32 = 1ull << 26; // m32bcst
static const uint64_t T_B64 = 1ull << 27; // m64bcst
static const uint64_t T_B16 = T_B32 | T_B64; // m16bcst (Be careful)
static const uint64_t T_M_K = 1ull << 28; // mem{k}
static const uint64_t T_VSIB = 1ull << 29;
static const uint64_t T_MEM_EVEX = 1ull << 30; // use evex if mem
static const uint64_t T_MAP6 = 1ull << 31;
static const uint64_t T_NF = 1ull << 32; // T_nf
static const uint64_t T_CODE1_IF1 = 1ull << 33; // code|=1 if !r.isBit(8)
static const uint64_t T_ND1 = 1ull << 35; // ND=1
static const uint64_t T_ZU = 1ull << 36; // ND=ZU
static const uint64_t T_F2 = 1ull << 37; // pp = 3
static const uint64_t T_SENTRY = (1ull << 38)-1; // attribute(>=T_SENTRY) is for error check
static const uint64_t T_ALLOW_DIFF_SIZE = 1ull << 38; // allow difference reg size
static const uint64_t T_ALLOW_ABCDH = 1ull << 39; // allow [abcd]h reg
// T_66 = 1, T_F3 = 2, T_F2 = 3
static inline uint32_t getPP(uint64_t type) { return (type & T_66) ? 1 : (type & T_F3) ? 2 : (type & T_F2) ? 3 : 0; }
// @@@end of avx_type_def.h

17
external/xbyak/gen/b2hex.cpp vendored Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
int main()
{
puts("enum {");
for (int i = 0; i < 256; i++) {
printf(" B");
for (int j = 0; j < 8; j++) {
putchar(i & (1 << (7 - j)) ? '1' : '0');
}
printf("= %d", i);
if (i < 255) putchar(',');
putchar('\n');
}
puts("};");
return 0;
}

1205
external/xbyak/gen/gen_avx512.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

2208
external/xbyak/gen/gen_code.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

23
external/xbyak/gen/sortline.cpp vendored Normal file
View File

@@ -0,0 +1,23 @@
#include <iostream>
#include <fstream>
#include <string>
#include <set>
typedef std::set<std::string> StrSet;
int main()
{
StrSet ss;
std::string line;
while (std::getline(std::cin, line)) {
if (!line.empty() && line[line.size() - 1] == '\n') {
line.resize(line.size() - 1);
}
if (!line.empty()) {
ss.insert(line);
}
}
for (StrSet::const_iterator i = ss.begin(), ie = ss.end(); i != ie; ++i) {
std::cout << *i << std::endl;
}
}

17
external/xbyak/gen/update.bat vendored Normal file
View File

@@ -0,0 +1,17 @@
@echo off
set OPT=/EHsc -I../ /W4 -D_CRT_SECURE_NO_WARNINGS
set TARGET=..\\xbyak\\xbyak_mnemonic.h
set SORT=sortline
cl gen_code.cpp %OPT%
gen_code | %SORT% > %TARGET%
echo #ifdef XBYAK_ENABLE_OMITTED_OPERAND>> %TARGET%
gen_code omit | %SORT% >> %TARGET%
echo #endif>>%TARGET%
gen_code fixed >> %TARGET%
cl gen_avx512.cpp %OPT%
echo #ifndef XBYAK_DISABLE_AVX512>> %TARGET%
gen_avx512 | %SORT% >> %TARGET%
echo #ifdef XBYAK64>> %TARGET%
gen_avx512 64 | %SORT% >> %TARGET%
echo #endif>> %TARGET%
echo #endif>> %TARGET%