mirror of
https://github.com/rdolbeau/VexRiscvBPluginGenerator.git
synced 2025-04-18 18:44:42 -04:00
more systematic synthetic tests
This commit is contained in:
parent
63aa6881f4
commit
86c0e2b282
4 changed files with 877 additions and 901 deletions
8
Makefile
8
Makefile
|
@ -136,7 +136,7 @@ include r5.mk
|
|||
|
||||
NEWINST_H=new_instructions_support_b.h new_instructions_support.h new_instructions_support_k.h new_instructions_support_p.h
|
||||
|
||||
tests: test_b test_p
|
||||
tests: test_b test_p test_b.txt test_p.txt
|
||||
|
||||
signal.o: signal.c
|
||||
$(R5IMA_GCC) $(R5IMA_OPT) -c $< -o $@
|
||||
|
@ -159,6 +159,12 @@ test_b: test_b.o signal.o
|
|||
test_p: test_p.o signal.o
|
||||
$(R5IMA_GCC) $(R5IMA_OPT) $^ -o $@
|
||||
|
||||
test_b.txt: test_b.c
|
||||
gcc -I. -O2 $< -o /tmp/a.out && /tmp/a.out | tee $@
|
||||
|
||||
test_p.txt: test_p.c
|
||||
gcc -I. -O2 $< -o /tmp/a.out && /tmp/a.out | tee $@
|
||||
|
||||
## avoid builtin rule for .o
|
||||
.SUFFIXES:
|
||||
SUFFIXES :=
|
||||
|
|
297
test_b.c
297
test_b.c
|
@ -29,6 +29,8 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#ifdef __riscv
|
||||
|
||||
#include "new_instructions_support_b.h"
|
||||
|
@ -39,7 +41,7 @@
|
|||
|
||||
typedef uint32_t uint_xlen_t;
|
||||
#define XLEN 32
|
||||
uint_xlen_t xperm(uint_xlen_t rs1, uint_xlen_t rs2, int sz_log2)
|
||||
uint_xlen_t xperm(uint_xlen_t rs1, uint_xlen_t rs2, int sz_log2)
|
||||
{
|
||||
uint_xlen_t r = 0;
|
||||
uint_xlen_t sz = 1LL << sz_log2;
|
||||
|
@ -75,207 +77,162 @@ uint_xlen_t _sh3add(uint_xlen_t rs1, uint_xlen_t rs2)
|
|||
/* emulates 64 bits clmul with 32 bit clmul/clmulh */
|
||||
static inline int64_t _rv64_clmul2(int64_t rs1, int64_t rs2)
|
||||
{
|
||||
int64_t r = 0;
|
||||
uint32_t rs1l = rs1 & 0xFFFFFFFF;
|
||||
uint32_t rs1h = (rs1>>32) & 0xFFFFFFFF;
|
||||
uint32_t rs2l = rs2 & 0xFFFFFFFF;
|
||||
uint32_t rs2h = (rs2>>32) & 0xFFFFFFFF;
|
||||
uint32_t lll = _rv32_clmul(rs1l, rs2l);
|
||||
uint32_t llh = _rv32_clmulh(rs1l, rs2l);
|
||||
//uint32_t hhl = _rv32_clmul(rs1h, rs2h);
|
||||
// hhh
|
||||
uint32_t lhl = _rv32_clmul(rs1l, rs2h);
|
||||
/* uint32_t lhh = _rv32_clmulh(rs1l, rs2h); */
|
||||
uint32_t hll = _rv32_clmul(rs1h, rs2l);
|
||||
/* uint32_t hlh = _rv32_clmulh(rs1h, rs2l); */
|
||||
int64_t r = 0;
|
||||
uint32_t rs1l = rs1 & 0xFFFFFFFF;
|
||||
uint32_t rs1h = (rs1>>32) & 0xFFFFFFFF;
|
||||
uint32_t rs2l = rs2 & 0xFFFFFFFF;
|
||||
uint32_t rs2h = (rs2>>32) & 0xFFFFFFFF;
|
||||
uint32_t lll = _rv32_clmul(rs1l, rs2l);
|
||||
uint32_t llh = _rv32_clmulh(rs1l, rs2l);
|
||||
//uint32_t hhl = _rv32_clmul(rs1h, rs2h);
|
||||
// hhh
|
||||
uint32_t lhl = _rv32_clmul(rs1l, rs2h);
|
||||
/* uint32_t lhh = _rv32_clmulh(rs1l, rs2h); */
|
||||
uint32_t hll = _rv32_clmul(rs1h, rs2l);
|
||||
/* uint32_t hlh = _rv32_clmulh(rs1h, rs2l); */
|
||||
|
||||
uint32_t L = lll;
|
||||
uint32_t H = llh ^ lhl ^ hll;
|
||||
r = (int64_t)(((uint64_t)L)| ((uint64_t)H) << 32);
|
||||
return r;
|
||||
uint32_t L = lll;
|
||||
uint32_t H = llh ^ lhl ^ hll;
|
||||
r = (int64_t)(((uint64_t)L)| ((uint64_t)H) << 32);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
unsigned int a = 0x01234567;
|
||||
|
||||
//#define CHECK_SIGILL
|
||||
|
||||
#if defined(CHECK_SIGILL)
|
||||
#include <setjmp.h>
|
||||
extern jmp_buf jb;
|
||||
void installillhandler(void);
|
||||
#endif // CHECK_SIGILL
|
||||
unsigned int a = 0x01234567;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned int b = 0xdeadbeef;
|
||||
unsigned int c;
|
||||
unsigned int d = 0xC0FFEE00;
|
||||
unsigned int index;
|
||||
unsigned int index2;
|
||||
unsigned int b = 0xdeadbeef;
|
||||
unsigned int c;
|
||||
unsigned int d = 0xC0FFEE00;
|
||||
unsigned int index, index1, index2, index3;
|
||||
|
||||
#if defined(CHECK_SIGILL)
|
||||
installillhandler();
|
||||
installillhandler();
|
||||
#endif // CHECK_SIGILL
|
||||
|
||||
if (argc > 1)
|
||||
a = strtoul(argv[1], NULL, 16);
|
||||
if (argc > 2)
|
||||
b = strtoul(argv[2], NULL, 16);
|
||||
if (argc > 3)
|
||||
d = strtoul(argv[3], NULL, 16);
|
||||
if (argc > 1)
|
||||
a = strtoul(argv[1], NULL, 16);
|
||||
if (argc > 2)
|
||||
b = strtoul(argv[2], NULL, 16);
|
||||
if (argc > 3)
|
||||
d = strtoul(argv[3], NULL, 16);
|
||||
|
||||
#if !defined(CHECK_SIGILL)
|
||||
#define T2(X) \
|
||||
c = X(a,b);printf(#X "(0x%08x, 0x%08x) -> 0x%08x\n", a, b, c)
|
||||
#define T1(X) \
|
||||
c = X(a);printf(#X "(0x%08x) -> 0x%08x\n", a, c)
|
||||
#define T3(X) \
|
||||
c = X(a,b,d);printf(#X "(0x%08x, 0x%08x, 0x%08x) -> 0x%08x\n", a, b, d, c)
|
||||
#define T2W(X) \
|
||||
cq = X(a,b);printf(#X "(0x%08x, 0x%08x) -> 0x%016llx\n", a, b, cq)
|
||||
#else
|
||||
#define T2(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x, 0x%08x) -> *SIGILL*\n", a, b); \
|
||||
} else { \
|
||||
c = X(a,b); \
|
||||
printf(#X "(0x%08x, 0x%08x) -> 0x%08x\n", a, b, c); \
|
||||
} \
|
||||
} while (0)
|
||||
#define T1(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x) -> *SIGILL*\n", a); \
|
||||
} else { \
|
||||
c = X(a); \
|
||||
printf(#X "(0x%08x) -> 0x%08x\n", a, c); \
|
||||
} \
|
||||
} while (0)
|
||||
#define T3(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x, 0x%08x, 0x%08x) -> *SIGILL*\n", a, b, d); \
|
||||
} else { \
|
||||
c = X(a,b,d); \
|
||||
printf(#X "(0x%08x, 0x%08x, 0x%08x) -> 0x%08x\n", a, b, d, c); \
|
||||
} \
|
||||
} while (0)
|
||||
#define T2W(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x, 0x%08x) -> *SIGILL*\n", a, b); \
|
||||
} else { \
|
||||
cq = X(a,b); \
|
||||
printf(#X "(0x%08x, 0x%08x) -> 0x%016llx\n", a, b, cq); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif // CHECK_SIGILL
|
||||
for (index = 0 ; index < nonrandom_cnt[0] ; index++) {
|
||||
a = nonrandom_a[index];
|
||||
|
||||
for (index = 0 ; index < 32 ; index++) {
|
||||
T1(_rv32_sext_b);
|
||||
T1(_rv32_sext_h);
|
||||
|
||||
T1(_rv32_clz);
|
||||
T1(_rv32_ctz);
|
||||
T1(_rv32_pcnt);
|
||||
|
||||
for (index1 = 0 ; index1 < nonrandom_cnt[1] ; index1++) {
|
||||
b = nonrandom_b[index1];
|
||||
|
||||
T2(_rv32_ror);
|
||||
T2(_rv32_rol);
|
||||
T2(_rv32_ror);
|
||||
T2(_rv32_rol);
|
||||
|
||||
T2(_rv32_grev);
|
||||
T2(_rv32_gorc);
|
||||
T2(_rv32_grev);
|
||||
T2(_rv32_gorc);
|
||||
|
||||
T2(_rv32_pack);
|
||||
T2(_rv32_packu);
|
||||
T2(_rv32_packh);
|
||||
T2(_rv32_pack);
|
||||
T2(_rv32_packu);
|
||||
T2(_rv32_packh);
|
||||
|
||||
T2(_rv32_shfl);
|
||||
T2(_rv32_unshfl);
|
||||
T2(_rv32_shfl);
|
||||
T2(_rv32_unshfl);
|
||||
|
||||
T2(_rv_andn);
|
||||
T2(_rv_xnor);
|
||||
T2(_rv_orn);
|
||||
T2(_rv_andn);
|
||||
T2(_rv_xnor);
|
||||
T2(_rv_orn);
|
||||
|
||||
//T2(_rv32_sh1add);
|
||||
//T2(_rv32_sh2add);
|
||||
//T2(_rv32_sh3add);
|
||||
//T2(_rv32_sh1add);
|
||||
//T2(_rv32_sh2add);
|
||||
//T2(_rv32_sh3add);
|
||||
|
||||
T2(_rv32_sbset);
|
||||
T2(_rv32_sbclr);
|
||||
T2(_rv32_sbinv);
|
||||
T2(_rv32_sbext);
|
||||
T2(_rv32_sbset);
|
||||
T2(_rv32_sbclr);
|
||||
T2(_rv32_sbinv);
|
||||
T2(_rv32_sbext);
|
||||
|
||||
T2(_rv32_min);
|
||||
T2(_rv32_minu);
|
||||
T2(_rv32_max);
|
||||
T2(_rv32_maxu);
|
||||
T2(_rv32_min);
|
||||
T2(_rv32_minu);
|
||||
T2(_rv32_max);
|
||||
T2(_rv32_maxu);
|
||||
|
||||
T2(_rv32_slo);
|
||||
T2(_rv32_sro);
|
||||
T2(_rv32_slo);
|
||||
T2(_rv32_sro);
|
||||
|
||||
//T2(_rv32_xperm_b);
|
||||
//T2(_rv32_xperm_b);
|
||||
|
||||
T1(_rv32_sext_b);
|
||||
T1(_rv32_sext_h);
|
||||
|
||||
T1(_rv32_clz);
|
||||
T1(_rv32_ctz);
|
||||
T1(_rv32_pcnt);
|
||||
|
||||
T2(_rv32_clmul);
|
||||
T2(_rv32_clmulr);
|
||||
T2(_rv32_clmulh);
|
||||
T2(_rv32_clmul);
|
||||
T2(_rv32_clmulr);
|
||||
T2(_rv32_clmulh);
|
||||
|
||||
#if defined(CHECK_SIGILL)
|
||||
if (setjmp(jb)) {
|
||||
printf("clmul[hr]: **SIGILL**\n");
|
||||
} else
|
||||
if (setjmp(jb)) {
|
||||
printf("clmul[hr]: **SIGILL**\n");
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
int64_t x = 0xc4f5a63e4ac4567bULL ^ (uint64_t)a << 32 ^ (uint64_t)c << 17 ^ (uint64_t)b;
|
||||
int64_t y = 0x9ff123456aabbcc9ULL ^ (uint64_t)c << 32 ^ (uint64_t)b << 23 ^ (uint64_t)a;
|
||||
int64_t z = _rv64_clmul(x, y);
|
||||
int64_t z2 = _rv64_clmul2(x, y);
|
||||
printf("0x%016llx 0x%016llx (0x%016llx)\n", z, z2, z^z2);
|
||||
}
|
||||
{
|
||||
int64_t x = 0xc4f5a63e4ac4567bULL ^ (uint64_t)a << 32 ^ (uint64_t)c << 17 ^ (uint64_t)b;
|
||||
int64_t y = 0x9ff123456aabbcc9ULL ^ (uint64_t)c << 32 ^ (uint64_t)b << 23 ^ (uint64_t)a;
|
||||
int64_t z = _rv64_clmul(x, y);
|
||||
int64_t z2 = _rv64_clmul2(x, y);
|
||||
printf("0x%016llx 0x%016llx (0x%016llx)\n", z, z2, z^z2);
|
||||
}
|
||||
|
||||
// extra stuff
|
||||
T2(_sh1add);
|
||||
T2(_sh2add);
|
||||
T2(_sh3add);
|
||||
// extra stuff
|
||||
T2(_sh1add);
|
||||
T2(_sh2add);
|
||||
T2(_sh3add);
|
||||
|
||||
T2(xperm_n);
|
||||
T2(xperm_b);
|
||||
T2(xperm_h);
|
||||
T2(xperm_n);
|
||||
T2(xperm_b);
|
||||
T2(xperm_h);
|
||||
|
||||
T3(_rv_cmix);
|
||||
T3(_rv_cmov);
|
||||
T2(_rv32_bfp);
|
||||
|
||||
T3(_rv32_fsl);
|
||||
T3(_rv32_fsr);
|
||||
for (index2 = 0 ; index2 < nonrandom_cnt[2] ; index2++) {
|
||||
d = nonrandom_d[index2];
|
||||
T3(_rv_cmix);
|
||||
T3(_rv_cmov);
|
||||
|
||||
T2(_rv32_bfp);
|
||||
T3(_rv32_fsl);
|
||||
T3(_rv32_fsr);
|
||||
|
||||
b = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
#if defined(CHECK_SIGILL)
|
||||
if (setjmp(jb)) {
|
||||
printf("bfp: **SIGILL**\n");
|
||||
} else
|
||||
if (setjmp(jb)) {
|
||||
printf("bfp: **SIGILL**\n");
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
for (index2 = 0 ; index2 < 16 ; index2++) {
|
||||
for (index = 0 ; index < 32 ; index++){
|
||||
{
|
||||
unsigned int a2, b2, c2;
|
||||
b2 = (index2<<24) | (index<<16) | 0;
|
||||
a2 = 0xFFFFFFFF;
|
||||
c2 = _rv32_bfp(a2,b2);printf("_rv32_bfp (0x%08x, 0x%08x) -> 0x%08x\n", a2, b2, c2);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (index2 = 0 ; index2 < 16 ; index2++) {
|
||||
for (index = 0 ; index < 32 ; index++){
|
||||
{
|
||||
unsigned int a2, b2, c2;
|
||||
b2 = (index2<<24) | (index<<16) | (a&0xFFFF);
|
||||
a2 = 0;
|
||||
c2 = _rv32_bfp(a2,b2);printf("_rv32_bfp (0x%08x, 0x%08x) -> 0x%08x\n", a2, b2, c2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
for (index2 = 0 ; index2 < 16 ; index2++) {
|
||||
for (index = 0 ; index < 32 ; index++){
|
||||
{
|
||||
unsigned int a2, b2, c2;
|
||||
b2 = (index2<<24) | (index<<16) | 0;
|
||||
a2 = 0xFFFFFFFF;
|
||||
c2 = _rv32_bfp(a2,b2);printf("_rv32_bfp (0x%08x, 0x%08x) -> 0x%08x\n", a2, b2, c2);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (index2 = 0 ; index2 < 16 ; index2++) {
|
||||
for (index = 0 ; index < 32 ; index++){
|
||||
{
|
||||
unsigned int a2, b2, c2;
|
||||
b2 = (index2<<24) | (index<<16) | (a&0xFFFF);
|
||||
a2 = 0;
|
||||
c2 = _rv32_bfp(a2,b2);printf("_rv32_bfp (0x%08x, 0x%08x) -> 0x%08x\n", a2, b2, c2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
65
test_common.h
Normal file
65
test_common.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
#ifndef __TEST_COMMON_H__
|
||||
#define __TEST_COMMON_H__
|
||||
|
||||
#if !defined(CHECK_SIGILL)
|
||||
#define T2(X) \
|
||||
c = X(a,b);printf(#X "(0x%08x, 0x%08x) -> 0x%08x\n", a, b, c)
|
||||
#define T1(X) \
|
||||
c = X(a);printf(#X "(0x%08x) -> 0x%08x\n", a, c)
|
||||
#define T3(X) \
|
||||
c = X(a,b,d);printf(#X "(0x%08x, 0x%08x, 0x%08x) -> 0x%08x\n", a, b, d, c)
|
||||
#define T2W(X) \
|
||||
cq = X(a,b);printf(#X "(0x%08x, 0x%08x) -> 0x%016llx\n", a, b, cq)
|
||||
#else
|
||||
#define T2(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x, 0x%08x) -> *SIGILL*\n", a, b); \
|
||||
} else { \
|
||||
c = X(a,b); \
|
||||
printf(#X "(0x%08x, 0x%08x) -> 0x%08x\n", a, b, c); \
|
||||
} \
|
||||
} while (0)
|
||||
#define T1(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x) -> *SIGILL*\n", a); \
|
||||
} else { \
|
||||
c = X(a); \
|
||||
printf(#X "(0x%08x) -> 0x%08x\n", a, c); \
|
||||
} \
|
||||
} while (0)
|
||||
#define T3(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x, 0x%08x, 0x%08x) -> *SIGILL*\n", a, b, d); \
|
||||
} else { \
|
||||
c = X(a,b,d); \
|
||||
printf(#X "(0x%08x, 0x%08x, 0x%08x) -> 0x%08x\n", a, b, d, c); \
|
||||
} \
|
||||
} while (0)
|
||||
#define T2W(X) do { \
|
||||
if (setjmp(jb)) { \
|
||||
printf(#X "(0x%08x, 0x%08x) -> *SIGILL*\n", a, b); \
|
||||
} else { \
|
||||
cq = X(a,b); \
|
||||
printf(#X "(0x%08x, 0x%08x) -> 0x%016llx\n", a, b, cq); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#include <setjmp.h>
|
||||
extern jmp_buf jb;
|
||||
void installillhandler(void);
|
||||
|
||||
#endif // CHECK_SIGILL
|
||||
|
||||
const unsigned int nonrandom_a[15] = { 0x01234567, 0, 1, 2, 3, 4, 5, 6, 7,
|
||||
0x80000000, 0xFFFFFFFF, 0x7FFFFFFF, 0x7FFF7FFF,
|
||||
0x7F7F7F7F, 0x80808080 };
|
||||
const unsigned int nonrandom_b[15] = { 0xdeadbeef, 0, 1, 2, 3, 4, 5, 6, 7,
|
||||
0x80000000, 0xFFFFFFFF, 0x7FFFFFFF, 0x7FFF7FFF,
|
||||
0x7F7F7F7F, 0x80808080 };
|
||||
const unsigned int nonrandom_d[14] = { 0, 1, 2, 3, 4, 5, 6, 7,
|
||||
0x80000000, 0xFFFFFFFF, 0x7FFFFFFF, 0x7FFF7FFF,
|
||||
0x7F7F7F7F, 0x80808080 };
|
||||
|
||||
const int nonrandom_cnt[4] = { 15, 14, 14};
|
||||
|
||||
#endif // __TEST_COMMON_H__
|
Loading…
Add table
Reference in a new issue