          |
CBC
The C ByteCode processor is optimized to compactly encode programs written in the C programming language. It is a variation of the CRISP design that became the short lived commercial AT&T Hobbit processor. The encoding is closer to the VAX, however, which is easier to implement on SiliconSqueak.
The first byte of the instruction indicates the operation as well as the number of operands. In the case of operations for which there are versions with 3 operands, the versions with 2 will reuse the second as the destination.
| 7 6 5 4 3 2 1 0 | Addresses | Instruction |
| 0 0 s s s d d d | 2 | add s,d |
| 0 1 k k k d d d | 2 | addk k,d |
| 1 0 0 0 x x x x | 0 | nop, cpu, kret, cret, clre |
| 1 0 0 1 x x x x | 2 | umul, udiv, urem, move, movea, addi, andi, ori, dqm, ldraa |
| 1 0 1 0 x x x x | 2 | add, sub, mul, div, rem, and, or, xor, shr, shl, ushr |
| 1 0 1 1 x x x x | 2 | fadd, fsub, fmul, fdiv, frem, fclass, flogb, fmov, fnext, fscalb, fsqrt |
| 1 1 0 0 x x x x | 1 | jmp, call, kcall, enter, return, catch, popn |
| 1 1 0 1 x x x x | 3 | cmpeq, cmpgt, cmphi, testc, testv, fcmpge, fcmpgt, fcmpeq, fcmpeqn, fcmpn |
| 1 1 1 0 x x x x | 3 | add, sub, mul, div, rem, and, or, xor, shr, shl, ushr |
| 1 1 1 1 x x x x | 3 | fadd, fsub, fmul, fdiv, frem |
The 0 to 3 operands all start with a byte with the following format:
| 7 6 5 4 | 3 2 1 0 |
| Mode | Offset |
Offset: 0 to B means 0 to 11, C to F means 1 to 4 bytes. This means that an operand can take up from 1 to 5 bytes depending on the offset, so instructions can be up to 16 bytes long. Note that the size of the offset is entirely independent from the size of the operand, which is determined by the mode.
| Mode | Address | Int Type | Float Type |
| 0 | local | unsigned char | single |
| 1 | local | signed char | double |
| 2 | local | unsigned short | extended |
| 3 | local | signed short |
| 4 | local pointer | unsigned char | single |
| 5 | local pointer | signed char | double |
| 6 | local pointer | unsigned short | extended |
| 7 | local pointer | signed short |
| 8 | global | unsigned char | single |
| 9 | global | signed char | double |
| A | global | unsigned short | extended |
| B | global | signed short |
| C | local | int | int |
| D | local pointer | int | int |
| E | global | int | int |
| F | immediate | int | single |
For jumps and calls the modes (encoded as C to F) are: global pointer, local pointer global and relative.
Note that the first two instructions are just more efficient encodings for:
1100 0000 1100 0sss 1100 0ddd
1100 0000 1111 0kkk 1100 0ddd
In a hardware implementation, both versions should have the same performance but on SiliconSqueak the shorter versions can be faster.
|