name
stringlengths 6
30
| function_name
stringlengths 4
28
| c_src
stringlengths 60
6.91k
|
|---|---|---|
core_init_matrix.c
|
core_init_matrix
|
#include <stdint.h>
#include <stdio.h>
typedef unsigned short u16;
/* align an offset to point to a 32b value */
#define align_mem(x) (void *)(4 + (((uintptr_t)(x)-1) & ~3))
#define matrix_clip(x, y) ((y) ? (x) & 0x0ff : (x) & 0x0ffff)
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
unsigned core_init_matrix(unsigned blksize, void *memblk, int seed,
mat_params *p) {
unsigned N = 0;
short *A;
short *B;
int order = 1;
short val;
unsigned i = 0, j = 0;
if (seed == 0)
seed = 1;
while (j < blksize) {
i++;
j = i * i * 2 * 4;
}
N = i - 1;
A = (short *)align_mem(memblk);
B = A + N * N;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
seed = ((order * seed) % 65536);
val = (seed + order);
val = matrix_clip(val, 0);
B[i * N + j] = val;
val = (val + order);
val = matrix_clip(val, 1);
A[i * N + j] = val;
order++;
}
}
p->A = A;
p->B = B;
p->C = (int *)align_mem(B + N * N);
p->N = N;
return N;
}
|
get_time.c
|
get_time
|
#include <time.h>
extern struct timespec start_time_val, stop_time_val;
clock_t get_time(void) {
clock_t elapsed =
((stop_time_val.tv_sec - start_time_val.tv_sec) * 1000 +
(stop_time_val.tv_nsec - start_time_val.tv_nsec) / 1000000);
return elapsed;
}
|
portable_init.c
|
portable_init
|
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
void portable_init(core_portable *p) { p->portable_id = 1; }
|
core_list_find.c
|
core_list_find
|
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
list_head *core_list_find(list_head *list, list_data *info) {
if (info->idx >= 0) {
while (list && (list->info->idx != info->idx))
list = list->next;
return list;
} else {
while (list && ((list->info->data16 & 0xff) != info->data16))
list = list->next;
return list;
}
}
|
copy_info.c
|
copy_info
|
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
void copy_info(list_data *to, list_data *from) {
to->data16 = from->data16;
to->idx = from->idx;
}
|
main.c
|
main
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
u16 crc16(short newval, u16 crc);
u16 crcu16(u16 newval, u16 crc);
void portable_init(core_portable *p);
void portable_fini(core_portable *p);
void *portable_malloc(size_t size);
void portable_free(void *p);
u8 check_data_types();
void *iterate(void *pres);
void start_time(void);
void stop_time(void);
clock_t get_time(void);
double time_in_secs(clock_t ticks);
list_head *core_list_init(unsigned blksize, list_head *memblock, short seed);
void core_init_state(unsigned size, short seed, u8 *p);
unsigned core_init_matrix(unsigned blksize, void *memblk, int seed,
mat_params *p);
struct timespec start_time_val, stop_time_val;
static u16 list_known_crc[] = {(u16)0xd4b0, (u16)0x3340, (u16)0x6a79,
(u16)0xe714, (u16)0xe3c1};
static u16 matrix_known_crc[] = {(u16)0xbe52, (u16)0x1199, (u16)0x5608,
(u16)0x1fd7, (u16)0x0747};
static u16 state_known_crc[] = {(u16)0x5e47, (u16)0x39bf, (u16)0xe5a4,
(u16)0x8e3a, (u16)0x8d84};
int main() {
u16 i, j = 0, num_algorithms = 3;
short known_id = -1, total_errors = 0;
u16 seedcrc = 0;
clock_t total_time;
core_results results[1];
portable_init(&(results[0].port));
results[0].seed1 = 0;
results[0].seed2 = 0;
results[0].seed3 = 0x66;
results[0].iterations = 0;
results[0].execs = 7;
results[0].size = 2000;
results[0].memblock[0] = portable_malloc(results[i].size);
results[0].err = 0;
results[0].size = results[0].size / num_algorithms;
for (i = 0; i < 3; i++) {
unsigned ctx;
for (ctx = 0; ctx < 1; ctx++)
results[ctx].memblock[i + 1] =
(char *)(results[ctx].memblock[0]) + results[0].size * j;
j++;
}
results[0].list =
core_list_init(results[0].size, results[0].memblock[1], results[0].seed1);
core_init_matrix(results[0].size, results[0].memblock[2],
(int)results[0].seed1 | (((int)results[0].seed2) << 16),
&(results[0].mat));
core_init_state(results[0].size, results[0].seed1, results[0].memblock[3]);
/* automatically determine number of iterations if not set */
if (results[0].iterations == 0) {
double secs_passed = 0;
unsigned divisor;
results[0].iterations = 1;
while (secs_passed < (double)1) {
results[0].iterations *= 10;
start_time();
iterate(&results[0]);
stop_time();
secs_passed = time_in_secs(get_time());
}
/* now we know it executes for at least 1 sec, set actual run time at
* about 10 secs */
divisor = (unsigned)secs_passed;
if (divisor == 0) /* some machines cast float to int as 0 since this
conversion is not defined by ANSI, but we know at
least one second passed */
divisor = 1;
results[0].iterations *= 1 + 10 / divisor;
}
/* perform actual benchmark */
start_time();
iterate(&results[0]);
stop_time();
total_time = get_time();
/* get a function of the input to report */
seedcrc = crc16(results[0].seed1, seedcrc);
seedcrc = crc16(results[0].seed2, seedcrc);
seedcrc = crc16(results[0].seed3, seedcrc);
seedcrc = crc16(results[0].size, seedcrc);
switch (seedcrc) { /* test known output for common seeds */
case 0xe9f5: /* seed1=0, seed2=0, seed3=0x66, size 666 per algorithm */
known_id = 3;
printf("2K performance run parameters for coremark.\n");
break;
default:
total_errors = -1;
break;
}
if (known_id >= 0) {
results[i].err = 0;
if ((results[i].execs & 1) &&
(results[i].crclist != list_known_crc[known_id])) {
printf("[%u]ERROR! list crc 0x%04x - should be 0x%04x\n", i,
results[i].crclist, list_known_crc[known_id]);
results[i].err++;
}
if ((results[i].execs & 2) &&
(results[i].crcmatrix != matrix_known_crc[known_id])) {
printf("[%u]ERROR! matrix crc 0x%04x - should be 0x%04x\n", i,
results[i].crcmatrix, matrix_known_crc[known_id]);
results[i].err++;
}
if ((results[i].execs & 4) &&
(results[i].crcstate != state_known_crc[known_id])) {
printf("[%u]ERROR! state crc 0x%04x - should be 0x%04x\n", i,
results[i].crcstate, state_known_crc[known_id]);
results[i].err++;
}
total_errors += results[i].err;
}
total_errors += check_data_types();
/* and report results */
printf("CoreMark Size : %lu\n", (long unsigned)results[0].size);
printf("Total ticks : %lu\n", (long unsigned)total_time);
printf("Total time (secs): %f\n", time_in_secs(total_time));
if (time_in_secs(total_time) > 0)
printf("Iterations/Sec : %f\n",
1 * results[0].iterations / time_in_secs(total_time));
if (time_in_secs(total_time) < 10) {
printf("ERROR! Must execute for at least 10 secs for a valid result!\n");
total_errors++;
}
printf("Iterations : %lu\n", (long unsigned)results[0].iterations);
printf("Compiler version : AICC 1.0\n");
/* output for verification */
printf("seedcrc : 0x%04x\n", seedcrc);
if (results[0].execs & 1)
printf("[%d]crclist : 0x%04x\n", i, results[i].crclist);
if (results[0].execs & 2)
printf("[%d]crcmatrix : 0x%04x\n", i, results[i].crcmatrix);
if (results[0].execs & 4)
printf("[%d]crcstate : 0x%04x\n", i, results[i].crcstate);
printf("[%d]crcfinal : 0x%04x\n", i, results[i].crc);
if (total_errors == 0) {
printf("Correct operation validated. See README.md for run and reporting "
"rules.\n");
if (known_id == 3) {
printf("Function Level CoreMark 1.0 : %f by AICC 1.0",
results[0].iterations / time_in_secs(total_time));
printf(" / Heap");
printf("\n");
}
}
if (total_errors > 0)
printf("Errors detected\n");
if (total_errors < 0)
printf("Cannot validate operation for these seed values, please compare "
"with results on a known platform.\n");
portable_free(results[0].memblock[0]);
/* And last call any target specific code for finalizing */
portable_fini(&(results[0].port));
return 0;
}
|
cmp_complex.c
|
cmp_complex
|
#include <stdio.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
extern short calc_func(short *pdata, core_results *res);
int cmp_complex(list_data *a, list_data *b, core_results *res) {
short val1 = calc_func(&(a->data16), res);
short val2 = calc_func(&(b->data16), res);
return val1 - val2;
}
|
stop_time.c
|
stop_time
|
#include <time.h>
extern struct timespec start_time_val, stop_time_val;
void stop_time(void) { clock_gettime(CLOCK_REALTIME, &stop_time_val); }
|
portable_free.c
|
portable_free
|
#include <stdlib.h>
void portable_free(void *p) { free(p); }
|
crc16.c
|
crc16
|
typedef unsigned short u16;
typedef unsigned char u8;
u16 crcu16(u16 newval, u16 crc);
u16 crc16(short newval, u16 crc) { return crcu16((u16)newval, crc); }
|
calc_func.c
|
calc_func
|
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
u16 crcu16(u16 newval, u16 crc);
u16 core_bench_state(unsigned blksize, u8 *memblock, short seed1, short seed2,
short step, u16 crc);
u16 core_bench_matrix(mat_params *p, short seed, u16 crc);
short calc_func(short *pdata, core_results *res) {
short data = *pdata;
short retval;
u8 optype = (data >> 7) & 1;
if (optype)
return (data & 0x007f);
else {
short flag = data & 0x7;
short dtype = ((data >> 3) & 0xf);
dtype |= dtype << 4;
switch (flag) {
case 0:
if (dtype < 0x22)
dtype = 0x22;
retval = core_bench_state(res->size, res->memblock[3], res->seed1,
res->seed2, dtype, res->crc);
if (res->crcstate == 0)
res->crcstate = retval;
break;
case 1:
retval = core_bench_matrix(&(res->mat), dtype, res->crc);
if (res->crcmatrix == 0)
res->crcmatrix = retval;
break;
default:
retval = data;
break;
}
res->crc = crcu16(retval, res->crc);
retval &= 0x007f;
*pdata = (data & 0xff00) | 0x0080 | retval;
return retval;
}
}
|
core_list_insert_new.c
|
core_list_insert_new
|
#include <stdio.h>
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
void copy_info(list_data *to, list_data *from);
list_head *core_list_insert_new(list_head *insert_point, list_data *info,
list_head **memblock, list_data **datablock,
list_head *memblock_end,
list_data *datablock_end) {
list_head *newitem;
if ((*memblock + 1) >= memblock_end)
return NULL;
if ((*datablock + 1) >= datablock_end)
return NULL;
newitem = *memblock;
(*memblock)++;
newitem->next = insert_point->next;
insert_point->next = newitem;
newitem->info = *datablock;
(*datablock)++;
copy_info(newitem->info, info);
return newitem;
}
|
portable_fini.c
|
portable_fini
|
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
void portable_fini(core_portable *p) { p->portable_id = 0; }
|
core_list_remove.c
|
core_list_remove
|
#include <stdio.h>
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
list_head *core_list_remove(list_head *item) {
list_data *tmp;
list_head *ret = item->next;
/* swap data pointers */
tmp = item->info;
item->info = ret->info;
ret->info = tmp;
/* and eliminate item */
item->next = item->next->next;
ret->next = NULL;
return ret;
}
|
core_list_mergesort.c
|
core_list_mergesort
|
#include <stdio.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
typedef int (*list_cmp)(list_data *a, list_data *b, core_results *res);
list_head *core_list_mergesort(list_head *list, list_cmp cmp,
core_results *res) {
list_head *p, *q, *e, *tail;
int insize, nmerges, psize, qsize, i;
insize = 1;
while (1) {
p = list;
list = NULL;
tail = NULL;
nmerges = 0;
while (p) {
nmerges++;
q = p;
psize = 0;
for (i = 0; i < insize; i++) {
psize++;
q = q->next;
if (!q)
break;
}
qsize = insize;
while (psize > 0 || (qsize > 0 && q)) {
if (psize == 0) {
e = q;
q = q->next;
qsize--;
} else if (qsize == 0 || !q) {
e = p;
p = p->next;
psize--;
} else if (cmp(p->info, q->info, res) <= 0) {
e = p;
p = p->next;
psize--;
} else {
e = q;
q = q->next;
qsize--;
}
if (tail) {
tail->next = e;
} else {
list = e;
}
tail = e;
}
p = q;
}
tail->next = NULL;
if (nmerges <= 1)
return list;
insize *= 2;
}
}
|
crcu32.c
|
crcu32
|
typedef unsigned short u16;
typedef unsigned char u8;
u16 crc16(short newval, u16 crc);
u16 crcu32(unsigned newval, u16 crc) {
crc = crc16((short)newval, crc);
crc = crc16((short)(newval >> 16), crc);
return crc;
}
|
matrix_mul_matrix_bitextract.c
|
matrix_mul_matrix_bitextract
|
#define bit_extract(x, from, to) (((x) >> (from)) & (~(0xffffffff << (to))))
void matrix_mul_matrix_bitextract(unsigned N, int *C, short *A, short *B) {
unsigned i, j, k;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i * N + j] = 0;
for (k = 0; k < N; k++) {
int tmp = (int)A[i * N + k] * (int)B[k * N + j];
C[i * N + j] += bit_extract(tmp, 2, 4) * bit_extract(tmp, 5, 7);
}
}
}
}
|
crcu8.c
|
crcu8
|
typedef unsigned short u16;
typedef unsigned char u8;
u16 crcu8(u8 data, u16 crc) {
u8 i = 0, x16 = 0, carry = 0;
for (i = 0; i < 8; i++) {
x16 = (u8)((data & 1) ^ ((u8)crc & 1));
data >>= 1;
if (x16 == 1) {
crc ^= 0x4002;
carry = 1;
} else
carry = 0;
crc >>= 1;
if (carry)
crc |= 0x8000;
else
crc &= 0x7fff;
}
return crc;
}
|
matrix_add_const.c
|
matrix_add_const
|
void matrix_add_const(unsigned N, short *A, short val) {
unsigned i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
A[i * N + j] += val;
}
}
}
|
crcu16.c
|
crcu16
|
typedef unsigned short u16;
typedef unsigned char u8;
u16 crcu8(u8 data, u16 crc);
u16 crcu16(u16 newval, u16 crc) {
crc = crcu8((u8)(newval), crc);
crc = crcu8((u8)((newval) >> 8), crc);
return crc;
}
|
core_list_init.c
|
core_list_init
|
#include <stdint.h>
#include <stdio.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
list_head *core_list_insert_new(list_head *insert_point, list_data *info,
list_head **memblock, list_data **datablock,
list_head *memblock_end,
list_data *datablock_end);
typedef int (*list_cmp)(list_data *a, list_data *b, core_results *res);
list_head *core_list_mergesort(list_head *list, list_cmp cmp,
core_results *res);
int cmp_idx(list_data *a, list_data *b, core_results *res);
list_head *core_list_init(unsigned blksize, list_head *memblock, short seed) {
unsigned per_item = 16 + sizeof(struct list_data_s);
unsigned size = (blksize / per_item) - 2;
list_head *memblock_end = memblock + size;
list_data *datablock = (list_data *)(memblock_end);
list_data *datablock_end = datablock + size;
unsigned i;
list_head *finder, *list = memblock;
list_data info;
list->next = NULL;
list->info = datablock;
list->info->idx = 0x0000;
list->info->data16 = (short)0x8080;
memblock++;
datablock++;
info.idx = 0x7fff;
info.data16 = (short)0xffff;
core_list_insert_new(list, &info, &memblock, &datablock, memblock_end,
datablock_end);
for (i = 0; i < size; i++) {
u16 datpat = ((u16)(seed ^ i) & 0xf);
u16 dat = (datpat << 3) | (i & 0x7);
info.data16 = (dat << 8) | dat;
core_list_insert_new(list, &info, &memblock, &datablock, memblock_end,
datablock_end);
}
finder = list->next;
i = 1;
while (finder->next != NULL) {
if (i < size / 5)
finder->info->idx = i++;
else {
u16 pat = (u16)(i++ ^ seed);
finder->info->idx = 0x3fff & (((i & 0x07) << 8) | pat);
}
finder = finder->next;
}
list = core_list_mergesort(list, cmp_idx, NULL);
return list;
}
|
core_state_transition.c
|
core_state_transition
|
#include <stdint.h>
#include <stdio.h>
typedef unsigned char u8;
typedef enum CORE_STATE {
CORE_START = 0,
CORE_INVALID,
CORE_S1,
CORE_S2,
CORE_INT,
CORE_FLOAT,
CORE_EXPONENT,
CORE_SCIENTIFIC,
NUM_CORE_STATES
} core_state_e;
u8 ee_isdigit(u8 c);
enum CORE_STATE core_state_transition(u8 **instr, unsigned *transition_count) {
u8 *str = *instr;
u8 NEXT_SYMBOL;
enum CORE_STATE state = CORE_START;
for (; *str && state != CORE_INVALID; str++) {
NEXT_SYMBOL = *str;
if (NEXT_SYMBOL == ',') {
str++;
break;
}
switch (state) {
case CORE_START:
if (ee_isdigit(NEXT_SYMBOL)) {
state = CORE_INT;
} else if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-') {
state = CORE_S1;
} else if (NEXT_SYMBOL == '.') {
state = CORE_FLOAT;
} else {
state = CORE_INVALID;
transition_count[CORE_INVALID]++;
}
transition_count[CORE_START]++;
break;
case CORE_S1:
if (ee_isdigit(NEXT_SYMBOL)) {
state = CORE_INT;
transition_count[CORE_S1]++;
} else if (NEXT_SYMBOL == '.') {
state = CORE_FLOAT;
transition_count[CORE_S1]++;
} else {
state = CORE_INVALID;
transition_count[CORE_S1]++;
}
break;
case CORE_INT:
if (NEXT_SYMBOL == '.') {
state = CORE_FLOAT;
transition_count[CORE_INT]++;
} else if (!ee_isdigit(NEXT_SYMBOL)) {
state = CORE_INVALID;
transition_count[CORE_INT]++;
}
break;
case CORE_FLOAT:
if (NEXT_SYMBOL == 'E' || NEXT_SYMBOL == 'e') {
state = CORE_S2;
transition_count[CORE_FLOAT]++;
} else if (!ee_isdigit(NEXT_SYMBOL)) {
state = CORE_INVALID;
transition_count[CORE_FLOAT]++;
}
break;
case CORE_S2:
if (NEXT_SYMBOL == '+' || NEXT_SYMBOL == '-') {
state = CORE_EXPONENT;
transition_count[CORE_S2]++;
} else {
state = CORE_INVALID;
transition_count[CORE_S2]++;
}
break;
case CORE_EXPONENT:
if (ee_isdigit(NEXT_SYMBOL)) {
state = CORE_SCIENTIFIC;
transition_count[CORE_EXPONENT]++;
} else {
state = CORE_INVALID;
transition_count[CORE_EXPONENT]++;
}
break;
case CORE_SCIENTIFIC:
if (!ee_isdigit(NEXT_SYMBOL)) {
state = CORE_INVALID;
transition_count[CORE_INVALID]++;
}
break;
default:
break;
}
}
*instr = str;
return state;
}
|
core_bench_matrix.c
|
core_bench_matrix
|
#include <time.h>
#include <stdint.h>
#include <stdio.h>
typedef unsigned short u16;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
u16 crc16(short newval, u16 crc);
short matrix_test(unsigned N, int *C, short *A, short *B, short val);
u16 core_bench_matrix(mat_params *p, short seed, u16 crc) {
unsigned N = p->N;
int *C = p->C;
short *A = p->A;
short *B = p->B;
short val = (short)seed;
crc = crc16(matrix_test(N, C, A, B, val), crc);
return crc;
}
|
ee_isdigit.c
|
ee_isdigit
|
typedef unsigned char u8;
u8 ee_isdigit(u8 c) {
u8 retval;
retval = ((c >= '0') & (c <= '9')) ? 1 : 0;
return retval;
}
|
core_init_state.c
|
core_init_state
|
typedef unsigned short u16;
typedef unsigned char u8;
/* Default initialization patterns */
static u8 *intpat[4] = {(u8 *)"5012", (u8 *)"1234", (u8 *)"-874", (u8 *)"+122"};
static u8 *floatpat[4] = {(u8 *)"35.54400", (u8 *)".1234500", (u8 *)"-110.700",
(u8 *)"+0.64400"};
static u8 *scipat[4] = {(u8 *)"5.500e+3", (u8 *)"-.123e-2", (u8 *)"-87e+832",
(u8 *)"+0.6e-12"};
static u8 *errpat[4] = {(u8 *)"T0.3e-1F", (u8 *)"-T.T++Tq", (u8 *)"1T3.4e4z",
(u8 *)"34.0e-T^"};
void core_init_state(unsigned size, short seed, u8 *p) {
unsigned total = 0, next = 0, i;
u8 *buf = 0;
size--;
next = 0;
while ((total + next + 1) < size) {
if (next > 0) {
for (i = 0; i < next; i++)
*(p + total + i) = buf[i];
*(p + total + i) = ',';
total += next + 1;
}
seed++;
switch (seed & 0x7) {
case 0: /* int */
case 1: /* int */
case 2: /* int */
buf = intpat[(seed >> 3) & 0x3];
next = 4;
break;
case 3: /* float */
case 4: /* float */
buf = floatpat[(seed >> 3) & 0x3];
next = 8;
break;
case 5: /* scientific */
case 6: /* scientific */
buf = scipat[(seed >> 3) & 0x3];
next = 8;
break;
case 7: /* invalid */
buf = errpat[(seed >> 3) & 0x3];
next = 8;
break;
default: /* Never happen, just to make some compilers happy */
break;
}
}
size++;
while (total < size) { /* fill the rest with 0 */
*(p + total) = 0;
total++;
}
}
|
core_list_reverse.c
|
core_list_reverse
|
#include <stdio.h>
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
list_head *core_list_reverse(list_head *list) {
list_head *next = NULL, *tmp;
while (list) {
tmp = list->next;
list->next = next;
next = list;
list = tmp;
}
return next;
}
|
matrix_test.c
|
matrix_test
|
#include <stdint.h>
#include <stdio.h>
typedef unsigned short u16;
#define matrix_big(x) (0xf000 | (x))
u16 crc16(short newval, u16 crc);
short matrix_sum(unsigned N, int *C, short clipval);
void matrix_mul_const(unsigned N, int *C, short *A, short val);
void matrix_mul_vect(unsigned N, int *C, short *A, short *B);
void matrix_mul_matrix(unsigned N, int *C, short *A, short *B);
void matrix_mul_matrix_bitextract(unsigned N, int *C, short *A, short *B);
void matrix_add_const(unsigned N, short *A, short val);
short matrix_test(unsigned N, int *C, short *A, short *B, short val) {
u16 crc = 0;
short clipval = matrix_big(val);
matrix_add_const(N, A, val);
matrix_mul_const(N, C, A, val);
crc = crc16(matrix_sum(N, C, clipval), crc);
matrix_mul_vect(N, C, A, B);
crc = crc16(matrix_sum(N, C, clipval), crc);
matrix_mul_matrix(N, C, A, B);
crc = crc16(matrix_sum(N, C, clipval), crc);
matrix_mul_matrix_bitextract(N, C, A, B);
crc = crc16(matrix_sum(N, C, clipval), crc);
matrix_add_const(N, A, -val);
return crc;
}
|
core_bench_list.c
|
core_bench_list
|
#include <stdint.h>
#include <stdio.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
u16 crc16(short newval, u16 crc);
u16 crcu16(u16 newval, u16 crc);
list_head *core_list_find(list_head *list, list_data *info);
list_head *core_list_reverse(list_head *list);
list_head *core_list_remove(list_head *item);
list_head *core_list_undo_remove(list_head *item_removed,
list_head *item_modified);
typedef int (*list_cmp)(list_data *a, list_data *b, core_results *res);
list_head *core_list_mergesort(list_head *list, list_cmp cmp,
core_results *res);
int cmp_idx(list_data *a, list_data *b, core_results *res);
int cmp_complex(list_data *a, list_data *b, core_results *res);
u16 core_bench_list(core_results *res, short finder_idx) {
u16 retval = 0;
u16 found = 0, missed = 0;
list_head *list = res->list;
short find_num = res->seed3;
list_head *this_find;
list_head *finder, *remover;
list_data info = {0};
short i;
info.idx = finder_idx;
for (i = 0; i < find_num; i++) {
info.data16 = (i & 0xff);
this_find = core_list_find(list, &info);
list = core_list_reverse(list);
if (this_find == NULL) {
missed++;
retval += (list->next->info->data16 >> 8) & 1;
} else {
found++;
if (this_find->info->data16 & 0x1)
retval += (this_find->info->data16 >> 9) & 1;
if (this_find->next != NULL) {
finder = this_find->next;
this_find->next = finder->next;
finder->next = list->next;
list->next = finder;
}
}
if (info.idx >= 0)
info.idx++;
}
retval += found * 4 - missed;
if (finder_idx > 0)
list = core_list_mergesort(list, cmp_complex, res);
remover = core_list_remove(list->next);
finder = core_list_find(list, &info);
if (!finder)
finder = list->next;
while (finder) {
retval = crc16(list->info->data16, retval);
finder = finder->next;
}
remover = core_list_undo_remove(remover, list->next);
list = core_list_mergesort(list, cmp_idx, NULL);
finder = list->next;
while (finder) {
retval = crc16(list->info->data16, retval);
finder = finder->next;
}
return retval;
}
|
time_in_secs.c
|
time_in_secs
|
#include <time.h>
double time_in_secs(clock_t ticks) {
double retval = ((double)ticks) / (double)1000;
return retval;
}
|
cmp_idx.c
|
cmp_idx
|
#include <stdio.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
int cmp_idx(list_data *a, list_data *b, core_results *res) {
if (res == NULL) {
a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16 >> 8));
b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16 >> 8));
}
return a->idx - b->idx;
}
|
matrix_sum.c
|
matrix_sum
|
short matrix_sum(unsigned N, int *C, short clipval) {
int tmp = 0, prev = 0, cur = 0;
short ret = 0;
unsigned i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
cur = C[i * N + j];
tmp += cur;
if (tmp > clipval) {
ret += 10;
tmp = 0;
} else {
ret += (cur > prev) ? 1 : 0;
}
prev = cur;
}
}
return ret;
}
|
core_list_undo_remove.c
|
core_list_undo_remove
|
typedef struct list_data_s {
short data16;
short idx;
} list_data;
typedef struct list_head_s {
struct list_head_s *next;
struct list_data_s *info;
} list_head;
list_head *core_list_undo_remove(list_head *item_removed,
list_head *item_modified) {
list_data *tmp;
/* swap data pointers */
tmp = item_removed->info;
item_removed->info = item_modified->info;
item_modified->info = tmp;
/* and insert item */
item_removed->next = item_modified->next;
item_modified->next = item_removed;
return item_removed;
}
|
core_bench_state.c
|
core_bench_state
|
typedef unsigned short u16;
typedef unsigned char u8;
typedef enum CORE_STATE {
CORE_START = 0,
CORE_INVALID,
CORE_S1,
CORE_S2,
CORE_INT,
CORE_FLOAT,
CORE_EXPONENT,
CORE_SCIENTIFIC,
NUM_CORE_STATES
} core_state_e;
u16 crcu32(unsigned newval, u16 crc);
enum CORE_STATE core_state_transition(u8 **instr, unsigned *transition_count);
u16 core_bench_state(unsigned blksize, u8 *memblock, short seed1, short seed2,
short step, u16 crc) {
unsigned final_counts[NUM_CORE_STATES];
unsigned track_counts[NUM_CORE_STATES];
u8 *p = memblock;
unsigned i;
for (i = 0; i < NUM_CORE_STATES; i++) {
final_counts[i] = track_counts[i] = 0;
}
while (*p != 0) {
enum CORE_STATE fstate = core_state_transition(&p, track_counts);
final_counts[fstate]++;
}
p = memblock;
while (p < (memblock + blksize)) {
if (*p != ',')
*p ^= (u8)seed1;
p += step;
}
p = memblock;
while (*p != 0) {
enum CORE_STATE fstate = core_state_transition(&p, track_counts);
final_counts[fstate]++;
}
p = memblock;
while (p < (memblock +
blksize)) {
if (*p != ',')
*p ^= (u8)seed2;
p += step;
}
for (i = 0; i < NUM_CORE_STATES; i++) {
crc = crcu32(final_counts[i], crc);
crc = crcu32(track_counts[i], crc);
}
return crc;
}
|
start_time.c
|
start_time
|
#include <time.h>
extern struct timespec start_time_val, stop_time_val;
void start_time(void) { clock_gettime(CLOCK_REALTIME, &start_time_val); }
|
portable_malloc.c
|
portable_malloc
|
#include <stdlib.h>
void *portable_malloc(size_t size) { return malloc(size); }
|
matrix_mul_vect.c
|
matrix_mul_vect
|
void matrix_mul_vect(unsigned N, int *C, short *A, short *B) {
unsigned i, j;
for (i = 0; i < N; i++) {
C[i] = 0;
for (j = 0; j < N; j++) {
C[i] += (int)A[i * N + j] * (int)B[j];
}
}
}
|
matrix_mul_const.c
|
matrix_mul_const
|
void matrix_mul_const(unsigned N, int *C, short *A, short val) {
unsigned i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i * N + j] = (int)A[i * N + j] * (int)val;
}
}
}
|
iterate.c
|
iterate
|
#include <stdio.h>
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct CORE_PORTABLE_S {
u8 portable_id;
} core_portable;
typedef struct MAT_PARAMS_S {
int N;
short *A;
short *B;
int *C;
} mat_params;
typedef struct RESULTS_S {
short seed1;
short seed2;
short seed3;
void *memblock[4];
unsigned size;
unsigned iterations;
unsigned execs;
struct list_head_s *list;
mat_params mat;
u16 crc;
u16 crclist;
u16 crcmatrix;
u16 crcstate;
short err;
core_portable port;
} core_results;
u16 crc16(short newval, u16 crc);
u16 crcu16(u16 newval, u16 crc);
u16 core_bench_list(core_results *res, short finder_idx);
void *iterate(void *pres) {
unsigned i;
u16 crc;
core_results *res = (core_results *)pres;
unsigned iterations = res->iterations;
res->crc = 0;
res->crclist = 0;
res->crcmatrix = 0;
res->crcstate = 0;
for (i = 0; i < iterations; i++) {
crc = core_bench_list(res, 1);
res->crc = crcu16(crc, res->crc);
crc = core_bench_list(res, -1);
res->crc = crcu16(crc, res->crc);
if (i == 0)
res->crclist = res->crc;
}
return NULL;
}
|
check_data_types.c
|
check_data_types
|
#include <stdio.h>
#include <stdint.h>
typedef unsigned short u16;
typedef unsigned char u8;
u8 check_data_types() {
u8 retval = 0;
if (sizeof(u8) != 1) {
printf("ERROR: u8 is not an 8b datatype!\n");
retval++;
}
if (sizeof(u16) != 2) {
printf("ERROR: u16 is not a 16b datatype!\n");
retval++;
}
if (sizeof(short) != 2) {
printf("ERROR: short is not a 16b datatype!\n");
retval++;
}
if (sizeof(int) != 4) {
printf("ERROR: int is not a 32b datatype!\n");
retval++;
}
if (sizeof(unsigned) != 4) {
printf("ERROR: unsigned is not a 32b datatype!\n");
retval++;
}
if (sizeof(uintptr_t) != sizeof(int *)) {
printf("ERROR: uintptr_t is not a datatype that holds an int pointer!\n");
retval++;
}
if (retval > 0) {
printf("ERROR: Please modify the datatypes in core_portme.h!\n");
}
return retval;
}
|
matrix_mul_matrix.c
|
matrix_mul_matrix
|
void matrix_mul_matrix(unsigned N, int *C, short *A, short *B) {
unsigned i, j, k;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
C[i * N + j] = 0;
for (k = 0; k < N; k++) {
C[i * N + j] += (int)A[i * N + k] * (int)B[k * N + j];
}
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.