Behavior of shift built-ins with large shift operand #57
-
|
VADL defines the following built-in function What is the defined behavior of these built-ins if QEMU defines undefined behavior in these cases. @AndreasKrall do you already have a definition for such a case? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
As VADL is a processor description language, we should not have undefined behavior there. Some processors expect a certain behavior, e.g. the result is zero for a shift left or the result sets all bits to the sign bit. Others masks out the lower bits ( If we leave the behavior undefined, it is the responsibility of the processor specification to describe the correct behavior. If the specification is not complete, it can give different results when executing the ISS on different hardware. I do not think that this is a good idea. I suggest to define the behavior in the following way: Then we do not need the masking when defining the variable shift for RISC-V and AArch64. The QEMU emulator can make an analysis, if the shift factor always is smaller than N and then does not need to generate the masking. It is more complex, but a lot safer. |
Beta Was this translation helpful? Give feedback.
-
|
I just noticed that the masking only gives defined behavior if N is a power of 2. The correct specification should be: Of course this should be optimized to Anton also thinks that this would be the best definition. I will give best practice code in the reference manual how to specify other behaviors with our primitive which should guide the optimizations in the generators. |
Beta Was this translation helpful? Give feedback.
-
|
QEMU supports the following host architectures: i386/x86-64,AArch32,AArch64,Power(PC),MIPS,Sparc,S390x The shift behavior with shift counts bigger than the word size for the following architectures is: It is possible to dynamically check if the host architecture does a remainder with the correct size. When the test fails, the TCG frontend has to issue an additional mask operation, otherwise the mask operation can be eliminated. |
Beta Was this translation helpful? Give feedback.
I just noticed that the masking only gives defined behavior if N is a power of 2. The correct specification should be:
Of course this should be optimized to
b & zext(N-1)if N is a power of 2.Anton also thinks that this would be the best definition.
I will give best practice code in the reference manual how to specify other behaviors with our primitive which should guide the optimizations in the generators.