[abi] Reorganized instruction DB, removed deprecated instructions

* Removed AVX512_ER, AVX512_PF, AVX512_4FMAPS, and AVX512_4VNNIW
    extensions and corresponding instructions (these were never
    advertised by any x86 CPU and were only used by Xeon Phi acc.,
    which AsmJit never supported)
  * Removed CPU extensions HLE, MPX, and TSX
  * Kept extension RTM, which is only for backward compatibility to
    recognize instructions, but it's no longer checked by CpuInfo as
    it's been deprecated together with HLE and MPX
  * The xtest instruction now reports it requires RTM
  * Reorganized x86 extensions a bit - they are now reordered to group
    them by category, preparing for the future where extension IDs will
    be always added after existing records for ABI compatibility
  * Instruction vcvtneps2bf16 no longer accepts form without an explicit
    memory operand size
  * Removed aliased instructions in CMOVcc, Jcc, And SETcc categories,
    now there is only a single instruction id for all aliased instructions.
  * Added a new feature to always show instruction aliases in Logger, which
    includes formatting instructio nodes (Builder, Compiler)

Instruction DB-only updates (not applied to C++ yet):

  * AsmJit DB from now uses the same license as AsmJit (Zlib) and
    no longer applies dual licensing (Zlib and Public Domain)
  * Added support for aggregated instruction definitions in
    x86 instruction database, which should simplify the maintenance
    and reduce bugs (also the syntax is comparable to descriptions
    used by Intel APX instruction manuals)
  * Added support for APX instructions and new features
  * Added support for AVX10.1 and AVX10.2 instructions (both new
    instructions and new encodings of existing instructions)
  * Added support for MOVRS instructions
  * Added support for KL instructions (loadiwkey)
  * Added support for AESKLE instructions
  * Added support for AESKLEWIDE_KL instructions
  * Added support for AMX_[AVX512|MOVRS|FP8|TF32|TRANSPOSE]
  * NOTE: None of the instruction additions is currently used by
    Asmjit, it's a pure database update that needs more work to
    make all the instructions available in future AsmJit
This commit is contained in:
kobalicek
2025-05-10 15:03:54 +02:00
parent 9eb6edbf71
commit 6c9a6b2454
52 changed files with 10539 additions and 10602 deletions

View File

