Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Speed up uncompiled code by "IFDEF'ing" disabled code, rare asserts, …
Browse files Browse the repository at this point in the history
…etc.
  • Loading branch information
jeffpar committed Jul 18, 2015
1 parent 5e0d356 commit 5b160ac
Show file tree
Hide file tree
Showing 13 changed files with 796 additions and 777 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ module.exports = function(grunt) {
banner: '"use strict";\n\n',
process: function(src, filepath) {
return "// " + filepath + "\n\n" +
src.replace(/(^|\n)[ \t]*(['"])use strict\2;?\s*/g, '$1').replace(/[ \t]*if\s*\(typeof\s+(module|APP_PCJS)\s*!==\s*(['"])undefined\2\)\s*(\{[^}]*}|[^\n]*)(\n|$)/gm, '').replace(/[ \t]*[A-Za-z_][A-Za-z0-9_\.]*\.assert\(.*\);[^\n]*(\n|$)/g, '');
src.replace(/(^|\n)[ \t]*(['"])use strict\2;?\s*/g, '$1').replace(/[ \t]*if\s*\(typeof\s+(module|APP_PCJS)\s*!==\s*(['"])undefined\2\)\s*(\{[^}]*}|[^\n]*)(\n|$)/gm, '').replace(/[ \t]*[A-Za-z_][A-Za-z0-9_\.]*\.assert\([^\n]*\);[^\n]*/g, '');
}
}
},
Expand All @@ -182,7 +182,7 @@ module.exports = function(grunt) {
banner: '"use strict";\n\n',
process: function(src, filepath) {
return "// " + filepath + "\n\n" +
src.replace(/(^|\n)[ \t]*(['"])use strict\2;?\s*/g, '$1').replace(/[ \t]*if\s*\(typeof\s+(module|APP_PCJS)\s*!==\s*(['"])undefined\2\)\s*(\{[^}]*}|[^\n]*)(\n|$)/gm, '').replace(/[ \t]*[A-Za-z_][A-Za-z0-9_\.]*\.assert\(.*\);[^\n]*(\n|$)/g, '');
src.replace(/(^|\n)[ \t]*(['"])use strict\2;?\s*/g, '$1').replace(/[ \t]*if\s*\(typeof\s+(module|APP_PCJS)\s*!==\s*(['"])undefined\2\)\s*(\{[^}]*}|[^\n]*)(\n|$)/gm, '').replace(/[ \t]*[A-Za-z_][A-Za-z0-9_\.]*\.assert\([^\n]*\);[^\n]*/g, '');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion blog/2015/07/17/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ NOTE: This is a pre-release version of Windows 95, as I don't currently have the

To be continued....

[Embedded DeskPro 386](/devices/pc/machine/compaq/deskpro386/vga/4096kb/machine.xml "PCjs:deskpro386-vga-4096k:::debugger")
[Embedded DeskPro 386](/devices/pc/machine/compaq/deskpro386/vga/4096kb/machine.xml "PCjs:deskpro386-vga-4096k::uncompiled:debugger")

*[@jeffpar](http://twitter.com/jeffpar)*
*July 17, 2015*
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<rom id="romBIOS" addr="0xf8000" size="0x8000" alias="[0xf0000,0xffff0000,0xffff8000]" file="/devices/pc/bios/compaq/deskpro386/1988-01-28/1988-01-28.json"/>
<video ref="/devices/pc/video/ibm/vga/ibm-vga-lockfs.xml"/>
<keyboard id="keyboard"/>
<debugger id="debugger" messages="fault|int" commands=""/>
<debugger id="debugger" messages="fault" commands=""/>
<panel ref="/devices/pc/panel/wide386.xml"/>
<fdc ref="/disks/pc/library.xml" automount='{B: {name: "Win95 Build 499 (Disk 1)", path: "/disks/pc/windows/win95/build499/WIN95-DISK01.json"}}'/>
<hdc id="hdcAT" type="at" drives='[{name:"68Mb Hard Disk",type:4,path:"/devices/pc/machine/compaq/deskpro386/vga/4096kb/68mb.json"}]'/>
Expand Down
2 changes: 1 addition & 1 deletion docs/pcjs/demos/components.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<xsl:variable name="MACHINECLASS">pc</xsl:variable>
<xsl:variable name="APPCLASS">pcjs</xsl:variable>
<xsl:variable name="APPVERSION">1.18.4</xsl:variable>
<xsl:variable name="APPVERSION">1.18.5</xsl:variable>
<xsl:variable name="SITEHOST">www.pcjs.org</xsl:variable>

<xsl:template name="componentStyles">
Expand Down
368 changes: 184 additions & 184 deletions docs/pcjs/demos/pc-dbg.js

Large diffs are not rendered by default.

370 changes: 185 additions & 185 deletions docs/pcjs/demos/pc.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions modules/pcjs/lib/chipset.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ ChipSet.prototype.updateRTCTime = function()
* Step 3: Update the RTC date/time and deal with Update Interrupts
*/
var nCyclesDelta = nCyclesUpdate - this.nRTCCyclesLastUpdate;
this.assert(nCyclesDelta >= 0);
// DEBUG: this.assert(nCyclesDelta >= 0);
var nSecondsDelta = Math.floor(nCyclesDelta / nCyclesPerSecond);

/*
Expand All @@ -1546,7 +1546,7 @@ ChipSet.prototype.updateRTCTime = function()
* (nCyclesDelta % nCyclesPerSecond) back into nRTCCyclesLastUpdate, so that we will eventually
* see a one-second delta.
*/
this.assert(nSecondsDelta <= 1);
// DEBUG: this.assert(nSecondsDelta <= 1);

/*
* Make sure that CMOS.STATUSB.SET isn't set; if it is, then the once-per-second RTC updates must be
Expand Down Expand Up @@ -3673,11 +3673,11 @@ ChipSet.prototype.getTimerCycleLimit = function(iTimer, nCycles)
if (timer.fCounting) {
var nCyclesUpdate = this.cpu.getCycles(this.fScaleTimers);
var ticksElapsed = ((nCyclesUpdate - timer.nCyclesStart) / this.nTicksDivisor) | 0;
this.assert(ticksElapsed >= 0);
// DEBUG: this.assert(ticksElapsed >= 0);
var countStart = this.getTimerStart(iTimer);
var count = countStart - ticksElapsed;
if (timer.mode == ChipSet.PIT_CTRL.MODE3) count -= ticksElapsed;
this.assert(count > 0);
// DEBUG: this.assert(count > 0);
var nCyclesRemain = (count * this.nTicksDivisor) | 0;
if (timer.mode == ChipSet.PIT_CTRL.MODE3) nCyclesRemain >>= 1;
if (nCycles > nCyclesRemain) nCycles = nCyclesRemain;
Expand Down
2 changes: 1 addition & 1 deletion modules/pcjs/lib/defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var TYPEDARRAYS = (typeof ArrayBuffer !== 'undefined');
* we'll have to rethink that choice OR provide a Debugger command that dynamically enables/disables as much of
* the backtracking support as possible.
*/
var BACKTRACK = !COMPILED;
var BACKTRACK = false; // !COMPILED;

/**
* @define {boolean}
Expand Down
45 changes: 23 additions & 22 deletions modules/pcjs/lib/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ Memory.prototype = {
* memory blocks installed at the programmed address, and so we arrived here at a block with
* no controller AND no data.
*/
Component.assert(adw != null);
// DEBUG: Component.assert(adw != null);

if (adw && this.size == adw.length << 2) {
var i;
if (FATARRAYS) {
Expand Down Expand Up @@ -635,7 +636,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeShortDefault: function writeShortDefault(off, w, addr) {
Component.assert(!(w & ~0xffff));
// DEBUG: Component.assert(!(w & ~0xffff));
this.writeByte(off, w & 0xff, addr);
this.writeByte(off + 1, w >> 8, addr);
},
Expand All @@ -662,7 +663,7 @@ Memory.prototype = {
* @return {number}
*/
readByteMemory: function readByteMemory(off, addr) {
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
if (FATARRAYS) {
return this.ab[off];
}
Expand All @@ -677,7 +678,7 @@ Memory.prototype = {
* @return {number}
*/
readShortMemory: function readShortMemory(off, addr) {
Component.assert(off >= 0 && off < this.size - 1);
// DEBUG: Component.assert(off >= 0 && off < this.size - 1);
if (FATARRAYS) {
return this.ab[off] | (this.ab[off + 1] << 8);
}
Expand All @@ -701,7 +702,7 @@ Memory.prototype = {
* @return {number}
*/
readLongMemory: function readLongMemory(off, addr) {
Component.assert(off >= 0 && off < this.size - 3);
// DEBUG: Component.assert(off >= 0 && off < this.size - 3);
if (FATARRAYS) {
return this.ab[off] | (this.ab[off + 1] << 8) | (this.ab[off + 2] << 16) | (this.ab[off + 3] << 24);
}
Expand All @@ -723,7 +724,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeByteMemory: function writeByteMemory(off, b, addr) {
Component.assert(off >= 0 && off < this.size && (b & 0xff) == b);
// DEBUG: Component.assert(off >= 0 && off < this.size && (b & 0xff) == b);
if (FATARRAYS) {
this.ab[off] = b;
} else {
Expand All @@ -742,7 +743,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeShortMemory: function writeShortMemory(off, w, addr) {
Component.assert(off >= 0 && off < this.size - 1 && (w & 0xffff) == w);
// DEBUG: Component.assert(off >= 0 && off < this.size - 1 && (w & 0xffff) == w);
if (FATARRAYS) {
this.ab[off] = (w & 0xff);
this.ab[off + 1] = (w >> 8);
Expand All @@ -768,7 +769,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeLongMemory: function writeLongMemory(off, l, addr) {
Component.assert(off >= 0 && off < this.size - 3);
// DEBUG: Component.assert(off >= 0 && off < this.size - 3);
if (FATARRAYS) {
this.ab[off] = (l & 0xff);
this.ab[off + 1] = (l >> 8) & 0xff;
Expand Down Expand Up @@ -1029,7 +1030,7 @@ Memory.prototype = {
* @return {number}
*/
readByteBigEndian: function readByteBigEndian(off, addr) {
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
return this.ab[off];
},
/**
Expand All @@ -1041,7 +1042,7 @@ Memory.prototype = {
* @return {number}
*/
readByteLittleEndian: function readByteLittleEndian(off, addr) {
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
return this.ab[off];
},
/**
Expand All @@ -1053,7 +1054,7 @@ Memory.prototype = {
* @return {number}
*/
readShortBigEndian: function readShortBigEndian(off, addr) {
Component.assert(off >= 0 && off < this.size - 1);
// DEBUG: Component.assert(off >= 0 && off < this.size - 1);
return this.dv.getUint16(off, true);
},
/**
Expand All @@ -1065,7 +1066,7 @@ Memory.prototype = {
* @return {number}
*/
readShortLittleEndian: function readShortLittleEndian(off, addr) {
Component.assert(off >= 0 && off < this.size - 1);
// DEBUG: Component.assert(off >= 0 && off < this.size - 1);
/*
* TODO: It remains to be seen if there's any advantage to checking the offset
* for an aligned read vs. always reading the bytes separately; it seems a safe bet
Expand All @@ -1082,7 +1083,7 @@ Memory.prototype = {
* @return {number}
*/
readLongBigEndian: function readLongBigEndian(off, addr) {
Component.assert(off >= 0 && off < this.size - 3);
// DEBUG: Component.assert(off >= 0 && off < this.size - 3);
return this.dv.getInt32(off, true);
},
/**
Expand All @@ -1094,7 +1095,7 @@ Memory.prototype = {
* @return {number}
*/
readLongLittleEndian: function readLongLittleEndian(off, addr) {
Component.assert(off >= 0 && off < this.size - 3);
// DEBUG: Component.assert(off >= 0 && off < this.size - 3);
/*
* TODO: It remains to be seen if there's any advantage to checking the offset
* for an aligned read vs. always reading the bytes separately; it seems a safe bet
Expand All @@ -1111,7 +1112,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeByteBigEndian: function writeByteBigEndian(off, b, addr) {
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
this.ab[off] = b;
this.fDirty = true;
},
Expand All @@ -1124,7 +1125,7 @@ Memory.prototype = {
* @param {number} b
*/
writeByteLittleEndian: function writeByteLittleEndian(off, b, addr) {
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
this.ab[off] = b;
this.fDirty = true;
},
Expand All @@ -1137,7 +1138,7 @@ Memory.prototype = {
* @param {number} w
*/
writeShortBigEndian: function writeShortBigEndian(off, w, addr) {
Component.assert(off >= 0 && off < this.size - 1);
// DEBUG: Component.assert(off >= 0 && off < this.size - 1);
this.dv.setUint16(off, w, true);
this.fDirty = true;
},
Expand All @@ -1150,7 +1151,7 @@ Memory.prototype = {
* @param {number} w
*/
writeShortLittleEndian: function writeShortLittleEndian(off, w, addr) {
Component.assert(off >= 0 && off < this.size - 1);
// DEBUG: Component.assert(off >= 0 && off < this.size - 1);
/*
* TODO: It remains to be seen if there's any advantage to checking the offset
* for an aligned write vs. always writing the bytes separately; it seems a safe bet
Expand All @@ -1173,7 +1174,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeLongBigEndian: function writeLongBigEndian(off, l, addr) {
Component.assert(off >= 0 && off < this.size - 3);
// DEBUG: Component.assert(off >= 0 && off < this.size - 3);
this.dv.setInt32(off, l, true);
this.fDirty = true;
},
Expand All @@ -1186,7 +1187,7 @@ Memory.prototype = {
* @param {number} addr
*/
writeLongLittleEndian: function writeLongLittleEndian(off, l, addr) {
Component.assert(off >= 0 && off < this.size - 3);
// DEBUG: Component.assert(off >= 0 && off < this.size - 3);
/*
* TODO: It remains to be seen if there's any advantage to checking the offset
* for an aligned write vs. always writing the bytes separately; it seems a safe bet
Expand Down Expand Up @@ -1238,7 +1239,7 @@ Memory.prototype = {
* @return {number}
*/
readBackTrackIndex: function readBackTrackIndex(off) {
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
return this.abtIndexes[off];
},
/**
Expand All @@ -1251,7 +1252,7 @@ Memory.prototype = {
*/
writeBackTrackIndex: function writeBackTrackIndex(off, bti) {
var btiPrev;
Component.assert(off >= 0 && off < this.size);
// DEBUG: Component.assert(off >= 0 && off < this.size);
btiPrev = this.abtIndexes[off];
this.abtIndexes[off] = bti;
return btiPrev;
Expand Down
27 changes: 21 additions & 6 deletions modules/pcjs/lib/x86cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,8 @@ X86CPU.prototype.setCSBase = function(addr)
*/
X86CPU.prototype.advanceIP = function(inc)
{
this.assert(inc > 0);
// DEBUG: this.assert(inc > 0);

this.regLIP = (this.regLIP + inc)|0;
/*
* Properly comparing regLIP to regLIPLimit would normally require coercing both to unsigned
Expand Down Expand Up @@ -2109,7 +2110,8 @@ X86CPU.prototype.advanceIP = function(inc)
*/
X86CPU.prototype.rewindIP = function(dec)
{
this.assert(dec < 0);
// DEBUG: this.assert(dec < 0);

this.regLIP = (this.regLIP + dec)|0;
/*
* Since rewindIP() is used only for discrete "intra-instruction" IP adjustments, there should be no need
Expand Down Expand Up @@ -3683,7 +3685,8 @@ X86CPU.prototype.pushWord = function(w)
*/
X86CPU.prototype.checkINTR = function()
{
this.assert(this.intFlags);
// DEBUG: this.assert(this.intFlags);

if (!(this.opFlags & X86.OPFLAG.NOINTR)) {
/*
* As discussed above, the 8086/8088 give hardware interrupts higher priority than the TRAP interrupt,
Expand Down Expand Up @@ -4003,6 +4006,9 @@ X86CPU.prototype.stepCPU = function(nMinCycles)
nDebugState = 1;
}

/*
* SAMPLER:
*
if (SAMPLER) {
if (++this.iSampleFreq >= this.nSampleFreq) {
this.iSampleFreq = 0;
Expand All @@ -4029,16 +4035,24 @@ X86CPU.prototype.stepCPU = function(nMinCycles)
}
}
}
*/

this.opFlags = 0;

/*
* DEBUG || PREFETCH:
*
if (DEBUG || PREFETCH) {
this.nBusCycles = 0;
this.nSnapCycles = this.nStepCycles;
}
*/

this.aOps[this.getIPByte()].call(this);

/*
* DEBUG || PREFETCH:
*
if (PREFETCH) {
var nSpareCycles = (this.nSnapCycles - this.nStepCycles) - this.nBusCycles;
if (nSpareCycles >= 4) {
Expand All @@ -4047,16 +4061,17 @@ X86CPU.prototype.stepCPU = function(nMinCycles)
}
if (DEBUG) {
/*
* Make sure that every instruction is assessing a cycle cost, and that the cost is a net positive.
*/
//
// Make sure that every instruction is assessing a cycle cost, and that the cost is a net positive.
//
if (this.aFlags.fComplete && this.nStepCycles >= this.nSnapCycles && !(this.opFlags & X86.OPFLAG_PREFIXES)) {
this.println("cycle miscount: " + (this.nSnapCycles - this.nStepCycles));
this.setIP(this.opLIP - this.segCS.base);
this.stopCPU();
break;
}
}
*/

} while (this.nStepCycles > 0);

Expand Down
5 changes: 4 additions & 1 deletion modules/pcjs/lib/x86func.js
Original file line number Diff line number Diff line change
Expand Up @@ -3723,8 +3723,11 @@ X86.fnFaultMessage = function(nFault, nError, fHalt)
/*
* However, the foregoing notwithstanding, if MESSAGE.HALT is enabled along with all the other required
* MESSAGE bits, then we want to halt regardless.
*
* TODO: Eventually remove the code below that halts on all MODEL_80386 GP_FAULTs; this is just to make it
* easier to catch bad faults on DeskPro 386 configurations.
*/
if (DEBUG && nFault == X86.EXCEPTION.GP_FAULT || this.messageEnabled(bitsMessage | Messages.HALT)) {
if (DEBUGGER && this.model == X86.MODEL_80386 && nFault == X86.EXCEPTION.GP_FAULT || this.messageEnabled(bitsMessage | Messages.HALT)) {
fHalt = true;
}

Expand Down
Loading

0 comments on commit 5b160ac

Please sign in to comment.