trillek-team / trillek-computer

Trillek Virtual Computer specs
http://trillek-team.github.io/trillek-computer/
Other
51 stars 8 forks source link

TR3200 : Enforce align of 8 byte instructions (long literal instructions) #20

Closed Zardoz89 closed 9 years ago

Zardoz89 commented 9 years ago

Catageek suggested that long instructions, that uses 8 bytes (ie, instructions with long literals), must be enforced to be aligned to 8 byte boundary so pipe-lining could be more easy implemented. Also, could make more easy to implement a JIT cpu core with this change.

The side effects are :

Additionally, we can add a penalty (+1 cycle) when a code try to read/write a word or dword not aligned to 4 byte boundary.

milesrout commented 9 years ago

We have two options, as I see it. We have the 'nice' option where we detect and add a slowdown cycle or something, and the same with unaligned loads and stores in general.

We also have the 'ruthless' option, where we just raise an illegal instruction exception - or some sort of 'illegal unaligned load or store' exception that we also use for normal unaligned loads and stores, e.g. LOAD %r0, 1.

milesrout commented 9 years ago

For the record, I totally support the 'ruthless' option where 8-byte instructions that are not 8-byte-aligned are always illegal, and unaligned loads and stores (LOAD %r0, 1) are also illegal.

milesrout commented 9 years ago

@catageek @Meisaka @Zardoz89 thoughts?

catageek commented 9 years ago

I agree about the unaligned code that should be illegal, but I don't understand why we should make illegal unaligned load. Is this justified by a possible limitation of a CPU ?

milesrout commented 9 years ago

The CPU just might not have the silicon to do unaligned loads and stores. The Alpha didn't, for example. The Alpha was a pretty weird architecture all things considered.

Zardoz89 commented 9 years ago

unaligned load/store on real silicon with a 32 bit data bus, means that the CPU would need do two access to RAM to read/write stuff.

Also, depends on the size of the data to be load/stored :

Meisaka commented 9 years ago

IMO, the entire 8 byte/64 bit alignment of instructions does not really seem to make sense in the context of 32 bit CPU, which would supposedly be accessing memory at most 32 bits a time. That seems like it would be more trouble to program around than just leaving it as is. I also think we should keep the unaligned load/store, that keeps the CPU simpler to use.

If either does get enforced, unaligned things should end up sending a CPU trap.

Zardoz89 commented 9 years ago

I agree with Meisaka, that seems like it would be more trouble to program around than just leaving it as is. Also, it will introduce more "if"s to the cpu interpreter, and make a bit more harder to program at low level.