MSP430: sim: Fix incorrect simulation of unsigned widening multiply
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Tue, 28 Jul 2020 09:36:10 +0000 (10:36 +0100)
committerJozef Lawrynowicz <jozef.l@mittosystems.com>
Wed, 5 Aug 2020 14:02:30 +0000 (15:02 +0100)
commite8a387fb5f91cdb9674f19703c0e7bfbaf895a84
tree162d6decb4ea00d04438bf2e2ce3620cd8b1b9da
parent5555c86d3e85e85d76555acdb955aba062beb02f
MSP430: sim: Fix incorrect simulation of unsigned widening multiply

Operand sizes used for simulation of MSP430 hardware multiply
operations are not aligned with the sizes used on the target, resulting
in the simulator storing signed operands with too much precision.

Additionally, simulation of unsigned multiplication is missing explicit
casts to prevent any implicit sign extension.

gcc.c-torture/execute/pr91450-1.c uses unsigned widening multiplication
of 32-bit operands -4 and 2, to produce a 64-bit result:
0xffff fffc * 0x2 = 0x1 ffff fff8

If -4 is stored in 64-bit precision, then the multiplication is
essentially signed and the result is -8 in 64-bit precision
(0xffff ffff ffff fffc), which is not correct.

sim/msp430/ChangeLog:

* msp430-sim.c (put_op): For unsigned multiplication, explicitly cast
operands to the unsigned type before multiplying.
* msp430-sim.h (struct msp430_cpu_state): Fix types used to store hwmult
operands.

sim/testsuite/sim/msp430/ChangeLog:

* mpyull_hwmult.s: New test.
sim/msp430/ChangeLog
sim/msp430/msp430-sim.c
sim/msp430/msp430-sim.h
sim/testsuite/sim/msp430/ChangeLog
sim/testsuite/sim/msp430/mpyull_hwmult.s [new file with mode: 0644]