tests/tcg/mips: Add tests for R5900 three-operand MULT
Add a test for MULT. Reviewed-by: Aleksandar Markovic <amarkovic@wavecomp.com> Signed-off-by: Fredrik Noring <noring@nocrew.org> Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
This commit is contained in:
parent
96631327be
commit
9d35580a57
25
tests/tcg/mips/mipsr5900/Makefile
Normal file
25
tests/tcg/mips/mipsr5900/Makefile
Normal file
|
@ -0,0 +1,25 @@
|
|||
-include ../../config-host.mak
|
||||
|
||||
CROSS=mipsr5900el-unknown-linux-gnu-
|
||||
|
||||
SIM=qemu-mipsel
|
||||
SIM_FLAGS=-cpu R5900
|
||||
|
||||
CC = $(CROSS)gcc
|
||||
CFLAGS = -Wall -mabi=32 -march=r5900 -static
|
||||
|
||||
TESTCASES = mult.tst
|
||||
|
||||
all: $(TESTCASES)
|
||||
|
||||
%.tst: %.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
check: $(TESTCASES)
|
||||
@for case in $(TESTCASES); do \
|
||||
echo $(SIM) $(SIM_FLAGS) ./$$case;\
|
||||
$(SIM) $(SIM_FLAGS) ./$$case; \
|
||||
done
|
||||
|
||||
clean:
|
||||
$(RM) -rf $(TESTCASES)
|
47
tests/tcg/mips/mipsr5900/mult.c
Normal file
47
tests/tcg/mips/mipsr5900/mult.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Test R5900-specific three-operand MULT.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
static int64_t mult(int32_t rs, int32_t rt)
|
||||
{
|
||||
int32_t rd, lo, hi;
|
||||
int64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" mult %0, %3, %4\n"
|
||||
" mflo %1\n"
|
||||
" mfhi %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt));
|
||||
r = ((int64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert((int64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void verify_mult_negations(int32_t rs, int32_t rt, int64_t expected)
|
||||
{
|
||||
assert(mult(rs, rt) == expected);
|
||||
assert(mult(-rs, rt) == -expected);
|
||||
assert(mult(rs, -rt) == -expected);
|
||||
assert(mult(-rs, -rt) == expected);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
verify_mult_negations(17, 19, 323);
|
||||
verify_mult_negations(77773, 99991, 7776600043);
|
||||
verify_mult_negations(12207031, 305175781, 3725290219116211);
|
||||
|
||||
assert(mult(-0x80000000, 0x7FFFFFFF) == -0x3FFFFFFF80000000);
|
||||
assert(mult(-0x80000000, -0x7FFFFFFF) == 0x3FFFFFFF80000000);
|
||||
assert(mult(-0x80000000, -0x80000000) == 0x4000000000000000);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue