mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-22 14:33:51 +00:00
verilog: made $readmem a lot faster
This commit is contained in:
parent
5c98c2eb7d
commit
eff53c0d92
@ -3,9 +3,9 @@
|
||||
import { Platform, BasePlatform } from "../baseplatform";
|
||||
import { PLATFORMS, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, getMousePos, KeyFlags } from "../emu";
|
||||
import { SampleAudio } from "../audio";
|
||||
import { safe_extend, clamp } from "../util";
|
||||
import { safe_extend, clamp, byteArrayToString } from "../util";
|
||||
import { WaveformView, WaveformProvider, WaveformMeta } from "../waveform";
|
||||
import { setFrameRateUI } from "../ui";
|
||||
import { setFrameRateUI, current_project } from "../ui";
|
||||
|
||||
declare var Split;
|
||||
|
||||
@ -67,7 +67,7 @@ export var vl_finished = false;
|
||||
export var vl_stopped = false;
|
||||
|
||||
export function VL_UL(x) { return x|0; }
|
||||
export function VL_ULL(x) { return x|0; }
|
||||
//export function VL_ULL(x) { return x|0; }
|
||||
export function VL_TIME_Q() { return (new Date().getTime())|0; }
|
||||
|
||||
/// Return true if data[bit] set
|
||||
@ -121,9 +121,32 @@ export function VL_RAND_RESET_I(bits) { return 0 | Math.floor(Math.random() * (1
|
||||
|
||||
export function VL_RANDOM_I(bits) { return 0 | Math.floor(Math.random() * (1<<bits)); }
|
||||
|
||||
//export function VL_READMEM_Q(hex,width,depth,array_lsb,fnwords,filename,memp,start,end) {
|
||||
//console.log(hex,width,depth,array_lsb,fnwords,filename,memp,start,end);
|
||||
//}
|
||||
export function VL_READMEM_Q(ishex,width,depth,array_lsb,fnwords,filename,memp,start,end) {
|
||||
VL_READMEM_W(ishex,width,depth,array_lsb,fnwords,filename,memp,start,end);
|
||||
}
|
||||
export function VL_READMEM_W(ishex,width,depth,array_lsb,fnwords,filename,memp,start,end) {
|
||||
// parse filename from 32-bit values into characters
|
||||
var barr = [];
|
||||
for (var i=0; i<filename.length; i++) {
|
||||
barr.push((filename[i] >> 0) & 0xff);
|
||||
barr.push((filename[i] >> 8) & 0xff);
|
||||
barr.push((filename[i] >> 16) & 0xff);
|
||||
barr.push((filename[i] >> 24) & 0xff);
|
||||
}
|
||||
barr = barr.filter(x => x != 0); // ignore zeros
|
||||
barr.reverse(); // reverse it
|
||||
var strfn = byteArrayToString(barr); // convert to string
|
||||
// parse hex/binary file
|
||||
var strdata = current_project.getFile(strfn) as string;
|
||||
if (strdata == null) throw "Could not $readmem '" + strfn + "'";
|
||||
var data = strdata.split('\n').filter(s => s !== '').map(s => parseInt(s, ishex ? 16 : 2));
|
||||
console.log('$readmem', ishex, strfn, data.length);
|
||||
// copy into destination array
|
||||
if (memp === null) throw "No destination array to $readmem " + strfn;
|
||||
if (memp.length < data.length) throw "Destination array too small to $readmem " + strfn;
|
||||
for (i=0; i<data.length; i++)
|
||||
memp[i] = data[i];
|
||||
}
|
||||
|
||||
// SIMULATOR BASE
|
||||
|
||||
|
@ -128,6 +128,10 @@ function translateFunction(text : string) : string {
|
||||
text = text.replace(/^#/gm, '//#');
|
||||
text = text.replace(/VL_LIKELY/g, '!!');
|
||||
text = text.replace(/VL_UNLIKELY/g, '!!');
|
||||
// for memread
|
||||
text = text.replace(/VL_SIGW[(](\w+),(\d+),(\d+),(\d+)[)]/g, 'var $1 = new Uint32Array($4)');
|
||||
// convert VL_ULL() 64-bits into an array of two 32-bits
|
||||
text = text.replace(/VL_ULL[(]0x([0-9a-f]+?)([0-9a-f]{8})[)]/g, '[0x$2, 0x$1]');
|
||||
//[%0t] %Error: scoreboard.v:53: Assertion failed in %Nscoreboard_top.scoreboard_gen: reset 64 -935359306 Vscoreboard_top
|
||||
text = text.replace(/Verilated::(\w+)Error/g, 'console.log');
|
||||
text = text.replace(/vlSymsp.name[(][)]/g, '"'+moduleName+'"');
|
||||
|
@ -1563,28 +1563,6 @@ function compileInlineASM(code:string, platform, options, errors, asmlines) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// convert $readmem(bh) to array assigns
|
||||
function compileReadmemStmts(code, errors) {
|
||||
var re3 = /\$readmem([bh])\("(.+?)",\s*(\w+)\)/gmi;
|
||||
return code.replace(re3, function(_s,type,path,mem,index) {
|
||||
var datafile = getWorkFileAsString(path);
|
||||
if (datafile) {
|
||||
var lines = datafile.split('\n');
|
||||
var out = '';
|
||||
for (var i=0; i<lines.length; i++) {
|
||||
var line = lines[i].trim();
|
||||
if (line !== '') {
|
||||
out += mem + '[' + i + ']=\'' + type + line + ';'
|
||||
}
|
||||
}
|
||||
return out;
|
||||
} else {
|
||||
errors.push({line:0, msg:"Could not load $readmem file '"+path+'"'});
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function compileVerilator(step:BuildStep) {
|
||||
loadNative("verilator_bin");
|
||||
loadGen("worker/verilator2js");
|
||||
@ -1610,7 +1588,6 @@ function compileVerilator(step:BuildStep) {
|
||||
populateFiles(step, FS, {
|
||||
mainFilePath:step.path,
|
||||
processFn:(code) => {
|
||||
code = compileReadmemStmts(code, errors);
|
||||
code = compileInlineASM(code, platform, step, errors, asmlines);
|
||||
return code;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user