By whygee on Sunday 8 May 2011, 23:25 - Architecture
(update : 2011/05/11)
I've been wondering since march of this year if the Least Significant Bit
(LSB) of the Next Instruction Pointer (NIP or NPC) could be better used than
now.
The YASEP instructions are 16-bits aligned and the instruction addresses have their LSB cleared by convention. This bit is usually wasted in word-aligned byte-oriented computer architectures.
In the current YASEP architecture, this LSB holds the carry flag of ADD/SUB operations. It is the only status flag that I couldn't get rid of with the usual architectural tricks. As a reminder, instructions can check 3 conditions : register is cleared, has its LSB cleared (odd/even) or MSB (sign) cleared. Every condition can be negated and a 4th condition serves as "always" or "reserved" case. Reading the LSB and MSB is easy, checking for a cleared register is more costly. In some implementation, the register set has "shadow" bits with precomputed/cached "register is clear" bits. But otherwise, no dirty trick is employed.
The Carry bit is less easy to handle : it's a dynamic result that can't be reconstructed from the 16 or 32 bits of the registers. It is not possible to restore it after a thread switch. It can't be added to the "condition cache" because it will have to be saved and restored (16 more bits to save ? Bleh...)
Here come the latest changes :
- The carry bit is now "hidden", not available from the register set for computations (that would make other things more difficult). It exists as a bit that can only be tested via a specific condition code in the conditional instruction forms (certainly one that tests NIP).
- The LSB of NIP is always cleared. However, when saving/restoring the state in memory, it will hold the carry bit. This is the only case when the two functions (carry and pointer) are mixed.
- Writing a "1" to the LSB of NIP (other than for saving/restoring the state) triggers a trap. There are several uses :
- Breakpointing / tracing / debugging : inject a "1" in the LSB and you can see where the pointer is used.
- Safety : for example if the stack is corrupted, there is a chance that the LSB will be set and trigger the trap
In future iterations, this bit could be used for something else more pertinent
(such as a second instruction memory bank selector) so it must be carefully
handled by programers now.
20200409:
I was still undecided ... That damned carry bit is still a pebble in my shoe but this log is now moot : these days, the data and program memory space must be separate and the instruction pointers address 16-bit aligned words, not bytes.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.