Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,43 @@ Many thanks to all of the individuals who helped with the development or testing
* Rob Cosaro, NXP
* Shumpei Kawasaki, RENESAS

# Code changes Q3-2026

- coremark.h
- "size" element in typedef struct core_results is renamed to datasize to workaround a limitation in Keil C51 compiler.
In this compiler, "size", "data", "pdata" are considered reserved keywords and cannot be used by the program code
as names for variables.
- Update function prototype for crcu8 function from core_util.c due to change in input parameter name.
- Add HAS_C99 macro, and add inttypes.h if the compiler supports C99 (HAS_C99 set to 1)
- core_main.c:
- Various code changes in main() due to "size" renamed to "datasize" in core_results structure.
- Adding STATIC_MEMBLK_ATTR macro for sttribute of the static_memblk[TOTAL_DATA_SIZE]
- This allows static_memblk[] to be declared as xdata when using MCS51 architecture.
- This also addressed the request in https://github.com/eembc/coremark/pull/58
- Update result report to use the new HAS_C99 macro to select if PRIu32 format specifier can be used.
- core_util.c:
- crcu8 function: input parameter is renamed from "data" to "newval" to allow the code to be compiled by Keil C51
- This change also align crcu8 function with other crc functions where the first parameters are named as "newval"
- check_data_types function: update the comparison between size of pointer and size of integer ee_ptr_int
- This change remove the error message.
- core_list_join.c
- Adding __COREMARK_REENTRANT macro
- This macro is added to support MCS51 architecture. When using MCS51 architecture, by default the C compiler allocate
variables in functions with fixed address. This causes problems to functions that can be reentrant.
This problem can be worked around by adding a reentrant function attribute, and this attribute is compiler specific.
By declaring the __COREMARK_REENTRANT macro, users can define the compiler specific reentrant attribute easily.
The __COREMARK_REENTRANT macro is defined for function pointers "*list_cmp" and "*core_list_mergesort".
- clac_func function: Several variable/parameter names are changed to work around the limitations in Keil C51 compiler.
The name changes incuded:
- parameter *pdata changed to *ptr_data
- variable data changed to curr_data
- res->size changed to res->datasize
- core_portme.h in barebones, simple and posix
- Data type : Added stdint.h and changed the following mapping.
- Maps ee_s32 to int32_t (it was "signed int" but this could maps to 16-bit integer in 8-bit and 16-bit architectures)
- Maps ee_u32 to uint32_t (it was "unsigned int" but this could maps to 16-bit integer in 8-bit and 16-bit architectures)


# Legal
Please refer to LICENSE.md in this repository for a description of your rights to use this code.

Expand Down
2 changes: 1 addition & 1 deletion barebones/core_portme.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ portable_init(core_portable *p, int *argc, char *argv[])
(void)argc; // prevent unused warning
(void)argv; // prevent unused warning

