Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hexagon (tests/tcg/hexagon) Clean up Hexagon check-tcg tests
Move test infra to header file
    check functions (always print line number on error)
    USR manipulation
    Useful floating point values
Use stdint.h types
Use stdbool.h bool where appropriate
Use trip counts local to for loop

Suggested-by: Anton Johansson <anjo@rev.ng>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Tested-by: Anton Johansson <anjo@rev.ng>
Message-Id: <20230522174341.1805460-1-tsimpson@quicinc.com>
  • Loading branch information
taylorsimpson committed May 26, 2023
1 parent a3cb6d5 commit 0d57cd6
Show file tree
Hide file tree
Showing 19 changed files with 1,030 additions and 1,206 deletions.
19 changes: 18 additions & 1 deletion tests/tcg/hexagon/Makefile.target
Expand Up @@ -91,8 +91,25 @@ HEX_TESTS += v73_scalar

TESTS += $(HEX_TESTS)

atomics: atomics.c hex_test.h
brev: brev.c hex_test.h
circ: circ.c hex_test.h
dual_stores: dual_stores.c hex_test.h
fpstuff: fpstuff.c hex_test.h
hex_sigsegv: hex_sigsegv.c hex_test.h
load_align: load_align.c hex_test.h
load_unpack: load_unpack.c hex_test.h
mem_noshuf_exception: mem_noshuf_exception.c hex_test.h
mem_noshuf: mem_noshuf.c hex_test.h
misc: misc.c hex_test.h
multi_result: multi_result.c hex_test.h
overflow: overflow.c hex_test.h
preg_alias: preg_alias.c hex_test.h
read_write_overlap: read_write_overlap.c hex_test.h
reg_mut: reg_mut.c hex_test.h

# This test has to be compiled for the -mv67t target
usr: usr.c
usr: usr.c hex_test.h
$(CC) $(CFLAGS) -mv67t -O2 -Wno-inline-asm -Wno-expansion-to-defined $< -o $@ $(LDFLAGS)

# Build this test with -mv71 to exercise the CABAC instruction
Expand Down
51 changes: 20 additions & 31 deletions tests/tcg/hexagon/atomics.c
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
* Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,15 +17,19 @@

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <pthread.h>

/* Using volatile because we are testing atomics */
static inline int atomic_inc32(volatile int *x)
int err;

#include "hex_test.h"

