-
Notifications
You must be signed in to change notification settings - Fork 202
Compressed instruction encodings #72
Comments
Compute exact EBB header offsets and check that branches are in range. Not implemented yet: Relax branches that are not in range. Invoke the relax_branches() pass from the 'test binemit' file tests so they can verify the proper encoding of branch instructions too.
@stoklund I'd like to get back into the project, could I start on the compressed RISC-V encodings? |
Sure, go for it! |
@angusholder has just landed compressed instruction support for the |
Another possible approach here would be to change the concept of a recipe such that recipes have a fixed maximum size, with their actual size being computed, considering their immediates and register assignments. That would mean we wouldn't need separate REX and non-REX versions of many x86-64 recipes, for example, and we wouldn't need a separate pass to update all the encodings after register allocation. Having a separate pass has the advantage of making it easy to disable, for debugging, or for minimizing compile time in the case where we don't care about optimizing the encodings. However, having it integrated would make it easier for the register allocator to ask an instruction encoding what registers it prefers. And it might have slightly faster compile time for the case where we do want to optimize the encodings. So it's worth considering. |
It is common for instruction set architectures to provide alternative encodings for common instructions that use less code space. The compressed encodings have additional constraints on the range of immediate operands and sometimes tighter register operand constraints too.
iadd
can be encoded as anlea
or as a smalleradd
instruction which has tied register operands.Representation
Cretonne represents encoding variants of the same instruction using separate encoding recipes and bits. This also means that each recipe maps to an exact instruction size in bytes. All of the valid encodings for an instruction appear in the encoding tables used by
TargetIsa::encode()
. The legalizer will always pick the first encoding with a matching predicate, but there can be more encodings after that.We should add a
TargetIsa
method that makes it possible to enumerate all of the valid encodings for an instruction. Probably by returning an iterator.Selecting the best encoding
Sometimes, the legalizer is able to select a compact encoding up front. This is the case with Intel 8-bit immediates when the immediate operand is known, for example. Often, the legalizer does not have enough information to determine if a compact encoding would be valid:
Instruction compression pass
The legalizer selects a compact encoding when it has enough information to do so, and it won't constrain the register allocator.
The instruction compression pass is a pure optimization pass — it can be skipped without violating correctness. It runs late when we have more information:
Compressing instructions obviously changes code size, so the final offsets of EBB headers are not known, and so branch displacements are not yet known.
The text was updated successfully, but these errors were encountered: