mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-18 04:54:36 +03:00
[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:
124
db/base.js
124
db/base.js
@@ -1,24 +1,28 @@
|
||||
// This file is part of AsmJit project <https://asmjit.com>
|
||||
//
|
||||
// See asmjit.h or LICENSE.md for license and copyright information
|
||||
// SPDX-License-Identifier: (Zlib or Unlicense)
|
||||
// SPDX-License-Identifier: Zlib
|
||||
|
||||
(function($scope, $as) {
|
||||
"use strict";
|
||||
|
||||
function FAIL(msg) { throw new Error("[BASE] " + msg); }
|
||||
|
||||
// Import.
|
||||
const hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
const exp = $scope.exp ? $scope.exp : require("./exp.js");
|
||||
|
||||
|
||||
// Export.
|
||||
const base = $scope[$as] = Object.create(null);
|
||||
|
||||
base.exp = exp;
|
||||
|
||||
// Import.
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
function hasOwn(object, key) {
|
||||
return hasOwnProperty.call(object, key);
|
||||
}
|
||||
base.hasOwn = hasOwn;
|
||||
|
||||
function dict(src) {
|
||||
const dst = Object.create(null);
|
||||
if (src)
|
||||
@@ -131,8 +135,14 @@ base.Parsing = Parsing;
|
||||
// asmdb.base.MapUtils
|
||||
// ===================
|
||||
|
||||
const MapUtils = {
|
||||
cloneExcept(map, except) {
|
||||
class MapUtils {
|
||||
static cloneExcept(map, except) {
|
||||
if (typeof except === "string") {
|
||||
const key = except;
|
||||
except = Object.create(null);
|
||||
except[key] = true;
|
||||
}
|
||||
|
||||
const out = Object.create(null);
|
||||
for (let k in map) {
|
||||
if (k in except)
|
||||
@@ -141,6 +151,14 @@ const MapUtils = {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static mapFromArray(array) {
|
||||
const out = Object.create(null);
|
||||
for (let k of array) {
|
||||
out[k] = true;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
base.MapUtils = MapUtils;
|
||||
|
||||
@@ -158,9 +176,9 @@ const OperandFlags = Object.freeze({
|
||||
base.OperandFlags = OperandFlags;
|
||||
|
||||
class Operand {
|
||||
constructor(data) {
|
||||
constructor() {
|
||||
this.type = ""; // Type of the operand ("reg", "reg-list", "mem", "reg/mem", "imm", "rel").
|
||||
this.data = data; // The operand's data (possibly processed).
|
||||
this.data = ""; // The operand's data (possibly processed).
|
||||
this.flags = 0;
|
||||
|
||||
this.reg = ""; // Register operand's definition.
|
||||
@@ -246,7 +264,7 @@ class Instruction {
|
||||
|
||||
this.specialRegs = dict(); // Information about read/write to special registers.
|
||||
|
||||
this.altForm = false; // This is an alternative form, not needed to create a signature.
|
||||
this.alt = false; // This is an alternative form, not needed to create a signature.
|
||||
this.volatile = false; // Instruction is volatile and should not be reordered.
|
||||
this.control = "none"; // Control flow type (none by default).
|
||||
this.privilege = ""; // Privilege-level required to execute the instruction.
|
||||
@@ -373,8 +391,8 @@ class InstructionGroup extends Array {
|
||||
unionCpuFeatures(name) {
|
||||
const result = dict();
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
const inst = this[i];
|
||||
const features = inst.ext;
|
||||
const instruction = this[i];
|
||||
const features = instruction.ext;
|
||||
for (let k in features)
|
||||
result[k] = features[k];
|
||||
}
|
||||
@@ -401,13 +419,14 @@ class ISA {
|
||||
this._instructionNames = null; // Instruction names (sorted), regenerated when needed.
|
||||
this._instructionMap = dict(); // Instruction name to `Instruction[]` mapping.
|
||||
this._aliases = dict(); // Instruction aliases.
|
||||
this._aliasMap = dict(); // Instruction aliases.
|
||||
this._cpuLevels = dict(); // Architecture versions.
|
||||
this._extensions = dict(); // Architecture extensions.
|
||||
this._attributes = dict(); // Instruction attributes.
|
||||
this._specialRegs = dict(); // Special registers.
|
||||
this._shortcuts = dict(); // Shortcuts used by instructions metadata.
|
||||
this.stats = {
|
||||
insts : 0, // Number of all instructions.
|
||||
instructions : 0, // Number of all instructions.
|
||||
groups: 0 // Number of grouped instructions (having unique name).
|
||||
};
|
||||
}
|
||||
@@ -436,7 +455,7 @@ class ISA {
|
||||
}
|
||||
|
||||
get instructionMap() { return this._instructionMap; }
|
||||
get aliases() { return this._aliases; }
|
||||
get aliases() { return this._aliasMap; }
|
||||
get cpuLevels() { return this._cpuLevels; }
|
||||
get extensions() { return this._extensions; }
|
||||
get attributes() { return this._attributes; }
|
||||
@@ -458,27 +477,31 @@ class ISA {
|
||||
return result;
|
||||
}
|
||||
|
||||
aliasData(name) {
|
||||
return this._aliases[name] || null;
|
||||
}
|
||||
|
||||
_queryByName(name, copy) {
|
||||
let result = EmptyInstructionGroup;
|
||||
const map = this._instructionMap;
|
||||
|
||||
if (typeof name === "string") {
|
||||
const insts = map[name];
|
||||
if (insts) result = insts;
|
||||
const instructions = map[name];
|
||||
if (instructions) result = instructions;
|
||||
return copy ? result.slice() : result;
|
||||
}
|
||||
|
||||
if (Array.isArray(name)) {
|
||||
const names = name;
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const insts = map[names[i]];
|
||||
if (!insts) continue;
|
||||
const instructions = map[names[i]];
|
||||
if (!instructions) continue;
|
||||
|
||||
if (result === EmptyInstructionGroup)
|
||||
result = new InstructionGroup();
|
||||
|
||||
for (let j = 0; j < insts.length; j++)
|
||||
result.push(insts[j]);
|
||||
for (let j = 0; j < instructions.length; j++)
|
||||
result.push(instructions[j]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -507,23 +530,24 @@ class ISA {
|
||||
if (data.specialRegs) this._addSpecialRegs(data.specialRegs);
|
||||
if (data.shortcuts) this._addShortcuts(data.shortcuts);
|
||||
if (data.instructions) this._addInstructions(data.instructions);
|
||||
if (data.aliases) this._addAliases(data.aliases);
|
||||
if (data.postproc) this._postProc(data.postproc);
|
||||
}
|
||||
|
||||
_postProc(groups) {
|
||||
for (let group of groups) {
|
||||
for (let iRule of group.instructions) {
|
||||
const names = iRule.inst.split(" ");
|
||||
const names = iRule.name.split(" ");
|
||||
for (let name of names) {
|
||||
const insts = this._instructionMap[name];
|
||||
if (!insts)
|
||||
const instructions = this._instructionMap[name];
|
||||
if (!instructions)
|
||||
FAIL(`Instruction ${name} referenced by '${group.group}' group doesn't exist`);
|
||||
|
||||
for (let k in iRule) {
|
||||
if (k === "inst" || k === "data")
|
||||
if (k === "name" || k === "data")
|
||||
continue;
|
||||
for (let inst of insts) {
|
||||
inst._assignAttribute(k, iRule[k]);
|
||||
for (let instruction of instructions) {
|
||||
instruction._assignAttribute(k, iRule[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -630,28 +654,60 @@ class ISA {
|
||||
FAIL("ISA._addInstructions() must be reimplemented");
|
||||
}
|
||||
|
||||
_addInstruction(inst) {
|
||||
_addInstruction(instruction) {
|
||||
let group;
|
||||
|
||||
if (hasOwn.call(this._instructionMap, inst.name)) {
|
||||
group = this._instructionMap[inst.name];
|
||||
if (hasOwn(this._instructionMap, instruction.name)) {
|
||||
group = this._instructionMap[instruction.name];
|
||||
}
|
||||
else {
|
||||
group = new InstructionGroup();
|
||||
this._instructionNames = null;
|
||||
this._instructionMap[inst.name] = group;
|
||||
this._instructionMap[instruction.name] = group;
|
||||
this.stats.groups++;
|
||||
}
|
||||
|
||||
if (inst.aliasOf)
|
||||
this._aliases[inst.name] = inst.aliasOf;
|
||||
if (instruction.aliasOf) {
|
||||
this._addAlias(instruction.name, instruction.aliasOf);
|
||||
}
|
||||
|
||||
group.push(inst);
|
||||
this.stats.insts++;
|
||||
group.push(instruction);
|
||||
this.stats.instructions++;
|
||||
this._instructions = null;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// Add aliases from instruction database - aliases must be an object where each key is a non-aliased instruction.
|
||||
_addAliases(aliases) {
|
||||
for (let instructionName in aliases) {
|
||||
const data = aliases[instructionName];
|
||||
for (let aliasName of data.aliases) {
|
||||
this._addAlias(instructionName, aliasName, data.format || "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_addAlias(instructionName, aliasName, aliasFormat) {
|
||||
const group = this._instructionMap[instructionName];
|
||||
if (!group) {
|
||||
FAIL(`Instruction ${instructionName} doesn't exist when processing alias (${aliasName})`);
|
||||
}
|
||||
|
||||
let alias = this._aliases[instructionName];
|
||||
if (!alias) {
|
||||
alias = dict({
|
||||
primaryName: instructionName,
|
||||
aliasNames: [],
|
||||
format: ""
|
||||
});
|
||||
this._aliases[instructionName] = alias;
|
||||
}
|
||||
|
||||
this._aliasMap[aliasName] = instructionName;
|
||||
alias.aliasNames.push(aliasName);
|
||||
alias.format = aliasFormat || "";
|
||||
}
|
||||
}
|
||||
base.ISA = ISA;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user