static inline int32_t atomic_inc32(int32_t *x)
{
int old, dummy;
int32_t old, dummy;
__asm__ __volatile__(
"1: %0 = memw_locked(%2)\n\t"
" %1 = add(%0, #1)\n\t"
Expand All @@ -37,10 +41,9 @@ static inline int atomic_inc32(volatile int *x)
return old;
}

/* Using volatile because we are testing atomics */
static inline long long atomic_inc64(volatile long long *x)
static inline int64_t atomic_inc64(int64_t *x)
{
long long old, dummy;
int64_t old, dummy;
__asm__ __volatile__(
"1: %0 = memd_locked(%2)\n\t"
" %1 = #1\n\t"
Expand All @@ -53,10 +56,9 @@ static inline long long atomic_inc64(volatile long long *x)
return old;
}

/* Using volatile because we are testing atomics */
static inline int atomic_dec32(volatile int *x)
static inline int32_t atomic_dec32(int32_t *x)
{
int old, dummy;
int32_t old, dummy;
__asm__ __volatile__(
"1: %0 = memw_locked(%2)\n\t"
" %1 = add(%0, #-1)\n\t"
Expand All @@ -68,10 +70,9 @@ static inline int atomic_dec32(volatile int *x)
return old;
}

/* Using volatile because we are testing atomics */
static inline long long atomic_dec64(volatile long long *x)
static inline int64_t atomic_dec64(int64_t *x)
{
long long old, dummy;
int64_t old, dummy;
__asm__ __volatile__(
"1: %0 = memd_locked(%2)\n\t"
" %1 = #-1\n\t"
Expand All @@ -85,17 +86,12 @@ static inline long long atomic_dec64(volatile long long *x)
}

#define LOOP_CNT 1000
/* Using volatile because we are testing atomics */
volatile int tick32 = 1;
/* Using volatile because we are testing atomics */
volatile long long tick64 = 1;
int err;
volatile int32_t tick32 = 1; /* Using volatile because we are testing atomics */
volatile int64_t tick64 = 1; /* Using volatile because we are testing atomics */

void *thread1_func(void *arg)
{
int i;

for (i = 0; i < LOOP_CNT; i++) {
for (int i = 0; i < LOOP_CNT; i++) {
atomic_inc32(&tick32);
atomic_dec64(&tick64);
}
Expand All @@ -104,8 +100,7 @@ void *thread1_func(void *arg)

void *thread2_func(void *arg)
{
int i;
for (i = 0; i < LOOP_CNT; i++) {
for (int i = 0; i < LOOP_CNT; i++) {
atomic_dec32(&tick32);
atomic_inc64(&tick64);
}
Expand All @@ -121,14 +116,8 @@ void test_pthread(void)
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);

if (tick32 != 1) {
printf("ERROR: tick32 %d != 1\n", tick32);
err++;
}
if (tick64 != 1) {
printf("ERROR: tick64 %lld != 1\n", tick64);
err++;
}
check32(tick32, 1);
check64(tick64, 1);
}

int main(int argc, char **argv)
Expand Down
73 changes: 33 additions & 40 deletions tests/tcg/hexagon/brev.c
@@ -1,5 +1,5 @@
/*
* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
* Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,16 +17,19 @@

#include <stdio.h>
#include <string.h>
#include <stdint.h>

int err;

#include "hex_test.h"

#define NBITS 8
#define SIZE (1 << NBITS)

long long dbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
int wbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
short hbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
unsigned char bbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
int64_t dbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
int32_t wbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
int16_t hbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
uint8_t bbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};

/*
* We use the C preporcessor to deal with the combinations of types
Expand Down Expand Up @@ -90,62 +93,53 @@ unsigned char bbuf[SIZE] __attribute__((aligned(1 << 16))) = {0};
#define BREV_STORE_wnew(ADDR, VAL, INC) \
BREV_STORE_NEW(w, ADDR, VAL, INC)

int bitreverse(int x)
uint32_t bitreverse(uint32_t x)
{
int result = 0;
int i;
for (i = 0; i < NBITS; i++) {
uint32_t result = 0;
for (int i = 0; i < NBITS; i++) {
result <<= 1;
result |= x & 1;
x >>= 1;
}
return result;
}

int sext8(int x)
int32_t sext8(int32_t x)
{
return (x << 24) >> 24;
}

void check(int i, long long result, long long expect)
{
if (result != expect) {
printf("ERROR(%d): 0x%04llx != 0x%04llx\n", i, result, expect);
err++;
}
}

#define TEST_BREV_LOAD(SZ, TYPE, BUF, SHIFT, EXP) \
do { \
p = BUF; \
for (i = 0; i < SIZE; i++) { \
for (int i = 0; i < SIZE; i++) { \
TYPE result; \
BREV_LOAD_##SZ(result, p, 1 << (SHIFT - NBITS)); \
check(i, result, EXP); \
check32(result, EXP); \
} \
} while (0)

#define TEST_BREV_STORE(SZ, TYPE, BUF, VAL, SHIFT) \
do { \
p = BUF; \
memset(BUF, 0xff, sizeof(BUF)); \
for (i = 0; i < SIZE; i++) { \
for (int i = 0; i < SIZE; i++) { \
BREV_STORE_##SZ(p, (TYPE)(VAL), 1 << (SHIFT - NBITS)); \
} \
for (i = 0; i < SIZE; i++) { \
check(i, BUF[i], bitreverse(i)); \
for (int i = 0; i < SIZE; i++) { \
check32(BUF[i], bitreverse(i)); \
} \
} while (0)

#define TEST_BREV_STORE_NEW(SZ, BUF, SHIFT) \
do { \
p = BUF; \
memset(BUF, 0xff, sizeof(BUF)); \
for (i = 0; i < SIZE; i++) { \
for (int i = 0; i < SIZE; i++) { \
BREV_STORE_##SZ(p, i, 1 << (SHIFT - NBITS)); \
} \
for (i = 0; i < SIZE; i++) { \
check(i, BUF[i], bitreverse(i)); \
for (int i = 0; i < SIZE; i++) { \
check32(BUF[i], bitreverse(i)); \
} \
} while (0)

Expand All @@ -158,28 +152,27 @@ int high_half[SIZE];
int main()
{
void *p;
int i;

for (i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
bbuf[i] = bitreverse(i);
hbuf[i] = bitreverse(i);
wbuf[i] = bitreverse(i);
dbuf[i] = bitreverse(i);
high_half[i] = i << 16;
}

TEST_BREV_LOAD(b, int, bbuf, 16, sext8(i));
TEST_BREV_LOAD(ub, int, bbuf, 16, i);
TEST_BREV_LOAD(h, int, hbuf, 15, i);
TEST_BREV_LOAD(uh, int, hbuf, 15, i);
TEST_BREV_LOAD(w, int, wbuf, 14, i);
TEST_BREV_LOAD(d, long long, dbuf, 13, i);

TEST_BREV_STORE(b, int, bbuf, i, 16);
TEST_BREV_STORE(h, int, hbuf, i, 15);
TEST_BREV_STORE(f, int, hbuf, high_half[i], 15);
TEST_BREV_STORE(w, int, wbuf, i, 14);
TEST_BREV_STORE(d, long long, dbuf, i, 13);
TEST_BREV_LOAD(b, int32_t, bbuf, 16, sext8(i));
TEST_BREV_LOAD(ub, int32_t, bbuf, 16, i);
TEST_BREV_LOAD(h, int32_t, hbuf, 15, i);
TEST_BREV_LOAD(uh, int32_t, hbuf, 15, i);
TEST_BREV_LOAD(w, int32_t, wbuf, 14, i);
TEST_BREV_LOAD(d, int64_t, dbuf, 13, i);

TEST_BREV_STORE(b, int32_t, bbuf, i, 16);
TEST_BREV_STORE(h, int32_t, hbuf, i, 15);
TEST_BREV_STORE(f, int32_t, hbuf, high_half[i], 15);
TEST_BREV_STORE(w, int32_t, wbuf, i, 14);
TEST_BREV_STORE(d, int64_t, dbuf, i, 13);

TEST_BREV_STORE_NEW(bnew, bbuf, 16);
TEST_BREV_STORE_NEW(hnew, hbuf, 15);
Expand Down

0 comments on commit 0d57cd6

Please sign in to comment.