On 2016-11-25 13:06, Richard Henderson wrote: > On 11/25/2016 04:31 AM, Jin Guojie wrote: > > 32-bit condition functions(like brcond_i32) should only > > compare the low half parts of two 64-bit host registers. > > However, MIPS64 does not have distinct instruction for > > such operation. The operands should be sign extended > > to fit the case. > > > > Gcc handles 32-bit comparison in the same way, as the > > following example shows: > > > > [a.c] > > main() > > { > > long a = 0xcccccccc; > > long b = 0xdddddddd; > > int c = (int)a > (int)b; > > } > > This problem is why opcodes like > > OPC_INDEX_extrl_i64_i32 > OPC_INDEX_extrh_i64_i32 > OPC_INDEX_ext_i32_i64 > OPC_INDEX_extu_i32_i64 > > exist. The intention is to keep 32-bit values in their sign-extended form, > exactly as the mips hardware manual requires. At which point all 32-bit > opcodes (ADDIU, SLL, etc) will preserve the 32-bit sign extension property.
It's even stronger than that. It's required for 32-bit opcodes to work correctly. The manual says: | If GPR rs does not contain a sign-extended 32-bit value (bits 63..31 | equal), then the result of the operation is UNPREDICTABLE. Aurelien -- Aurelien Jarno GPG: 4096R/1DDD8C9B aurel...@aurel32.net http://www.aurel32.net