Fix right shifts in mcore simulator on 64 bit hosts.

If the value to be shifted has the sign bit set, the sign
bit would get copied into bits 32..63 of the temporary.  Those
would then be right shifted into the final value giving an
incorrect final result.

This was observed with upcoming GCC improvements which eliminate
unnecessary extensions.
This commit is contained in:
Jeff Law
2023-12-01 07:19:50 -07:00
parent fbd9e35c54
commit 37d6ee9350
3 changed files with 55 additions and 2 deletions

View File

@@ -757,7 +757,7 @@ step_once (SIM_DESC sd, SIM_CPU *cpu)
break;
case 0x0B: /* lsr */
{
unsigned long dst, src;
uint32_t dst, src;
dst = gr[RD];
src = gr[RS];
/* We must not rely solely upon the native shift operations, since they
@@ -1060,7 +1060,7 @@ step_once (SIM_DESC sd, SIM_CPU *cpu)
case 0x3E: case 0x3F: /* lsrc, lsri */
{
unsigned imm = IMM5;
unsigned long tmp = gr[RD];
uint32_t tmp = gr[RD];
if (imm == 0)
{
NEW_C (tmp);