@@ -56,35 +56,50 @@ class InstructionNameData {
this.maxNameLength = 0;
}
add(s) {
// First try to encode the string with 5-bit characters that fit into a 32-bit int.
if (/^[a-z0-4]{0,6}$/.test(s)) {
let index = 0;
for (let i = 0; i < s.length; i++)
index |= charTo5Bit(s[i]) << (i * 5);
add(name, alt) {
if (name === alt) {
alt = "";
}
this.names.push(s);
if (this.maxNameLength < name.length) {
this.maxNameLength = name.length;
}
this.names.push(name);
// First try to encode the string with 5-bit characters that fit into a 32-bit int.
if (/^[a-z0-4]{0,6}$/.test(name) && !alt) {
let index = 0;
for (let i = 0; i < name.length; i++) {
index |= charTo5Bit(name[i]) << (i * 5);
}
this.indexComment.push(`Small '${name}'.`);
this.primaryTable.push(index | (1 << 31));
this.indexComment.push(`Small '${s}'.`);
}
else if (alt) {
const prefixIndex = this.addOrReferenceString(name + String.fromCharCode(alt.length) + alt);
if (name === "jz") {
console.log(`jz prefix: ${prefixIndex}`);
}
this.indexComment.push(`Large '${name}' + '${alt}'`);
this.primaryTable.push(prefixIndex | (name.length << 12) | (0xFFF << 16) | 0);
}
else {
// Put the string into a string table.
this.names.push(s);
this.primaryTable.push(-1);
this.indexComment.push(``);
this.primaryTable.push(0);
}
if (this.maxNameLength < s.length)
this.maxNameLength = s.length;
}
index() {
const kMaxPrefixSize = 15;
const kMaxSuffixSize = 7;
const kMaxSuffixSize = 6;
const names = [];
for (let idx = 0; idx < this.primaryTable.length; idx++) {
if (this.primaryTable[idx] === -1) {
if (this.primaryTable[idx] === 0) {
names.push({ name: this.names[idx], index: idx });
}
}
@@ -205,11 +220,20 @@ class InstructionNameData {
FATAL(`IndexedString.formatStringTable(): Not indexed yet, call index()`);
let s = "";
for (let i = 0; i < this.stringTable.length; i += 80) {
if (s)
s += "\n"
s += '"' + this.stringTable.substring(i, i + 80) + '"';
let line = "";
for (let i = 0; i < this.stringTable.length; i++) {
const c = this.stringTable.charCodeAt(i);
line += "\\x" + cxx.Utils.toHexRaw(c, 2);
if (line.length >= 115 || i === this.stringTable.length - 1) {
if (s)
s += "\n"
s += `"${line}"`;
line = "";
}
}
s += ";\n";
return `const char ${tableName}[] =\n${StringUtils.indent(s, " ")}\n`;
@@ -288,7 +312,9 @@ class Injector {
const path = kAsmJitRoot + "/" + file;
console.log(`MODIFIED '${file}'`);
fs.writeFileSync(path + ".backup", obj.prev, "utf8");
if (!fs.existsSync(path + ".backup")) {
fs.writeFileSync(path + ".backup", obj.prev, "utf8");
}
fs.writeFileSync(path, obj.data, "utf8");
}
}
@@ -346,7 +372,7 @@ exports.Injector = Injector;
// Main context used to load, generate, and store instruction tables. The idea
// is to be extensible, so it stores 'Task's to be executed with minimal deps
// management.
class TableGen extends Injector{
class TableGen extends Injector {
constructor(arch) {
super();
@@ -418,7 +444,7 @@ class TableGen extends Injector{
// [Instruction Management]
// --------------------------------------------------------------------------
addInst(inst) {
addInstruction(inst) {
if (this.instMap[inst.name])
FATAL(`TableGen.addInst(): Instruction '${inst.name}' already added`);
@@ -471,19 +497,35 @@ class IdEnum extends Task {
run() {
const insts = this.ctx.insts;
var s = "";
for (var i = 0; i < insts.length; i++) {
let s = "";
let aliases = "";
for (let i = 0; i < insts.length; i++) {
const inst = insts[i];
var line = "kId" + inst.enum + (i ? "" : " = 0") + ",";
var text = this.comment(inst);
let line = "kId" + inst.enum + (i ? "" : " = 0") + ",";
let text = this.comment(inst);
if (text)
line = line.padEnd(37) + "//!< " + text;
s += line + "\n";
if (inst.aliases) {
for (let aliasName of inst.aliases.aliasNames) {
if (aliases) aliases += ",\n";
aliases += `kId${StringUtils.makeEnumName(aliasName)} = kId${inst.enum}`;
}
}
}
s += "_kIdCount";
if (aliases) {
s += ",\n\n" + "// Aliases.\n" + aliases + "\n";
}
else {
s += "\n";
}
s += "_kIdCount\n";
return this.ctx.inject("InstId", s);
}
@@ -507,16 +549,43 @@ class Output {
};
exports.Output = Output;
function generateNameData(out, instructions) {
function cmp(a, b) { return (a < b) ? -1 : a > b ? 1 : 0; }
function generateNameData(out, instructions, generateAliases) {
const none = "Inst::kIdNone";
const aliases = [];
const aliasNameData = new InstructionNameData();
const aliasLinkData = [];
const instFirst = new Array(26);
const instLast = new Array(26);
const instNameData = new InstructionNameData();
for (let i = 0; i < instructions.length; i++)
instNameData.add(instructions[i].displayName);
for (let i = 0; i < instructions.length; i++) {
const instruction = instructions[i];
if (instruction.aliases) {
instNameData.add(instruction.displayName, instruction.aliases.format);
for (let aliasName of instruction.aliases.aliasNames) {
aliases.push({ name: instruction.name, alt: aliasName });
}
}
else {
instNameData.add(instruction.displayName);
}
}
aliases.sort(function(a, b) { return cmp(a.alt, b.alt); });
for (let i = 0; i < aliases.length; i++) {
const alias = aliases[i];
aliasNameData.add(alias.alt);
aliasLinkData.push(`Inst::kId${StringUtils.makeEnumName(alias.name)}`);
}
instNameData.index();
aliasNameData.index();
for (let i = 0; i < instructions.length; i++) {
const inst = instructions[i];
@@ -548,21 +617,41 @@ function generateNameData(out, instructions) {
s += `\n`;
s += instNameData.formatIndexTable("InstDB::_instNameIndexTable");
const dataSize = instNameData.getSize() + 26 * 4;
let dataSize = instNameData.getSize() + 26 * 4;
if (generateAliases) {
s += `\n`;
s += aliasNameData.formatStringTable("InstDB::_aliasNameStringTable");
s += `\n`;
s += aliasNameData.formatIndexTable("InstDB::_aliasNameIndexTable");
s += "\n";
s += "const uint32_t InstDB::_aliasIndexToInstId[] = {\n" + StringUtils.format(aliasLinkData, " ", true, null) + "\n};\n";
dataSize += aliasNameData.getSize();
let info = `static constexpr uint32_t kAliasTableSize = ${aliasLinkData.length};\n`;
out.add("NameDataInfo", StringUtils.disclaimer(info), 0);
}
out.add("NameData", StringUtils.disclaimer(s), dataSize);
return out;
}
exports.generateNameData = generateNameData;
class NameTable extends Task {
constructor(name, deps) {
constructor(name, deps, generateAliases) {
super(name || "NameTable", deps);
this.generateAliases = generateAliases;
}
run() {
const output = new Output();
generateNameData(output, this.ctx.insts);
generateNameData(output, this.ctx.insts, this.generateAliases);
this.ctx.inject("NameData", output.content["NameData"], output.tableSize["NameData"]);
if (this.generateAliases) {
this.ctx.inject("NameDataInfo", output.content["NameDataInfo"], output.tableSize["NameDataInfo"]);
}
}
}
exports.NameTable = NameTable;