if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
if (sizeof(ee_ptr_int) < sizeof(ee_u8 *))
{
ee_printf(
"ERROR! Please define ee_ptr_int to a type that holds a "
Expand Down
35 changes: 32 additions & 3 deletions barebones/core_portme.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,58 @@ Original Author: Shay Gal-on
#define MEM_LOCATION "STACK"
#endif

#ifdef __C51__
/* Example: Additional settings for Keil C51 Compiler */
#define __COREMARK_REENTRANT reentrant
#define MEM_METHOD MEM_STATIC
#define MEM_STATIC_ATTR xdata
#define HAS_C99 0
#endif

#ifdef __SDCC
/* Example: Additional settings for SDCC Compiler */
#define __COREMARK_REENTRANT __reentrant
#define MEM_METHOD MEM_STATIC
#define MEM_STATIC_ATTR __xdata
#endif

/* Data Types :
To avoid compiler issues, define the data types that need ot be used for
8b, 16b and 32b in <core_portme.h>.

*Imprtant* :
*Important* :
ee_ptr_int needs to be the data type used to hold pointers, otherwise
coremark may fail!!!
*/

#include <stddef.h> /* Note: Required for size_t */
#include <stdint.h> /* Note: Required for int32_t and uint32_t */

typedef signed short ee_s16;
typedef unsigned short ee_u16;
typedef signed int ee_s32;
typedef int32_t ee_s32;
typedef float ee_f32;
typedef unsigned char ee_u8;
typedef unsigned int ee_u32;
typedef uint32_t ee_u32;
typedef ee_u32 ee_ptr_int;
typedef size_t ee_size_t;
#define NULL ((void *)0)
/* align_mem :
This macro is used to align an offset to point to a 32b value. It is
used in the Matrix algorithm to initialize the input memory blocks.

Example for Keil C51
#define align_mem(x) \
((void xdata *)((((unsigned int)(void xdata *)(x)) + 3u) & 0xFFFCu))

Example for SDCC
#define align_mem(x) \
((void __xdata *)((((unsigned int)(void __xdata *)(x)) + 3u) & 0xFFFCu))

*/
#define align_mem(x) (void *)(4 + (((ee_ptr_int)(x)-1) & ~3))


/* Configuration : CORE_TICKS
Define type of return from the timing functions.
*/
Expand Down
2 changes: 1 addition & 1 deletion barebones_porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ portable_init(core_portable *p, int *argc, char *argv[])
cache_init();
timer_config();

if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
if (sizeof(ee_ptr_int) < sizeof(ee_u8 *))
{
ee_printf(
"ERROR! Please define ee_ptr_int to a type that holds a "
Expand Down
32 changes: 18 additions & 14 deletions core_list_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ input for the operation.

*/

#ifndef __COREMARK_REENTRANT
#define __COREMARK_REENTRANT
#endif

/* local functions */

list_head *core_list_find(list_head *list, list_data *info);
Expand All @@ -61,34 +65,34 @@ list_head *core_list_insert_new(list_head * insert_point,
list_data **datablock,
list_head * memblock_end,
list_data * datablock_end);
typedef ee_s32 (*list_cmp)(list_data *a, list_data *b, core_results *res);
typedef ee_s32 (*list_cmp)(list_data *a, list_data *b, core_results *res) __COREMARK_REENTRANT;
list_head *core_list_mergesort(list_head * list,
list_cmp cmp,
core_results *res);
core_results *res) __COREMARK_REENTRANT;

ee_s16
calc_func(ee_s16 *pdata, core_results *res)
calc_func(ee_s16 *ptr_data, core_results *res)
{
ee_s16 data = *pdata;
ee_s16 curr_data = *ptr_data;
ee_s16 retval;
ee_u8 optype
= (data >> 7)
= (curr_data >> 7)
& 1; /* bit 7 indicates if the function result has been cached */
if (optype) /* if cached, use cache */
return (data & 0x007f);
return (curr_data & 0x007f);
else
{ /* otherwise calculate and cache the result */
ee_s16 flag = data & 0x7; /* bits 0-2 is type of function to perform */
ee_s16 flag = curr_data & 0x7; /* bits 0-2 is type of function to perform */
ee_s16 dtype
= ((data >> 3)
= ((curr_data >> 3)
& 0xf); /* bits 3-6 is specific data for the operation */
dtype |= dtype << 4; /* replicate the lower 4 bits to get an 8b value */
switch (flag)
{
case 0:
if (dtype < 0x22) /* set min period for bit corruption */
dtype = 0x22;
retval = core_bench_state(res->size,
retval = core_bench_state(res->datasize,
res->memblock[3],
res->seed1,
res->seed2,
Expand All @@ -103,12 +107,12 @@ calc_func(ee_s16 *pdata, core_results *res)
res->crcmatrix = retval;
break;
default:
retval = data;
retval = curr_data;
break;
}
res->crc = crcu16(retval, res->crc);
retval &= 0x007f;
*pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */
*ptr_data = (curr_data & 0xff00) | 0x0080 | retval; /* cache the result */
return retval;
}
}
Expand All @@ -118,7 +122,7 @@ calc_func(ee_s16 *pdata, core_results *res)
Can be used by mergesort.
*/
ee_s32
cmp_complex(list_data *a, list_data *b, core_results *res)
cmp_complex(list_data *a, list_data *b, core_results *res) __COREMARK_REENTRANT
{
ee_s16 val1 = calc_func(&(a->data16), res);
ee_s16 val2 = calc_func(&(b->data16), res);
Expand All @@ -131,7 +135,7 @@ cmp_complex(list_data *a, list_data *b, core_results *res)
Can be used by mergesort.
*/
ee_s32
cmp_idx(list_data *a, list_data *b, core_results *res)
cmp_idx(list_data *a, list_data *b, core_results *res) __COREMARK_REENTRANT
{
if (res == NULL)
{
Expand Down Expand Up @@ -497,7 +501,7 @@ core_list_reverse(list_head *list)

*/
list_head *
core_list_mergesort(list_head *list, list_cmp cmp, core_results *res)
core_list_mergesort(list_head *list, list_cmp cmp, core_results *res) __COREMARK_REENTRANT
{
list_head *p, *q, *e, *tail;
ee_s32 insize, nmerges, psize, qsize, i;
Expand Down
37 changes: 24 additions & 13 deletions core_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ ee_s32 get_seed_32(int i);
#endif

#if (MEM_METHOD == MEM_STATIC)
#ifdef STATIC_MEMBLK_ATTR
STATIC_MEMBLK_ATTR ee_u8 static_memblk[TOTAL_DATA_SIZE];
#else
ee_u8 static_memblk[TOTAL_DATA_SIZE];
#endif
#endif
char *mem_name[3] = { "Static", "Heap", "Stack" };
/* Function: main
Main entry routine for the benchmark.
Expand Down Expand Up @@ -160,7 +164,7 @@ main(int argc, char *argv[])
}
#if (MEM_METHOD == MEM_STATIC)
results[0].memblock[0] = (void *)static_memblk;
results[0].size = TOTAL_DATA_SIZE;
results[0].datasize = TOTAL_DATA_SIZE;
results[0].err = 0;
#if (MULTITHREAD > 1)
#error "Cannot use a static data area with multiple contexts!"
Expand All @@ -170,10 +174,10 @@ main(int argc, char *argv[])
{
ee_s32 malloc_override = get_seed(7);
if (malloc_override != 0)
results[i].size = malloc_override;
results[i].datasize = malloc_override;
else
results[i].size = TOTAL_DATA_SIZE;
results[i].memblock[0] = portable_malloc(results[i].size);
results[i].datasize = TOTAL_DATA_SIZE;
results[i].memblock[0] = portable_malloc(results[i].datasize);
results[i].seed1 = results[0].seed1;
results[i].seed2 = results[0].seed2;
results[i].seed3 = results[0].seed3;
Expand All @@ -184,7 +188,7 @@ main(int argc, char *argv[])
for (i = 0; i < MULTITHREAD; i++)
{
results[i].memblock[0] = stack_memblock + i * TOTAL_DATA_SIZE;
results[i].size = TOTAL_DATA_SIZE;
results[i].datasize = TOTAL_DATA_SIZE;
results[i].seed1 = results[0].seed1;
results[i].seed2 = results[0].seed2;
results[i].seed3 = results[0].seed3;
Expand All @@ -202,7 +206,7 @@ for (i = 0; i < MULTITHREAD; i++)
num_algorithms++;
}
for (i = 0; i < MULTITHREAD; i++)
results[i].size = results[i].size / num_algorithms;
results[i].datasize = results[i].datasize / num_algorithms;
/* Assign pointers */
for (i = 0; i < NUM_ALGORITHMS; i++)
{
Expand All @@ -211,7 +215,7 @@ for (i = 0; i < MULTITHREAD; i++)
{
for (ctx = 0; ctx < MULTITHREAD; ctx++)
results[ctx].memblock[i + 1]
= (char *)(results[ctx].memblock[0]) + results[0].size * j;
= (char *)(results[ctx].memblock[0]) + results[0].datasize * j;
j++;
}
}
Expand All @@ -221,11 +225,11 @@ for (i = 0; i < MULTITHREAD; i++)
if (results[i].execs & ID_LIST)
{
results[i].list = core_list_init(
results[0].size, results[i].memblock[1], results[i].seed1);
results[0].datasize, results[i].memblock[1], results[i].seed1);
}
if (results[i].execs & ID_MATRIX)
{
core_init_matrix(results[0].size,
core_init_matrix(results[0].datasize,
results[i].memblock[2],
(ee_s32)results[i].seed1
| (((ee_s32)results[i].seed2) << 16),
Expand All @@ -234,7 +238,7 @@ for (i = 0; i < MULTITHREAD; i++)
if (results[i].execs & ID_STATE)
{
core_init_state(
results[0].size, results[i].seed1, results[i].memblock[3]);
results[0].datasize, results[i].seed1, results[i].memblock[3]);
}
}

Expand Down Expand Up @@ -287,8 +291,7 @@ for (i = 0; i < MULTITHREAD; i++)
seedcrc = crc16(results[0].seed1, seedcrc);
seedcrc = crc16(results[0].seed2, seedcrc);
seedcrc = crc16(results[0].seed3, seedcrc);
seedcrc = crc16(results[0].size, seedcrc);

seedcrc = crc16(results[0].datasize, seedcrc);
switch (seedcrc)
{ /* test known output for common seeds */
case 0x8a02: /* seed1=0, seed2=0, seed3=0x66, size 2000 per algorithm */
Expand Down Expand Up @@ -355,7 +358,7 @@ for (i = 0; i < MULTITHREAD; i++)
}
total_errors += check_data_types();
/* and report results */
ee_printf("CoreMark Size : %lu\n", (long unsigned)results[0].size);
ee_printf("CoreMark Size : %lu\n", (long unsigned)results[0].datasize);
ee_printf("Total ticks : %lu\n", (long unsigned)total_time);
#if HAS_FLOAT
ee_printf("Total time (secs): %f\n", time_in_secs(total_time));
Expand All @@ -364,11 +367,19 @@ for (i = 0; i < MULTITHREAD; i++)
default_num_contexts * results[0].iterations
/ time_in_secs(total_time));
#else
#if HAS_C99
ee_printf("Total time (secs): %"PRIu32"\n", time_in_secs(total_time));
if (time_in_secs(total_time) > 0)
ee_printf("Iterations/Sec : %"PRIu32"\n",
default_num_contexts * results[0].iterations
/ time_in_secs(total_time));
#else
ee_printf("Total time (secs): %d\n", (int)time_in_secs(total_time));
if (time_in_secs(total_time) > 0)
ee_printf("Iterations/Sec : %d\n", (int) (
default_num_contexts * results[0].iterations
/ time_in_secs(total_time)));
#endif
#endif
if (time_in_secs(total_time) < 10)
{
Expand Down
8 changes: 4 additions & 4 deletions core_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ get_seed_32(int i)

*/
ee_u16
crcu8(ee_u8 data, ee_u16 crc)
crcu8(ee_u8 newval, ee_u16 crc)
{
ee_u8 i = 0, x16 = 0, carry = 0;

for (i = 0; i < 8; i++)
{
x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1));
data >>= 1;
x16 = (ee_u8)((newval & 1) ^ ((ee_u8)crc & 1));
newval >>= 1;

if (x16 == 1)
{
Expand Down Expand Up @@ -235,7 +235,7 @@ check_data_types()
ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
retval++;
}
if (sizeof(ee_ptr_int) != sizeof(int *))
if (sizeof(ee_ptr_int) < sizeof(int *))
{
ee_printf(
"ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n");
Expand Down
Loading