add math gates, fix 32-bit shifters

This commit is contained in:
Redo
2025-02-19 10:15:56 -07:00
parent a571ac5f3c
commit 68562d4d66
11 changed files with 20291 additions and 20082 deletions

View File

@@ -80,12 +80,36 @@ enum GateFuncs {
GateFunc_Demux6,
GateFunc_Demux7,
GateFunc_Demux8,
GateFunc_Adder1,
GateFunc_Adder2,
GateFunc_Adder4,
GateFunc_Adder8,
GateFunc_Adder16,
GateFunc_Adder32,
GateFunc_Incrementer2,
GateFunc_Incrementer4,
GateFunc_Incrementer8,
GateFunc_Incrementer16,
GateFunc_Incrementer32,
GateFunc_Multiplier2,
GateFunc_Multiplier4,
GateFunc_Multiplier8,
GateFunc_Multiplier16,
GateFunc_Multiplier32,
GateFunc_Divider2,
GateFunc_Divider4,
GateFunc_Divider8,
GateFunc_Divider16,
GateFunc_Divider32,
GateFunc_ShifterLeft2,
GateFunc_ShifterLeft4,
GateFunc_ShifterLeft8,
GateFunc_ShifterLeft16,
GateFunc_ShifterLeft32,
GateFunc_ShifterRight2,
GateFunc_ShifterRight4,
GateFunc_ShifterRight8,
GateFunc_ShifterRight16,
GateFunc_ShifterRight32,
GateFunc_And2,
GateFunc_And3,
GateFunc_And4,
@@ -249,12 +273,36 @@ GATEFUNC(Demux5) { int pa = getdata(0); if(getport(38)) { int a = getword(5, 1)
GATEFUNC(Demux6) { int pa = getdata(0); if(getport(71)) { int a = getword(6, 1) + 7; if(pa != a) { if(pa) { setport(pa, 0); } setport(a, 1); setdata(0, a); } } else { if(pa) { setport(pa, 0); setdata(0, 0); } } }
GATEFUNC(Demux7) { int pa = getdata(0); if(getport(136)) { int a = getword(7, 1) + 8; if(pa != a) { if(pa) { setport(pa, 0); } setport(a, 1); setdata(0, a); } } else { if(pa) { setport(pa, 0); setdata(0, 0); } } }
GATEFUNC(Demux8) { int pa = getdata(0); if(getport(265)) { int a = getword(8, 1) + 9; if(pa != a) { if(pa) { setport(pa, 0); } setport(a, 1); setdata(0, a); } } else { if(pa) { setport(pa, 0); setdata(0, 0); } } }
GATEFUNC(Adder1) { int v = getword(1, 1) + getword(1, 2) + getport(4); setword(1, 3, v); setport(5, (v>>1) & 1); }
GATEFUNC(Adder2) { int v = getword(2, 1) + getword(2, 3) + getport(7); setword(2, 5, v); setport(8, (v>>2) & 1); }
GATEFUNC(Adder4) { int v = getword(4, 1) + getword(4, 5) + getport(13); setword(4, 9, v); setport(14, (v>>4) & 1); }
GATEFUNC(Adder8) { int v = getword(8, 1) + getword(8, 9) + getport(25); setword(8, 17, v); setport(26, (v>>8) & 1); }
GATEFUNC(Adder16) { int v = getword(16, 1) + getword(16, 17) + getport(49); setword(16, 33, v); setport(50, (v>>16) & 1); }
GATEFUNC(Adder32) { unsigned long long v = getword(32, 1) + getword(32, 33) + getport(97); setword(32, 65, v); setport(98, (v>>32) & 1); }
GATEFUNC(Adder2) { unsigned int v = getword(2, 1) + (getword(2, 3)^(getport(9)*3)) + getport(7); setword(2, 5, v); setport(8, (v>>2) & 1); }
GATEFUNC(Adder4) { unsigned int v = getword(4, 1) + (getword(4, 5)^(getport(15)*15)) + getport(13); setword(4, 9, v); setport(14, (v>>4) & 1); }
GATEFUNC(Adder8) { unsigned int v = getword(8, 1) + (getword(8, 9)^(getport(27)*255)) + getport(25); setword(8, 17, v); setport(26, (v>>8) & 1); }
GATEFUNC(Adder16) { unsigned int v = getword(16, 1) + (getword(16, 17)^(getport(51)*65535)) + getport(49); setword(16, 33, v); setport(50, (v>>16) & 1); }
GATEFUNC(Adder32) { unsigned long long v = (unsigned long long)getword(32, 1) + (unsigned long long)(getword(32, 33)^(getport(99)*4294967295)) + (unsigned long long)getport(97); setword(32, 65, v); setport(98, (v>>32ull) & 1); }
GATEFUNC(Incrementer2) { unsigned int a = (getword(2, 1)^(getport(8)*3)) + getport(5) + (getport(6)*3); setword(2, 3, a); setport(7, (a>>2) & 1); }
GATEFUNC(Incrementer4) { unsigned int a = (getword(4, 1)^(getport(12)*15)) + getport(9) + (getport(10)*15); setword(4, 5, a); setport(11, (a>>4) & 1); }
GATEFUNC(Incrementer8) { unsigned int a = (getword(8, 1)^(getport(20)*255)) + getport(17) + (getport(18)*255); setword(8, 9, a); setport(19, (a>>8) & 1); }
GATEFUNC(Incrementer16) { unsigned int a = (getword(16, 1)^(getport(36)*65535)) + getport(33) + (getport(34)*65535); setword(16, 17, a); setport(35, (a>>16) & 1); }
GATEFUNC(Incrementer32) { unsigned long long a = (unsigned long long)(getword(32, 1)^(getport(68)*4294967295)) + (unsigned long long)getport(65) + (unsigned long long)(getport(66)*4294967295); setword(32, 33, a); setport(67, (a>>32ull) & 1); }
GATEFUNC(Multiplier2) { setword(4, 5, getword(2, 1) * getword(2, 3)); }
GATEFUNC(Multiplier4) { setword(8, 9, getword(4, 1) * getword(4, 5)); }
GATEFUNC(Multiplier8) { setword(16, 17, getword(8, 1) * getword(8, 9)); }
GATEFUNC(Multiplier16) { setword(32, 33, getword(16, 1) * getword(16, 17)); }
GATEFUNC(Multiplier32) { setword64(64, 65, (unsigned long long)getword(32, 1) * (unsigned long long)getword(32, 33)); }
GATEFUNC(Divider2) { unsigned int a = getword(2, 1); unsigned int b = getword(2, 3); setword(2, 5, b!=0 ? a/b : 0); setword(2, 7, b!=0 ? a%b : 0); }
GATEFUNC(Divider4) { unsigned int a = getword(4, 1); unsigned int b = getword(4, 5); setword(4, 9, b!=0 ? a/b : 0); setword(4, 13, b!=0 ? a%b : 0); }
GATEFUNC(Divider8) { unsigned int a = getword(8, 1); unsigned int b = getword(8, 9); setword(8, 17, b!=0 ? a/b : 0); setword(8, 25, b!=0 ? a%b : 0); }
GATEFUNC(Divider16) { unsigned int a = getword(16, 1); unsigned int b = getword(16, 17); setword(16, 33, b!=0 ? a/b : 0); setword(16, 49, b!=0 ? a%b : 0); }
GATEFUNC(Divider32) { unsigned int a = getword(32, 1); unsigned int b = getword(32, 33); setword(32, 65, b!=0 ? a/b : 0); setword(32, 97, b!=0 ? a%b : 0); }
GATEFUNC(ShifterLeft2) { int dist = getword(1, 7); setword(4, 3, ((getword(2, 1))<<dist) | (getport(8) ? (3>>(2-dist)) : 0)); }
GATEFUNC(ShifterLeft4) { int dist = getword(2, 13); setword(8, 5, ((getword(4, 1))<<dist) | (getport(15) ? (15>>(4-dist)) : 0)); }
GATEFUNC(ShifterLeft8) { int dist = getword(3, 25); setword(16, 9, ((getword(8, 1))<<dist) | (getport(28) ? (255>>(8-dist)) : 0)); }
GATEFUNC(ShifterLeft16) { int dist = getword(4, 49); setword(32, 17, ((getword(16, 1))<<dist) | (getport(53) ? (65535>>(16-dist)) : 0)); }
GATEFUNC(ShifterLeft32) { int dist = getword(5, 97); setword64(64, 33, (((unsigned long long)getword(32, 1))<<dist) | (getport(102) ? (4294967295ull>>(32-dist)) : 0ull)); }
GATEFUNC(ShifterRight2) { int dist = getword(1, 7); setword(4, 3, ((getword(2, 1))<<(2-dist)) | (getport(8) ? (3<<(4-dist)) : 0)); }
GATEFUNC(ShifterRight4) { int dist = getword(2, 13); setword(8, 5, ((getword(4, 1))<<(4-dist)) | (getport(15) ? (15<<(8-dist)) : 0)); }
GATEFUNC(ShifterRight8) { int dist = getword(3, 25); setword(16, 9, ((getword(8, 1))<<(8-dist)) | (getport(28) ? (255<<(16-dist)) : 0)); }
GATEFUNC(ShifterRight16) { int dist = getword(4, 49); setword(32, 17, ((getword(16, 1))<<(16-dist)) | (dist!=0 && getport(53) ? (65535<<(32-dist)) : 0)); }
GATEFUNC(ShifterRight32) { int dist = getword(5, 97); setword64(64, 33, (((unsigned long long)getword(32, 1))<<(32-dist)) | (dist!=0 && getport(102) ? (4294967295ull<<(64-dist)) : 0ull)); }
GATEFUNC(And2) { setport(3, (getport(1) && getport(2))); }
GATEFUNC(And3) { setport(4, (getport(1) && getport(2) && getport(3))); }
GATEFUNC(And4) { setport(5, (getport(1) && getport(2) && getport(3) && getport(4))); }
@@ -419,12 +467,36 @@ GateFunc sim_logic_functions[] = {
GATEFUNCID(Demux6),
GATEFUNCID(Demux7),
GATEFUNCID(Demux8),
GATEFUNCID(Adder1),
GATEFUNCID(Adder2),
GATEFUNCID(Adder4),
GATEFUNCID(Adder8),
GATEFUNCID(Adder16),
GATEFUNCID(Adder32),
GATEFUNCID(Incrementer2),
GATEFUNCID(Incrementer4),
GATEFUNCID(Incrementer8),
GATEFUNCID(Incrementer16),
GATEFUNCID(Incrementer32),
GATEFUNCID(Multiplier2),
GATEFUNCID(Multiplier4),
GATEFUNCID(Multiplier8),
GATEFUNCID(Multiplier16),
GATEFUNCID(Multiplier32),
GATEFUNCID(Divider2),
GATEFUNCID(Divider4),
GATEFUNCID(Divider8),
GATEFUNCID(Divider16),
GATEFUNCID(Divider32),
GATEFUNCID(ShifterLeft2),
GATEFUNCID(ShifterLeft4),
GATEFUNCID(ShifterLeft8),
GATEFUNCID(ShifterLeft16),
GATEFUNCID(ShifterLeft32),
GATEFUNCID(ShifterRight2),
GATEFUNCID(ShifterRight4),
GATEFUNCID(ShifterRight8),
GATEFUNCID(ShifterRight16),
GATEFUNCID(ShifterRight32),
GATEFUNCID(And2),
GATEFUNCID(And3),
GATEFUNCID(And4),