[llvm-dev] 16-bit bytes support

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 12 03:47:30 PST 2017


On 11 Jan 2017, at 21:08, Ivan Krasin via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> My memory is cloudy, since that fun was in 2012, but if I remember correctly, the major mistake I made with that backend is the decision to pack to 8-bit chars into one 16-bit memory word. It made impossible to have pointers to odd chars in the string, and complicated everything. The port might have been cleaner if we had one 8-bit char in one 16-bit word. In this case, half of the memory for the strings is wasted, but some things would have been easier.
> 
> Another issue was the pointer arithmetic, and there's no good answer to that: the fixes were intrusive and non-upstreamable, and they would have been the same, if this port is done again.
> 
> The real solution would be to modify DCPU16 to be friendlier to C compilers. One way to achieve that is to make the registers 32-bit and allow addressing memory at 8-bit boundaries. It's okay to keep the amount of RAM available at low numbers, if it adds fun.

Note that the C specification doesn’t require that the representation of pointers to different types be the same.  This was explicitly included to make this kind of system possible, where int* or long* would be a simple pointer and char* and void* would be a pointer plus the low bit stored in another machine word.  You can represent this in LLVM by using two different address spaces to represent pointers to i8 and pointers to anything else.  

David



More information about the llvm-dev mailing list