qemu/tests/tcg
Fabiano Rosas 936fda4d77 target/ppc: Fix bcdsub. emulation when result overflows
The commit d03b174a83 (target/ppc: simplify bcdadd/sub functions)
meant to simplify some of the code but it inadvertently altered the
way the CR6 field is set after the operation has overflowed.

The CR6 bits are set based on the *unbounded* result of the operation,
so we need to look at the result before returning from bcd_add_mag,
otherwise we will look at 0 when it overflows.

Consider the following subtraction:

v0 = 0x9999999999999999999999999999999c (maximum positive BCD value)
v1 = 0x0000000000000000000000000000001d (negative one BCD value)
bcdsub. v0,v0,v1,0

The Power ISA 2.07B says:
If the unbounded result is greater than zero, do the following.
  If PS=0, the sign code of the result is set to 0b1100.
  If PS=1, the sign code of the result is set to 0b1111.
  If the operation overflows, CR field 6 is set to 0b0101. Otherwise,
  CR field 6 is set to 0b0100.

POWER9 hardware:
vr0 = 0x0000000000000000000000000000000c (positive zero BCD value)
cr6 = 0b0101 (0x5) (positive, overflow)

QEMU:
vr0 = 0x0000000000000000000000000000000c (positive zero BCD value)
cr6 = 0b0011 (0x3) (zero, overflow) <--- wrong

This patch reverts the part of d03b174a83 that introduced the
problem and adds a test-case to avoid further regressions:

before:
$ make run-tcg-tests-ppc64le-linux-user
(...)
  TEST    bcdsub on ppc64le
bcdsub: qemu/tests/tcg/ppc64le/bcdsub.c:58: test_bcdsub_gt:
Assertion `(cr >> 4) == ((1 << 2) | (1 << 0))' failed.

Fixes: d03b174a83 (target/ppc: simplify bcdadd/sub functions)
Reported-by: Paul Clarke <pc@us.ibm.com>
Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
Message-Id: <20210222194035.2723056-1-farosas@linux.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-10 09:07:09 +11:00
..
aarch64 tests/tcg/aarch64: Add mte smoke tests 2021-02-16 13:17:28 +00:00
alpha tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
arm tests: remove GCC < 4 fallbacks 2020-12-15 12:52:10 -05:00
cris tests/tcg: add a multiarch linux-user gdb test 2020-05-06 09:29:26 +01:00
hexagon Hexagon (tests/tcg/hexagon) TCG tests - floating point 2021-02-18 07:48:22 -08:00
hppa tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
i386 tests/plugin: expand insn test to detect duplicate instructions 2021-02-18 08:19:23 +00:00
lm32 test: lm32: use semihosting for testing 2014-05-24 19:42:29 +02:00
m68k tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
minilib tests/tcg: use EXTRA_CFLAGS everywhere 2019-09-10 09:38:33 +01:00
mips tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
multiarch tests/tcg: fix silent skipping of softmmu gdb tests 2021-02-15 09:38:54 +00:00
openrisc target/openrisc: Rename the cpu from or32 to or1k 2017-02-14 08:14:58 +11:00
ppc tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
ppc64 target/ppc: Fix bcdsub. emulation when result overflows 2021-03-10 09:07:09 +11:00
ppc64le target/ppc: Fix bcdsub. emulation when result overflows 2021-03-10 09:07:09 +11:00
s390x tests/tcg/s390x: Fix EXRL tests 2021-01-21 11:19:45 +01:00
sh4 tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
sparc64 tests/tcg: move configuration to a sub-shell script 2019-09-10 14:09:00 +01:00
x86_64 tests/plugin: expand insn test to detect duplicate instructions 2021-02-18 08:19:23 +00:00
xtensa tests/tcg/xtensa: add DFP0 arithmetic tests 2020-08-21 12:48:16 -07:00
configure.sh target/ppc: Fix bcdsub. emulation when result overflows 2021-03-10 09:07:09 +11:00
Makefile.prereqs tests/tcg: ensure we re-configure if configure.sh is updated 2019-12-19 08:20:16 +00:00
Makefile.qemu tests/tcg: Replace /bin/true by true (required on macOS) 2021-02-08 10:55:20 +00:00
Makefile.target tests/tcg: build tests with -Werror 2021-01-02 21:03:09 +01:00
README tests/tcg/README: fix location for lm32 tests 2018-10-26 17:17:32 +02:00

This directory contains various interesting guest programs for
regression testing. Tests are either multi-arch, meaning they can be
built for all guest architectures that support linux-user executable,
or they are architecture specific.

CRIS
====
The testsuite for CRIS is in tests/tcg/cris.  You can run it
with "make test-cris".

LM32
====
The testsuite for LM32 is in tests/tcg/lm32.  You can run it
with "make test-lm32".