Skip to content

Commit

Permalink
convert hwtest to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
mwkmwkmwk committed Aug 9, 2016
1 parent b3fcb08 commit 87a1562
Show file tree
Hide file tree
Showing 27 changed files with 411 additions and 308 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
project(ENVYTOOLS C)
project(ENVYTOOLS C CXX)
cmake_minimum_required(VERSION 2.6)
enable_testing()

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif (NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -44,6 +45,7 @@ message("-- Summary --")
message("")
message("General:")
message(" C-flags: '${CMAKE_C_FLAGS}' (-DCMAKE_C_FLAGS=\"...\")")
message(" CXX-flags: '${CMAKE_CXX_FLAGS}' (-DCMAKE_CXX_FLAGS=\"...\")")
message(" Build type: ${CMAKE_BUILD_TYPE} (-DCMAKE_BUILD_TYPE=\"...\")")
message("")
message("Install:")
Expand Down
10 changes: 8 additions & 2 deletions hwtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(ENVYTOOLS C)
project(ENVYTOOLS C CXX)
cmake_minimum_required(VERSION 2.6)

option(DISABLE_HWTEST "Disable building hwtest" OFF)
Expand All @@ -11,7 +11,13 @@ if (NOT DISABLE_HWTEST)
include_directories(${PC_PCIACCESS_INCLUDE_DIRS})
link_directories(${PC_PCIACCESS_LIBRARY_DIRS})

add_executable(hwtest hwtest.c common.c vram.c nv01_pgraph.c nv10_tile.c nv50_ptherm.c nv84_ptherm.c pvcomp_isa.c vp2_macro.c mpeg_crypt.c vp1.c g80_gr.c g80_sfu.c g80_int.c g80_fp.c g80_fp64.c g80_atom32.c g80_atom64.c)
add_executable(hwtest hwtest.cc common.cc
nv01_pgraph.cc
vram.cc nv10_tile.cc
nv50_ptherm.cc nv84_ptherm.cc
mpeg_crypt.cc vp1.cc vp2_macro.cc pvcomp_isa.cc
g80_gr.cc g80_sfu.cc g80_int.cc g80_fp.cc g80_fp64.cc g80_atom32.cc g80_atom64.cc
)
target_link_libraries(hwtest nva nvhw m)

install(TARGETS hwtest
Expand Down
2 changes: 1 addition & 1 deletion hwtest/common.c → hwtest/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int hwtest_run_group(struct hwtest_ctx *ctx, const struct hwtest_group *group, c
if (pres != HWTEST_RES_PASS) {
return pres;
}
int flen = 0;
size_t flen = 0;
const char *fnext = 0;
if (filter) {
fnext = strchr(filter, '/');
Expand Down
2 changes: 1 addition & 1 deletion hwtest/g80_atom32.c → hwtest/g80_atom32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int atom32_prep_code(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2)
0xf0000001,
0xe0000781,
};
int i;
unsigned i;
/* Poke code and flush it. */
nva_wr32(ctx->cnum, 0x1700, 0x100);
for (i = 0; i < ARRAY_SIZE(code); i++)
Expand Down
4 changes: 2 additions & 2 deletions hwtest/g80_atom64.c → hwtest/g80_atom64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ op2,
0xf0000001,
0xe0000781,
};
int i;
unsigned i;
/* Poke code and flush it. */
nva_wr32(ctx->cnum, 0x1700, 0x100);
for (i = 0; i < ARRAY_SIZE(code); i++)
Expand Down Expand Up @@ -170,7 +170,7 @@ static int atom64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2,
break;
}
if (real != exp || cc != ecc || (is_atom && realold != expold)) {
printf("atom64 %08x %08x (%016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64")[%d]: got %016"PRIx64".%x %016"PRIx64" expected %016"PRIx64".%x %016"PRIx64"\n", op1, op2, src1[i], src2[i], src3[i], s1, i&3, real, cc, realold, exp, ecc, expold);
printf("atom64 %08x %08x (%016" PRIx64 " %016" PRIx64 " %016" PRIx64 " %016" PRIx64 ")[%d]: got %016" PRIx64 ".%x %016" PRIx64 " expected %016" PRIx64 ".%x %016" PRIx64 "\n", op1, op2, src1[i], src2[i], src3[i], s1, i&3, real, cc, realold, exp, ecc, expold);
return 1;
}
}
Expand Down
18 changes: 9 additions & 9 deletions hwtest/g80_fp.c → hwtest/g80_fp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static int fp_prep_code(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2) {
0xf0000001,
0xe0000781,
};
int i;
unsigned i;
/* Poke code and flush it. */
nva_wr32(ctx->cnum, 0x1700, 0x100);
for (i = 0; i < ARRAY_SIZE(code); i++)
Expand Down Expand Up @@ -194,7 +194,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
static const int cmpbit[4] = { 16, 15, 14, 17 };
int swz;
int sop;
int rm;
enum fp_rm rm;
bool neg = false;
uint64_t t64;
bool fnz = (ctx->chipset >= 0xa0 && ctx->chipset != 0xaa && ctx->chipset != 0xac) && (xtra & 0x80000);
Expand Down Expand Up @@ -266,7 +266,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
{
bool crap_i2f64 = ctx->chipset == 0xa0 && (op2 & 0x00400000);
bool i16 = !(op2 & 0x00004000) && !crap_i2f64;
rm = op2 >> 17 & 3;
rm = (enum fp_rm)(op2 >> 17 & 3);
if (!(op2 & 0x00010000)) {
/* zero-extend */
if (i16)
Expand Down Expand Up @@ -310,7 +310,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
if (op2 & 0x00080000)
exp = fp32_sat(exp, fnz);
if (!(op2 & 0x04000000)) {
exp = fp32_to_fp16(exp, op2 >> 17 & 3, false);
exp = fp32_to_fp16(exp, (enum fp_rm)(op2 >> 17 & 3), false);
real &= 0xffff;
ecc = fp32_cmp(fp16_to_fp32(exp), 0, true);
} else {
Expand All @@ -328,7 +328,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
s1 &= ~0x80000000;
if (op2 & 0x20000000)
s1 ^= 0x80000000;
rm = op2 >> 17 & 3;
rm = (enum fp_rm)(op2 >> 17 & 3);
if (s1 & 0x80000000) {
neg = true;
s1 ^= 0x80000000;
Expand Down Expand Up @@ -386,9 +386,9 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
if (op2 & 0x00080000)
exp = fp32_sat(exp, fnz);
if (op2 & 0x08000000)
exp = fp32_rint(exp, op2 >> 17 & 3);
exp = fp32_rint(exp, (enum fp_rm)(op2 >> 17 & 3));
if (!(op2 & 0x04000000)) {
exp = fp32_to_fp16(exp, op2 >> 17 & 3, op2 >> 27 & 1);
exp = fp32_to_fp16(exp, (enum fp_rm)(op2 >> 17 & 3), op2 >> 27 & 1);
real &= 0xffff;
ecc = fp32_cmp(fp16_to_fp32(exp), 0, true);
} else {
Expand All @@ -402,7 +402,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
s1 ^= 0x80000000;
if (op2 & 0x08000000)
s3 ^= 0x80000000;
exp = fp32_add(s1, s3, op1 >> 16 & 3);
exp = fp32_add(s1, s3, (enum fp_rm)(op1 >> 16 & 3));
if (op2 & 0x20000000) {
if (ctx->chipset == 0xa0 && !FP32_ISNAN(s1) && !FP32_ISNAN(s3)) {
/* hw bugs are fun! */
Expand Down Expand Up @@ -444,7 +444,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
s1 ^= 0x80000000;
if (op2 & 0x08000000)
s2 ^= 0x80000000;
exp = fp32_mul(s1, s2, op2 >> 14 & 3, xtra >> 1 & 1);
exp = fp32_mul(s1, s2, (enum fp_rm)(op2 >> 14 & 3), xtra >> 1 & 1);
if (ctx->chipset == 0xa0 && !FP32_ISNAN(s1) && !FP32_ISNAN(s2)) {
/* hw bugs are fun! */
fnz = false;
Expand Down
18 changes: 9 additions & 9 deletions hwtest/g80_fp64.c → hwtest/g80_fp64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ op2,
0xf0000001,
0xe0000781,
};
int i;
unsigned i;
/* Poke code and flush it. */
nva_wr32(ctx->cnum, 0x1700, 0x100);
for (i = 0; i < ARRAY_SIZE(code); i++)
Expand Down Expand Up @@ -197,7 +197,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
case 0xa2: /* i2f */
case 0xa3: /* i2f */
{
rm = op2 >> 17 & 3;
rm = (enum fp_rm)(op2 >> 17 & 3);
if (op2 >> 16 & 1) {
if (!(op2 >> 14 & 1))
s1 = (int32_t)s1;
Expand Down Expand Up @@ -231,7 +231,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
case 0xa4: /* f2i */
case 0xa5: /* f2i */
{
rm = op2 >> 17 & 3;
rm = (enum fp_rm)(op2 >> 17 & 3);
int sbit = op2 >> 14 & 1 ? 63 : 31;
if (op2 >> 20 & 1)
s1 &= ~(1ull << sbit);
Expand All @@ -251,7 +251,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
exp = fp64_to_u64(s1, rm);
else
exp = fp32_to_u64(s1, rm, false);
if (exp == -1)
if (exp == -1u)
ovf = true;
if (op2 >> 27 & 1) {
uint64_t limit = 1ull << 63;
Expand Down Expand Up @@ -299,7 +299,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
case 0xa6: /* f2f */
case 0xa7: /* f2f */
{
rm = op2 >> 17 & 3;
rm = (enum fp_rm)(op2 >> 17 & 3);
if (op2 >> 14 & 1) {
exp = s1;
} else {
Expand Down Expand Up @@ -340,7 +340,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
if (op2 & 0x08000000)
s3 ^= (1ull << 63);
}
exp = fp64_fma(s1, s2, s3, op2 >> 22 & 3);
exp = fp64_fma(s1, s2, s3, (enum fp_rm)(op2 >> 22 & 3));
ecc = fp64_cmp(exp, 0);
break;
case 0xe3: /* dadd */
Expand All @@ -356,7 +356,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
if (op2 & 0x08000000)
s3 ^= (1ull << 63);
}
exp = fp64_add(s1, s3, op1 >> 16 & 3);
exp = fp64_add(s1, s3, (enum fp_rm)(op1 >> 16 & 3));
ecc = fp64_cmp(exp, 0);
break;
case 0xe4: /* dmul */
Expand All @@ -369,7 +369,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
if (FP64_ISNAN(s2)) {
s2 |= 1ull << 51;
}
exp = fp64_mul(s1, s2, op2 >> 17 & 3);
exp = fp64_mul(s1, s2, (enum fp_rm)(op2 >> 17 & 3));
ecc = fp64_cmp(exp, 0);
break;
case 0xe5: /* dmin */
Expand Down Expand Up @@ -412,7 +412,7 @@ static int fp64_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, c
abort();
}
if (real != exp || cc != ecc) {
printf("fp64 %08x %08x (%016"PRIx64" %016"PRIx64" %016"PRIx64"): got %016"PRIx64".%x expected %016"PRIx64".%x diff %"PRId64"\n", op1, op2, src1[i], src2[i], src3[i], real, cc, exp, ecc, real-exp);
printf("fp64 %08x %08x (%016" PRIx64 " %016" PRIx64 " %016" PRIx64 "): got %016" PRIx64 ".%x expected %016" PRIx64 ".%x diff %" PRId64 "\n", op1, op2, src1[i], src2[i], src3[i], real, cc, exp, ecc, real-exp);
return 1;
}
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions hwtest/g80_int.c → hwtest/g80_int.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static int fp_prep_code(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2) {
0xf0000001,
0xe0000781,
};
int i;
unsigned i;
/* Poke code and flush it. */
nva_wr32(ctx->cnum, 0x1700, 0x100);
for (i = 0; i < ARRAY_SIZE(code); i++)
Expand Down Expand Up @@ -286,7 +286,7 @@ static int fp_check_data(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2, con
case 0x36: /* shl */
case 0x37: /* shr */
{
int bits = (op2 >> 26 & 1) ? 32 : 16;
uint32_t bits = (op2 >> 26 & 1) ? 32 : 16;
if (op2 >> 20 & 1) {
/* const shift count */
s2 = op1 >> 16 & 0x7f;
Expand Down
8 changes: 4 additions & 4 deletions hwtest/g80_sfu.c → hwtest/g80_sfu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int test_sfu_tab(struct hwtest_ctx *ctx) {
/* XXX: why is the and necessary? */
uint64_t r = ((uint64_t)hi << 32 | lo) & 0xfffffffffffffull;
if (e != r) {
printf("TPC %d MP %d SFU %03x: expected %016"PRIx64" got %016"PRIx64"\n",
printf("TPC %d MP %d SFU %03x: expected %016" PRIx64 " got %016" PRIx64 "\n",
tpc, mp, i, e, r);
return HWTEST_RES_FAIL;
}
Expand All @@ -104,7 +104,7 @@ static int sfu_prep_code(struct hwtest_ctx *ctx, uint32_t op1, uint32_t op2) {
0xf0000001,
0xe0000781,
};
int i;
unsigned i;
/* Poke code and flush it. */
nva_wr32(ctx->cnum, 0x1700, 0x100);
for (i = 0; i < ARRAY_SIZE(code); i++)
Expand Down Expand Up @@ -219,7 +219,7 @@ static int sfu_check_data(struct hwtest_ctx *ctx, uint32_t base, uint32_t op1, u
rin &= ~0x80000000;
if (op2 & 0x04000000)
rin ^= 0x80000000;
exp = sfu_pre(rin, op2 >> 14 & 1);
exp = sfu_pre(rin, (enum sfu_pre_mode)(op2 >> 14 & 1));
} else {
abort();
}
Expand Down Expand Up @@ -361,7 +361,7 @@ static int test_sfu_sincos_rnd(struct hwtest_ctx *ctx) {
}

static int test_sfu_ex2_one(struct hwtest_ctx *ctx) {
int i;
uint32_t i;
uint32_t op1 = 0x90000209;
uint32_t op2 = 0xc0000780;
if (sfu_prep_code(ctx, op1, op2) || sfu_prep_grid(ctx, 0))
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 87a1562

Please sign in to comment.