mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 11:04:58 -06:00
tests: tcg: mips: Move source files to new locations
MIPS TCG test will be organized by ISAs and ASEs in future. Reviewed-by: Aleksandar Rikalo <arikalo@wavecomp.com> Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
This commit is contained in:
parent
b304981f52
commit
073d9f2ce0
168 changed files with 0 additions and 0 deletions
73
tests/tcg/mips/user/isa/r5900/test_r5900_div1.c
Normal file
73
tests/tcg/mips/user/isa/r5900/test_r5900_div1.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Test R5900-specific DIV1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct quotient_remainder { int32_t quotient, remainder; };
|
||||
|
||||
static struct quotient_remainder div1(int32_t rs, int32_t rt)
|
||||
{
|
||||
int32_t lo, hi;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" div1 $0, %2, %3\n"
|
||||
" mflo1 %0\n"
|
||||
" mfhi1 %1\n"
|
||||
: "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt));
|
||||
|
||||
assert(rs / rt == lo);
|
||||
assert(rs % rt == hi);
|
||||
|
||||
return (struct quotient_remainder) { .quotient = lo, .remainder = hi };
|
||||
}
|
||||
|
||||
static void verify_div1(int32_t rs, int32_t rt,
|
||||
int32_t expected_quotient,
|
||||
int32_t expected_remainder)
|
||||
{
|
||||
struct quotient_remainder qr = div1(rs, rt);
|
||||
|
||||
assert(qr.quotient == expected_quotient);
|
||||
assert(qr.remainder == expected_remainder);
|
||||
}
|
||||
|
||||
static void verify_div1_negations(int32_t rs, int32_t rt,
|
||||
int32_t expected_quotient,
|
||||
int32_t expected_remainder)
|
||||
{
|
||||
verify_div1(rs, rt, expected_quotient, expected_remainder);
|
||||
verify_div1(rs, -rt, -expected_quotient, expected_remainder);
|
||||
verify_div1(-rs, rt, -expected_quotient, -expected_remainder);
|
||||
verify_div1(-rs, -rt, expected_quotient, -expected_remainder);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
verify_div1_negations(0, 1, 0, 0);
|
||||
verify_div1_negations(1, 1, 1, 0);
|
||||
verify_div1_negations(1, 2, 0, 1);
|
||||
verify_div1_negations(17, 19, 0, 17);
|
||||
verify_div1_negations(19, 17, 1, 2);
|
||||
verify_div1_negations(77773, 101, 770, 3);
|
||||
|
||||
verify_div1(-0x80000000, 1, -0x80000000, 0);
|
||||
|
||||
/*
|
||||
* Supplementary explanation from the Toshiba TX System RISC TX79 Core
|
||||
* Architecture manual, A-38 and B-7, https://wiki.qemu.org/File:C790.pdf
|
||||
*
|
||||
* Normally, when 0x80000000 (-2147483648) the signed minimum value is
|
||||
* divided by 0xFFFFFFFF (-1), the operation will result in an overflow.
|
||||
* However, in this instruction an overflow exception doesn't occur and
|
||||
* the result will be as follows:
|
||||
*
|
||||
* Quotient is 0x80000000 (-2147483648), and remainder is 0x00000000 (0).
|
||||
*/
|
||||
verify_div1(-0x80000000, -1, -0x80000000, 0);
|
||||
|
||||
return 0;
|
||||
}
|
48
tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c
Normal file
48
tests/tcg/mips/user/isa/r5900/test_r5900_divu1.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Test R5900-specific DIVU1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct quotient_remainder { uint32_t quotient, remainder; };
|
||||
|
||||
static struct quotient_remainder divu1(uint32_t rs, uint32_t rt)
|
||||
{
|
||||
uint32_t lo, hi;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" divu1 $0, %2, %3\n"
|
||||
" mflo1 %0\n"
|
||||
" mfhi1 %1\n"
|
||||
: "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt));
|
||||
|
||||
assert(rs / rt == lo);
|
||||
assert(rs % rt == hi);
|
||||
|
||||
return (struct quotient_remainder) { .quotient = lo, .remainder = hi };
|
||||
}
|
||||
|
||||
static void verify_divu1(uint32_t rs, uint32_t rt,
|
||||
uint32_t expected_quotient,
|
||||
uint32_t expected_remainder)
|
||||
{
|
||||
struct quotient_remainder qr = divu1(rs, rt);
|
||||
|
||||
assert(qr.quotient == expected_quotient);
|
||||
assert(qr.remainder == expected_remainder);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
verify_divu1(0, 1, 0, 0);
|
||||
verify_divu1(1, 1, 1, 0);
|
||||
verify_divu1(1, 2, 0, 1);
|
||||
verify_divu1(17, 19, 0, 17);
|
||||
verify_divu1(19, 17, 1, 2);
|
||||
verify_divu1(77773, 101, 770, 3);
|
||||
|
||||
return 0;
|
||||
}
|
78
tests/tcg/mips/user/isa/r5900/test_r5900_madd.c
Normal file
78
tests/tcg/mips/user/isa/r5900/test_r5900_madd.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Test R5900-specific three-operand MADD and MADD1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
int64_t madd(int64_t a, int32_t rs, int32_t rt)
|
||||
{
|
||||
int32_t lo = a;
|
||||
int32_t hi = a >> 32;
|
||||
int32_t rd;
|
||||
int64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" mtlo %5\n"
|
||||
" mthi %6\n"
|
||||
" madd %0, %3, %4\n"
|
||||
" mflo %1\n"
|
||||
" mfhi %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt), "r" (lo), "r" (hi));
|
||||
r = ((int64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert(a + (int64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int64_t madd1(int64_t a, int32_t rs, int32_t rt)
|
||||
{
|
||||
int32_t lo = a;
|
||||
int32_t hi = a >> 32;
|
||||
int32_t rd;
|
||||
int64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" mtlo1 %5\n"
|
||||
" mthi1 %6\n"
|
||||
" madd1 %0, %3, %4\n"
|
||||
" mflo1 %1\n"
|
||||
" mfhi1 %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt), "r" (lo), "r" (hi));
|
||||
r = ((int64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert(a + (int64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int64_t madd_variants(int64_t a, int32_t rs, int32_t rt)
|
||||
{
|
||||
int64_t rd = madd(a, rs, rt);
|
||||
int64_t rd1 = madd1(a, rs, rt);
|
||||
|
||||
assert(rd == rd1);
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
static void verify_madd(int64_t a, int32_t rs, int32_t rt, int64_t expected)
|
||||
{
|
||||
assert(madd_variants(a, rs, rt) == expected);
|
||||
assert(madd_variants(a, -rs, rt) == a + a - expected);
|
||||
assert(madd_variants(a, rs, -rt) == a + a - expected);
|
||||
assert(madd_variants(a, -rs, -rt) == expected);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
verify_madd(13, 17, 19, 336);
|
||||
|
||||
return 0;
|
||||
}
|
70
tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c
Normal file
70
tests/tcg/mips/user/isa/r5900/test_r5900_maddu.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Test R5900-specific three-operand MADDU and MADDU1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
uint64_t maddu(uint64_t a, uint32_t rs, uint32_t rt)
|
||||
{
|
||||
uint32_t lo = a;
|
||||
uint32_t hi = a >> 32;
|
||||
uint32_t rd;
|
||||
uint64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" mtlo %5\n"
|
||||
" mthi %6\n"
|
||||
" maddu %0, %3, %4\n"
|
||||
" mflo %1\n"
|
||||
" mfhi %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt), "r" (lo), "r" (hi));
|
||||
r = ((uint64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert(a + (uint64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64_t maddu1(uint64_t a, uint32_t rs, uint32_t rt)
|
||||
{
|
||||
uint32_t lo = a;
|
||||
uint32_t hi = a >> 32;
|
||||
uint32_t rd;
|
||||
uint64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" mtlo1 %5\n"
|
||||
" mthi1 %6\n"
|
||||
" maddu1 %0, %3, %4\n"
|
||||
" mflo1 %1\n"
|
||||
" mfhi1 %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt), "r" (lo), "r" (hi));
|
||||
r = ((uint64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert(a + (uint64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int64_t maddu_variants(int64_t a, int32_t rs, int32_t rt)
|
||||
{
|
||||
int64_t rd = maddu(a, rs, rt);
|
||||
int64_t rd1 = maddu1(a, rs, rt);
|
||||
|
||||
assert(rd == rd1);
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(maddu_variants(13, 17, 19) == 336);
|
||||
|
||||
return 0;
|
||||
}
|
35
tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c
Normal file
35
tests/tcg/mips/user/isa/r5900/test_r5900_mflohi1.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Test R5900-specific MFLO1 and MFHI1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int32_t rs = 12207031, rt = 305175781;
|
||||
int32_t rs1 = 32452867, rt1 = 49979687;
|
||||
int64_t lo, hi, lo1, hi1;
|
||||
int64_t r, r1;
|
||||
|
||||
/* Test both LO/HI and LO1/HI1 to verify separation. */
|
||||
__asm__ __volatile__ (
|
||||
" mult $0, %4, %5\n"
|
||||
" mult1 $0, %6, %7\n"
|
||||
" mflo %0\n"
|
||||
" mfhi %1\n"
|
||||
" mflo1 %2\n"
|
||||
" mfhi1 %3\n"
|
||||
: "=r" (lo), "=r" (hi),
|
||||
"=r" (lo1), "=r" (hi1)
|
||||
: "r" (rs), "r" (rt),
|
||||
"r" (rs1), "r" (rt1));
|
||||
r = ((int64_t)hi << 32) | (uint32_t)lo;
|
||||
r1 = ((int64_t)hi1 << 32) | (uint32_t)lo1;
|
||||
|
||||
assert(r == 3725290219116211);
|
||||
assert(r1 == 1621984134912629);
|
||||
|
||||
return 0;
|
||||
}
|
40
tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c
Normal file
40
tests/tcg/mips/user/isa/r5900/test_r5900_mtlohi1.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Test R5900-specific MTLO1 and MTHI1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int32_t tlo = 12207031, thi = 305175781;
|
||||
int32_t tlo1 = 32452867, thi1 = 49979687;
|
||||
int32_t flo, fhi, flo1, fhi1;
|
||||
|
||||
/* Test both LO/HI and LO1/HI1 to verify separation. */
|
||||
__asm__ __volatile__ (
|
||||
" mtlo %4\n"
|
||||
" mthi %5\n"
|
||||
" mtlo1 %6\n"
|
||||
" mthi1 %7\n"
|
||||
" move %0, $0\n"
|
||||
" move %1, $0\n"
|
||||
" move %2, $0\n"
|
||||
" move %3, $0\n"
|
||||
" mflo %0\n"
|
||||
" mfhi %1\n"
|
||||
" mflo1 %2\n"
|
||||
" mfhi1 %3\n"
|
||||
: "=r" (flo), "=r" (fhi),
|
||||
"=r" (flo1), "=r" (fhi1)
|
||||
: "r" (tlo), "r" (thi),
|
||||
"r" (tlo1), "r" (thi1));
|
||||
|
||||
assert(flo == 12207031);
|
||||
assert(fhi == 305175781);
|
||||
assert(flo1 == 32452867);
|
||||
assert(fhi1 == 49979687);
|
||||
|
||||
return 0;
|
||||
}
|
76
tests/tcg/mips/user/isa/r5900/test_r5900_mult.c
Normal file
76
tests/tcg/mips/user/isa/r5900/test_r5900_mult.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Test R5900-specific three-operand MULT and MULT1.
|
||||
*/
|
||||
|
||||
#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 int64_t mult1(int32_t rs, int32_t rt)
|
||||
{
|
||||
int32_t rd, lo, hi;
|
||||
int64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" mult1 %0, %3, %4\n"
|
||||
" mflo1 %1\n"
|
||||
" mfhi1 %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 int64_t mult_variants(int32_t rs, int32_t rt)
|
||||
{
|
||||
int64_t rd = mult(rs, rt);
|
||||
int64_t rd1 = mult1(rs, rt);
|
||||
|
||||
assert(rd == rd1);
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
static void verify_mult_negations(int32_t rs, int32_t rt, int64_t expected)
|
||||
{
|
||||
assert(mult_variants(rs, rt) == expected);
|
||||
assert(mult_variants(-rs, rt) == -expected);
|
||||
assert(mult_variants(rs, -rt) == -expected);
|
||||
assert(mult_variants(-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_variants(-0x80000000, 0x7FFFFFFF) == -0x3FFFFFFF80000000);
|
||||
assert(mult_variants(-0x80000000, -0x7FFFFFFF) == 0x3FFFFFFF80000000);
|
||||
assert(mult_variants(-0x80000000, -0x80000000) == 0x4000000000000000);
|
||||
|
||||
return 0;
|
||||
}
|
68
tests/tcg/mips/user/isa/r5900/test_r5900_multu.c
Normal file
68
tests/tcg/mips/user/isa/r5900/test_r5900_multu.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Test R5900-specific three-operand MULTU and MULTU1.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
|
||||
static uint64_t multu(uint32_t rs, uint32_t rt)
|
||||
{
|
||||
uint32_t rd, lo, hi;
|
||||
uint64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" multu %0, %3, %4\n"
|
||||
" mflo %1\n"
|
||||
" mfhi %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt));
|
||||
r = ((uint64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert((uint64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static uint64_t multu1(uint32_t rs, uint32_t rt)
|
||||
{
|
||||
uint32_t rd, lo, hi;
|
||||
uint64_t r;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" multu1 %0, %3, %4\n"
|
||||
" mflo1 %1\n"
|
||||
" mfhi1 %2\n"
|
||||
: "=r" (rd), "=r" (lo), "=r" (hi)
|
||||
: "r" (rs), "r" (rt));
|
||||
r = ((uint64_t)hi << 32) | (uint32_t)lo;
|
||||
|
||||
assert((uint64_t)rs * rt == r);
|
||||
assert(rd == lo);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static uint64_t multu_variants(uint32_t rs, uint32_t rt)
|
||||
{
|
||||
uint64_t rd = multu(rs, rt);
|
||||
uint64_t rd1 = multu1(rs, rt);
|
||||
|
||||
assert(rd == rd1);
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
assert(multu_variants(17, 19) == 323);
|
||||
assert(multu_variants(77773, 99991) == 7776600043);
|
||||
assert(multu_variants(12207031, 305175781) == 3725290219116211);
|
||||
|
||||
assert(multu_variants(0x80000000U, 0x7FFFFFFF) == 0x3FFFFFFF80000000);
|
||||
assert(multu_variants(0x80000000U, 0x80000000U) == 0x4000000000000000);
|
||||
assert(multu_variants(0xFFFFFFFFU, 0xFFFFFFFFU) == 0xFFFFFFFE00000001U);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue