if SootB? is also SHORT, i guess we really should find a way to at least call custom instructions from there.
also, if we've 'broken the seal' of non-fixed-size instructions in SHORT, OR if we use 16-bit fixed size instructions, should consider if we can do better and get some other 'addressing modes' in there besides pure stack.
if we throw some register addressing in there, that doesn't really increase the complexity of implementation very much imo, it's still a good bootstrap language.
---
we basically want 3 addr modes:
we need at least ~4 bits for opcode, plus some way to call longer 'custom' instructions.
3-operand format is nice but 2-operand mode is probably more efficient.
do we need to call first-class instructions? nah, save that for MEDIUM. So we never need the 4-th (3rd) operand.
With fixed length, we'd need at least 16 bits; because you really want at least 8 bits for absolute jumps, and you want the bitlength to be a power of 2. Another reason for this is 4 opcode bits + 2 operands * (2 addr mode bits) = 8 bits, without even putting in the operands yet.
So let's say we have 16 bits.
For absolute jumps, that gives us an instruction format with 4-bit opcodes and 12 bits of data.
For 2 operands with 2 bit addr modes, that's (16 - 4-bit opcode - 2*2 addr mode bits)/2 = 4 bits per operand left.
Now if we need more opcode bits, so that we can have more instructions, that reduces the above number. For 3 bits per operand, we can have 6-bit opcodes, and for 2 bits per operand, 8-bit opcodes.
but recall that since this is SHORT mode, we need 2 form bits now.
---
Since we only really need 3 addr modes, and since stack addr mode doesn't need an operand, we could compress things further:
---
So we're looking at:
---
wait, we COULD do first-class functions in here pretty easily, since we have 6 opcode bits, if we just use the first 2 bits to indicate when that happens;
---
if we added a 4th format we could also pack 3 4-bit stack opcodes in there.. jeez this is getting to be a lot of formats. Also, that would no longer be fixed-length. So mb not? Also, will chains of 3 stack-addressed instructions be all that common when we allow register addressing too?
---
could we possibly reduce this whole thing to about 8 bits?
---
so that reminds me, we'd really like at least 4 addr modes:
---
previous proposal is nice but 5-bit immediates isn't much; that only gives us a JMP table with 32 entries. We could accept variable-length addressing w/r/t the FORM bits. This wouldn't be too much more crazy than the old, simpler, 4-bit proposal:
---
so how about:
2 formats:
well now we're getting into the same sort of packed SHORT format we had before, where the first (and maybe the last) instruction has a special encoding, to accomodate those 2 form bits. But now we're trying to do a 2-operand format instead of 1. The old ootAssemblyNotes7 SHORT format used a system similar to the limitations on expressions in terms of pushes/pops and parenthesis described slightly earlier in ootAssemblyNotes11. The idea is that you probably want to PUSH the outcome of most of the instructions except at the end.
---
So how about:
2 formats:
hmm:
---
for the SHORT ones:
| out)2 (in | out)2: 2x 2-bit ordinary (see below) |
| out)2 imm2: 2-bit ordinary + 2-bit immediate |
| POP, or if it's an imm4, then it becomes an imm3 |
instructions:
plus one MEDIUM instruction (LOADI 16-bits; note it can fit more than 16 bits but for SootB? we don't assume that our regs can hold more than 16 bits; i guess we should offer variants of LOADI that load into register 0, register 1, stack, or TOS? ordinary MEDIUM mode can support each of those. Maybe we also offer a 'STOREI' which writes a 16-bit immediate to any 11-bit address in (register?) memory)
NOTE: in MEDIUM, 'BR' in user-level code is constrained to only use 8-bits (one of the two inputs). The other input is reserved for the implementation. It is expected that the implementation uses this when inlining custom instructions (which increases the distance between points in user-level code).
todo: for hierarchical modules, need a way to LOADK an imported module into somewhere, and then LOADK from that memory location to access something exported by that module. I guess just treat modules as address subspaces.
---
y'know, i'm backing off the idea of unifying SootB? and SHORT. The thing is, SHORT is supposed to be efficient, and we won't know what's efficient until we profile, and we may want to change it each release to be most efficient. Whereas SootB? is for bootstrapping, so it prboably shouldn't change so rapidly. Otoh SootB? bootstrapping will run more efficiently if code density is high.
i guess the answer is, unify them but not yet? mb until then just use the subset-of-MEDIUM thing?
---
eh, maybe unifying SootB? and SHORT is good after all.
i guess what's really going on is that i think it's not worth spending as much time and energy as i have been on the details of SootB? (and even OotB?