mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Commented out remaining ehitoa function declaration/calls and related char buff instances. Also commented out extra libraries not currently in use
This commit is contained in:
parent
9f9b38db9f
commit
ac92823c8d
@ -17,6 +17,8 @@ Original Author: Shay Gal-on
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "coremark.h"
|
#include "coremark.h"
|
||||||
|
//#include <stdlib.h>
|
||||||
|
//#include <string.h>
|
||||||
/*
|
/*
|
||||||
Topic: Description
|
Topic: Description
|
||||||
Benchmark using a linked list.
|
Benchmark using a linked list.
|
||||||
@ -26,8 +28,7 @@ Topic: Description
|
|||||||
For our purposes, this will excercise the memory units of the processor.
|
For our purposes, this will excercise the memory units of the processor.
|
||||||
In particular, usage of the list pointers to find and alter data.
|
In particular, usage of the list pointers to find and alter data.
|
||||||
|
|
||||||
We are not using Malloc since some platforms do not support this
|
We are not using Malloc since some platforms do not support this library.
|
||||||
library.
|
|
||||||
|
|
||||||
Instead, the memory block being passed in is used to create a list,
|
Instead, the memory block being passed in is used to create a list,
|
||||||
and the benchmark takes care not to add more items then can be
|
and the benchmark takes care not to add more items then can be
|
||||||
@ -40,73 +41,54 @@ library.
|
|||||||
Data items contain the following:
|
Data items contain the following:
|
||||||
|
|
||||||
idx - An index that captures the initial order of the list.
|
idx - An index that captures the initial order of the list.
|
||||||
data - Variable data initialized based on the input parameters. The 16b
|
data - Variable data initialized based on the input parameters. The 16b are divided as follows:
|
||||||
are divided as follows: o Upper 8b are backup of original data. o Bit 7
|
o Upper 8b are backup of original data.
|
||||||
indicates if the lower 7 bits are to be used as is or calculated. o Bits 0-2
|
o Bit 7 indicates if the lower 7 bits are to be used as is or calculated.
|
||||||
indicate type of operation to perform to get a 7b value. o Bits 3-6 provide
|
o Bits 0-2 indicate type of operation to perform to get a 7b value.
|
||||||
input for the operation.
|
o Bits 3-6 provide input for the operation.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* local functions */
|
/* local functions */
|
||||||
|
|
||||||
list_head *core_list_find(list_head *list, list_data *info);
|
list_head *core_list_find(list_head *list,list_data *info);
|
||||||
list_head *core_list_reverse(list_head *list);
|
list_head *core_list_reverse(list_head *list);
|
||||||
list_head *core_list_remove(list_head *item);
|
list_head *core_list_remove(list_head *item);
|
||||||
list_head *core_list_undo_remove(list_head *item_removed,
|
list_head *core_list_undo_remove(list_head *item_removed, list_head *item_modified);
|
||||||
list_head *item_modified);
|
list_head *core_list_insert_new(list_head *insert_point
|
||||||
list_head *core_list_insert_new(list_head * insert_point,
|
, list_data *info, list_head **memblock, list_data **datablock
|
||||||
list_data * info,
|
, list_head *memblock_end, list_data *datablock_end);
|
||||||
list_head **memblock,
|
typedef ee_s32(*list_cmp)(list_data *a, list_data *b, core_results *res);
|
||||||
list_data **datablock,
|
list_head *core_list_mergesort(list_head *list, list_cmp cmp, core_results *res);
|
||||||
list_head * memblock_end,
|
|
||||||
list_data * datablock_end);
|
|
||||||
typedef ee_s32 (*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);
|
|
||||||
|
|
||||||
ee_s16
|
ee_s16 calc_func(ee_s16 *pdata, core_results *res) {
|
||||||
calc_func(ee_s16 *pdata, core_results *res)
|
ee_s16 data=*pdata;
|
||||||
{
|
|
||||||
ee_s16 data = *pdata;
|
|
||||||
ee_s16 retval;
|
ee_s16 retval;
|
||||||
ee_u8 optype
|
ee_u8 optype=(data>>7) & 1; /* bit 7 indicates if the function result has been cached */
|
||||||
= (data >> 7)
|
|
||||||
& 1; /* bit 7 indicates if the function result has been cached */
|
|
||||||
if (optype) /* if cached, use cache */
|
if (optype) /* if cached, use cache */
|
||||||
return (data & 0x007f);
|
return (data & 0x007f);
|
||||||
else
|
else { /* otherwise calculate and cache the result */
|
||||||
{ /* otherwise calculate and cache the result */
|
ee_s16 flag=data & 0x7; /* bits 0-2 is type of function to perform */
|
||||||
ee_s16 flag = data & 0x7; /* bits 0-2 is type of function to perform */
|
ee_s16 dtype=((data>>3) & 0xf); /* bits 3-6 is specific data for the operation */
|
||||||
ee_s16 dtype
|
|
||||||
= ((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 */
|
dtype |= dtype << 4; /* replicate the lower 4 bits to get an 8b value */
|
||||||
switch (flag)
|
switch (flag) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
if (dtype < 0x22) /* set min period for bit corruption */
|
if (dtype<0x22) /* set min period for bit corruption */
|
||||||
dtype = 0x22;
|
dtype=0x22;
|
||||||
retval = core_bench_state(res->size,
|
retval=core_bench_state(res->size,res->memblock[3],res->seed1,res->seed2,dtype,res->crc);
|
||||||
res->memblock[3],
|
if (res->crcstate==0)
|
||||||
res->seed1,
|
res->crcstate=retval;
|
||||||
res->seed2,
|
|
||||||
dtype,
|
|
||||||
res->crc);
|
|
||||||
if (res->crcstate == 0)
|
|
||||||
res->crcstate = retval;
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
retval = core_bench_matrix(&(res->mat), dtype, res->crc);
|
retval=core_bench_matrix(&(res->mat),dtype,res->crc);
|
||||||
if (res->crcmatrix == 0)
|
if (res->crcmatrix==0)
|
||||||
res->crcmatrix = retval;
|
res->crcmatrix=retval;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
retval = data;
|
retval=data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
res->crc = crcu16(retval, res->crc);
|
res->crc=crcu16(retval,res->crc);
|
||||||
retval &= 0x007f;
|
retval &= 0x007f;
|
||||||
*pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */
|
*pdata = (data & 0xff00) | 0x0080 | retval; /* cache the result */
|
||||||
return retval;
|
return retval;
|
||||||
@ -117,11 +99,9 @@ calc_func(ee_s16 *pdata, core_results *res)
|
|||||||
|
|
||||||
Can be used by mergesort.
|
Can be used by mergesort.
|
||||||
*/
|
*/
|
||||||
ee_s32
|
ee_s32 cmp_complex(list_data *a, list_data *b, core_results *res) {
|
||||||
cmp_complex(list_data *a, list_data *b, core_results *res)
|
ee_s16 val1=calc_func(&(a->data16),res);
|
||||||
{
|
ee_s16 val2=calc_func(&(b->data16),res);
|
||||||
ee_s16 val1 = calc_func(&(a->data16), res);
|
|
||||||
ee_s16 val2 = calc_func(&(b->data16), res);
|
|
||||||
return val1 - val2;
|
return val1 - val2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,22 +110,36 @@ cmp_complex(list_data *a, list_data *b, core_results *res)
|
|||||||
|
|
||||||
Can be used by mergesort.
|
Can be used by mergesort.
|
||||||
*/
|
*/
|
||||||
ee_s32
|
ee_s32 cmp_idx(list_data *a, list_data *b, core_results *res) {
|
||||||
cmp_idx(list_data *a, list_data *b, core_results *res)
|
if (res==NULL) {
|
||||||
{
|
a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16>>8));
|
||||||
if (res == NULL)
|
b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16>>8));
|
||||||
{
|
|
||||||
a->data16 = (a->data16 & 0xff00) | (0x00ff & (a->data16 >> 8));
|
|
||||||
b->data16 = (b->data16 & 0xff00) | (0x00ff & (b->data16 >> 8));
|
|
||||||
}
|
}
|
||||||
return a->idx - b->idx;
|
return a->idx - b->idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/*void ehitoa(int value, char *str, int base){
|
||||||
copy_info(list_data *to, list_data *from)
|
if (value>100000) strcpy(str,"too big");
|
||||||
{
|
else{
|
||||||
to->data16 = from->data16;
|
int places[6] = {100000, 10000, 1000, 100, 10, 1};
|
||||||
to->idx = from->idx;
|
int col;
|
||||||
|
int pv;
|
||||||
|
for(col = 0; col<6; col++){
|
||||||
|
pv = 0;
|
||||||
|
while (value >= places[col]){
|
||||||
|
value=value -places[col];
|
||||||
|
pv++;
|
||||||
|
|
||||||
|
}
|
||||||
|
str[col]=pv+'0';
|
||||||
|
}
|
||||||
|
str[6]=0;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void copy_info(list_data *to,list_data *from) {
|
||||||
|
to->data16=from->data16;
|
||||||
|
to->idx=from->idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Benchmark for linked list:
|
/* Benchmark for linked list:
|
||||||
@ -155,81 +149,74 @@ copy_info(list_data *to, list_data *from)
|
|||||||
- Single remove/reinsert
|
- Single remove/reinsert
|
||||||
* At the end of this function, the list is back to original state
|
* At the end of this function, the list is back to original state
|
||||||
*/
|
*/
|
||||||
ee_u16
|
ee_u16 core_bench_list(core_results *res, ee_s16 finder_idx) {
|
||||||
core_bench_list(core_results *res, ee_s16 finder_idx)
|
ee_u16 retval=0;
|
||||||
{
|
ee_u16 found=0,missed=0;
|
||||||
ee_u16 retval = 0;
|
list_head *list=res->list;
|
||||||
ee_u16 found = 0, missed = 0;
|
ee_s16 find_num=res->seed3;
|
||||||
list_head *list = res->list;
|
|
||||||
ee_s16 find_num = res->seed3;
|
|
||||||
list_head *this_find;
|
list_head *this_find;
|
||||||
list_head *finder, *remover;
|
list_head *finder, *remover;
|
||||||
list_data info;
|
list_data info;
|
||||||
ee_s16 i;
|
ee_s16 i;
|
||||||
|
//ee_printf("entered corebenchlist \n");
|
||||||
info.idx = finder_idx;
|
info.idx=finder_idx;
|
||||||
/* find <find_num> values in the list, and change the list each time
|
/* find <find_num> values in the list, and change the list each time (reverse and cache if value found) */
|
||||||
* (reverse and cache if value found) */
|
for (i=0; i<find_num; i++) {
|
||||||
for (i = 0; i < find_num; i++)
|
//ee_printf("for loop \n");
|
||||||
{
|
info.data16= (i & 0xff) ;
|
||||||
info.data16 = (i & 0xff);
|
this_find=core_list_find(list,&info);
|
||||||
this_find = core_list_find(list, &info);
|
list=core_list_reverse(list);
|
||||||
list = core_list_reverse(list);
|
if (this_find==NULL) {
|
||||||
if (this_find == NULL)
|
|
||||||
{
|
|
||||||
missed++;
|
missed++;
|
||||||
retval += (list->next->info->data16 >> 8) & 1;
|
retval+=(list->next->info->data16 >> 8) & 1;
|
||||||
|
//ee_printf("if statement \n");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
found++;
|
found++;
|
||||||
|
//ee_printf("else statement \n");
|
||||||
if (this_find->info->data16 & 0x1) /* use found value */
|
if (this_find->info->data16 & 0x1) /* use found value */
|
||||||
retval += (this_find->info->data16 >> 9) & 1;
|
retval+=(this_find->info->data16 >> 9) & 1;
|
||||||
/* and cache next item at the head of the list (if any) */
|
/* and cache next item at the head of the list (if any) */
|
||||||
if (this_find->next != NULL)
|
if (this_find->next != NULL) {
|
||||||
{
|
|
||||||
finder = this_find->next;
|
finder = this_find->next;
|
||||||
this_find->next = finder->next;
|
this_find->next = finder->next;
|
||||||
finder->next = list->next;
|
finder->next=list->next;
|
||||||
list->next = finder;
|
list->next=finder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (info.idx >= 0)
|
if (info.idx>=0)
|
||||||
info.idx++;
|
info.idx++;
|
||||||
#if CORE_DEBUG
|
#if CORE_DEBUG
|
||||||
ee_printf("List find %d: [%d,%d,%d]\n", i, retval, missed, found);
|
//ee_printf("List find %d: [%d,%d,%d]\n",i,retval,missed,found);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
retval += found * 4 - missed;
|
retval+=found*4-missed;
|
||||||
/* sort the list by data content and remove one item*/
|
/* sort the list by data content and remove one item*/
|
||||||
if (finder_idx > 0)
|
if (finder_idx>0)
|
||||||
list = core_list_mergesort(list, cmp_complex, res);
|
list=core_list_mergesort(list,cmp_complex,res);
|
||||||
remover = core_list_remove(list->next);
|
remover=core_list_remove(list->next);
|
||||||
/* CRC data content of list from location of index N forward, and then undo
|
/* CRC data content of list from location of index N forward, and then undo remove */
|
||||||
* remove */
|
finder=core_list_find(list,&info);
|
||||||
finder = core_list_find(list, &info);
|
|
||||||
if (!finder)
|
if (!finder)
|
||||||
finder = list->next;
|
finder=list->next;
|
||||||
while (finder)
|
while (finder) {
|
||||||
{
|
retval=crc16(list->info->data16,retval);
|
||||||
retval = crc16(list->info->data16, retval);
|
finder=finder->next;
|
||||||
finder = finder->next;
|
|
||||||
}
|
}
|
||||||
#if CORE_DEBUG
|
#if CORE_DEBUG
|
||||||
ee_printf("List sort 1: %04x\n", retval);
|
//ee_printf("List sort 1: %04x\n",retval);
|
||||||
#endif
|
#endif
|
||||||
remover = core_list_undo_remove(remover, list->next);
|
remover=core_list_undo_remove(remover,list->next);
|
||||||
/* sort the list by index, in effect returning the list to original state */
|
/* sort the list by index, in effect returning the list to original state */
|
||||||
list = core_list_mergesort(list, cmp_idx, NULL);
|
list=core_list_mergesort(list,cmp_idx,NULL);
|
||||||
/* CRC data content of list */
|
/* CRC data content of list */
|
||||||
finder = list->next;
|
finder=list->next;
|
||||||
while (finder)
|
while (finder) {
|
||||||
{
|
retval=crc16(list->info->data16,retval);
|
||||||
retval = crc16(list->info->data16, retval);
|
finder=finder->next;
|
||||||
finder = finder->next;
|
|
||||||
}
|
}
|
||||||
#if CORE_DEBUG
|
#if CORE_DEBUG
|
||||||
ee_printf("List sort 2: %04x\n", retval);
|
//ee_printf("List sort 2: %04x\n",retval);
|
||||||
#endif
|
#endif
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -240,80 +227,96 @@ core_bench_list(core_results *res, ee_s16 finder_idx)
|
|||||||
blksize - Size of memory to be initialized.
|
blksize - Size of memory to be initialized.
|
||||||
memblock - Pointer to memory block.
|
memblock - Pointer to memory block.
|
||||||
seed - Actual values chosen depend on the seed parameter.
|
seed - Actual values chosen depend on the seed parameter.
|
||||||
The seed parameter MUST be supplied from a source that cannot be
|
The seed parameter MUST be supplied from a source that cannot be determined at compile time
|
||||||
determined at compile time
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Pointer to the head of the list.
|
Pointer to the head of the list.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
list_head *
|
list_head *core_list_init(ee_u32 blksize, list_head *memblock, ee_s16 seed) {
|
||||||
core_list_init(ee_u32 blksize, list_head *memblock, ee_s16 seed)
|
|
||||||
{
|
|
||||||
/* calculated pointers for the list */
|
/* calculated pointers for the list */
|
||||||
ee_u32 per_item = 16 + sizeof(struct list_data_s);
|
//ee_printf("%d \n blksize", blksize);
|
||||||
ee_u32 size = (blksize / per_item)
|
ee_u32 per_item=16+sizeof(struct list_data_s);
|
||||||
- 2; /* to accomodate systems with 64b pointers, and make sure
|
//ee_printf("%d \n sizeof", sizeof(struct list_data_s));
|
||||||
same code is executed, set max list elements */
|
//ee_printf("%d \n per_item", per_item);
|
||||||
list_head *memblock_end = memblock + size;
|
ee_u32 size=(blksize/per_item)-2;
|
||||||
list_data *datablock = (list_data *)(memblock_end);
|
//char bufftwo[200];
|
||||||
list_data *datablock_end = datablock + size;
|
//ehitoa(size, bufftwo, 10);
|
||||||
|
//ee_printf(" size = %s done \n", bufftwo);
|
||||||
|
//ee_printf("%d", size);/* to accomodate systems with 64b pointers, and make sure same code is executed, set max list elements */
|
||||||
|
list_head *memblock_end=memblock+size;
|
||||||
|
|
||||||
|
list_data *datablock=(list_data *)(memblock_end);
|
||||||
|
list_data *datablock_end=datablock+size;
|
||||||
|
//ee_printf("datablock_end");
|
||||||
/* some useful variables */
|
/* some useful variables */
|
||||||
ee_u32 i;
|
ee_u32 i;
|
||||||
list_head *finder, *list = memblock;
|
list_head *finder,*list=memblock;
|
||||||
list_data info;
|
list_data info;
|
||||||
|
//ehitoa(size, bufftwo, 10);
|
||||||
|
//ee_printf(" size2 = %s done \n", bufftwo);
|
||||||
|
|
||||||
/* create a fake items for the list head and tail */
|
/* create a fake items for the list head and tail */
|
||||||
list->next = NULL;
|
list->next=NULL;
|
||||||
list->info = datablock;
|
list->info=datablock;
|
||||||
list->info->idx = 0x0000;
|
list->info->idx=0x0000;
|
||||||
list->info->data16 = (ee_s16)0x8080;
|
list->info->data16=(ee_s16)0x8080;
|
||||||
memblock++;
|
memblock++;
|
||||||
datablock++;
|
datablock++;
|
||||||
info.idx = 0x7fff;
|
info.idx=0x7fff;
|
||||||
info.data16 = (ee_s16)0xffff;
|
info.data16=(ee_s16)0xffff;
|
||||||
core_list_insert_new(
|
//ehitoa(size, bufftwo, 10);
|
||||||
list, &info, &memblock, &datablock, memblock_end, datablock_end);
|
//ee_printf(" size3 = %s done \n", bufftwo);
|
||||||
|
core_list_insert_new(list,&info,&memblock,&datablock,memblock_end,datablock_end);
|
||||||
|
//ehitoa(size, bufftwo, 10);
|
||||||
|
//ee_printf(" size4 = %s done \n", bufftwo);;
|
||||||
/* then insert size items */
|
/* then insert size items */
|
||||||
for (i = 0; i < size; i++)
|
for (i=0; i<size; i++) {
|
||||||
{
|
ee_u16 datpat=((ee_u16)(seed^i) & 0xf);
|
||||||
ee_u16 datpat = ((ee_u16)(seed ^ i) & 0xf);
|
ee_u16 dat=(datpat<<3) | (i&0x7); /* alternate between algorithms */
|
||||||
ee_u16 dat
|
info.data16=(dat<<8) | dat; /* fill the data with actual data and upper bits with rebuild value */
|
||||||
= (datpat << 3) | (i & 0x7); /* alternate between algorithms */
|
core_list_insert_new(list,&info,&memblock,&datablock,memblock_end,datablock_end);
|
||||||
info.data16 = (dat << 8) | dat; /* fill the data with actual data and
|
//ehitoa(i, bufftwo, 10);
|
||||||
upper bits with rebuild value */
|
//ee_printf(" i = %s done \n", bufftwo);
|
||||||
core_list_insert_new(
|
//ee_printf("%d \n", i);
|
||||||
list, &info, &memblock, &datablock, memblock_end, datablock_end);
|
/*char grow[200];
|
||||||
|
char growtwo[200];
|
||||||
|
itoa(i, growtwo, 10);
|
||||||
|
sprintf(grow, "test %u buff2 %s goodbyeadd \n", i, growtwo);*/
|
||||||
}
|
}
|
||||||
|
//ee_printf("exited for \n");
|
||||||
/* and now index the list so we know initial seed order of the list */
|
/* and now index the list so we know initial seed order of the list */
|
||||||
finder = list->next;
|
finder=list->next;
|
||||||
i = 1;
|
i=1;
|
||||||
while (finder->next != NULL)
|
//ehitoa(i, bufftwo, 10);
|
||||||
{
|
//ee_printf(" i = %s done \n", bufftwo);
|
||||||
if (i < size / 5) /* first 20% of the list in order */
|
while (finder->next!=NULL) {
|
||||||
finder->info->idx = i++;
|
//ee_printf("enter while statement \n");
|
||||||
else
|
if (i<size/5){ /* first 20% of the list in order */
|
||||||
{
|
finder->info->idx=i++;
|
||||||
ee_u16 pat = (ee_u16)(i++ ^ seed); /* get a pseudo random number */
|
//ehitoa(i, bufftwo, 10);
|
||||||
finder->info->idx = 0x3fff
|
//ee_printf(" if i = %s done \n", bufftwo);
|
||||||
& (((i & 0x07) << 8)
|
|
||||||
| pat); /* make sure the mixed items end up
|
|
||||||
after the ones in sequence */
|
|
||||||
}
|
}
|
||||||
finder = finder->next;
|
|
||||||
|
else {
|
||||||
|
ee_u16 pat=(ee_u16)(i++ ^ seed); /* get a pseudo random number */
|
||||||
|
finder->info->idx=0x3fff & (((i & 0x07) << 8) | pat); /* make sure the mixed items end up after the ones in sequence */
|
||||||
|
//ehitoa(i, bufftwo, 10);
|
||||||
|
//ee_printf(" else i = %s done \n", bufftwo);
|
||||||
}
|
}
|
||||||
list = core_list_mergesort(list, cmp_idx, NULL);
|
finder=finder->next;
|
||||||
|
}
|
||||||
|
//ehitoa(i, bufftwo, 10);
|
||||||
|
//ee_printf(" i2 = %s done \n", bufftwo);
|
||||||
|
list = core_list_mergesort(list,cmp_idx,NULL);
|
||||||
#if CORE_DEBUG
|
#if CORE_DEBUG
|
||||||
ee_printf("Initialized list:\n");
|
//ee_printf("Initialized list:\n");
|
||||||
finder = list;
|
finder=list;
|
||||||
while (finder)
|
while (finder) {
|
||||||
{
|
//ee_printf("[%04x,%04x]",finder->info->idx,(ee_u16)finder->info->data16);
|
||||||
ee_printf(
|
finder=finder->next;
|
||||||
"[%04x,%04x]", finder->info->idx, (ee_u16)finder->info->data16);
|
|
||||||
finder = finder->next;
|
|
||||||
}
|
}
|
||||||
ee_printf("\n");
|
//ee_printf("\n");
|
||||||
#endif
|
#endif
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -332,29 +335,23 @@ core_list_init(ee_u32 blksize, list_head *memblock, ee_s16 seed)
|
|||||||
Returns:
|
Returns:
|
||||||
Pointer to new item.
|
Pointer to new item.
|
||||||
*/
|
*/
|
||||||
list_head *
|
list_head *core_list_insert_new(list_head *insert_point, list_data *info, list_head **memblock, list_data **datablock
|
||||||
core_list_insert_new(list_head * insert_point,
|
, list_head *memblock_end, list_data *datablock_end) {
|
||||||
list_data * info,
|
|
||||||
list_head **memblock,
|
|
||||||
list_data **datablock,
|
|
||||||
list_head * memblock_end,
|
|
||||||
list_data * datablock_end)
|
|
||||||
{
|
|
||||||
list_head *newitem;
|
list_head *newitem;
|
||||||
|
|
||||||
if ((*memblock + 1) >= memblock_end)
|
if ((*memblock+1) >= memblock_end)
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((*datablock + 1) >= datablock_end)
|
if ((*datablock+1) >= datablock_end)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
newitem = *memblock;
|
newitem=*memblock;
|
||||||
(*memblock)++;
|
(*memblock)++;
|
||||||
newitem->next = insert_point->next;
|
newitem->next=insert_point->next;
|
||||||
insert_point->next = newitem;
|
insert_point->next=newitem;
|
||||||
|
|
||||||
newitem->info = *datablock;
|
newitem->info=*datablock;
|
||||||
(*datablock)++;
|
(*datablock)++;
|
||||||
copy_info(newitem->info, info);
|
copy_info(newitem->info,info);
|
||||||
|
|
||||||
return newitem;
|
return newitem;
|
||||||
}
|
}
|
||||||
@ -367,24 +364,21 @@ core_list_insert_new(list_head * insert_point,
|
|||||||
over to the current cell, and unlinking the next item.
|
over to the current cell, and unlinking the next item.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
since there is always a fake item at the end of the list, no need to
|
since there is always a fake item at the end of the list, no need to check for NULL.
|
||||||
check for NULL.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Removed item.
|
Removed item.
|
||||||
*/
|
*/
|
||||||
list_head *
|
list_head *core_list_remove(list_head *item) {
|
||||||
core_list_remove(list_head *item)
|
|
||||||
{
|
|
||||||
list_data *tmp;
|
list_data *tmp;
|
||||||
list_head *ret = item->next;
|
list_head *ret=item->next;
|
||||||
/* swap data pointers */
|
/* swap data pointers */
|
||||||
tmp = item->info;
|
tmp=item->info;
|
||||||
item->info = ret->info;
|
item->info=ret->info;
|
||||||
ret->info = tmp;
|
ret->info=tmp;
|
||||||
/* and eliminate item */
|
/* and eliminate item */
|
||||||
item->next = item->next->next;
|
item->next=item->next->next;
|
||||||
ret->next = NULL;
|
ret->next=NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,17 +398,15 @@ core_list_remove(list_head *item)
|
|||||||
The item that was linked back to the list.
|
The item that was linked back to the list.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
list_head *
|
list_head *core_list_undo_remove(list_head *item_removed, list_head *item_modified) {
|
||||||
core_list_undo_remove(list_head *item_removed, list_head *item_modified)
|
|
||||||
{
|
|
||||||
list_data *tmp;
|
list_data *tmp;
|
||||||
/* swap data pointers */
|
/* swap data pointers */
|
||||||
tmp = item_removed->info;
|
tmp=item_removed->info;
|
||||||
item_removed->info = item_modified->info;
|
item_removed->info=item_modified->info;
|
||||||
item_modified->info = tmp;
|
item_modified->info=tmp;
|
||||||
/* and insert item */
|
/* and insert item */
|
||||||
item_removed->next = item_modified->next;
|
item_removed->next=item_modified->next;
|
||||||
item_modified->next = item_removed;
|
item_modified->next=item_removed;
|
||||||
return item_removed;
|
return item_removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,19 +423,23 @@ core_list_undo_remove(list_head *item_removed, list_head *item_modified)
|
|||||||
Returns:
|
Returns:
|
||||||
Found item, or NULL if not found.
|
Found item, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
list_head *
|
list_head *core_list_find(list_head *list,list_data *info) {
|
||||||
core_list_find(list_head *list, list_data *info)
|
//ee_printf("entered core_list_find \n");
|
||||||
{
|
if (info->idx>=0) {
|
||||||
if (info->idx >= 0)
|
//ee_printf("find if \n");
|
||||||
{
|
while (list && (list->info->idx != info->idx)){
|
||||||
while (list && (list->info->idx != info->idx))
|
list=list->next;
|
||||||
list = list->next;
|
//ee_printf("find while if \n");
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
else
|
//ee_printf("core_list_find end \n");
|
||||||
{
|
return list;
|
||||||
while (list && ((list->info->data16 & 0xff) != info->data16))
|
} else {
|
||||||
list = list->next;
|
//ee_printf("find else");
|
||||||
|
while (list && ((list->info->data16 & 0xff) != info->data16)){
|
||||||
|
list=list->next;
|
||||||
|
//ee_printf("find while else \n");
|
||||||
|
}
|
||||||
|
//ee_printf("core list find end \n");
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,17 +457,16 @@ core_list_find(list_head *list, list_data *info)
|
|||||||
Found item, or NULL if not found.
|
Found item, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
list_head *
|
list_head *core_list_reverse(list_head *list) {
|
||||||
core_list_reverse(list_head *list)
|
// ee_printf("entered core_list_reverse");
|
||||||
{
|
list_head *next=NULL, *tmp;
|
||||||
list_head *next = NULL, *tmp;
|
while (list) {
|
||||||
while (list)
|
tmp=list->next;
|
||||||
{
|
list->next=next;
|
||||||
tmp = list->next;
|
next=list;
|
||||||
list->next = next;
|
list=tmp;
|
||||||
next = list;
|
|
||||||
list = tmp;
|
|
||||||
}
|
}
|
||||||
|
//ee_printf("core_list_reverse done");
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
/* Function: core_list_mergesort
|
/* Function: core_list_mergesort
|
||||||
@ -479,10 +474,9 @@ core_list_reverse(list_head *list)
|
|||||||
|
|
||||||
Description:
|
Description:
|
||||||
Use mergesort, as for linked list this is a realistic solution.
|
Use mergesort, as for linked list this is a realistic solution.
|
||||||
Also, since this is aimed at embedded, care was taken to use iterative
|
Also, since this is aimed at embedded, care was taken to use iterative rather then recursive algorithm.
|
||||||
rather then recursive algorithm. The sort can either return the list to
|
The sort can either return the list to original order (by idx) ,
|
||||||
original order (by idx) , or use the data item to invoke other other
|
or use the data item to invoke other other algorithms and change the order of the list.
|
||||||
algorithms and change the order of the list.
|
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
list - list to be sorted.
|
list - list to be sorted.
|
||||||
@ -496,81 +490,70 @@ core_list_reverse(list_head *list)
|
|||||||
but the algorithm could theoretically modify where the list starts.
|
but the algorithm could theoretically modify where the list starts.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
list_head *
|
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)
|
|
||||||
{
|
|
||||||
list_head *p, *q, *e, *tail;
|
list_head *p, *q, *e, *tail;
|
||||||
ee_s32 insize, nmerges, psize, qsize, i;
|
ee_s32 insize, nmerges, psize, qsize, i;
|
||||||
|
|
||||||
insize = 1;
|
insize = 1;
|
||||||
|
//char bufftwo[200];
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
p = list;
|
p = list;
|
||||||
list = NULL;
|
list = NULL;
|
||||||
tail = NULL;
|
tail = NULL;
|
||||||
|
|
||||||
nmerges = 0; /* count number of merges we do in this pass */
|
nmerges = 0; /* count number of merges we do in this pass */
|
||||||
|
//ehitoa(nmerges, bufftwo, 10);
|
||||||
while (p)
|
//ee_printf(" nmerges default value = %s done \n", bufftwo);
|
||||||
{
|
while (p) {
|
||||||
nmerges++; /* there exists a merge to be done */
|
nmerges++; /* there exists a merge to be done */
|
||||||
|
//ehitoa(nmerges, bufftwo, 10);
|
||||||
|
//ee_printf(" current nmerges = %s done \n", bufftwo);
|
||||||
/* step `insize' places along from p */
|
/* step `insize' places along from p */
|
||||||
q = p;
|
q = p;
|
||||||
psize = 0;
|
psize = 0;
|
||||||
for (i = 0; i < insize; i++)
|
//ehitoa(insize, bufftwo, 10);
|
||||||
{
|
//ee_printf(" insize = %s done \n", bufftwo);
|
||||||
|
for (i = 0; i < insize; i++) {
|
||||||
|
//ehitoa(i, bufftwo, 10);
|
||||||
|
//ee_printf(" i = %s done \n", bufftwo);
|
||||||
psize++;
|
psize++;
|
||||||
q = q->next;
|
q = q->next;
|
||||||
if (!q)
|
if (!q) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if q hasn't fallen off end, we have two lists to merge */
|
/* if q hasn't fallen off end, we have two lists to merge */
|
||||||
qsize = insize;
|
qsize = insize;
|
||||||
|
//ehitoa(qsize, bufftwo, 10);
|
||||||
|
//ee_printf(" qsize = %s done \n", bufftwo);
|
||||||
|
|
||||||
/* now we have two lists; merge them */
|
/* now we have two lists; merge them */
|
||||||
while (psize > 0 || (qsize > 0 && q))
|
while (psize > 0 || (qsize > 0 && q)) {
|
||||||
{
|
|
||||||
|
|
||||||
/* decide whether next element of merge comes from p or q */
|
/* decide whether next element of merge comes from p or q */
|
||||||
if (psize == 0)
|
if (psize == 0) {
|
||||||
{
|
//ee_printf("if \n");
|
||||||
/* p is empty; e must come from q. */
|
/* p is empty; e must come from q. */
|
||||||
e = q;
|
e = q; q = q->next; qsize--;
|
||||||
q = q->next;
|
} else if (qsize == 0 || !q) {
|
||||||
qsize--;
|
//ee_printf("else if \n");
|
||||||
}
|
|
||||||
else if (qsize == 0 || !q)
|
|
||||||
{
|
|
||||||
/* q is empty; e must come from p. */
|
/* q is empty; e must come from p. */
|
||||||
e = p;
|
e = p; p = p->next; psize--;
|
||||||
p = p->next;
|
} else if (cmp(p->info,q->info,res) <= 0) {
|
||||||
psize--;
|
//ee_printf("else if 2 \n");
|
||||||
}
|
/* First element of p is lower (or same); e must come from p. */
|
||||||
else if (cmp(p->info, q->info, res) <= 0)
|
e = p; p = p->next; psize--;
|
||||||
{
|
} else {
|
||||||
/* First element of p is lower (or same); e must come from
|
//ee_printf("else \n");
|
||||||
* p. */
|
|
||||||
e = p;
|
|
||||||
p = p->next;
|
|
||||||
psize--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* First element of q is lower; e must come from q. */
|
/* First element of q is lower; e must come from q. */
|
||||||
e = q;
|
e = q; q = q->next; qsize--;
|
||||||
q = q->next;
|
|
||||||
qsize--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the next element to the merged list */
|
/* add the next element to the merged list */
|
||||||
if (tail)
|
if (tail) {
|
||||||
{
|
//ee_printf("tail if \n");
|
||||||
tail->next = e;
|
tail->next = e;
|
||||||
}
|
} else {
|
||||||
else
|
//ee_printf("tail else \n");
|
||||||
{
|
|
||||||
list = e;
|
list = e;
|
||||||
}
|
}
|
||||||
tail = e;
|
tail = e;
|
||||||
@ -588,6 +571,8 @@ core_list_mergesort(list_head *list, list_cmp cmp, core_results *res)
|
|||||||
|
|
||||||
/* Otherwise repeat, merging lists twice the size */
|
/* Otherwise repeat, merging lists twice the size */
|
||||||
insize *= 2;
|
insize *= 2;
|
||||||
|
//ehitoa(insize, bufftwo, 10);
|
||||||
|
//ee_printf(" insize2 = %s done \n", bufftwo);
|
||||||
}
|
}
|
||||||
#if COMPILER_REQUIRES_SORT_RETURN
|
#if COMPILER_REQUIRES_SORT_RETURN
|
||||||
return list;
|
return list;
|
||||||
|
Loading…
Reference in New Issue
Block a user