mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-09-17 23:03:49 +00:00
Compare commits
5
Commits
2c38a73709
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f49c071d1 | ||
|
|
e6cd2539d8 | ||
|
|
0e9034cbd4 | ||
|
|
1faf3539d8 | ||
|
|
6b3fbab387 |
@@ -30,7 +30,7 @@
|
|||||||
"editorHoverWidget.background": "#2c334b"
|
"editorHoverWidget.background": "#2c334b"
|
||||||
},
|
},
|
||||||
"semanticTokenColors": {
|
"semanticTokenColors": {
|
||||||
"comment": { "foreground": "#868686", "fontStyle": "italic" },
|
"comment": { "foreground": "#868686", }, //"fontStyle": "italic" },
|
||||||
"keyword": { "foreground": "#d8bd5b" },
|
"keyword": { "foreground": "#d8bd5b" },
|
||||||
"string": { "foreground": "#d46a54" },
|
"string": { "foreground": "#d46a54" },
|
||||||
"number": { "foreground": "#b5cea8" },
|
"number": { "foreground": "#b5cea8" },
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
"tapeDelaySlot": { "foreground": "#ff5647" }
|
"tapeDelaySlot": { "foreground": "#ff5647" }
|
||||||
},
|
},
|
||||||
"tokenColors": [
|
"tokenColors": [
|
||||||
{ "scope": ["comment", "comment.block", "comment.line", "comment.block.documentation"], "settings": { "foreground": "#868686", "fontStyle": "italic" } },
|
{ "scope": ["comment", "comment.block", "comment.line", "comment.block.documentation"], "settings": { "foreground": "#868686", } }, //"fontStyle": "italic" } },
|
||||||
{ "scope": ["keyword", "keyword.control", "keyword.other"], "settings": { "foreground": "#d8bd5b" } },
|
{ "scope": ["keyword", "keyword.control", "keyword.other"], "settings": { "foreground": "#d8bd5b" } },
|
||||||
{ "scope": ["string", "string.quoted"], "settings": { "foreground": "#d46a54" } },
|
{ "scope": ["string", "string.quoted"], "settings": { "foreground": "#d46a54" } },
|
||||||
{ "scope": ["string.quoted.other"], "settings": { "foreground": "#d69d85" } },
|
{ "scope": ["string.quoted.other"], "settings": { "foreground": "#d69d85" } },
|
||||||
|
|||||||
+118
-73
@@ -26,67 +26,103 @@ const TOKEN_TYPES = [
|
|||||||
"macro",
|
"macro",
|
||||||
];
|
];
|
||||||
|
|
||||||
const TOKEN_MODIFIERS = ["declaration", "tapeRead", "tapeWrite", "tapeAuto"];
|
const TOKEN_MODIFIERS = ["declaration", "tapeRead", "tapeWrite", "tapeAuto"];
|
||||||
const TOKEN_TYPE_INDEX = new Map(TOKEN_TYPES.map((name, index) => [name, index]));
|
const TOKEN_TYPE_INDEX = new Map(TOKEN_TYPES.map((name, index) => [name, index]));
|
||||||
const TOKEN_MODIFIER_INDEX = new Map(TOKEN_MODIFIERS.map((name, index) => [name, index]));
|
const TOKEN_MODIFIER_INDEX = new Map(TOKEN_MODIFIERS.map((name, index) => [name, index]));
|
||||||
|
|
||||||
const ATOM_KEYWORDS = new Set(["MipsAtom_", "MipsAtom_Proc_"]);
|
const ATOM_KEYWORDS = new Set(["MipsAtom_", "MipsAtom_Proc_"]);
|
||||||
const COMPONENT_KEYWORDS = new Set(["MipsAtomComp_", "MipsAtomComp_Proc_"]);
|
const COMPONENT_KEYWORDS = new Set(["MipsAtomComp_", "MipsAtomComp_Proc_"]);
|
||||||
const ANNOTATIONS = new Set([
|
const ANNOTATIONS = new Set([
|
||||||
"atom_info", "atom_bind", "atom_reads", "atom_writes", "atom_label",
|
"atom_info",
|
||||||
"atom_offset", "atom_reg", "atom_type", "atom_ctx", "atom_phase",
|
"atom_bind",
|
||||||
"atom_auto_reg", "phase_auto_reg", "atom_dbg_skip",
|
"atom_reads",
|
||||||
|
"atom_writes",
|
||||||
|
"atom_label",
|
||||||
|
"atom_offset",
|
||||||
|
"atom_reg",
|
||||||
|
"atom_type",
|
||||||
|
"atom_ctx",
|
||||||
|
"atom_phase",
|
||||||
|
"atom_auto_reg",
|
||||||
|
"phase_auto_reg",
|
||||||
|
"atom_dbg_skip",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const DSL_KEYWORDS = new Set([
|
const DSL_KEYWORDS = new Set([
|
||||||
"FI_", "I_", "NI_", "Relative_", "Struct_", "Enum_", "Union_", "Array_",
|
"enum", "struct", "union",
|
||||||
"Slice_", "TypeR_", "TypeV_", "align_", "internal", "local_persist", "global",
|
"offset_of", "static_assert", "typeof", "typeof_ptr", "typeof_same",
|
||||||
"RO_", "LP_", "gknown", "expect_", "cexpr_",
|
"glue", "tmpl",
|
||||||
|
"A_", "FI_", "I_", "NI_",
|
||||||
|
"Array_", "Enum_", "Proc_", "Relative_", "Struct_", "Union_", "Slice_",
|
||||||
|
|
||||||
|
// "TypeR_", "TypeV_",
|
||||||
|
|
||||||
|
"align_",
|
||||||
|
"internal", "local_persist", "global",
|
||||||
|
|
||||||
|
"RO_", "LP_",
|
||||||
|
"gknown", "expect_", "cexpr_",
|
||||||
|
|
||||||
|
"O_", "OA_", "S_", "C_", "T_", "T_same", "R_", "V_",
|
||||||
|
"r_", "v_", "rt_", "vt_",
|
||||||
|
|
||||||
"asm", "asm_words", "asm_rpins", "asm_clobber",
|
"asm", "asm_words", "asm_rpins", "asm_clobber",
|
||||||
"O_", "S_", "C_", "T_", "tmpl", "glue", "r_", "v_", "rt_", "vt_",
|
|
||||||
"rgcc", "r_use", "r_set", "r_mod", "r_imm", "r_mem",
|
"rgcc", "r_use", "r_set", "r_mod", "r_imm", "r_mem",
|
||||||
"u1_", "u2_", "u4_", "u8_", "s1_", "s2_", "s4_", "s8_",
|
|
||||||
"u1_r", "u2_r", "u4_r", "u8_r", "u1_v", "u2_v", "u4_v", "u8_v",
|
"b1_", "b2_", "b4_", "b8_",
|
||||||
|
"u1_", "u2_", "u4_", "u8_",
|
||||||
|
"s1_", "s2_", "s4_", "s8_",
|
||||||
|
"b1_r", "b2_r", "b4_r", "b8_r",
|
||||||
|
"b1_v", "b2_v", "b4_v", "b8_v",
|
||||||
|
"u1_r", "u2_r", "u4_r", "u8_r",
|
||||||
|
"u1_v", "u2_v", "u4_v", "u8_v",
|
||||||
|
|
||||||
|
"u4_lo", "u4_hi",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const DELAY_SLOT_KEYWORDS = new Set(["LdSlot_", "BdSlot_", "DmaSlot_", "GteDelay_"]);
|
const DELAY_SLOT_KEYWORDS = new Set([
|
||||||
|
"LdSlot_",
|
||||||
|
"BdSlot_",
|
||||||
|
"DmaSlot_",
|
||||||
|
"GteDelay_"
|
||||||
|
]);
|
||||||
|
|
||||||
const CONTROL_FLOW_PREFIXES = /^(?:branch_|jump_|call_)/;
|
const CONTROL_FLOW_PREFIXES = /^(?:branch_|jump_|call_)/;
|
||||||
|
|
||||||
const ROLE_TO_TYPE = {
|
const ROLE_TO_TYPE = {
|
||||||
atomName: "tapeAtomName",
|
atomName: "tapeAtomName",
|
||||||
componentName: "tapeComponentName",
|
componentName: "tapeComponentName",
|
||||||
bindType: "tapeBindType",
|
bindType: "tapeBindType",
|
||||||
duffleType: "tapeDuffleType",
|
duffleType: "tapeDuffleType",
|
||||||
gprRegister: "tapeGprRegister",
|
gprRegister: "tapeGprRegister",
|
||||||
cop2Register: "tapeCop2Register",
|
cop2Register: "tapeCop2Register",
|
||||||
};
|
};
|
||||||
|
|
||||||
function registerType(name, index) {
|
function registerType(name, index) {
|
||||||
const kind = index.registers.get(name);
|
const kind = index.registers.get(name);
|
||||||
if (kind === "gpr" || /^R_[A-Za-z0-9_]+$/.test(name)) return "tapeGprRegister";
|
if (kind === "gpr" || /^R_[A-Za-z0-9_] + $/.test(name)) return "tapeGprRegister";
|
||||||
if (kind === "cop2" || /^(?:C2_|gte_cr_)[A-Za-z0-9_]+$/.test(name)) return "tapeCop2Register";
|
if (kind === "cop2" || /^(?:C2_|gte_cr_)[A-Za-z0-9_] + $/.test(name)) return "tapeCop2Register";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function instructionType(name, index) {
|
function instructionType(name, index) {
|
||||||
const domain = index.macros.get(name);
|
const domain = index.macros.get(name);
|
||||||
if (domain === "control") return "tapeControlFlow";
|
if (domain === "control") return "tapeControlFlow";
|
||||||
if (domain === "cpu") return "tapeCpuInstruction";
|
if (domain === "cpu") return "tapeCpuInstruction";
|
||||||
if (domain === "gte") return "tapeGteInstruction";
|
if (domain === "gte") return "tapeGteInstruction";
|
||||||
if (domain === "gpu") return "tapeGpuInstruction";
|
if (domain === "gpu") return "tapeGpuInstruction";
|
||||||
if (domain === "component") {
|
if (domain === "component") {
|
||||||
if (/^mac_gte_/.test(name)) return "tapeGteInstruction";
|
if (/^mac_gte_/.test(name)) return "tapeGteInstruction";
|
||||||
if (/^mac_gp/.test(name)) return "tapeGpuInstruction";
|
if (/^mac_gp/.test(name)) return "tapeGpuInstruction";
|
||||||
if (/^mac_/.test(name)) return "tapeComponentInstruction";
|
if (/^mac_/.test(name)) return "tapeComponentInstruction";
|
||||||
return "macro";
|
return "macro";
|
||||||
}
|
}
|
||||||
if (domain === "utility") return "macro";
|
if (domain === "utility") return "macro";
|
||||||
if (/^gte_(?!cr_)/.test(name)) return "tapeGteInstruction";
|
if (/^gte_(?!cr_)/.test(name)) return "tapeGteInstruction";
|
||||||
if (/^gp[01]_/.test(name)) return "tapeGpuInstruction";
|
if (/^gp[01]_/.test(name)) return "tapeGpuInstruction";
|
||||||
if (/^mac_gte_/.test(name)) return "tapeGteInstruction";
|
if (/^mac_gte_/.test(name)) return "tapeGteInstruction";
|
||||||
if (/^mac_gp/.test(name)) return "tapeGpuInstruction";
|
if (/^mac_gp/.test(name)) return "tapeGpuInstruction";
|
||||||
if (/^mac_/.test(name)) return "tapeComponentInstruction";
|
if (/^mac_/.test(name)) return "tapeComponentInstruction";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,13 +136,11 @@ function modifierMask(modifiers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isRegUseAccess(tokens, tokenIndex) {
|
function isRegUseAccess(tokens, tokenIndex) {
|
||||||
const prev = tokens[tokenIndex - 1];
|
const prev = tokens[tokenIndex - 1]; if (!prev || prev.text !== ".") return false;
|
||||||
if (!prev || prev.text !== ".") return false;
|
const prevPrev = tokens[tokenIndex - 2]; if (!prevPrev || prevPrev.kind !== "identifier") return false;
|
||||||
const prevPrev = tokens[tokenIndex - 2];
|
const next = tokens[tokenIndex + 1];
|
||||||
if (!prevPrev || prevPrev.kind !== "identifier") return false;
|
|
||||||
const next = tokens[tokenIndex + 1];
|
|
||||||
if (next && next.text === ".") return false;
|
if (next && next.text === ".") return false;
|
||||||
if (prevPrev.text === "r") return true;
|
if (prevPrev.text === "r") return true;
|
||||||
const prev3 = tokens[tokenIndex - 3];
|
const prev3 = tokens[tokenIndex - 3];
|
||||||
const prev4 = tokens[tokenIndex - 4];
|
const prev4 = tokens[tokenIndex - 4];
|
||||||
if (prev3 && prev3.text === "." && prev4 && prev4.kind === "identifier" && prev4.text === "r") return true;
|
if (prev3 && prev3.text === "." && prev4 && prev4.kind === "identifier" && prev4.text === "r") return true;
|
||||||
@@ -115,81 +149,92 @@ function isRegUseAccess(tokens, tokenIndex) {
|
|||||||
|
|
||||||
function classifyDocument(source, filePath, workspaceIndex, shouldCancel = () => false) {
|
function classifyDocument(source, filePath, workspaceIndex, shouldCancel = () => false) {
|
||||||
const scanned = scanSource(source, filePath);
|
const scanned = scanSource(source, filePath);
|
||||||
const index = mergeIndexes(workspaceIndex, scanned.index);
|
const index = mergeIndexes(workspaceIndex, scanned.index);
|
||||||
const spans = [];
|
const spans = [];
|
||||||
|
|
||||||
for (let tokenIndex = 0; tokenIndex < scanned.tokens.length; tokenIndex += 1) {
|
for (let tokenIndex = 0; tokenIndex < scanned.tokens.length; tokenIndex += 1) {
|
||||||
if (shouldCancel()) break;
|
if (shouldCancel()) break;
|
||||||
const token = scanned.tokens[tokenIndex];
|
const token = scanned.tokens[tokenIndex]; if (token.kind !== "identifier") continue;
|
||||||
if (token.kind !== "identifier") continue;
|
|
||||||
|
|
||||||
let type = null;
|
let type = null;
|
||||||
let modifiers = [];
|
let modifiers = [];
|
||||||
const declaration = scanned.declarations.get(token.start);
|
const declaration = scanned.declarations.get(token.start);
|
||||||
const context = nearestCall(scanned.contexts, tokenIndex);
|
const context = nearestCall(scanned.contexts, tokenIndex);
|
||||||
|
|
||||||
if (declaration) {
|
if (declaration) {
|
||||||
type = ROLE_TO_TYPE[declaration.role] || null;
|
type = ROLE_TO_TYPE[declaration.role] || null;
|
||||||
modifiers = declaration.modifiers.slice();
|
modifiers = declaration.modifiers.slice();
|
||||||
} else if (ATOM_KEYWORDS.has(token.text)) {
|
}
|
||||||
|
else if (ATOM_KEYWORDS.has(token.text)) {
|
||||||
type = "tapeAtomKeyword";
|
type = "tapeAtomKeyword";
|
||||||
} else if (COMPONENT_KEYWORDS.has(token.text)) {
|
}
|
||||||
|
else if (COMPONENT_KEYWORDS.has(token.text)) {
|
||||||
type = "keyword";
|
type = "keyword";
|
||||||
} else if (ANNOTATIONS.has(token.text)) {
|
}
|
||||||
|
else if (ANNOTATIONS.has(token.text)) {
|
||||||
type = "tapeAnnotation";
|
type = "tapeAnnotation";
|
||||||
} else if (context && context.callee === "atom_bind" && context.argIndex === 0) {
|
}
|
||||||
|
else if (context && context.callee === "atom_bind" && context.argIndex === 0) {
|
||||||
type = "tapeBindType";
|
type = "tapeBindType";
|
||||||
} else if (context && context.callee === "atom_phase" && context.argIndex === 0) {
|
}
|
||||||
|
else if (context && context.callee === "atom_phase" && context.argIndex === 0) {
|
||||||
type = "tapePhase";
|
type = "tapePhase";
|
||||||
modifiers = ["declaration"];
|
modifiers = ["declaration"];
|
||||||
} else if (context && context.callee === "atom_ctx" && context.argIndex === 0) {
|
}
|
||||||
|
else if (context && context.callee === "atom_ctx" && context.argIndex === 0) {
|
||||||
type = "tapeAtomName";
|
type = "tapeAtomName";
|
||||||
} else if (context && context.callee === "atom_label" && context.argIndex === 0) {
|
}
|
||||||
|
else if (context && context.callee === "atom_label" && context.argIndex === 0) {
|
||||||
type = "tapeLabel";
|
type = "tapeLabel";
|
||||||
modifiers = ["declaration"];
|
modifiers = ["declaration"];
|
||||||
} else if (context && context.callee === "atom_offset" && context.argIndex <= 1) {
|
}
|
||||||
|
else if (context && context.callee === "atom_offset" && context.argIndex <= 1) {
|
||||||
type = "tapeLabel";
|
type = "tapeLabel";
|
||||||
} else if (context && context.callee === "atom_reads") {
|
}
|
||||||
|
else if (context && context.callee === "atom_reads") {
|
||||||
type = registerType(token.text, index);
|
type = registerType(token.text, index);
|
||||||
if (type) modifiers = ["tapeRead"];
|
if (type) modifiers = ["tapeRead"];
|
||||||
} else if (context && context.callee === "atom_writes") {
|
}
|
||||||
|
else if (context && context.callee === "atom_writes") {
|
||||||
type = registerType(token.text, index);
|
type = registerType(token.text, index);
|
||||||
if (type) modifiers = ["tapeWrite"];
|
if (type) modifiers = ["tapeWrite"];
|
||||||
} else if (context && context.callee === "atom_auto_reg") {
|
}
|
||||||
|
else if (context && context.callee === "atom_auto_reg") {
|
||||||
if (context.argIndex === 0) type = "tapeAtomName";
|
if (context.argIndex === 0) type = "tapeAtomName";
|
||||||
if (context.argIndex === 1) {
|
if (context.argIndex === 1) {
|
||||||
type = "tapeGprRegister";
|
type = "tapeGprRegister";
|
||||||
modifiers = ["declaration", "tapeAuto"];
|
modifiers = ["declaration", "tapeAuto"];
|
||||||
}
|
}
|
||||||
} else if (context && context.callee === "phase_auto_reg") {
|
}
|
||||||
|
else if (context && context.callee === "phase_auto_reg") {
|
||||||
if (context.argIndex === 0) type = "tapePhase";
|
if (context.argIndex === 0) type = "tapePhase";
|
||||||
if (context.argIndex === 1) {
|
if (context.argIndex === 1) {
|
||||||
type = "tapeGprRegister";
|
type = "tapeGprRegister";
|
||||||
modifiers = ["declaration", "tapeAuto"];
|
modifiers = ["declaration", "tapeAuto"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!type && index.bindTypes.has(token.text)) type = "tapeBindType";
|
if (! type && index.bindTypes.has(token.text)) type = "tapeBindType";
|
||||||
if (!type && DSL_KEYWORDS.has(token.text)) type = "keyword";
|
if (! type && DSL_KEYWORDS.has(token.text)) type = "keyword";
|
||||||
if (!type && index.types.has(token.text)) type = "tapeDuffleType";
|
if (! type && index.types.has(token.text)) type = "tapeDuffleType";
|
||||||
if (!type && index.attributes.has(token.text)) type = "tapeAttribute";
|
if (! type && index.attributes.has(token.text)) type = "tapeAttribute";
|
||||||
if (!type) type = registerType(token.text, index);
|
if (! type) type = registerType(token.text, index);
|
||||||
if (!type && DELAY_SLOT_KEYWORDS.has(token.text)) type = "tapeDelaySlot";
|
if (! type && DELAY_SLOT_KEYWORDS.has(token.text)) type = "tapeDelaySlot";
|
||||||
if (!type) {
|
if (! type) {
|
||||||
const domain = index.macros.get(token.text);
|
const domain = index.macros.get(token.text);
|
||||||
if (domain === "control" || (domain && CONTROL_FLOW_PREFIXES.test(token.text))) {
|
if (domain === "control" || (domain && CONTROL_FLOW_PREFIXES.test(token.text))) {
|
||||||
type = "tapeControlFlow";
|
type = "tapeControlFlow";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!type && isRegUseAccess(scanned.tokens, tokenIndex)) type = "tapeGprRegister";
|
if (! type && isRegUseAccess(scanned.tokens, tokenIndex)) type = "tapeGprRegister";
|
||||||
if (!type) type = instructionType(token.text, index);
|
if (! type) type = instructionType(token.text, index);
|
||||||
if (!type && /^(?:Slice_|A[0-9]+_)/.test(token.text)) type = "tapeDuffleType";
|
if (! type && /^(?:Slice_|A[0-9]+_)/.test(token.text)) type = "tapeDuffleType";
|
||||||
if (!type && /_[RV]$/.test(token.text)) type = "tapeDuffleType";
|
if (! type && /_[RV]$/.test(token.text)) type = "tapeDuffleType";
|
||||||
if (!type && index.atoms.has(token.text)) type = "tapeAtomName";
|
if (! type && index.atoms.has(token.text)) type = "tapeAtomName";
|
||||||
if (!type && index.components.has(token.text)) type = "tapeComponentName";
|
if (! type && index.components.has(token.text)) type = "tapeComponentName";
|
||||||
if (!type && index.phases.has(token.text)) type = "tapePhase";
|
if (! type && index.phases.has(token.text)) type = "tapePhase";
|
||||||
if (!type && index.labels.has(token.text)) type = "tapeLabel";
|
if (! type && index.labels.has(token.text)) type = "tapeLabel";
|
||||||
if (!type) continue;
|
if (! type) continue;
|
||||||
|
|
||||||
spans.push({
|
spans.push({
|
||||||
text: token.text,
|
text: token.text,
|
||||||
|
|||||||
+22
-18
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
const vscode = require("vscode");
|
const vscode = require("vscode");
|
||||||
const { TOKEN_MODIFIERS, TOKEN_TYPES, classifyDocument } = require("./classifier");
|
const { TOKEN_MODIFIERS, TOKEN_TYPES, classifyDocument } = require("./classifier");
|
||||||
const { createIndex, mergeIndexes, scanSource } = require("./source-index");
|
const { createIndex, mergeIndexes, scanSource } = require("./source-index");
|
||||||
|
|
||||||
const SOURCE_GLOB = "**/*.{c,h,cc,cpp,cxx,hh,hpp,hxx}";
|
const SOURCE_GLOB = "**/*.{c,h,cc,cpp,cxx,hh,hpp,hxx}";
|
||||||
const EXCLUDE_GLOB = "**/{gen,build,.slop_cache,toolchain,node_modules}/**";
|
const EXCLUDE_GLOB = "**/{gen,build,.slop_cache,toolchain,node_modules}/**";
|
||||||
const EXCLUDED_SEGMENTS = new Set(["gen", "build", ".slop_cache", "toolchain", "node_modules"]);
|
const EXCLUDED_SEGMENTS = new Set(["gen", "build", ".slop_cache", "toolchain", "node_modules"]);
|
||||||
|
|
||||||
function isExcluded(uri) {
|
function isExcluded(uri) {
|
||||||
@@ -18,28 +18,29 @@ function formatError(filePath, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function activate(context) {
|
async function activate(context) {
|
||||||
const output = vscode.window.createOutputChannel("Tape Atom DSL");
|
const output = vscode.window.createOutputChannel("Tape Atom DSL");
|
||||||
const emitter = new vscode.EventEmitter();
|
const emitter = new vscode.EventEmitter();
|
||||||
const legend = new vscode.SemanticTokensLegend(TOKEN_TYPES, TOKEN_MODIFIERS);
|
const legend = new vscode.SemanticTokensLegend(TOKEN_TYPES, TOKEN_MODIFIERS);
|
||||||
let workspaceIndex = createIndex();
|
let workspaceIndex = createIndex();
|
||||||
let rebuildGeneration = 0;
|
let rebuildGeneration = 0;
|
||||||
let debounceHandle = null;
|
let debounceHandle = null;
|
||||||
|
|
||||||
async function rebuildIndex() {
|
async function rebuildIndex() {
|
||||||
const generation = ++rebuildGeneration;
|
const generation = ++rebuildGeneration;
|
||||||
const files = await vscode.workspace.findFiles(SOURCE_GLOB, EXCLUDE_GLOB);
|
const files = await vscode.workspace.findFiles(SOURCE_GLOB, EXCLUDE_GLOB);
|
||||||
let nextIndex = createIndex();
|
let nextIndex = createIndex();
|
||||||
|
|
||||||
for (const uri of files) {
|
for (const uri of files) {
|
||||||
if (generation !== rebuildGeneration) return;
|
if (generation !== rebuildGeneration) return;
|
||||||
if (isExcluded(uri)) continue;
|
if (isExcluded(uri)) continue;
|
||||||
try {
|
try {
|
||||||
const bytes = await vscode.workspace.fs.readFile(uri);
|
const bytes = await vscode.workspace.fs.readFile(uri);
|
||||||
const source = Buffer.from(bytes).toString("utf8");
|
const source = Buffer.from(bytes).toString("utf8");
|
||||||
const result = scanSource(source, uri.fsPath);
|
const result = scanSource(source, uri.fsPath);
|
||||||
nextIndex = mergeIndexes(nextIndex, result.index);
|
nextIndex = mergeIndexes(nextIndex, result.index);
|
||||||
for (const error of result.errors) output.appendLine(formatError(uri.fsPath, error));
|
for (const error of result.errors) output.appendLine(formatError(uri.fsPath, error));
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
output.appendLine(`${uri.fsPath}: ${error.stack || error.message || error}`);
|
output.appendLine(`${uri.fsPath}: ${error.stack || error.message || error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,9 +54,11 @@ async function activate(context) {
|
|||||||
if (uri && isExcluded(uri)) return;
|
if (uri && isExcluded(uri)) return;
|
||||||
if (debounceHandle !== null) clearTimeout(debounceHandle);
|
if (debounceHandle !== null) clearTimeout(debounceHandle);
|
||||||
debounceHandle = setTimeout(() => {
|
debounceHandle = setTimeout(() => {
|
||||||
debounceHandle = null;
|
debounceHandle = null;
|
||||||
rebuildIndex().catch((error) => output.appendLine(error.stack || String(error)));
|
rebuildIndex().catch((error) => output.appendLine(error.stack || String(error)));
|
||||||
}, 100);
|
},
|
||||||
|
100
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = {
|
const provider = {
|
||||||
@@ -77,7 +80,8 @@ async function activate(context) {
|
|||||||
output.appendLine(formatError(document.uri.fsPath || document.uri.toString(), error));
|
output.appendLine(formatError(document.uri.fsPath || document.uri.toString(), error));
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
output.appendLine(`${document.uri}: ${error.stack || error.message || error}`);
|
output.appendLine(`${document.uri}: ${error.stack || error.message || error}`);
|
||||||
return new vscode.SemanticTokensBuilder(legend).build();
|
return new vscode.SemanticTokensBuilder(legend).build();
|
||||||
}
|
}
|
||||||
@@ -85,8 +89,8 @@ async function activate(context) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const selector = [
|
const selector = [
|
||||||
{ language: "c", scheme: "file" },
|
{ language: "c", scheme: "file" },
|
||||||
{ language: "c", scheme: "untitled" },
|
{ language: "c", scheme: "untitled" },
|
||||||
{ language: "cpp", scheme: "file" },
|
{ language: "cpp", scheme: "file" },
|
||||||
{ language: "cpp", scheme: "untitled" },
|
{ language: "cpp", scheme: "untitled" },
|
||||||
];
|
];
|
||||||
|
|||||||
Vendored
+38
-31
@@ -10,29 +10,30 @@ function isIdentifierContinue(code) {
|
|||||||
return isIdentifierStart(code) || (code >= 48 && code <= 57);
|
return isIdentifierStart(code) || (code >= 48 && code <= 57);
|
||||||
}
|
}
|
||||||
|
|
||||||
function lex(source) {
|
function lex(source)
|
||||||
|
{
|
||||||
if (typeof source !== "string") throw new TypeError("source must be a string");
|
if (typeof source !== "string") throw new TypeError("source must be a string");
|
||||||
|
|
||||||
const tokens = [];
|
const tokens = [];
|
||||||
const errors = [];
|
const errors = [];
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let line = 0;
|
let line = 0;
|
||||||
let character = 0;
|
let character = 0;
|
||||||
|
|
||||||
function advance() {
|
function advance() {
|
||||||
if (source[offset] === "\r" && source[offset + 1] === "\n") {
|
if (source[offset] === "\r" && source[offset + 1] === "\n") {
|
||||||
offset += 2;
|
offset += 2;
|
||||||
line += 1;
|
line += 1;
|
||||||
character = 0;
|
character = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (source[offset] === "\n") {
|
if (source[offset] === "\n") {
|
||||||
offset += 1;
|
offset += 1;
|
||||||
line += 1;
|
line += 1;
|
||||||
character = 0;
|
character = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
offset += 1;
|
offset += 1;
|
||||||
character += 1;
|
character += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +48,8 @@ function lex(source) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
while (offset < source.length) {
|
while (offset < source.length)
|
||||||
|
{
|
||||||
const ch = source[offset];
|
const ch = source[offset];
|
||||||
|
|
||||||
if (/\s/.test(ch)) {
|
if (/\s/.test(ch)) {
|
||||||
@@ -60,12 +62,14 @@ function lex(source) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch === "/" && source[offset + 1] === "*") {
|
if (ch === "/" && source[offset + 1] === "*")
|
||||||
|
{
|
||||||
const start = offset;
|
const start = offset;
|
||||||
advance();
|
advance();
|
||||||
advance();
|
advance();
|
||||||
let closed = false;
|
let closed = false;
|
||||||
while (offset < source.length) {
|
while (offset < source.length)
|
||||||
|
{
|
||||||
if (source[offset] === "*" && source[offset + 1] === "/") {
|
if (source[offset] === "*" && source[offset + 1] === "/") {
|
||||||
advance();
|
advance();
|
||||||
advance();
|
advance();
|
||||||
@@ -78,12 +82,14 @@ function lex(source) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch === "\"" || ch === "'") {
|
if (ch === "\"" || ch === "'")
|
||||||
|
{
|
||||||
const quote = ch;
|
const quote = ch;
|
||||||
const start = offset;
|
const start = offset;
|
||||||
advance();
|
advance();
|
||||||
let closed = false;
|
let closed = false;
|
||||||
while (offset < source.length) {
|
while (offset < source.length)
|
||||||
|
{
|
||||||
if (source[offset] === "\\") {
|
if (source[offset] === "\\") {
|
||||||
advance();
|
advance();
|
||||||
if (offset < source.length) advance();
|
if (offset < source.length) advance();
|
||||||
@@ -97,14 +103,14 @@ function lex(source) {
|
|||||||
if (source[offset] === "\n" || source[offset] === "\r") break;
|
if (source[offset] === "\n" || source[offset] === "\r") break;
|
||||||
advance();
|
advance();
|
||||||
}
|
}
|
||||||
if (!closed) errors.push({ kind: "unterminated-literal", offset: start });
|
if (! closed) errors.push({ kind: "unterminated-literal", offset: start });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const code = source.charCodeAt(offset);
|
const code = source.charCodeAt(offset);
|
||||||
if (isIdentifierStart(code)) {
|
if (isIdentifierStart(code)) {
|
||||||
const start = offset;
|
const start = offset;
|
||||||
const startLine = line;
|
const startLine = line;
|
||||||
const startCharacter = character;
|
const startCharacter = character;
|
||||||
advance();
|
advance();
|
||||||
while (offset < source.length && isIdentifierContinue(source.charCodeAt(offset))) advance();
|
while (offset < source.length && isIdentifierContinue(source.charCodeAt(offset))) advance();
|
||||||
@@ -112,8 +118,8 @@ function lex(source) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = offset;
|
const start = offset;
|
||||||
const startLine = line;
|
const startLine = line;
|
||||||
const startCharacter = character;
|
const startCharacter = character;
|
||||||
advance();
|
advance();
|
||||||
pushToken("punctuation", start, startLine, startCharacter);
|
pushToken("punctuation", start, startLine, startCharacter);
|
||||||
@@ -124,9 +130,9 @@ function lex(source) {
|
|||||||
|
|
||||||
function buildCallContexts(tokens) {
|
function buildCallContexts(tokens) {
|
||||||
const contexts = Array.from({ length: tokens.length }, () => []);
|
const contexts = Array.from({ length: tokens.length }, () => []);
|
||||||
const calls = [];
|
const calls = [];
|
||||||
const errors = [];
|
const errors = [];
|
||||||
const stack = [];
|
const stack = [];
|
||||||
|
|
||||||
for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 1) {
|
for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 1) {
|
||||||
const token = tokens[tokenIndex];
|
const token = tokens[tokenIndex];
|
||||||
@@ -134,7 +140,8 @@ function buildCallContexts(tokens) {
|
|||||||
if (token.text === ")") {
|
if (token.text === ")") {
|
||||||
if (stack.length === 0) {
|
if (stack.length === 0) {
|
||||||
errors.push({ kind: "unmatched-close-paren", offset: token.start });
|
errors.push({ kind: "unmatched-close-paren", offset: token.start });
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
const frame = stack.pop();
|
const frame = stack.pop();
|
||||||
if (frame.callee !== null) calls.push({ ...frame, closeTokenIndex: tokenIndex });
|
if (frame.callee !== null) calls.push({ ...frame, closeTokenIndex: tokenIndex });
|
||||||
}
|
}
|
||||||
@@ -143,20 +150,20 @@ function buildCallContexts(tokens) {
|
|||||||
contexts[tokenIndex] = stack
|
contexts[tokenIndex] = stack
|
||||||
.filter((frame) => frame.callee !== null)
|
.filter((frame) => frame.callee !== null)
|
||||||
.map((frame) => ({
|
.map((frame) => ({
|
||||||
callee: frame.callee,
|
callee: frame.callee,
|
||||||
calleeTokenIndex: frame.calleeTokenIndex,
|
calleeTokenIndex: frame.calleeTokenIndex,
|
||||||
openTokenIndex: frame.openTokenIndex,
|
openTokenIndex: frame.openTokenIndex,
|
||||||
argIndex: frame.argIndex,
|
argIndex: frame.argIndex,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (token.text === "(") {
|
if (token.text === "(") {
|
||||||
const previous = tokens[tokenIndex - 1];
|
const previous = tokens[tokenIndex - 1];
|
||||||
const hasCallee = previous && previous.kind === "identifier";
|
const hasCallee = previous && previous.kind === "identifier";
|
||||||
stack.push({
|
stack.push({
|
||||||
callee: hasCallee ? previous.text : null,
|
callee: hasCallee ? previous.text : null,
|
||||||
calleeTokenIndex: hasCallee ? tokenIndex - 1 : -1,
|
calleeTokenIndex: hasCallee ? tokenIndex - 1 : -1,
|
||||||
openTokenIndex: tokenIndex,
|
openTokenIndex: tokenIndex,
|
||||||
argIndex: 0,
|
argIndex: 0,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-38
@@ -4,8 +4,10 @@ const path = require("node:path");
|
|||||||
const { buildCallContexts, lex, nearestCall } = require("./lexer");
|
const { buildCallContexts, lex, nearestCall } = require("./lexer");
|
||||||
|
|
||||||
const BASE_TYPES = [
|
const BASE_TYPES = [
|
||||||
"B1", "B2", "B4", "B8", "F4", "F8", "S1", "S2", "S4", "S8",
|
"B1", "B2", "B4", "B8",
|
||||||
"U1", "U2", "U4", "U8", "MipsAtom", "MipsCode", "Reg",
|
"F4", "F8", "S1", "S2", "S4", "S8",
|
||||||
|
"U1", "U2", "U4", "U8",
|
||||||
|
"MipsAtom", "MipsCode", "Reg",
|
||||||
];
|
];
|
||||||
|
|
||||||
const C_BUILTINS = new Set([
|
const C_BUILTINS = new Set([
|
||||||
@@ -15,11 +17,13 @@ const C_BUILTINS = new Set([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const BASE_ATTRIBUTES = [
|
const BASE_ATTRIBUTES = [
|
||||||
"FI_", "I_", "NI_", "Relative_", "Struct_", "Enum_", "Union_", "Array_",
|
"FI_", "I_", "NI_",
|
||||||
"Slice_", "TypeR_", "TypeV_", "align_", "internal", "local_persist", "global",
|
"Relative_", "Struct_", "Enum_", "Union_", "Array_", "Slice_",
|
||||||
"RO_", "LP_", "gknown", "expect_", "cexpr_",
|
"align_", "internal", "local_persist", "global",
|
||||||
|
"RO_", "LP_",
|
||||||
|
"gknown", "expect_", "cexpr_",
|
||||||
"asm", "asm_words", "asm_rpins", "asm_clobber",
|
"asm", "asm_words", "asm_rpins", "asm_clobber",
|
||||||
"O_", "S_", "C_", "T_", "tmpl", "glue", "r_", "v_", "rt_", "vt_",
|
"O_", "OA_", "S_", "C_", "T_", "tmpl", "glue", "r_", "v_", "rt_", "vt_",
|
||||||
"rgcc", "r_use", "r_set", "r_mod", "r_imm", "r_mem",
|
"rgcc", "r_use", "r_set", "r_mod", "r_imm", "r_mem",
|
||||||
"u1_", "u2_", "u4_", "u8_", "s1_", "s2_", "s4_", "s8_",
|
"u1_", "u2_", "u4_", "u8_", "s1_", "s2_", "s4_", "s8_",
|
||||||
"u1_r", "u2_r", "u4_r", "u8_r", "u1_v", "u2_v", "u4_v", "u8_v",
|
"u1_r", "u2_r", "u4_r", "u8_r", "u1_v", "u2_v", "u4_v", "u8_v",
|
||||||
@@ -27,16 +31,16 @@ const BASE_ATTRIBUTES = [
|
|||||||
|
|
||||||
function createIndex() {
|
function createIndex() {
|
||||||
return {
|
return {
|
||||||
atoms: new Set(),
|
atoms: new Set(),
|
||||||
components: new Set(),
|
components: new Set(),
|
||||||
componentAliases: new Set(),
|
componentAliases: new Set(),
|
||||||
macros: new Map(),
|
macros: new Map(),
|
||||||
registers: new Map(),
|
registers: new Map(),
|
||||||
bindTypes: new Set(),
|
bindTypes: new Set(),
|
||||||
types: new Set(BASE_TYPES),
|
types: new Set(BASE_TYPES),
|
||||||
phases: new Set(),
|
phases: new Set(),
|
||||||
labels: new Set(),
|
labels: new Set(),
|
||||||
attributes: new Set(BASE_ATTRIBUTES),
|
attributes: new Set(BASE_ATTRIBUTES),
|
||||||
componentCallees: new Map(),
|
componentCallees: new Map(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -46,8 +50,8 @@ function cloneIndex(source) {
|
|||||||
for (const key of ["atoms", "components", "componentAliases", "bindTypes", "types", "phases", "labels", "attributes"]) {
|
for (const key of ["atoms", "components", "componentAliases", "bindTypes", "types", "phases", "labels", "attributes"]) {
|
||||||
for (const value of source[key]) result[key].add(value);
|
for (const value of source[key]) result[key].add(value);
|
||||||
}
|
}
|
||||||
for (const [name, domain] of source.macros) result.macros.set(name, domain);
|
for (const [name, domain] of source.macros) result.macros.set(name, domain);
|
||||||
for (const [name, domain] of source.registers) result.registers.set(name, domain);
|
for (const [name, domain] of source.registers) result.registers.set(name, domain);
|
||||||
for (const [name, callees] of source.componentCallees) result.componentCallees.set(name, callees.slice());
|
for (const [name, callees] of source.componentCallees) result.componentCallees.set(name, callees.slice());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -63,7 +67,7 @@ function mergeIndexes(...sources) {
|
|||||||
const existing = result.macros.get(name);
|
const existing = result.macros.get(name);
|
||||||
if (!existing || domainRank(domain) >= domainRank(existing)) result.macros.set(name, domain);
|
if (!existing || domainRank(domain) >= domainRank(existing)) result.macros.set(name, domain);
|
||||||
}
|
}
|
||||||
for (const [name, domain] of source.registers) result.registers.set(name, domain);
|
for (const [name, domain] of source.registers) result.registers.set(name, domain);
|
||||||
for (const [name, callees] of source.componentCallees) {
|
for (const [name, callees] of source.componentCallees) {
|
||||||
const existing = result.componentCallees.get(name) || [];
|
const existing = result.componentCallees.get(name) || [];
|
||||||
result.componentCallees.set(name, existing.concat(callees));
|
result.componentCallees.set(name, existing.concat(callees));
|
||||||
@@ -75,21 +79,21 @@ function mergeIndexes(...sources) {
|
|||||||
function domainFromPath(filePath) {
|
function domainFromPath(filePath) {
|
||||||
const base = path.basename(filePath.replaceAll("\\", "/")).toLowerCase();
|
const base = path.basename(filePath.replaceAll("\\", "/")).toLowerCase();
|
||||||
if (base === "mips.h") return "cpu";
|
if (base === "mips.h") return "cpu";
|
||||||
if (base === "gte.h") return "gte";
|
if (base === "gte.h") return "gte";
|
||||||
if (base === "gp.h") return "gpu";
|
if (base === "gp.h") return "gpu";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prefixDomain(name) {
|
function prefixDomain(name) {
|
||||||
if (/^(?:branch_|jump_|call_)/.test(name)) return "control";
|
if (/^(?:branch_|jump_|call_)/.test(name)) return "control";
|
||||||
if (/^gte_(?!cr_)/.test(name) || name.startsWith("mac_gte_") || name.startsWith("ac_gte_")) return "gte";
|
if (/^gte_(?!cr_)/.test(name) || name.startsWith("mac_gte_") || name.startsWith("ac_gte_")) return "gte";
|
||||||
if (/^gp[01]_/.test(name) || name.startsWith("mac_gp_") || name.startsWith("ac_gp_")) return "gpu";
|
if (/^gp[01]_/.test(name) || name.startsWith("mac_gp_") || name.startsWith("ac_gp_")) return "gpu";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectBraceIdentifiers(tokens, openBraceIndex) {
|
function collectBraceIdentifiers(tokens, openBraceIndex) {
|
||||||
const names = [];
|
const names = [];
|
||||||
let depth = 0;
|
let depth = 0;
|
||||||
for (let tokenIndex = openBraceIndex; tokenIndex < tokens.length; tokenIndex += 1) {
|
for (let tokenIndex = openBraceIndex; tokenIndex < tokens.length; tokenIndex += 1) {
|
||||||
if (tokens[tokenIndex].text === "{") depth += 1;
|
if (tokens[tokenIndex].text === "{") depth += 1;
|
||||||
if (tokens[tokenIndex].text === "}") {
|
if (tokens[tokenIndex].text === "}") {
|
||||||
@@ -103,17 +107,17 @@ function collectBraceIdentifiers(tokens, openBraceIndex) {
|
|||||||
|
|
||||||
function resolveComponentDomains(index) {
|
function resolveComponentDomains(index) {
|
||||||
const hardwareRank = { cpu: 1, gpu: 2, gte: 3, control: 4 };
|
const hardwareRank = { cpu: 1, gpu: 2, gte: 3, control: 4 };
|
||||||
let changed = true;
|
let changed = true;
|
||||||
while (changed) {
|
while (changed) {
|
||||||
changed = false;
|
changed = false;
|
||||||
for (const [alias, callees] of index.componentCallees) {
|
for (const [alias, callees] of index.componentCallees) {
|
||||||
let best = index.macros.get(alias) || "component";
|
let best = index.macros.get(alias) || "component";
|
||||||
let bestRank = hardwareRank[best] || 0;
|
let bestRank = hardwareRank[best] || 0;
|
||||||
for (const callee of callees) {
|
for (const callee of callees) {
|
||||||
const domain = prefixDomain(callee) || index.macros.get(callee);
|
const domain = prefixDomain(callee) || index.macros.get(callee);
|
||||||
const rank = hardwareRank[domain] || 0;
|
const rank = hardwareRank[domain] || 0;
|
||||||
if (rank > bestRank) {
|
if (rank > bestRank) {
|
||||||
best = domain;
|
best = domain;
|
||||||
bestRank = rank;
|
bestRank = rank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +138,7 @@ function domainRank(domain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerKind(name) {
|
function registerKind(name) {
|
||||||
if (/^R_[A-Za-z0-9_]+$/.test(name)) return "gpr";
|
if (/^R_[A-Za-z0-9_]+$/.test(name)) return "gpr";
|
||||||
if (/^(?:C2_|gte_cr_)[A-Za-z0-9_]+$/.test(name)) return "cop2";
|
if (/^(?:C2_|gte_cr_)[A-Za-z0-9_]+$/.test(name)) return "cop2";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -161,14 +165,15 @@ function findFunctionNameBefore(tokens, calleeTokenIndex) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function scanSource(source, filePath) {
|
function scanSource(source, filePath)
|
||||||
const lexical = lex(source);
|
{
|
||||||
const balanced = buildCallContexts(lexical.tokens);
|
const lexical = lex(source);
|
||||||
const tokens = lexical.tokens;
|
const balanced = buildCallContexts(lexical.tokens);
|
||||||
const contexts = balanced.contexts;
|
const tokens = lexical.tokens;
|
||||||
const index = createIndex();
|
const contexts = balanced.contexts;
|
||||||
|
const index = createIndex();
|
||||||
const declarations = new Map();
|
const declarations = new Map();
|
||||||
const domain = domainFromPath(filePath);
|
const domain = domainFromPath(filePath);
|
||||||
|
|
||||||
function mark(token, role, modifiers = ["declaration"]) {
|
function mark(token, role, modifiers = ["declaration"]) {
|
||||||
declarations.set(token.start, { role, modifiers });
|
declarations.set(token.start, { role, modifiers });
|
||||||
@@ -191,7 +196,8 @@ function scanSource(source, filePath) {
|
|||||||
if (!index.macros.has(alias)) index.macros.set(alias, "component");
|
if (!index.macros.has(alias)) index.macros.set(alias, "component");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 1) {
|
for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 1)
|
||||||
|
{
|
||||||
const token = tokens[tokenIndex];
|
const token = tokens[tokenIndex];
|
||||||
if (token.kind !== "identifier") continue;
|
if (token.kind !== "identifier") continue;
|
||||||
|
|
||||||
@@ -240,12 +246,14 @@ function scanSource(source, filePath) {
|
|||||||
mark(token, "gprRegister", ["declaration", "tapeAuto"]);
|
mark(token, "gprRegister", ["declaration", "tapeAuto"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.text === "define" && tokens[tokenIndex - 1] && tokens[tokenIndex - 1].text === "#") {
|
if (token.text === "define" && tokens[tokenIndex - 1] && tokens[tokenIndex - 1].text === "#")
|
||||||
|
{
|
||||||
const name = tokens[tokenIndex + 1];
|
const name = tokens[tokenIndex + 1];
|
||||||
if (name && name.kind === "identifier" && name.line === token.line) {
|
if (name && name.kind === "identifier" && name.line === token.line) {
|
||||||
if (/^(?:RegUse_|Struct_|Enum_|Union_|TypeR_|TypeV_|Relative_|Binds_)/.test(name.text)) {
|
if (/^(?:RegUse_|Struct_|Enum_|Union_|TypeR_|TypeV_|Relative_|Binds_)/.test(name.text)) {
|
||||||
index.types.add(name.text);
|
index.types.add(name.text);
|
||||||
} else if (/^(?:ac_|mac_)/.test(name.text)) {
|
}
|
||||||
|
else if (/^(?:ac_|mac_)/.test(name.text)) {
|
||||||
const alias = name.text.startsWith("ac_") ? componentAlias(name.text) : name.text;
|
const alias = name.text.startsWith("ac_") ? componentAlias(name.text) : name.text;
|
||||||
const rest = [];
|
const rest = [];
|
||||||
for (let restIndex = tokenIndex + 2; restIndex < tokens.length && tokens[restIndex].line === name.line; restIndex += 1) {
|
for (let restIndex = tokenIndex + 2; restIndex < tokens.length && tokens[restIndex].line === name.line; restIndex += 1) {
|
||||||
@@ -256,7 +264,8 @@ function scanSource(source, filePath) {
|
|||||||
index.macros.set(alias, prefixDomain(alias) || "component");
|
index.macros.set(alias, prefixDomain(alias) || "component");
|
||||||
if (rest.length) index.componentCallees.set(alias, rest);
|
if (rest.length) index.componentCallees.set(alias, rest);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
index.macros.set(name.text, domain || "utility");
|
index.macros.set(name.text, domain || "utility");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-8
@@ -14,8 +14,8 @@
|
|||||||
#define glue(A, B) glue_impl(A, B)
|
#define glue(A, B) glue_impl(A, B)
|
||||||
#define tmpl(prefix, type) prefix ## _ ## type
|
#define tmpl(prefix, type) prefix ## _ ## type
|
||||||
|
|
||||||
#define stringify_impl(S) #S
|
#define stringify_impl(S) #S
|
||||||
#define stringify(S) stringify_impl(S)
|
#define stringify(S) stringify_impl(S)
|
||||||
|
|
||||||
#define VA_Sel_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
|
#define VA_Sel_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
|
||||||
#define VA_Sel_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
|
#define VA_Sel_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
|
||||||
@@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
#define A_(data) (& (data))
|
#define A_(data) (& (data))
|
||||||
#define align_(value) __attribute__((aligned (value))) // for easy alignment
|
#define align_(value) __attribute__((aligned (value))) // for easy alignment
|
||||||
#define align_(value) __attribute__((aligned (value))) // for easy alignment
|
|
||||||
#define C_(type,data) ((type)(data)) // for enforced precedence
|
#define C_(type,data) ((type)(data)) // for enforced precedence
|
||||||
#define expect_(x, y) __builtin_expect(x, y) // so compiler knows the common path
|
#define expect_(x, y) __builtin_expect(x, y) // so compiler knows the common path
|
||||||
#define cexpr_ __builtin_constant_p
|
#define cexpr_ __builtin_constant_p
|
||||||
@@ -121,6 +120,10 @@ typedef unsigned char TSet_(B1);
|
|||||||
typedef __UINT16_TYPE__ TSet_(B2);
|
typedef __UINT16_TYPE__ TSet_(B2);
|
||||||
typedef __UINT32_TYPE__ TSet_(B4);
|
typedef __UINT32_TYPE__ TSet_(B4);
|
||||||
|
|
||||||
|
#define b1_(value) C_(B1, value)
|
||||||
|
#define b2_(value) C_(B2, value)
|
||||||
|
#define b4_(value) C_(B4, value)
|
||||||
|
|
||||||
#define u1_(value) C_(U1, value)
|
#define u1_(value) C_(U1, value)
|
||||||
#define u2_(value) C_(U2, value)
|
#define u2_(value) C_(U2, value)
|
||||||
#define u4_(value) C_(U4, value)
|
#define u4_(value) C_(U4, value)
|
||||||
@@ -128,6 +131,13 @@ typedef __UINT32_TYPE__ TSet_(B4);
|
|||||||
#define s2_(value) C_(S2, value)
|
#define s2_(value) C_(S2, value)
|
||||||
#define s4_(value) C_(S4, value)
|
#define s4_(value) C_(S4, value)
|
||||||
|
|
||||||
|
#define b1_r(value) C_(B1*R_, value)
|
||||||
|
#define b2_r(value) C_(B2*R_, value)
|
||||||
|
#define b4_r(value) C_(B4*R_, value)
|
||||||
|
#define b1_v(value) C_(B1 V_*, value)
|
||||||
|
#define b2_v(value) C_(B2 V_*, value)
|
||||||
|
#define b4_v(value) C_(B4 V_*, value)
|
||||||
|
|
||||||
#define u1_r(value) C_(U1 *R_, value)
|
#define u1_r(value) C_(U1 *R_, value)
|
||||||
#define u2_r(value) C_(U2 *R_, value)
|
#define u2_r(value) C_(U2 *R_, value)
|
||||||
#define u4_r(value) C_(U4 *R_, value)
|
#define u4_r(value) C_(U4 *R_, value)
|
||||||
@@ -184,12 +194,12 @@ def_signed_ops(le, <=)
|
|||||||
#undef def_generic_sop
|
#undef def_generic_sop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define alignas _Alignas
|
#define alignas _Alignas
|
||||||
#define alignof _Alignof
|
#define alignof _Alignof
|
||||||
#define byte_pad(amount, ...) B1 glue(_PAD_, __VA_ARGS__) [amount]
|
#define byte_pad(amount, ...) B1 glue(_PAD_, __VA_ARGS__) [amount]
|
||||||
#define C_ptr(type, data) (C_(type*, & (data)) [0])
|
#define C_ptr(type, data) (C_(type*, & (data)) [0])
|
||||||
|
|
||||||
#define dbg_args(...) __VA_ARGS__
|
#define dbg_args(...) __VA_ARGS__
|
||||||
|
|
||||||
#pragma region Control Flow & Iteration
|
#pragma region Control Flow & Iteration
|
||||||
#define each_iter(type, iter, end) (type iter = 0; iter < end; ++ iter)
|
#define each_iter(type, iter, end) (type iter = 0; iter < end; ++ iter)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
// source: C:\projects\Pikuma\ps1\code\duffle\pad.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\pad.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\math.atom.h
|
// source: C:\projects\Pikuma\ps1\code\duffle\math.atom.h
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\mips.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\mips.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\gte.atom.h
|
// source: C:\projects\Pikuma\ps1\code\duffle\gte.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\gp.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\gp.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\pad.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\pad.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\psyq.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\psyq.atom.c
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
* These do NOT yield. They are expanded inline inside Tape Atoms.
|
* These do NOT yield. They are expanded inline inside Tape Atoms.
|
||||||
* ---------------------------------------------------------------------------*/
|
* ---------------------------------------------------------------------------*/
|
||||||
// The 'Yield' sequence for Tape Atoms (mac_yield).
|
// The 'Yield' sequence for Tape Atoms (mac_yield).
|
||||||
|
// In Forth this is considered the "NEXT" mechanism.
|
||||||
#define mac_yield(...) \
|
#define mac_yield(...) \
|
||||||
load_word(R_AtomJmp, R_TapePtr, 0) \
|
load_word(R_AtomJmp, R_TapePtr, 0) \
|
||||||
LdSlot_ \
|
LdSlot_ \
|
||||||
@@ -55,6 +56,12 @@ WORD_COUNT(mac_yield_load, 1)
|
|||||||
, BdSlot_ nop
|
, BdSlot_ nop
|
||||||
WORD_COUNT(mac_yield_tail, 3)
|
WORD_COUNT(mac_yield_tail, 3)
|
||||||
|
|
||||||
|
/* atom_dbg_skip */
|
||||||
|
#define mac_yield_to(code_ptr) \
|
||||||
|
jump_reg(code_ptr) \
|
||||||
|
, BdSlot_ nop
|
||||||
|
WORD_COUNT(mac_yield_to, 2)
|
||||||
|
|
||||||
/* atom_dbg_skip */
|
/* atom_dbg_skip */
|
||||||
#define mac_load_half_v3(tx, ty, tz, base, offset) \
|
#define mac_load_half_v3(tx, ty, tz, base, offset) \
|
||||||
load_half(tx, base, offset + OA_(U2,[0])) \
|
load_half(tx, base, offset + OA_(U2,[0])) \
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
// source: C:\projects\Pikuma\ps1\code\duffle\pad.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\pad.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\math.atom.h
|
// source: C:\projects\Pikuma\ps1\code\duffle\math.atom.h
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\mips.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\mips.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\gte.atom.h
|
// source: C:\projects\Pikuma\ps1\code\duffle\gte.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\gp.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\gp.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\pad.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\pad.atom.c
|
||||||
// source: C:\projects\Pikuma\ps1\code\duffle\psyq.atom.c
|
// source: C:\projects\Pikuma\ps1\code\duffle\psyq.atom.c
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ ATOM_FILE_DEBUGGER_LINE_MARKER(gp_atom_c);
|
|||||||
|
|
||||||
#pragma region MACs (Mips Atom Components)
|
#pragma region MACs (Mips Atom Components)
|
||||||
|
|
||||||
FI_ Slice_MipsCode ac_gcmd_push(AtomBuilder_R ab, U4 cmd, U4 reg_transfer, U4 reg_base, U2 port)
|
FI_ Slice_MipsCode ac_gcmd_push(AtomBuilder_R ab, U2 cmd, Reg reg_transfer, Reg reg_base, U2 port)
|
||||||
atom_dbg_skip MipsAtomComp_Proc_(ab, {
|
atom_dbg_skip MipsAtomComp_Proc_(ab, {
|
||||||
mac_load_word_imm(reg_transfer, cmd),
|
mac_load_word_imm(reg_transfer, cmd),
|
||||||
store_word( reg_transfer, reg_base, port),
|
store_word( reg_transfer, reg_base, port),
|
||||||
|
|||||||
+19
-19
@@ -386,7 +386,7 @@ enum {
|
|||||||
* ============================================================================ */
|
* ============================================================================ */
|
||||||
|
|
||||||
/* ---------- RGB8 (3-byte packed color) ---------- */
|
/* ---------- RGB8 (3-byte packed color) ---------- */
|
||||||
typedef Struct_(RGB8) { B1 r; B1 g; B1 b; };
|
typedef Struct_(RGB8) { U1 r; U1 g; U1 b; };
|
||||||
#define rgb8(r,g,b) ((RGB8){r,g,b})
|
#define rgb8(r,g,b) ((RGB8){r,g,b})
|
||||||
|
|
||||||
/* ---------- PolyTag (the OT-link header; 1 word) ---------- */
|
/* ---------- PolyTag (the OT-link header; 1 word) ---------- */
|
||||||
@@ -416,7 +416,7 @@ typedef Struct_(PolyTag) {
|
|||||||
typedef Struct_(Poly_F3) {
|
typedef Struct_(Poly_F3) {
|
||||||
U4 tag;
|
U4 tag;
|
||||||
RGB8 color;
|
RGB8 color;
|
||||||
B1 code;
|
U1 code;
|
||||||
union {
|
union {
|
||||||
struct { V2_S2 p0; V2_S2 p1; V2_S2 p2; };
|
struct { V2_S2 p0; V2_S2 p1; V2_S2 p2; };
|
||||||
A3_V2_S2 points;
|
A3_V2_S2 points;
|
||||||
@@ -427,7 +427,7 @@ typedef Struct_(Poly_F3) {
|
|||||||
typedef Struct_(Poly_F4) {
|
typedef Struct_(Poly_F4) {
|
||||||
U4 tag;
|
U4 tag;
|
||||||
RGB8 color;
|
RGB8 color;
|
||||||
B1 code;
|
U1 code;
|
||||||
union {
|
union {
|
||||||
struct { V2_S2 p0; V2_S2 p1; V2_S2 p2; V2_S2 p3; };
|
struct { V2_S2 p0; V2_S2 p1; V2_S2 p2; V2_S2 p3; };
|
||||||
A4_V2_S2 points;
|
A4_V2_S2 points;
|
||||||
@@ -436,18 +436,18 @@ typedef Struct_(Poly_F4) {
|
|||||||
|
|
||||||
/* ---------- Poly_G3 (Gouraud Triangle; 7 words) ---------- */
|
/* ---------- Poly_G3 (Gouraud Triangle; 7 words) ---------- */
|
||||||
typedef Struct_(Poly_G3) {
|
typedef Struct_(Poly_G3) {
|
||||||
U4 tag; RGB8 c0; B1 code;
|
U4 tag; RGB8 c0; U1 code;
|
||||||
V2_S2 p0; RGB8 c1; B1 pad1;
|
V2_S2 p0; RGB8 c1; U1 pad1;
|
||||||
V2_S2 p1; RGB8 c2; B1 pad2;
|
V2_S2 p1; RGB8 c2; U1 pad2;
|
||||||
V2_S2 p2;
|
V2_S2 p2;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---------- Poly_G4 (Gouraud Quad; 9 words) ---------- */
|
/* ---------- Poly_G4 (Gouraud Quad; 9 words) ---------- */
|
||||||
typedef Struct_(Poly_G4) {
|
typedef Struct_(Poly_G4) {
|
||||||
U4 tag; RGB8 c0; B1 code;
|
U4 tag; RGB8 c0; U1 code;
|
||||||
V2_S2 p0; RGB8 c1; B1 pad1;
|
V2_S2 p0; RGB8 c1; U1 pad1;
|
||||||
V2_S2 p1; RGB8 c2; B1 pad2;
|
V2_S2 p1; RGB8 c2; U1 pad2;
|
||||||
V2_S2 p2; RGB8 c3; B1 pad3;
|
V2_S2 p2; RGB8 c3; U1 pad3;
|
||||||
V2_S2 p3;
|
V2_S2 p3;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -456,7 +456,7 @@ typedef Struct_(Poly_G4) {
|
|||||||
typedef Struct_(Poly_FT3) {
|
typedef Struct_(Poly_FT3) {
|
||||||
U4 tag;
|
U4 tag;
|
||||||
RGB8 color;
|
RGB8 color;
|
||||||
B1 code;
|
U1 code;
|
||||||
U4 tpage;
|
U4 tpage;
|
||||||
U4 clut;
|
U4 clut;
|
||||||
V2_S2 p0; U1 u0; U1 v0;
|
V2_S2 p0; U1 u0; U1 v0;
|
||||||
@@ -468,7 +468,7 @@ typedef Struct_(Poly_FT3) {
|
|||||||
typedef Struct_(Poly_FT4) {
|
typedef Struct_(Poly_FT4) {
|
||||||
U4 tag;
|
U4 tag;
|
||||||
RGB8 color;
|
RGB8 color;
|
||||||
B1 code;
|
U1 code;
|
||||||
U4 tpage;
|
U4 tpage;
|
||||||
U4 clut;
|
U4 clut;
|
||||||
V2_S2 p0; U1 u0; U1 v0;
|
V2_S2 p0; U1 u0; U1 v0;
|
||||||
@@ -479,9 +479,9 @@ typedef Struct_(Poly_FT4) {
|
|||||||
|
|
||||||
/* ---------- Poly_GT3 (Gouraud Textured Triangle) ---------- */
|
/* ---------- Poly_GT3 (Gouraud Textured Triangle) ---------- */
|
||||||
typedef Struct_(Poly_GT3) {
|
typedef Struct_(Poly_GT3) {
|
||||||
U4 tag; RGB8 c0; B1 code;
|
U4 tag; RGB8 c0; U1 code;
|
||||||
V2_S2 p0; RGB8 c1; B1 pad1;
|
V2_S2 p0; RGB8 c1; U1 pad1;
|
||||||
V2_S2 p1; RGB8 c2; B1 pad2;
|
V2_S2 p1; RGB8 c2; U1 pad2;
|
||||||
V2_S2 p2;
|
V2_S2 p2;
|
||||||
U4 tpage;
|
U4 tpage;
|
||||||
U4 clut;
|
U4 clut;
|
||||||
@@ -492,10 +492,10 @@ typedef Struct_(Poly_GT3) {
|
|||||||
|
|
||||||
/* ---------- Poly_GT4 (Gouraud Textured Quad) ---------- */
|
/* ---------- Poly_GT4 (Gouraud Textured Quad) ---------- */
|
||||||
typedef Struct_(Poly_GT4) {
|
typedef Struct_(Poly_GT4) {
|
||||||
U4 tag; RGB8 c0; B1 code;
|
U4 tag; RGB8 c0; U1 code;
|
||||||
V2_S2 p0; RGB8 c1; B1 pad1;
|
V2_S2 p0; RGB8 c1; U1 pad1;
|
||||||
V2_S2 p1; RGB8 c2; B1 pad2;
|
V2_S2 p1; RGB8 c2; U1 pad2;
|
||||||
V2_S2 p2; RGB8 c3; B1 pad3;
|
V2_S2 p2; RGB8 c3; U1 pad3;
|
||||||
V2_S2 p3;
|
V2_S2 p3;
|
||||||
U4 tpage;
|
U4 tpage;
|
||||||
U4 clut;
|
U4 clut;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
# include "gte.h"
|
# include "gte.h"
|
||||||
# include "gp.h"
|
# include "gp.h"
|
||||||
# include "tape.h"
|
# include "tape.h"
|
||||||
|
# include "math.atom.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ATOM_FILE_DEBUGGER_LINE_MARKER(gte_atom_c);
|
ATOM_FILE_DEBUGGER_LINE_MARKER(gte_atom_c);
|
||||||
@@ -183,60 +184,95 @@ MipsAtomComp_Proc_(ab, {
|
|||||||
gte_mv_from_data_r(fr_mac3, C2_MAC3),
|
gte_mv_from_data_r(fr_mac3, C2_MAC3),
|
||||||
})
|
})
|
||||||
|
|
||||||
FI_ Slice_MipsCode ac_gte_mv_from_data_r_mac123(AtomBuilder_R ab
|
FI_ Slice_MipsCode ac_gte_mv_from_data_r_mac123(AtomBuilder_R ab, Reg fr_mac1, Reg fr_mac2, Reg fr_mac3)
|
||||||
, Reg fr_mac1, Reg fr_mac2, Reg fr_mac3)
|
|
||||||
MipsAtomComp_Proc_(ab, {
|
MipsAtomComp_Proc_(ab, {
|
||||||
gte_mv_from_data_r(fr_mac1, C2_MAC1),
|
gte_mv_from_data_r(fr_mac1, C2_MAC1),
|
||||||
gte_mv_from_data_r(fr_mac2, C2_MAC2),
|
gte_mv_from_data_r(fr_mac2, C2_MAC2),
|
||||||
gte_mv_from_data_r(fr_mac3, C2_MAC3),
|
gte_mv_from_data_r(fr_mac3, C2_MAC3),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
FI_ Slice_MipsCode ac_gte_mv_from_mac123_v3s4(AtomBuilder_R ab, Reg_(V3_S4) v) MipsAtomComp_ProcMap_(ab, mac_gte_mv_from_data_r_mac123(v.x, v.y, v.z))
|
FI_ Slice_MipsCode ac_gte_mv_from_mac123_v3s4(AtomBuilder_R ab, Reg_(V3_S4) v) MipsAtomComp_ProcMap_(ab, mac_gte_mv_from_data_r_mac123(v.x, v.y, v.z))
|
||||||
|
|
||||||
#pragma endregion MACs (Mips Atom Components)
|
#pragma endregion MACs (Mips Atom Components)
|
||||||
|
|
||||||
#pragma region Atom Procs
|
#pragma region Atom Procs
|
||||||
|
|
||||||
/* ─── Local copy of PSYQ's sqrtbl (1/sqrt lookup table for VectorNormal). ───
|
/* Normalize V3_S4 using the PSYQ/libgte reciprocal-sqrt method:
|
||||||
* Source: PSYQ 4.7 libgte sqrtbl at 0x800185B4 in hello_camera.elf.
|
* |v|² = x² + y² + z²
|
||||||
* objdump -s --start-address=0x800185B4 --stop-address=0x800185F4 hello_camera.elf → 192 entries × 16-bit signed, in 1.12 fixed-point (max value 0x1000 = 1.0).
|
* LZCR determines the exponent of |v|².
|
||||||
|
* Round that exponent even and shift |v|² into [1, 4).
|
||||||
|
* sqrtbl approximates 1/sqrt(mantissa).
|
||||||
|
* GPF multiplies v by that reciprocal-sqrt mantissa.
|
||||||
|
* srav_shift restores the exponent scale.
|
||||||
|
* Effectively: v_normalized = v * (1 / sqrt(|v|²)).
|
||||||
*
|
*
|
||||||
|
* ─── Local port of PSYQ's sqrtbl (1/sqrt lookup table for VectorNormal). ───
|
||||||
|
* Source: PSYQ 4.7 libgte sqrtbl at 0x800185B4 in hello_camera.elf.
|
||||||
|
* objdump -s --start-address=0x800185B4 --stop-address=0x800185F4 hello_camera.elf -> 192 entries x 16-bit signed, stored in 1.12 fixed point.
|
||||||
* Data is identical to the libgte original (byte-for-byte verified).
|
* Data is identical to the libgte original (byte-for-byte verified).
|
||||||
*
|
*
|
||||||
* ─── Per-entry semantics (decoded from libgte msc02 VectorNormal) ───
|
* ─── Table semantics ───
|
||||||
* Each entry is `1/sqrt(x)` in 1.12 fixed point (value / 4096).
|
* For table index i in [0, 192):
|
||||||
* The 192 entries span 4 octaves of the input magnitude, with 48 entries per octave:
|
* x = 1 + i / 64
|
||||||
* Octave 0 (entries 0- 47): mantissa in [0x8000, 0x10000) output ~[1.000, 0.707]
|
* tbl[i] = floor(4096 / sqrt(x))
|
||||||
* Octave 1 (entries 48- 95): mantissa in [0x10000, 0x20000) output ~[0.707, 0.500]
|
* Thus the table uniformly samples 1/sqrt(x) over:
|
||||||
* Octave 2 (entries 96-143): mantissa in [0x20000, 0x40000) output ~[0.500, 0.354]
|
* x in [1.0, 4.0)
|
||||||
* Octave 3 (entries144-191): mantissa in [0x40000, 0x80000) output ~[0.354, 0.251]
|
* at steps of 1/64, with the result represented in 1.12 fixed point (0x1000 = 1.0).
|
||||||
* Within each octave, 8 sub-entries interpolate over the 8 fractional bits of the mantissa
|
|
||||||
* (the byte `(0x80 | (i mod 8))` for the lower-byte of the aligned value).
|
|
||||||
* Sampling the first value of each octave:
|
|
||||||
* [0] 0x1000 = 1.0000 ; 1 / sqrt(1.0000)
|
|
||||||
* [48] 0x0e4f = 0.8940 ; 1 / sqrt(1.2500)
|
|
||||||
* [96] 0x0d10 = 0.8164 ; 1 / sqrt(1.5000)
|
|
||||||
* [144] 0x0c0a = 0.7520 ; 1 / sqrt(1.7500)
|
|
||||||
* And representative sub-entries within octave 0 (mantissa in [0x8000, 0x8100)):
|
|
||||||
* [0] 0x1000 = 1.0000 ; 1 / sqrt(0x8000)
|
|
||||||
* [1] 0x0fe0 = 0.9922 ; 1 / sqrt(0x8100)
|
|
||||||
* [2] 0x0fc1 = 0.9846 ; 1 / sqrt(0x8200)
|
|
||||||
* [3] 0x0fa3 = 0.9773 ; 1 / sqrt(0x8300)
|
|
||||||
* [4] 0x0f85 = 0.9700 ; 1 / sqrt(0x8400)
|
|
||||||
* [5] 0x0f68 = 0.9629 ; 1 / sqrt(0x8500)
|
|
||||||
* [6] 0x0f4c = 0.9561 ; 1 / sqrt(0x8600)
|
|
||||||
* [7] 0x0f30 = 0.9492 ; 1 / sqrt(0x8700)
|
|
||||||
*
|
*
|
||||||
* The algorithm's `addi -64 / sll 1 / lh` selects the entry at `(aligned - 64) * 2` for the case where `aligned` has its top bit at bit 24.
|
* Representative entries:
|
||||||
* After the sllv/srav pair, `aligned` always lands in `[0x80, 0x100)`
|
* [ 0] 0x1000 = 1.000000 ; 1 / sqrt(1.000000)
|
||||||
* (with top bit at bit 24 → after `sub $aligned - 64`, the index sits in `[0x40, 0x80) * 2 = [0x80, 0x100)` bytes = entries [64, 128) within the sqrtbl).
|
* [ 16] 0x0e4f = 0.894287 ; 1 / sqrt(1.250000)
|
||||||
* The earlier 64 entries (octave 0) are reached when the magnitude after shifting puts the top bit below bit 24 (the `sllv` branch),
|
* [ 32] 0x0d10 = 0.816406 ; 1 / sqrt(1.500000)
|
||||||
* and the load upper_halves of the table bracket the input range.
|
* [ 48] 0x0c18 = 0.755859 ; 1 / sqrt(1.750000)
|
||||||
* The later 64 entries (octaves 2-3) are the `srav` branch when the magnitude's top bit is well above bit 24.
|
* [ 64] 0x0b50 = 0.707031 ; 1 / sqrt(2.000000)
|
||||||
|
* [128] 0x093c = 0.577148 ; 1 / sqrt(3.000000)
|
||||||
|
* [191] 0x0804 = 0.500977 ; 1 / sqrt(3.984375)
|
||||||
*
|
*
|
||||||
* Reproduced verbatim from libgte (verified against libpsn00b/psxgte/vector.s:100-123 — 24 rows × 8 halfwords, last entry 0x0804).
|
* ─── How VectorNormal indexes it ───
|
||||||
* */
|
* Let:
|
||||||
|
* mag_sq = x*x + y*y + z*z
|
||||||
|
* lzcr = leading-zero count of mag_sq
|
||||||
|
* For a non-zero magnitude, libgte first rounds LZCR down to an even number:
|
||||||
|
* lzcr_even = lzcr & ~1
|
||||||
|
*
|
||||||
|
* It then shifts mag_sq so that its significant bits land in one of two
|
||||||
|
* adjacent normalized ranges:
|
||||||
|
* if lzcr_even >= 24:
|
||||||
|
* aligned = mag_sq << (lzcr_even - 24)
|
||||||
|
* else:
|
||||||
|
* aligned = mag_sq >> (24 - lzcr_even)
|
||||||
|
*
|
||||||
|
* Because lzcr_even differs from the true LZCR by at most one bit:
|
||||||
|
* raw LZCR even -> aligned in [0x80, 0x100)
|
||||||
|
* raw LZCR odd -> aligned in [0x40, 0x080)
|
||||||
|
* therefore:
|
||||||
|
* aligned in [0x40, 0x100)
|
||||||
|
*
|
||||||
|
* Dividing this normalized integer by 64 gives exactly the table domain:
|
||||||
|
* x = aligned / 64
|
||||||
|
* x in [1.0, 4.0)
|
||||||
|
*
|
||||||
|
* The lookup is therefore:
|
||||||
|
* index = aligned - 0x40
|
||||||
|
* byte_offset = index * sizeof(S2)
|
||||||
|
* inv_len = sqrtbl[index]
|
||||||
|
* or equivalently, matching the libgte instructions:
|
||||||
|
* addi aligned, -64
|
||||||
|
* sll aligned, 1
|
||||||
|
* lh inv_len, sqrtbl + aligned
|
||||||
|
*
|
||||||
|
* ─── Why the domain spans [1, 4) instead of [1, 2) ───
|
||||||
|
* Square-root scaling depends on the parity of the exponent.
|
||||||
|
* Rounding LZCR to even absorbs exponent changes in pairs of bits, leaving the lookup mantissa normalized over a factor-of-four interval [1, 4).
|
||||||
|
*
|
||||||
|
* The corresponding exponent correction is retained separately as:
|
||||||
|
* srav_shift = (31 - lzcr_even) >> 1
|
||||||
|
*
|
||||||
|
* After GPF multiplies the original vector components by the table's reciprocal-square-root coefficient,
|
||||||
|
* this shift restores the exponent scale and yields the normalized vector.
|
||||||
|
*
|
||||||
|
* Reproduced verbatim from libgte; also matches PSn00bSDK VectorNormalS _norm_table (24 rows x 8 halfwords, final entry 0x0804).
|
||||||
|
**/
|
||||||
internal S2 const gte_normalize_sqr_tbl[192] align_(2) = {
|
internal S2 const gte_normalize_sqr_tbl[192] align_(2) = {
|
||||||
0x1000, 0x0fe0, 0x0fc1, 0x0fa3, 0x0f85, 0x0f68, 0x0f4c, 0x0f30,
|
0x1000, 0x0fe0, 0x0fc1, 0x0fa3, 0x0f85, 0x0f68, 0x0f4c, 0x0f30,
|
||||||
0x0f15, 0x0efb, 0x0ee1, 0x0ec7, 0x0eae, 0x0e96, 0x0e7e, 0x0e66,
|
0x0f15, 0x0efb, 0x0ee1, 0x0ec7, 0x0eae, 0x0e96, 0x0e7e, 0x0e66,
|
||||||
@@ -269,10 +305,10 @@ typedef Struct_(RegUse_normalize_v3s4) {
|
|||||||
union { Reg_(V3_S4) res, src; };
|
union { Reg_(V3_S4) res, src; };
|
||||||
union { Reg r0, src_ptr, mac2; };
|
union { Reg r0, src_ptr, mac2; };
|
||||||
union { Reg r1, dst_ptr; };
|
union { Reg r1, dst_ptr; };
|
||||||
union { Reg r2, dst_offset, mac1, v_sqr_aligned; };
|
union { Reg r2, dst_offset, mac1, v_sqr_aligned, sqrtbl_byte_offset; };
|
||||||
union { Reg r3, src_offset, btarget, shift_count, sqrtbl_index; };
|
union { Reg r3, src_offset, align_delta, shift_count, sqrtbl_lookup; };
|
||||||
union { Reg r4, mac3, v_sqr_sum, scale_exp, srav_shift; };
|
union { Reg r4, mac3, v_sqr_sum, srav_shift; };
|
||||||
union { Reg r5, lzcr, inv_len; };
|
union { Reg r5, lzcr_raw, lzcr_even, inv_len; };
|
||||||
};
|
};
|
||||||
/* ─── Full normalize (all 4 stages inline) ───
|
/* ─── Full normalize (all 4 stages inline) ───
|
||||||
* Generic 4-stage GTE normalize (SQR → sum+LZCR → align+sqrtbl → GPF+srav). */
|
* Generic 4-stage GTE normalize (SQR → sum+LZCR → align+sqrtbl → GPF+srav). */
|
||||||
@@ -294,30 +330,30 @@ MipsAtom_Proc_(aa, {
|
|||||||
add_u_self( r.v_sqr_sum, r.mac1),
|
add_u_self( r.v_sqr_sum, r.mac1),
|
||||||
add_u_self( r.v_sqr_sum, r.mac2),
|
add_u_self( r.v_sqr_sum, r.mac2),
|
||||||
gte_mv_to_data_r( r.v_sqr_sum, C2_LZCS), GteDelay_ nop2,
|
gte_mv_to_data_r( r.v_sqr_sum, C2_LZCS), GteDelay_ nop2,
|
||||||
gte_mv_from_data_r(r.lzcr, C2_LZCR), GteDelay_ nop,
|
gte_mv_from_data_r(r.lzcr_raw, C2_LZCR), GteDelay_ nop,
|
||||||
|
|
||||||
/* Stage 3: even(LZCR), half-shift, align |v|² to bit 24. */
|
/* Stage 3: even(LZCR), half-shift, align |v|² to bit 24. */
|
||||||
mac_lzcr_round_even_half_shift(r.lzcr, r.v_sqr_sum, r.v_sqr_aligned),
|
mac_lzcr_round_even_half_shift(r.lzcr_raw, r.v_sqr_sum, r.v_sqr_aligned),
|
||||||
add_si( r.btarget, r.lzcr, -24),
|
add_si( r.align_delta, r.lzcr_even, -24),
|
||||||
branch_lt_zero(r.btarget, atom_offset(aligned_done, srav_path)), BdSlot_ nop, /* bltz → srav_path (LZCR < 24 path) */
|
branch_lt_zero(r.align_delta, atom_offset(aligned_done, srav_path)), BdSlot_ nop, /* bltz → srav_path (LZCR < 24 path) */
|
||||||
jump_rel(atom_offset(srav_path, aligned_done)), /* b → aligned_done (LZCR >= 24 path) */
|
jump_rel(atom_offset(srav_path, aligned_done)), /* b → aligned_done (LZCR >= 24 path) */
|
||||||
BdSlot_ shift_lleft_var(r.v_sqr_aligned, r.v_sqr_aligned, r.btarget),
|
BdSlot_ shift_lleft_var(r.v_sqr_aligned, r.v_sqr_aligned, r.align_delta),
|
||||||
atom_label(srav_path)
|
atom_label(srav_path)
|
||||||
li_s( r.shift_count, 24),
|
li_s( r.shift_count, 24),
|
||||||
sub_s(r.shift_count, r.shift_count, r.lzcr),
|
sub_s(r.shift_count, r.shift_count, r.lzcr_even),
|
||||||
shift_aright_var(r.v_sqr_aligned, r.v_sqr_aligned, r.shift_count),
|
shift_aright_var(r.v_sqr_aligned, r.v_sqr_aligned, r.shift_count),
|
||||||
atom_label(aligned_done)
|
atom_label(aligned_done)
|
||||||
add_si( r.v_sqr_aligned, r.v_sqr_aligned, -64),
|
add_si( r.sqrtbl_byte_offset, r.v_sqr_aligned, -64),
|
||||||
shift_lleft(r.v_sqr_aligned, r.v_sqr_aligned, 1),
|
shift_lleft(r.sqrtbl_byte_offset, r.sqrtbl_byte_offset, 1),
|
||||||
mac_load_word_imm(r.sqrtbl_index, & gte_normalize_sqr_tbl), add_u_self(r.sqrtbl_index, r.v_sqr_aligned),
|
mac_load_word_imm(r.sqrtbl_lookup, & gte_normalize_sqr_tbl), add_u_self(r.sqrtbl_lookup, r.sqrtbl_byte_offset),
|
||||||
load_half(r.inv_len, r.sqrtbl_index, 0),
|
load_half(r.inv_len, r.sqrtbl_lookup, 0),
|
||||||
LdSlot_ nop,
|
LdSlot_ nop,
|
||||||
|
|
||||||
mac_gte_general_purpose_interopolation(r.inv_len,
|
mac_gte_general_purpose_interopolation(r.inv_len,
|
||||||
r.src.x, r.src.y, r.src.z,
|
r.src.x, r.src.y, r.src.z,
|
||||||
r.res.x, r.res.y, r.res.z,
|
r.res.x, r.res.y, r.res.z,
|
||||||
GteDelay_ load_word(R_AtomJmp, R_TapePtr, 0), LdSlot_ // ac_yield: word 1
|
GteDelay_ load_word(R_AtomJmp, R_TapePtr, 0), LdSlot_ // ac_yield: word 1
|
||||||
GteDelay_ add_ui_self( R_TapePtr, S_(MipsCode)) // ac_yield: word 2
|
GteDelay_ add_ui_self( R_TapePtr, S_(MipsCode)) // ac_yield: word
|
||||||
),
|
),
|
||||||
mac_shift_aright_var_v3s4_self(r.res, r.srav_shift),
|
mac_shift_aright_var_v3s4_self(r.res, r.srav_shift),
|
||||||
mac_store_v3s4(r.res, r.dst_ptr, 0),
|
mac_store_v3s4(r.res, r.dst_ptr, 0),
|
||||||
+15
-15
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#define MEM_ALIGNMENT_DEFAULT 4
|
#define MEM_ALIGNMENT_DEFAULT 4
|
||||||
|
|
||||||
#define assert_bounds(point, start, end) for(;0;){ \
|
#define assert_bounds(point, start, end) do{ \
|
||||||
assert((start) <= (point)); \
|
assert((start) <= (point)); \
|
||||||
assert((point) <= (end)); \
|
assert((point) <= (end)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
@@ -23,10 +23,10 @@ FI_ void mem_bump(U4 cap, U4*R_ used, U4 amount) {
|
|||||||
used[0] += amount;
|
used[0] += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
FI_ U4 mem_copy (U4 dest, U4 src, U4 len) { return (U4)(__builtin_memcpy ((void*)dest, (void const*)src, len)); }
|
FI_ U4 mem_copy (U1_R dest, U1_R src, U4 len) { return (U4)(__builtin_memcpy ((void*)dest, (void const*)src, len)); }
|
||||||
FI_ U4 mem_copy_overlapping(U4 dest, U4 src, U4 len) { return (U4)(__builtin_memmove((void*)dest, (void const*)src, len)); }
|
FI_ U4 mem_copy_overlapping(U1* dest, U1* src, U4 len) { return (U4)(__builtin_memmove((void*)dest, (void const*)src, len)); }
|
||||||
FI_ U4 mem_fill (U4 dest, U4 value, U4 len) { return (U4)(__builtin_memset ((void*)dest, (int) value, len)); }
|
FI_ U4 mem_fill (U1_R dest, U4 value, U4 len) { return (U4)(__builtin_memset ((void*)dest, (int) value, len)); }
|
||||||
FI_ B4 mem_zero (U4 dest, U4 len) { if(dest == 0){return false;} mem_fill(dest, 0, len); return true; }
|
FI_ B4 mem_zero (U1_R dest, U4 len) { if(dest == 0){return false;} mem_fill(dest, 0, len); return true; }
|
||||||
|
|
||||||
#pragma region DAG
|
#pragma region DAG
|
||||||
|
|
||||||
@@ -58,31 +58,30 @@ typedef Struct_(Str8) { UTF8* ptr; U4 len; };
|
|||||||
typedef Struct_(Slice_Str8) { Str8* ptr; U4 len; };
|
typedef Struct_(Slice_Str8) { Str8* ptr; U4 len; };
|
||||||
#define slit(string_literal) (Str8){ (UTF8*) string_literal, S_(string_literal) - 1 }
|
#define slit(string_literal) (Str8){ (UTF8*) string_literal, S_(string_literal) - 1 }
|
||||||
|
|
||||||
typedef Struct_(Slice) { B1* ptr; U4 len; };
|
typedef Struct_(Slice) { U1* ptr; U4 len; };
|
||||||
FI_ Slice slice_ut_(U4 ptr, U4 len) { return (Slice){(B1*)ptr, len}; }
|
FI_ Slice slice_ut_(U1* ptr, U4 len) { return (Slice){ptr, len}; }
|
||||||
|
|
||||||
#define Slice_(type) Struct_(tmpl(Slice,type)) { type* ptr; U4 len; }
|
#define Slice_(type) Struct_(tmpl(Slice,type)) { type* ptr; U4 len; }
|
||||||
typedef Slice_(B1);
|
|
||||||
#define slice_assert(s) do { assert((s).ptr != 0); assert((s).len > 0); } while(0)
|
#define slice_assert(s) do { assert((s).ptr != 0); assert((s).len > 0); } while(0)
|
||||||
#define slice_end(slice) ((slice).ptr + S_slice(slice) / S_(B1))
|
#define slice_end(slice) ((slice).ptr + S_slice(slice))
|
||||||
#define S_slice(s) ((s).len * S_((s).ptr[0]))
|
#define S_slice(s) ((s).len * S_((s).ptr[0]))
|
||||||
|
|
||||||
#define slice_ut(ptr,len) slice_ut_(u4_(ptr), u4_(len))
|
#define slice_ut(ptr,len) slice_ut_(C_(U1*,ptr), u4_(len))
|
||||||
#define slice_ut_arr(a) slice_ut_(u4_(a), S_(a))
|
#define slice_ut_arr(a) slice_ut_(C_(U1*,a), S_(a))
|
||||||
#define slice_to_ut(s) slice_ut_(u4_((s).ptr), S_slice(s))
|
#define slice_to_ut(s) slice_ut_(C_(U1*,(s).ptr), S_slice(s))
|
||||||
|
|
||||||
#define slice_iter(container, iter) (T_((container).ptr) iter = (container).ptr; iter != slice_end(container); ++ iter)
|
#define slice_iter(container, iter) (T_((container).ptr) iter = (container).ptr; iter != slice_end(container); ++ iter)
|
||||||
#define slice_arg_from_array(type, ...) & (tmpl(Slice,type)) { .ptr = Array_decl(type,__VA_ARGS__), .len = Array_len( Array_decl(type,__VA_ARGS__)) }
|
#define slice_arg_from_array(type, ...) & (tmpl(Slice,type)) { .ptr = Array_decl(type,__VA_ARGS__), .len = Array_len( Array_decl(type,__VA_ARGS__)) }
|
||||||
#define slice_from_array(type, array) (tmpl(Slice,type)) { .ptr = array, .len = Array_len(array) }
|
#define slice_from_array(type, array) (tmpl(Slice,type)) { .ptr = array, .len = Array_len(array) }
|
||||||
|
|
||||||
FI_ void slice_zero_(Slice s) { slice_assert(s); mem_zero(u4_(s.ptr), s.len); }
|
FI_ void slice_zero_(Slice s) { slice_assert(s); mem_zero(s.ptr, s.len); }
|
||||||
#define slice_zero(s) slice_zero_(slice_to_ut(s))
|
#define slice_zero(s) slice_zero_(slice_to_ut(s))
|
||||||
|
|
||||||
FI_ void slice_copy_(Slice dest, Slice src) {
|
FI_ void slice_copy_(Slice dest, Slice src) {
|
||||||
assert(S_slice(dest) >= S_slice(src));
|
assert(S_slice(dest) >= S_slice(src));
|
||||||
slice_assert(dest);
|
slice_assert(dest);
|
||||||
slice_assert(src);
|
slice_assert(src);
|
||||||
mem_copy(u4_(dest.ptr), u4_(src.ptr), S_slice(src));
|
mem_copy(dest.ptr, src.ptr, S_slice(src));
|
||||||
}
|
}
|
||||||
#define slice_copy(dest, src) do { \
|
#define slice_copy(dest, src) do { \
|
||||||
static_assert(T_same(dest, src)); \
|
static_assert(T_same(dest, src)); \
|
||||||
@@ -95,6 +94,7 @@ FI_ Slice slice_bump(U4_R used, U4 start, U4 len, U4 amount) {
|
|||||||
return slice_ut(ptr, amount);
|
return slice_ut(ptr, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef Slice_(B1);
|
||||||
typedef Slice_(U1);
|
typedef Slice_(U1);
|
||||||
typedef Slice_(U4);
|
typedef Slice_(U4);
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ I_ Slice farena_push(FArena_R arena, U4 amount, Opt_farena o) {
|
|||||||
U4 to_commit = align_pow2(desired, o.alignment ? o.alignment : MEM_ALIGNMENT_DEFAULT);
|
U4 to_commit = align_pow2(desired, o.alignment ? o.alignment : MEM_ALIGNMENT_DEFAULT);
|
||||||
U4 ptr = arena->start + arena->used;
|
U4 ptr = arena->start + arena->used;
|
||||||
mem_bump(arena->capacity, & arena->used, to_commit);
|
mem_bump(arena->capacity, & arena->used, to_commit);
|
||||||
return (Slice){ (B1*)ptr, to_commit };
|
return (Slice){ (U1*)ptr, to_commit };
|
||||||
}
|
}
|
||||||
FI_ void farena_reset (FArena_R arena) { arena->used = 0; }
|
FI_ void farena_reset (FArena_R arena) { arena->used = 0; }
|
||||||
FI_ void farena_rewind(FArena_R arena, U4 save_point) {
|
FI_ void farena_rewind(FArena_R arena, U4 save_point) {
|
||||||
|
|||||||
+53
-89
@@ -13,56 +13,32 @@
|
|||||||
|
|
||||||
#pragma region Tape Drive
|
#pragma region Tape Drive
|
||||||
/* -----------------------------------------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------------------------------------
|
||||||
* TAPE DRIVE ABI
|
* THREADED ATOMS - TAPE EXECUTION & ABI
|
||||||
|
* _________
|
||||||
|
* | ___ |
|
||||||
|
* | o___o | ,-----<-----.
|
||||||
|
* |__/___\__| V ^
|
||||||
|
* \_[Enter]_[A]->[A]->[A]->[A(B)]->[A]->[Exit]
|
||||||
* -----------------------------------------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------------------------------------
|
||||||
* Note(Ed): One of the main purposes of this codebase is to help me learn this,
|
* This ABI and its associated legos were directly inspired by researching the work of Timothy Lottes and
|
||||||
* as such the information below may not* be entirely realized or finalized conceptually.
|
* Onat Türkçüoğlu; Forth, threaded code system, and various other people or programming techniques.
|
||||||
* -----------------------------------------------------------------------------------------------------------
|
*
|
||||||
* This ABI and its associated legos were directly inspired by researching the work of
|
* The setup is simple:
|
||||||
* Timothy Lottes and Onat Türkçüoğlu; along with many others. It's the simplest bootstrap of a
|
* A tape is a linear stream containing addresses of directly executable native-code fragments ("Atoms").
|
||||||
* directly executed chain of assemby arrays (Atoms) that terminate with a yield sequence to the next atom.
|
* Most atoms terminate in a small yield sequence which loads the next atom address from the tape.
|
||||||
* These eventually lead to a terminal atom for the tape which is defined below as "tape_exit".
|
* It's a runtime composed of directly executed native machine-code sequences (Atoms) that usually terminate
|
||||||
|
* in a yield sequence to the next atom. These eventually lead to a terminal atom for the tape
|
||||||
|
* which is defined below as "tape_exit". Traditionally referred to as Direct Threaded Execution.
|
||||||
*
|
*
|
||||||
* It behaves as one of the simplest runtime harnesses ontop of a host-enviornment's execution engine
|
* It behaves as one of the simplest runtime harnesses ontop of a host-enviornment's execution engine
|
||||||
* to author and compose programs with. From here various conventions can be further applied.
|
* to author and compose programs with. From here various conventions can be further applied.
|
||||||
* To make things easier to understand it may be better to focus on what this ABI does not have.
|
* To make things easier to understand it may be better to focus on what this ABI does not have.
|
||||||
* It does not have have any branching within the tape but relative branches within atoms or between atoms.
|
* The tape itself does not have have any branching behavior.
|
||||||
* Branching nearly is always downstream. Automatic stack usage is non-existent.
|
* Branches, loops, skips, or other control-flow policies must be implemented explicitly by atoms.
|
||||||
* Push/Pop, FIFO, or Arena/Bump data structures are used by atoms explicitly.
|
* Push/Pop, FIFO, or Arena/Bump data structures are utilized by atoms explicitly.
|
||||||
* In it's current form with the C11 macro DSL, the user also has fullfill manual register allocation per atom.
|
* There is no implicit call-stack, return stack, or per-atom stack-frame.
|
||||||
*
|
* The user must also explictly handle register allocation per atom (by default).
|
||||||
* One of the remarkable things about utilizing this ABI is its essentially interopable with CPUs, GPUs, FPGA,
|
* However they could procedurally automate it using metaprogramming functionality.
|
||||||
* or, basically anything from the 5th generation consoles and onward.
|
|
||||||
* The ABI directly reflects how all computational hardware must be architected in order to execute
|
|
||||||
* digital logic effectively on current era tech.
|
|
||||||
* On the PS1 we don't have access to a few features like multi-threading, speculative execution, or L3 cache;
|
|
||||||
* but, we can set the foundation for legoing whats required for eventually expanding this ABI's paradigm
|
|
||||||
* and core atoms to take those newer hardware features into account. For example, you can easily expand
|
|
||||||
* this to support wave-based execution model on a PS2 or PS3. Not having a stack or
|
|
||||||
* automatic register allocation means the user cannot ignore excessive argument shuffle across workload or
|
|
||||||
* waves and thier phases. Crossing ABI boundaries to other runtimes that do has obviouss penalties.
|
|
||||||
*
|
|
||||||
* Learning data-oriented code becomes a natural progression. Your not fighting a stack-based procedural
|
|
||||||
* paradigm that wants to argument shuffle. There is no ambiguity due to the lack of constraints, for example,
|
|
||||||
* on how the user may "call" a procedure in traditional random dispatch runtimes. The user does have to
|
|
||||||
* hammer down "rules" or patterns for massaging the compiler to dissolve those call frames; just to get
|
|
||||||
* the asesmbly into its desired form. The form is obvious, and once the user gets to author these compoonents
|
|
||||||
* it becomes a game of tetris.
|
|
||||||
*
|
|
||||||
* Another feature is this ABI is very compatible with bootstrapping and developing simple toolchains built off
|
|
||||||
* of bit-packed annotated command streams the user can directly author, maintatain, and immediately execute.
|
|
||||||
* That being like a color forth, or maybe something more familar like an immediate mode library
|
|
||||||
* for various systems such as GUIs. This can make the tetris less of a chore with some helpful policy
|
|
||||||
* generation for allocation of registers, helping to choose resuable components, designing DSL on the fly, etc.
|
|
||||||
* -----------------------------------------------------------------------------------------------------------
|
|
||||||
* TODO(Ed): We need pretty ascii diagrams and proper guides, articles, etc.
|
|
||||||
* -----------------------------------------------------------------------------------------------------------
|
|
||||||
* For now this ideation has just started functioning. I'm abusing C11 & a lua metaprogram to help establish
|
|
||||||
* a hybrid toolchain to ideate on a traditional text-based authoring UX for this paradigm.
|
|
||||||
* If pcsx-redux provides viable hot-reload and persistent data storage beyond save-states
|
|
||||||
* (just copying ram to filesystem), I can author a color forth to mess around with.
|
|
||||||
* With either an editor in-emulator or on the actual machine itself. Assembly is tedius,
|
|
||||||
* but I think this codebase most likely has a pretty ergonomic flavor worst case...
|
|
||||||
* */
|
* */
|
||||||
/* Register Allocation Info */
|
/* Register Allocation Info */
|
||||||
enum {
|
enum {
|
||||||
@@ -121,7 +97,7 @@ typedef U2 Reg; // Register parameter used with atom or atom component procedure
|
|||||||
typedef U4 const MipsCode; // Underlying type to mips asm words.
|
typedef U4 const MipsCode; // Underlying type to mips asm words.
|
||||||
typedef Slice_(MipsCode);
|
typedef Slice_(MipsCode);
|
||||||
|
|
||||||
typedef U4 const MipsAtom; // Underlying type to a mips atom defnition
|
typedef U4 const MipsAtom; // Underlying type to a mips atom definition
|
||||||
typedef Slice_(MipsAtom);
|
typedef Slice_(MipsAtom);
|
||||||
|
|
||||||
// Sometimes a user will define a bundle of atoms that represent a procedure of work as:
|
// Sometimes a user will define a bundle of atoms that represent a procedure of work as:
|
||||||
@@ -176,7 +152,7 @@ typedef Slice_(MipsAtom);
|
|||||||
The constant is in `.rodata` so the linker may eliminate it. */
|
The constant is in `.rodata` so the linker may eliminate it. */
|
||||||
#define ATOM_FILE_DEBUGGER_LINE_MARKER(file_name) internal U4 const tmpl(atom_file_debugger_line_marker,file_name) = 0
|
#define ATOM_FILE_DEBUGGER_LINE_MARKER(file_name) internal U4 const tmpl(atom_file_debugger_line_marker,file_name) = 0
|
||||||
|
|
||||||
typedef Slice_MipsAtom Tape;
|
typedef Struct_(Tape) { union { MipsAtom* ptr; U4* inlaid_data; }; U4 len; };
|
||||||
|
|
||||||
typedef Struct_(TapeHostFrame) {
|
typedef Struct_(TapeHostFrame) {
|
||||||
U4 s0;
|
U4 s0;
|
||||||
@@ -242,19 +218,14 @@ FI_ void tape_run(Tape tape) { C_(TapeEntryFn*, tape_enter)(tape.ptr); }
|
|||||||
// Procedural authoring of tapes:
|
// Procedural authoring of tapes:
|
||||||
typedef Relative_(FArena) Struct_(TapeBuilder) { U4 ptr; U4 capacity; U4 used; };
|
typedef Relative_(FArena) Struct_(TapeBuilder) { U4 ptr; U4 capacity; U4 used; };
|
||||||
FI_ void tb_init(TapeBuilder* tb, FArena* arena) { tb->ptr = arena->start; tb->used = 0; }
|
FI_ void tb_init(TapeBuilder* tb, FArena* arena) { tb->ptr = arena->start; tb->used = 0; }
|
||||||
FI_ TapeBuilder tb_make_old( FArena* arena) { return (TapeBuilder){ arena->start, 0 }; }
|
|
||||||
FI_ TapeBuilder tb_make(Slice mem) { return (TapeBuilder){ u4_(mem.ptr), mem.len, 0 }; } /* capacity in elements (matches used units) */
|
FI_ TapeBuilder tb_make(Slice mem) { return (TapeBuilder){ u4_(mem.ptr), mem.len, 0 }; } /* capacity in elements (matches used units) */
|
||||||
|
|
||||||
FI_ void tb_emit(TapeBuilder* tb, MipsAtom* atom) { u4_r(tb->ptr)[tb->used] = u4_(atom); ++ tb->used; }
|
FI_ void tb_emit(TapeBuilder* tb, MipsAtom* atom) { u4_r(tb->ptr)[tb->used] = u4_(atom); ++ tb->used; }
|
||||||
FI_ void tb_data(TapeBuilder* tb, U4 data) { u4_r(tb->ptr)[tb->used] = u4_(data); ++ tb->used; }
|
FI_ void tb_data(TapeBuilder* tb, U4 data) { u4_r(tb->ptr)[tb->used] = u4_(data); ++ tb->used; }
|
||||||
#define tb_emit_(atom) tb_emit(& tb, atom)
|
#define tb_emit_(atom) tb_emit(& tb, atom)
|
||||||
|
|
||||||
FI_ void tb_bind(TapeBuilder* tb, Slice data) { mem_copy(tb->ptr + tb->used * S_(MipsCode), u4_(data.ptr), data.len); tb->used += data.len / S_(MipsCode); }
|
FI_ void tb_bind(TapeBuilder* tb, Slice data) { mem_copy(b1_r(tb->ptr + tb->used * S_(MipsCode)), data.ptr, data.len); tb->used += data.len / S_(MipsCode); }
|
||||||
#define tb_bind_(tb,type,...) tb_bind(tb, (Slice){ (B1*)(& (type){__VA_ARGS__}), S_(type) }); static_assert(S_(type) % S_(MipsCode) == 0)
|
#define tb_bind_(tb,type,...) tb_bind(tb, (Slice){ (U1*)(& (type){__VA_ARGS__}), S_(type) }); static_assert(S_(type) % S_(MipsCode) == 0)
|
||||||
|
|
||||||
// NOTE(Ed): Wip still ideating convention. Possibly will never use a composite.
|
|
||||||
#define tb_emit_wbind_(tb,atom,...) tb_emit(tb,atom); tb_bind_(tb,tmpl(Binds,atom),__VA_ARGS__)
|
|
||||||
#define tb_emit_wbind2_(tb,atom,type,...) tb_emit(tb,atom); tb_bind_(tb,type,__VA_ARGS__)
|
|
||||||
|
|
||||||
FI_ Tape tb_end (TapeBuilder* tb) { tb_emit(tb,tape_exit); return (Tape){ C_(U4*,tb->ptr), tb->used }; }
|
FI_ Tape tb_end (TapeBuilder* tb) { tb_emit(tb,tape_exit); return (Tape){ C_(U4*,tb->ptr), tb->used }; }
|
||||||
FI_ Tape tb_slice(TapeBuilder tb) { return (Tape){ C_(U4*,tb.ptr), tb.used }; }
|
FI_ Tape tb_slice(TapeBuilder tb) { return (Tape){ C_(U4*,tb.ptr), tb.used }; }
|
||||||
@@ -262,6 +233,12 @@ FI_ Tape tb_slice(TapeBuilder tb) { return (Tape){ C_(U4
|
|||||||
|
|
||||||
FI_ void tb_scope_run_end(TapeBuilder* tb) { tb_emit(tb,tape_exit); tape_run(tb_slice(tb[0])); }
|
FI_ void tb_scope_run_end(TapeBuilder* tb) { tb_emit(tb,tape_exit); tape_run(tb_slice(tb[0])); }
|
||||||
#define tb_scope_run(tb) for(U4 tbs_once=0;tbs_once==0;++tbs_once,tb_scope_run_end(tb))
|
#define tb_scope_run(tb) for(U4 tbs_once=0;tbs_once==0;++tbs_once,tb_scope_run_end(tb))
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE(Ed): Wip still ideating convention. Possibly will never use a composite.
|
||||||
|
#define tb_emit_wbind_(tb,atom,...) tb_emit(tb,atom); tb_bind_(tb,tmpl(Binds,atom),__VA_ARGS__)
|
||||||
|
#define tb_emit_wbind2_(tb,atom,type,...) tb_emit(tb,atom); tb_bind_(tb,type,__VA_ARGS__)
|
||||||
|
|
||||||
#pragma endregion Tape Drive
|
#pragma endregion Tape Drive
|
||||||
|
|
||||||
#pragma region Macro Mips Atom Components
|
#pragma region Macro Mips Atom Components
|
||||||
@@ -271,6 +248,7 @@ FI_ void tb_scope_run_end(TapeBuilder* tb) { tb_emit(tb,tape_exit); tape_run(tb_
|
|||||||
* ---------------------------------------------------------------------------*/
|
* ---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// The 'Yield' sequence for Tape Atoms (mac_yield).
|
// The 'Yield' sequence for Tape Atoms (mac_yield).
|
||||||
|
// In Forth this is considered the "NEXT" mechanism.
|
||||||
|
|
||||||
atom_dbg_skip MipsAtomComp_(ac_yield) {
|
atom_dbg_skip MipsAtomComp_(ac_yield) {
|
||||||
load_word(R_AtomJmp, R_TapePtr, 0), LdSlot_
|
load_word(R_AtomJmp, R_TapePtr, 0), LdSlot_
|
||||||
@@ -299,7 +277,7 @@ typedef Relative_(FArena) Struct_(AtomBuilder) { U4 start; U4 capacity; U4 used;
|
|||||||
FI_ void atombuilder_push(AtomBuilder_R ab, Slice_MipsCode code) {
|
FI_ void atombuilder_push(AtomBuilder_R ab, Slice_MipsCode code) {
|
||||||
assert(ab->capacity - ab->used - code.len);
|
assert(ab->capacity - ab->used - code.len);
|
||||||
U4 dest = ab->start + ab->used * S_(MipsCode); U4 size = S_slice(code);
|
U4 dest = ab->start + ab->used * S_(MipsCode); U4 size = S_slice(code);
|
||||||
mem_copy(dest, u4_(code.ptr), size); ab->used += size;
|
mem_copy(b1_r(dest), b1_r(code.ptr), size); ab->used += size;
|
||||||
}
|
}
|
||||||
#define atombuilder_push_mac(ab, mac) atombuilder_push(ab, slice_arg_from_array(Slice_MipsCode, mac))
|
#define atombuilder_push_mac(ab, mac) atombuilder_push(ab, slice_arg_from_array(Slice_MipsCode, mac))
|
||||||
|
|
||||||
@@ -323,7 +301,7 @@ FI_ AtomArena atomarena_make(Slice mem) { AtomArena a; atomarena_init(& a, mem);
|
|||||||
FI_ MipsAtom* atomarena_push(AtomArena_R aa, Slice_MipsCode code) {
|
FI_ MipsAtom* atomarena_push(AtomArena_R aa, Slice_MipsCode code) {
|
||||||
assert(aa->capacity - aa->used - code.len);
|
assert(aa->capacity - aa->used - code.len);
|
||||||
U4 dest = atomarena_unused_start(aa[0]); U4 size = S_slice(code);
|
U4 dest = atomarena_unused_start(aa[0]); U4 size = S_slice(code);
|
||||||
mem_copy(dest, u4_(code.ptr), size); aa->used += size;
|
mem_copy(b1_r(dest), b1_r(code.ptr), size); aa->used += size;
|
||||||
return C_(MipsAtom*, dest);
|
return C_(MipsAtom*, dest);
|
||||||
}
|
}
|
||||||
FI_ void atomarena_reset(AtomArena_R aa) { aa->used = 0; }
|
FI_ void atomarena_reset(AtomArena_R aa) { aa->used = 0; }
|
||||||
@@ -354,24 +332,14 @@ internal Reg const regfile_alloc_order[] = {
|
|||||||
R_T8, R_T9,
|
R_T8, R_T9,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Struct_(RegFile) {
|
typedef Struct_(RegFile) { A2_U2 GPR; };
|
||||||
A2_U2 GPR;
|
|
||||||
A2_U2 GTE;
|
|
||||||
};
|
|
||||||
#define regfile(pin_mask) {.GPR={u4_lo(pin_mask), u4_hi(pin_mask)} }
|
#define regfile(pin_mask) {.GPR={u4_lo(pin_mask), u4_hi(pin_mask)} }
|
||||||
FI_ void regfile_init(RegFile_R rf) {
|
FI_ void regfile_init(RegFile_R rf) {
|
||||||
/* pack the 32-bit ABI mask into the two U2s */
|
rf->GPR[0] = u4_lo(regfile_abi_mask); rf->GPR[1] = u4_hi(regfile_abi_mask);
|
||||||
rf->GPR[0] = u4_lo(regfile_abi_mask);
|
|
||||||
rf->GPR[1] = u4_hi(regfile_abi_mask);
|
|
||||||
rf->GTE[0] = rf->GTE[1] = 0;
|
|
||||||
}
|
}
|
||||||
FI_ RegFile regfile_make(void) { RegFile rf; regfile_init(& rf); return rf; }
|
FI_ RegFile regfile_make(void) { RegFile rf; regfile_init(& rf); return rf; }
|
||||||
|
|
||||||
typedef Struct_(RegFile_RInfo) {
|
typedef Struct_(RegFile_RInfo) { U2_R section; U2 mask; B2 occupied; };
|
||||||
U2_R section;
|
|
||||||
U2 mask;
|
|
||||||
B2 occupied;
|
|
||||||
};
|
|
||||||
FI_ RegFile_RInfo regfile_rinfo(A2_U2 file, Reg r_id) {
|
FI_ RegFile_RInfo regfile_rinfo(A2_U2 file, Reg r_id) {
|
||||||
U2 s_id = r_id >> 4;
|
U2 s_id = r_id >> 4;
|
||||||
U2_R section = & file[s_id];
|
U2_R section = & file[s_id];
|
||||||
@@ -381,15 +349,11 @@ FI_ RegFile_RInfo regfile_rinfo(A2_U2 file, Reg r_id) {
|
|||||||
}
|
}
|
||||||
FI_ Reg regfile__alloc_helper(A2_U2 file, Reg r_id) {
|
FI_ Reg regfile__alloc_helper(A2_U2 file, Reg r_id) {
|
||||||
Reg result = 0; RegFile_RInfo info = regfile_rinfo(file, r_id);
|
Reg result = 0; RegFile_RInfo info = regfile_rinfo(file, r_id);
|
||||||
if (info.occupied == false) {
|
if (info.occupied == false) { info.section[0] |= info.mask; result = r_id; }
|
||||||
info.section[0] |= info.mask;
|
|
||||||
result = r_id;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
I_ Reg regfile_alloc(RegFile_R rf) {
|
I_ Reg regfile_alloc(RegFile_R rf) {
|
||||||
Reg allocated = 0;
|
Reg allocated = 0; for index_iter(U4, r_id, R_V0, <, R_T9) {
|
||||||
for index_iter(U4, r_id, R_V0, <, R_T9) {
|
|
||||||
allocated = regfile__alloc_helper(rf->GPR, r_id);
|
allocated = regfile__alloc_helper(rf->GPR, r_id);
|
||||||
Jmp_nZero_(allocated,resolved);
|
Jmp_nZero_(allocated,resolved);
|
||||||
}
|
}
|
||||||
@@ -403,8 +367,7 @@ FI_ Reg regfile_pin(RegFile_R rf, Reg r_id) {
|
|||||||
return r_id;
|
return r_id;
|
||||||
}
|
}
|
||||||
FI_ void regfile_pin_mask(RegFile_R rf, U4 mask) {
|
FI_ void regfile_pin_mask(RegFile_R rf, U4 mask) {
|
||||||
B4 occupied = u4_r(rf->GPR)[0] & mask;
|
B4 occupied = u4_r(rf->GPR)[0] & mask; assert(occupied == false);
|
||||||
assert(occupied == false);
|
|
||||||
u4_r(rf->GPR)[0] |= mask;
|
u4_r(rf->GPR)[0] |= mask;
|
||||||
}
|
}
|
||||||
FI_ void regfile_free_mask(RegFile_R rf, U4 mask) {
|
FI_ void regfile_free_mask(RegFile_R rf, U4 mask) {
|
||||||
@@ -412,21 +375,23 @@ FI_ void regfile_free_mask(RegFile_R rf, U4 mask) {
|
|||||||
u4_r(rf->GPR)[0] &= ~mask;
|
u4_r(rf->GPR)[0] &= ~mask;
|
||||||
}
|
}
|
||||||
FI_ void regfile_free_reg(RegFile_R rf, Reg r_id) {
|
FI_ void regfile_free_reg(RegFile_R rf, Reg r_id) {
|
||||||
/* never free the ABI set */
|
if (regfile_abi_mask & (1u << r_id)) return; // never free the ABI set
|
||||||
if (regfile_abi_mask & (1u << r_id)) return;
|
|
||||||
RegFile_RInfo info = regfile_rinfo(rf->GPR, r_id);
|
RegFile_RInfo info = regfile_rinfo(rf->GPR, r_id);
|
||||||
info.section[0] &= ~info.mask;
|
info.section[0] &= ~info.mask;
|
||||||
}
|
}
|
||||||
FI_ void regfile_reset(RegFile_R rf) {
|
FI_ void regfile_reset (RegFile_R rf) { rf->GPR[0] = u4_lo(regfile_abi_mask); rf->GPR[1] = u4_hi(regfile_abi_mask); }
|
||||||
rf->GPR[0] = u4_lo(regfile_abi_mask);
|
FI_ void regfile_reset_to_mask(RegFile_R rf, U4 mask) { rf->GPR[0] = u4_lo(mask); rf->GPR[1] = u4_hi(mask); }
|
||||||
rf->GPR[1] = u4_hi(regfile_abi_mask);
|
|
||||||
}
|
|
||||||
FI_ void regfile_reset_to_mask(RegFile_R rf, U4 mask) {
|
|
||||||
rf->GPR[0] = u4_lo(mask);
|
|
||||||
rf->GPR[1] = u4_hi(mask);
|
|
||||||
}
|
|
||||||
#pragma endregion RegFileArena (Register File Allocator)
|
#pragma endregion RegFileArena (Register File Allocator)
|
||||||
|
|
||||||
|
#pragma region Mips Atom Components (Procedures)
|
||||||
|
|
||||||
|
// For doing direct-chaining of "atoms or fragments".
|
||||||
|
FI_ Slice_MipsCode ac_yield_to(AtomBuilder_R ab, Reg code_ptr) atom_dbg_skip MipsAtomComp_Proc_(ab, {
|
||||||
|
jump_reg(code_ptr), BdSlot_ nop,
|
||||||
|
})
|
||||||
|
|
||||||
|
#pragma endregion Mips Atom Components (Procedures)
|
||||||
|
|
||||||
#pragma region Mips Atom Procs
|
#pragma region Mips Atom Procs
|
||||||
/* RegUse structs are a convention to organize register allocations for a mips atom procedure.
|
/* RegUse structs are a convention to organize register allocations for a mips atom procedure.
|
||||||
Unlike the usual enum-based declarations, they provide a namespaced scope and have view types via union declarations. */
|
Unlike the usual enum-based declarations, they provide a namespaced scope and have view types via union declarations. */
|
||||||
@@ -447,7 +412,6 @@ FI_ void regfile_reset_to_mask(RegFile_R rf, U4 mask) {
|
|||||||
add_si(r.t1.view_3, r.usual_modifiable, 10),
|
add_si(r.t1.view_3, r.usual_modifiable, 10),
|
||||||
mac_yield(),
|
mac_yield(),
|
||||||
})
|
})
|
||||||
|
|
||||||
#pragma endregion Mips Atom Procs
|
#pragma endregion Mips Atom Procs
|
||||||
|
|
||||||
#pragma region Baked Mips Atoms
|
#pragma region Baked Mips Atoms
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
# include "duffle/word_count.metadata.h"
|
# include "duffle/word_count.metadata.h"
|
||||||
# include "duffle/psyq.h"
|
# include "duffle/psyq.h"
|
||||||
# include "duffle/math.atom.h"
|
# include "duffle/math.atom.h"
|
||||||
# include "duffle/gte.atom.h"
|
# include "duffle/gte.atom.c"
|
||||||
# include "duffle/mips.atom.c"
|
# include "duffle/mips.atom.c"
|
||||||
# include "duffle/gp.atom.c"
|
# include "duffle/gp.atom.c"
|
||||||
# include "duffle/psyq.atom.c"
|
# include "duffle/psyq.atom.c"
|
||||||
@@ -237,8 +237,8 @@ enum {
|
|||||||
};
|
};
|
||||||
//screen_env_init. Mirrors the libpsyx's SetDefDispEnv + SetDefDrawEnv + the manual enable_auto_clear / initial_bg_color writes.
|
//screen_env_init. Mirrors the libpsyx's SetDefDispEnv + SetDefDrawEnv + the manual enable_auto_clear / initial_bg_color writes.
|
||||||
internal MipsAtom_(screen_env_init) atom_info(atom_phase(screen_init)
|
internal MipsAtom_(screen_env_init) atom_info(atom_phase(screen_init)
|
||||||
, atom_reads(R_T0, R_ScreenX, R_ScreenY, R_ScreenBuf)
|
, atom_reads(R_ScreenBuf)
|
||||||
, atom_writes(R_T0, R_ScreenX, R_ScreenY)
|
, atom_writes(R_ScreenBuf)
|
||||||
) {
|
) {
|
||||||
/* display[0] = (0, 0, 320, 240); rest of struct zeroed. */
|
/* display[0] = (0, 0, 320, 240); rest of struct zeroed. */
|
||||||
add_ui(R_ScreenX, R_0, ScreenRes_X), add_ui(R_ScreenY, R_0, ScreenRes_Y),
|
add_ui(R_ScreenX, R_0, ScreenRes_X), add_ui(R_ScreenY, R_0, ScreenRes_Y),
|
||||||
@@ -441,7 +441,7 @@ typedef Struct_(Binds_PadInputCam) {
|
|||||||
Camera* cam;
|
Camera* cam;
|
||||||
};
|
};
|
||||||
internal MipsAtom_(pad_input_cam) atom_info(atom_bind(Binds_PadInputCam)
|
internal MipsAtom_(pad_input_cam) atom_info(atom_bind(Binds_PadInputCam)
|
||||||
, atom_reads( R_Cam, R_CamPadState, R_TapePtr)
|
, atom_reads( R_Cam, R_CamPadState)
|
||||||
, atom_writes(R_Cam)
|
, atom_writes(R_Cam)
|
||||||
) {
|
) {
|
||||||
/* Bind pop: state → R_CamPadState (R_T5), cam → R_Cam (R_T4), advance R_TapePtr by 8. */
|
/* Bind pop: state → R_CamPadState (R_T5), cam → R_Cam (R_T4), advance R_TapePtr by 8. */
|
||||||
@@ -499,20 +499,17 @@ enum {
|
|||||||
#define R_OtBase_Code R_T6_Code
|
#define R_OtBase_Code R_T6_Code
|
||||||
};
|
};
|
||||||
typedef Struct_(Binds_CubeTri) {
|
typedef Struct_(Binds_CubeTri) {
|
||||||
U4 PrimCursor;
|
U1* prim_cursor;
|
||||||
V4_S2* FaceCursor;
|
V4_S2* face_cursor;
|
||||||
V3_S2* VertBase;
|
V3_S2* vert_base;
|
||||||
U4* OtBase;
|
U4* ot_base;
|
||||||
};
|
};
|
||||||
internal MipsAtom_(rbind_cube_g4_face) atom_info(atom_bind(Binds_CubeTri), atom_phase(cube_g4)
|
internal MipsAtom_(rbind_cube_g4_face) atom_info(atom_bind(Binds_CubeTri), atom_phase(cube_g4)){
|
||||||
, atom_reads(R_TapePtr)
|
|
||||||
, atom_writes(R_PrimCursor, R_FaceCursor, R_VertBase, R_OtBase, R_TapePtr)
|
|
||||||
){
|
|
||||||
/* Pop 4 arguments from the tape directly into the workspace registers */
|
/* Pop 4 arguments from the tape directly into the workspace registers */
|
||||||
load_word(R_PrimCursor, R_TapePtr, O_(Binds_CubeTri,PrimCursor)),
|
load_word(R_PrimCursor, R_TapePtr, O_(Binds_CubeTri,prim_cursor)),
|
||||||
load_word(R_FaceCursor, R_TapePtr, O_(Binds_CubeTri,FaceCursor)),
|
load_word(R_FaceCursor, R_TapePtr, O_(Binds_CubeTri,face_cursor)),
|
||||||
load_word(R_VertBase, R_TapePtr, O_(Binds_CubeTri,VertBase)),
|
load_word(R_VertBase, R_TapePtr, O_(Binds_CubeTri,vert_base)),
|
||||||
load_word(R_OtBase, R_TapePtr, O_(Binds_CubeTri,OtBase)),
|
load_word(R_OtBase, R_TapePtr, O_(Binds_CubeTri,ot_base)),
|
||||||
LdSlot_ add_ui_self( R_TapePtr, S_(Binds_CubeTri)),
|
LdSlot_ add_ui_self( R_TapePtr, S_(Binds_CubeTri)),
|
||||||
mac_yield()
|
mac_yield()
|
||||||
};
|
};
|
||||||
@@ -530,11 +527,11 @@ MipsAtom_(cube_g4_face) atom_info(atom_phase(cube_g4),
|
|||||||
|
|
||||||
LdSlot_ mac_gte_load_tri_verts(R_VertBase, R_T0, R_T1, R_T2),
|
LdSlot_ mac_gte_load_tri_verts(R_VertBase, R_T0, R_T1, R_T2),
|
||||||
GteDelay_ load_half_u(R_T3, R_FaceCursor, 3 * S_(S2)), LdSlot_
|
GteDelay_ load_half_u(R_T3, R_FaceCursor, 3 * S_(S2)), LdSlot_
|
||||||
GteDelay_ load_word(R_AtomJmp, R_TapePtr, 0), LdSlot_ //ac_yield: word 2,
|
GteDelay_ load_word(R_AtomJmp, R_TapePtr, 0), LdSlot_ //ac_yield: word 1,
|
||||||
gte_cmdw_rotate_translate_perspective_triple,
|
gte_cmdw_rotate_translate_perspective_triple,
|
||||||
gte_cmdw_nclip,
|
gte_cmdw_nclip,
|
||||||
|
|
||||||
gte_mv_from_data_r(R_T0, C2_MAC0), GteDelay_ add_ui_self(R_TapePtr, S_(MipsCode)), // ac_yield: word 1
|
gte_mv_from_data_r(R_T0, C2_MAC0), GteDelay_ add_ui_self(R_TapePtr, S_(MipsCode)), // ac_yield: word 2
|
||||||
branch_le_zero(R_T0, atom_offset(cull, cube_g4_face_exit)),
|
branch_le_zero(R_T0, atom_offset(cull, cube_g4_face_exit)),
|
||||||
/* BD-slot: Write the prim tag (R_0=0; overwrites the legacy tag word in the prim_buffer).
|
/* BD-slot: Write the prim tag (R_0=0; overwrites the legacy tag word in the prim_buffer).
|
||||||
* If branch IS taken (face culled), the body is skipped and this 0-tag is stranded —
|
* If branch IS taken (face culled), the body is skipped and this 0-tag is stranded —
|
||||||
@@ -564,16 +561,16 @@ MipsAtom_(cube_g4_face) atom_info(atom_phase(cube_g4),
|
|||||||
// end: branch(cull)
|
// end: branch(cull)
|
||||||
|
|
||||||
atom_label(cube_g4_face_exit)
|
atom_label(cube_g4_face_exit)
|
||||||
add_ui_self(R_PrimCursor, S_(Poly_G4)), /* 9 words = Poly_G4 */
|
add_ui_self(R_PrimCursor, S_(Poly_G4)), // 9 words = Poly_G4
|
||||||
add_ui_self(R_FaceCursor, S_(S2) * 4), /* 4 × S2 = 8 bytes */
|
add_ui_self(R_FaceCursor, S_(S2) * 4), // 4 × S2 = 8 bytes
|
||||||
jump_reg(R_AtomJmp), BdSlot_ nop // ac_yield: word 3-4
|
jump_reg(R_AtomJmp), BdSlot_ nop // ac_yield: word 3-4
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Struct_(Binds_FloorTri) {
|
typedef Struct_(Binds_FloorTri) {
|
||||||
U4 PrimCursor;
|
U1* prim_cursor;
|
||||||
V3_S2* FaceCursor;
|
V3_S2* face_cursor;
|
||||||
V3_S2* VertBase;
|
V3_S2* vert_base;
|
||||||
U4* OtBase;
|
U4* ot_base;
|
||||||
};
|
};
|
||||||
internal
|
internal
|
||||||
MipsAtom_(rbind_floor_f3_face) atom_info(atom_bind(Binds_FloorTri), atom_phase(floor_f3)
|
MipsAtom_(rbind_floor_f3_face) atom_info(atom_bind(Binds_FloorTri), atom_phase(floor_f3)
|
||||||
@@ -581,10 +578,10 @@ MipsAtom_(rbind_floor_f3_face) atom_info(atom_bind(Binds_FloorTri), atom_phase(f
|
|||||||
, atom_writes(R_PrimCursor, R_FaceCursor, R_VertBase, R_OtBase, R_TapePtr)
|
, atom_writes(R_PrimCursor, R_FaceCursor, R_VertBase, R_OtBase, R_TapePtr)
|
||||||
){
|
){
|
||||||
/* Pop 4 arguments from the tape directly into the workspace registers */
|
/* Pop 4 arguments from the tape directly into the workspace registers */
|
||||||
load_word(R_PrimCursor, R_TapePtr, O_(Binds_FloorTri,PrimCursor)),
|
load_word(R_PrimCursor, R_TapePtr, O_(Binds_FloorTri,prim_cursor)),
|
||||||
load_word(R_FaceCursor, R_TapePtr, O_(Binds_FloorTri,FaceCursor)),
|
load_word(R_FaceCursor, R_TapePtr, O_(Binds_FloorTri,face_cursor)),
|
||||||
load_word(R_VertBase, R_TapePtr, O_(Binds_FloorTri,VertBase)),
|
load_word(R_VertBase, R_TapePtr, O_(Binds_FloorTri,vert_base)),
|
||||||
load_word(R_OtBase, R_TapePtr, O_(Binds_FloorTri,OtBase)),
|
load_word(R_OtBase, R_TapePtr, O_(Binds_FloorTri,ot_base)),
|
||||||
LdSlot_ add_ui_self( R_TapePtr, S_(Binds_FloorTri)),
|
LdSlot_ add_ui_self( R_TapePtr, S_(Binds_FloorTri)),
|
||||||
mac_yield()
|
mac_yield()
|
||||||
};
|
};
|
||||||
@@ -626,10 +623,9 @@ atom_label(floor_f3_face_exit)
|
|||||||
jump_reg(R_AtomJmp), BdSlot_ nop // ac_yield: word 3-4
|
jump_reg(R_AtomJmp), BdSlot_ nop // ac_yield: word 3-4
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Struct_(Binds_SyncPrimitiveArena) { U4 used; U4 cursor; };
|
typedef Struct_(Binds_SyncPrimitiveArena) { U4* used; U1* cursor; };
|
||||||
internal MipsAtom_(sync_primitive_arena) atom_info(atom_bind(Binds_SyncPrimitiveArena)
|
internal MipsAtom_(sync_primitive_arena) atom_info(atom_bind(Binds_SyncPrimitiveArena)
|
||||||
, atom_reads( R_TapePtr, R_PrimCursor)
|
, atom_reads(R_PrimCursor), atom_writes(R_AT)
|
||||||
, atom_writes(R_TapePtr)
|
|
||||||
){
|
){
|
||||||
load_word(R_AT, R_TapePtr, O_(Binds_SyncPrimitiveArena,used)),
|
load_word(R_AT, R_TapePtr, O_(Binds_SyncPrimitiveArena,used)),
|
||||||
load_word(R_T0, R_TapePtr, O_(Binds_SyncPrimitiveArena,cursor)), LdSlot_
|
load_word(R_T0, R_TapePtr, O_(Binds_SyncPrimitiveArena,cursor)), LdSlot_
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
#include "duffle/pad.c"
|
#include "duffle/pad.c"
|
||||||
#include "duffle/math.atom.h"
|
#include "duffle/math.atom.h"
|
||||||
#include "duffle/mips.atom.c"
|
#include "duffle/mips.atom.c"
|
||||||
#include "duffle/gte.atom.h"
|
#include "duffle/gte.atom.c"
|
||||||
#include "duffle/gp.atom.c"
|
#include "duffle/gp.atom.c"
|
||||||
#include "duffle/pad.atom.c"
|
#include "duffle/pad.atom.c"
|
||||||
#include "duffle/psyq.atom.c"
|
#include "duffle/psyq.atom.c"
|
||||||
@@ -93,11 +93,11 @@ extern SMemory smem;
|
|||||||
#define pad0_btn_(btn) btn & smem.pad[0].buttons
|
#define pad0_btn_(btn) btn & smem.pad[0].buttons
|
||||||
#define pad1_btn_(btn) btn & smem.pad[1].buttons
|
#define pad1_btn_(btn) btn & smem.pad[1].buttons
|
||||||
|
|
||||||
I_ B1* prim__alloc(U4 type_width, Str8 type_name) {
|
I_ U1* prim__alloc(U4 type_width, Str8 type_name) {
|
||||||
gknown PrimitiveArena* pa = & smem.primitives;
|
gknown PrimitiveArena* pa = & smem.primitives;
|
||||||
gknown B1* buf = (B1*) r_(smem.primitives.buf)[smem.active_buf_id];
|
gknown U1* buf = (U1*) r_(smem.primitives.buf)[smem.active_buf_id];
|
||||||
assert(pa->used + type_width < PrimitiveBuff_Len);
|
assert(pa->used + type_width < PrimitiveBuff_Len);
|
||||||
B1* next = buf + pa->used;
|
U1* next = buf + pa->used;
|
||||||
pa->used += type_width;
|
pa->used += type_width;
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
@@ -241,26 +241,15 @@ FI_ void camera_look_at(TapeBuilder_R tb, Camera* c, P3_S4* target, V3_S4* up_in
|
|||||||
void update(PrimitiveArena* pa, U4* ordering_buf)
|
void update(PrimitiveArena* pa, U4* ordering_buf)
|
||||||
{
|
{
|
||||||
TapeBuilder tb = tb_make(slice_ut_arr(smem.MemTape));
|
TapeBuilder tb = tb_make(slice_ut_arr(smem.MemTape));
|
||||||
|
/*Pad Input*/ {
|
||||||
// Pad Input
|
|
||||||
{
|
|
||||||
tb.used = 0; tb_scope_run(& tb) {
|
tb.used = 0; tb_scope_run(& tb) {
|
||||||
// Grab latest state from bios.
|
// Grab latest state from bios.
|
||||||
tb_emit_(pad_bios_snapshot);
|
tb_emit_(pad_bios_snapshot);
|
||||||
tb_data(& tb, u4_(& smem.pad_raw[0]));
|
tb_data(& tb, u4_(& smem.pad_raw[0]));
|
||||||
tb_data(& tb, u4_(& smem.pad[0]));
|
tb_data(& tb, u4_(& smem.pad[0]));
|
||||||
// tb_emit_(pad_bios_snapshot);
|
|
||||||
// tb_data_(raw, & smem.pad_raw[1]);
|
|
||||||
// tb_data_(state, & smem.pad[1]);
|
|
||||||
|
|
||||||
tb_emit_(pad_input_cam);
|
tb_emit_(pad_input_cam);
|
||||||
tb_data(& tb, u4_(& smem.pad[0]));
|
tb_data(& tb, u4_(& smem.pad[0]));
|
||||||
tb_data(& tb, u4_(& smem.cam));
|
tb_data(& tb, u4_(& smem.cam));
|
||||||
|
|
||||||
// tb_emit_(pad_input_cube_rotation);
|
|
||||||
// tb_data_(state, & smem.pad[0]);
|
|
||||||
// tb_data_(cube_rot, & smem.cube.rot);
|
|
||||||
// tb_data_(floor_rot, & smem.floor.rot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,33 +287,30 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
|
|||||||
mt3s2s4_rotation (& smem.cube.rot, & smem.tform_world);
|
mt3s2s4_rotation (& smem.cube.rot, & smem.tform_world);
|
||||||
mt3s2s4_translation(& smem.tform_world, & smem.cube.pos);
|
mt3s2s4_translation(& smem.tform_world, & smem.cube.pos);
|
||||||
mt3s2s4_scale (& smem.tform_world, & smem.cube.scale);
|
mt3s2s4_scale (& smem.tform_world, & smem.cube.scale);
|
||||||
|
|
||||||
// Combine world and look_at matrix.
|
// Combine world and look_at matrix.
|
||||||
gte_comp_coord_m3s2(& smem.cam.look_at, & smem.tform_world, & smem.tform_view);
|
gte_comp_coord_m3s2(& smem.cam.look_at, & smem.tform_world, & smem.tform_view);
|
||||||
gte_matrix_set_rotation (& smem.tform_view);
|
gte_matrix_set_rotation (& smem.tform_view);
|
||||||
gte_matrix_set_translation(& smem.tform_view);
|
gte_matrix_set_translation(& smem.tform_view);
|
||||||
|
|
||||||
U4 prim_base = u4_(pa->buf[smem.active_buf_id]);
|
// TODO(Ed): We should do a bounds check beforehand to confirm pa can hold all tris?
|
||||||
U4 prim_cursor = prim_base + pa->used;
|
// The tape atoms in-flight should not need to care.
|
||||||
|
U1* prim_base = u1_r(pa->buf[smem.active_buf_id]);
|
||||||
tb.used = 0; tb_scope(& tb) {
|
U1* prim_cursor = prim_base + pa->used;
|
||||||
tb_emit(& tb, rbind_cube_g4_face);
|
tb.used = 0; tb_scope_run(& tb) {
|
||||||
tb_data(& tb, prim_cursor);
|
tb_emit(& tb, rbind_cube_g4_face); tb_bind_(& tb, Binds_CubeTri,
|
||||||
tb_data(& tb, u4_(smem.cube.faces));
|
.prim_cursor = prim_cursor,
|
||||||
tb_data(& tb, u4_(smem.cube.verts));
|
.face_cursor = smem.cube.faces,
|
||||||
tb_data(& tb, u4_(ordering_buf));
|
.vert_base = smem.cube.verts,
|
||||||
|
.ot_base = ordering_buf,
|
||||||
|
);
|
||||||
for (U4 i = 0; i < Cube_num_faces; i++) {
|
for (U4 i = 0; i < Cube_num_faces; i++) {
|
||||||
// Two triangles per quad face: (x,y,z) and (x,z,w)
|
tb_emit(& tb, cube_g4_face); // Two triangles per quad face: (x,y,z) and (x,z,w)
|
||||||
tb_emit(& tb, cube_g4_face);
|
|
||||||
}
|
}
|
||||||
|
tb_emit(& tb, sync_primitive_arena); tb_bind_(& tb, Binds_SyncPrimitiveArena,
|
||||||
tb_emit(& tb, sync_primitive_arena);
|
.used = & pa->used,
|
||||||
tb_data(& tb, u4_(& pa->used));
|
.cursor = prim_base,
|
||||||
tb_data(& tb, prim_base);
|
);
|
||||||
}
|
}
|
||||||
tape_run(tb_slice(tb));// Fire off the tape (bigger-clobber variant).
|
|
||||||
|
|
||||||
// smem.cube.rot.y += 30;
|
// smem.cube.rot.y += 30;
|
||||||
}
|
}
|
||||||
// Draw floor
|
// Draw floor
|
||||||
@@ -333,40 +319,31 @@ void update(PrimitiveArena* pa, U4* ordering_buf)
|
|||||||
mt3s2s4_rotation (& smem.floor.rot, & smem.tform_world);
|
mt3s2s4_rotation (& smem.floor.rot, & smem.tform_world);
|
||||||
mt3s2s4_translation(& smem.tform_world, & smem.floor.pos);
|
mt3s2s4_translation(& smem.tform_world, & smem.floor.pos);
|
||||||
mt3s2s4_scale (& smem.tform_world, & smem.floor.scale);
|
mt3s2s4_scale (& smem.tform_world, & smem.floor.scale);
|
||||||
|
|
||||||
// Combine world and look_at matrix.
|
// Combine world and look_at matrix.
|
||||||
gte_comp_coord_m3s2(& smem.cam.look_at, & smem.tform_world, & smem.tform_view);
|
gte_comp_coord_m3s2(& smem.cam.look_at, & smem.tform_world, & smem.tform_view);
|
||||||
|
|
||||||
gte_matrix_set_rotation (& smem.tform_view);
|
gte_matrix_set_rotation (& smem.tform_view);
|
||||||
gte_matrix_set_translation(& smem.tform_view);
|
gte_matrix_set_translation(& smem.tform_view);
|
||||||
|
|
||||||
U4 prim_base = u4_(pa->buf[smem.active_buf_id]);
|
|
||||||
U4 prim_cursor = prim_base + pa->used;
|
|
||||||
|
|
||||||
// TODO(Ed): We should do a bounds check beforehand to confirm pa can hold all tris?
|
// TODO(Ed): We should do a bounds check beforehand to confirm pa can hold all tris?
|
||||||
// The tape atoms in-flight should not need to care.
|
// The tape atoms in-flight should not need to care.
|
||||||
|
U1_R prim_base = u1_r(pa->buf[smem.active_buf_id]);
|
||||||
// Prepare the tape. (Push protocol to tape)
|
U1_R prim_cursor = prim_base + pa->used;
|
||||||
tb.used = 0; tb_scope(& tb) {
|
tb.used = 0; tb_scope_run(& tb) { // Prepare the tape. (Push protocol to tape)
|
||||||
// tb_emit(& tb, set_gte_mt3s2s4);
|
tb_emit(& tb, rbind_floor_f3_face); tb_bind_(& tb, Binds_FloorTri,
|
||||||
// tb_data(& tb, u4_(& smem.tform_view));
|
.prim_cursor = prim_cursor,
|
||||||
|
.face_cursor = smem.floor.faces,
|
||||||
tb_emit(& tb, rbind_floor_f3_face);
|
.vert_base = smem.floor.verts,
|
||||||
// TODO(Ed): Just use a single context struct ref?
|
.ot_base = ordering_buf,
|
||||||
tb_data(& tb, prim_cursor);
|
);
|
||||||
tb_data(& tb, u4_(smem.floor.faces));
|
|
||||||
tb_data(& tb, u4_(smem.floor.verts));
|
|
||||||
tb_data(& tb, u4_(ordering_buf));
|
|
||||||
for (U4 i = 0; i < Floor_num_faces; i++) {
|
for (U4 i = 0; i < Floor_num_faces; i++) {
|
||||||
tb_emit(& tb, floor_f3_face);
|
tb_emit(& tb, floor_f3_face);
|
||||||
}
|
}
|
||||||
// After floor_f3_face iterations complete, the primitive arena's used counter needs updating.
|
// After floor_f3_face iterations complete, the primitive arena's used counter needs updating.
|
||||||
tb_emit(& tb, sync_primitive_arena);
|
tb_emit(& tb, sync_primitive_arena); tb_bind_(& tb, Binds_SyncPrimitiveArena,
|
||||||
tb_data(& tb, u4_(& pa->used));
|
.used = & pa->used,
|
||||||
tb_data(& tb, prim_base);
|
.cursor = prim_base,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
tape_run(tb_slice(tb));// Fire off the tape (bigger-clobber variant).
|
|
||||||
|
|
||||||
// C-side state (pa->used) has already been updated by the tape!
|
// C-side state (pa->used) has already been updated by the tape!
|
||||||
// smem.floor.rot.y += 5;
|
// smem.floor.rot.y += 5;
|
||||||
}
|
}
|
||||||
@@ -390,6 +367,19 @@ void gp_display_frame(DoubleBuffer* screen_buf, S4* active_buf_id, U4* ordering_
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
smem = (SMemory){0};
|
smem = (SMemory){0};
|
||||||
|
|
||||||
|
B4 basic_sample = false; if (basic_sample) {
|
||||||
|
// We will be defining the tape here along with its atom, then running the tape after.
|
||||||
|
TapeBuilder tb = tb_make(slice_ut_arr(smem.MemTape));
|
||||||
|
MipsCode add_one_to_R_T1[] = {
|
||||||
|
add_ui_self(R_T1, 1),
|
||||||
|
mac_yield(),
|
||||||
|
};
|
||||||
|
tb_emit(& tb, C_(MipsAtom*, add_one_to_R_T1));
|
||||||
|
Tape tape = tb_end(& tb);
|
||||||
|
tape_run(tape);
|
||||||
|
}
|
||||||
|
|
||||||
// smem.primitives.used = 0;
|
// smem.primitives.used = 0;
|
||||||
// smem.active_buf_id = 0;
|
// smem.active_buf_id = 0;
|
||||||
smem.cam.pos = v3s4(500, -1000, -1500);
|
smem.cam.pos = v3s4(500, -1000, -1500);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ enum {
|
|||||||
typedef U4 OrderingTable_Buffer[OrderingTbl_Len];
|
typedef U4 OrderingTable_Buffer[OrderingTbl_Len];
|
||||||
typedef Array_(OrderingTable_Buffer, 2);
|
typedef Array_(OrderingTable_Buffer, 2);
|
||||||
|
|
||||||
typedef B1 PrimitiveBuffer[PrimitiveBuff_Len];
|
typedef U1 PrimitiveBuffer[PrimitiveBuff_Len];
|
||||||
typedef Array_(PrimitiveBuffer, 2);
|
typedef Array_(PrimitiveBuffer, 2);
|
||||||
typedef Struct_(PrimitiveArena) {
|
typedef Struct_(PrimitiveArena) {
|
||||||
A2_PrimitiveBuffer buf;
|
A2_PrimitiveBuffer buf;
|
||||||
@@ -54,8 +54,8 @@ I_ void ent_cube128_init(A8_V3_S2* verts, A6_V4_S2* faces) {
|
|||||||
{ 2, 3, 6, 7 },
|
{ 2, 3, 6, 7 },
|
||||||
{ 3, 0, 7, 4 },
|
{ 3, 0, 7, 4 },
|
||||||
};
|
};
|
||||||
mem_copy(u4_(verts), u4_(& baked_verts), S_(A8_V3_S2) );
|
mem_copy(b1_r(verts), b1_r(& baked_verts), S_(A8_V3_S2) );
|
||||||
mem_copy(u4_(faces), u4_(& baked_faces), S_(A6_V4_S2) );
|
mem_copy(b1_r(faces), b1_r(& baked_faces), S_(A6_V4_S2) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
typedef Struct_(Ent_Cube) {
|
typedef Struct_(Ent_Cube) {
|
||||||
@@ -83,8 +83,8 @@ I_ void ent_floor_init(A4_V3_S2* verts, A2_V3_S2* faces) {
|
|||||||
{ 0, 1, 2 },
|
{ 0, 1, 2 },
|
||||||
{ 1, 3, 2 },
|
{ 1, 3, 2 },
|
||||||
};
|
};
|
||||||
mem_copy(u4_(verts), u4_(& baked_verts), S_(A4_V3_S2));
|
mem_copy(b1_r(verts), b1_r(& baked_verts), S_(A4_V3_S2));
|
||||||
mem_copy(u4_(faces), u4_(& baked_faces), S_(A2_V3_S2));
|
mem_copy(b1_r(faces), b1_r(& baked_faces), S_(A2_V3_S2));
|
||||||
};
|
};
|
||||||
typedef Struct_(Ent_Floor) {
|
typedef Struct_(Ent_Floor) {
|
||||||
V3_S4 accel;
|
V3_S4 accel;
|
||||||
|
|||||||
Reference in New Issue
Block a user