OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [coremark/] [core_util.c] - Diff between revs 355 and 406

Only display areas with differences | Details | Blame | View Log

Rev 355 Rev 406
/*
/*
Author : Shay Gal-On, EEMBC
Author : Shay Gal-On, EEMBC
 
 
This file is part of  EEMBC(R) and CoreMark(TM), which are Copyright (C) 2009
This file is part of  EEMBC(R) and CoreMark(TM), which are Copyright (C) 2009
All rights reserved.
All rights reserved.
 
 
EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
EEMBC CoreMark Software is a product of EEMBC and is provided under the terms of the
CoreMark License that is distributed with the official EEMBC COREMARK Software release.
CoreMark License that is distributed with the official EEMBC COREMARK Software release.
If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
If you received this EEMBC CoreMark Software without the accompanying CoreMark License,
you must discontinue use and download the official release from www.coremark.org.
you must discontinue use and download the official release from www.coremark.org.
 
 
Also, if you are publicly displaying scores generated from the EEMBC CoreMark software,
Also, if you are publicly displaying scores generated from the EEMBC CoreMark software,
make sure that you are in compliance with Run and Reporting rules specified in the accompanying readme.txt file.
make sure that you are in compliance with Run and Reporting rules specified in the accompanying readme.txt file.
 
 
EEMBC
EEMBC
4354 Town Center Blvd. Suite 114-200
4354 Town Center Blvd. Suite 114-200
El Dorado Hills, CA, 95762
El Dorado Hills, CA, 95762
*/
*/
#include "coremark.h"
#include "coremark.h"
/* Function: get_seed
/* Function: get_seed
        Get a values that cannot be determined at compile time.
        Get a values that cannot be determined at compile time.
 
 
        Since different embedded systems and compilers are used, 3 different methods are provided:
        Since different embedded systems and compilers are used, 3 different methods are provided:
        1 - Using a volatile variable. This method is only valid if the compiler is forced to generate code that
        1 - Using a volatile variable. This method is only valid if the compiler is forced to generate code that
        reads the value of a volatile variable from memory at run time.
        reads the value of a volatile variable from memory at run time.
        Please note, if using this method, you would need to modify core_portme.c to generate training profile.
        Please note, if using this method, you would need to modify core_portme.c to generate training profile.
        2 - Command line arguments. This is the preferred method if command line arguments are supported.
        2 - Command line arguments. This is the preferred method if command line arguments are supported.
        3 - System function. If none of the first 2 methods is available on the platform,
        3 - System function. If none of the first 2 methods is available on the platform,
        a system function which is not a stub can be used.
        a system function which is not a stub can be used.
 
 
        e.g. read the value on GPIO pins connected to switches, or invoke special simulator functions.
        e.g. read the value on GPIO pins connected to switches, or invoke special simulator functions.
*/
*/
#if (SEED_METHOD==SEED_VOLATILE)
#if (SEED_METHOD==SEED_VOLATILE)
        extern volatile ee_s32 seed1_volatile;
extern volatile ee_s32 seed1_volatile;
        extern volatile ee_s32 seed2_volatile;
extern volatile ee_s32 seed2_volatile;
        extern volatile ee_s32 seed3_volatile;
extern volatile ee_s32 seed3_volatile;
        extern volatile ee_s32 seed4_volatile;
extern volatile ee_s32 seed4_volatile;
        extern volatile ee_s32 seed5_volatile;
        extern volatile ee_s32 seed5_volatile;
        ee_s32 get_seed_32(int i) {
ee_s32 get_seed_32(int i)
 
{
                ee_s32 retval;
                ee_s32 retval;
                switch (i) {
        switch (i) {
                        case 1:
        case 1:
                                retval=seed1_volatile;
                retval = seed1_volatile;
                                break;
                break;
                        case 2:
        case 2:
                                retval=seed2_volatile;
                retval = seed2_volatile;
                                break;
                break;
                        case 3:
        case 3:
                                retval=seed3_volatile;
                retval = seed3_volatile;
                                break;
                break;
                        case 4:
        case 4:
                                retval=seed4_volatile;
                retval = seed4_volatile;
                                break;
                break;
                        case 5:
        case 5:
                                retval=seed5_volatile;
                retval = seed5_volatile;
                                break;
                break;
                        default:
        default:
                                retval=0;
                retval = 0;
                                break;
                break;
                }
        }
                return retval;
        return retval;
        }
}
#elif (SEED_METHOD==SEED_ARG)
#elif (SEED_METHOD==SEED_ARG)
ee_s32 parseval(char *valstring) {
ee_s32 parseval(char *valstring)
 
{
        ee_s32 retval=0;
        ee_s32 retval=0;
        ee_s32 neg=1;
        ee_s32 neg = 1;
        int hexmode=0;
        int hexmode = 0;
        if (*valstring == '-') {
        if (*valstring == '-') {
                neg=-1;
                neg = -1;
                valstring++;
                valstring++;
        }
        }
        if ((valstring[0] == '0') && (valstring[1] == 'x')) {
        if ((valstring[0] == '0') && (valstring[1] == 'x')) {
                hexmode=1;
                hexmode = 1;
                valstring+=2;
                valstring += 2;
        }
        }
                /* first look for digits */
        /* first look for digits */
        if (hexmode) {
        if (hexmode) {
                while (((*valstring >= '0') && (*valstring <= '9')) || ((*valstring >= 'a') && (*valstring <= 'f'))) {
                while (((*valstring >= '0') && (*valstring <= '9'))
                        ee_s32 digit=*valstring-'0';
                       || ((*valstring >= 'a') && (*valstring <= 'f'))) {
 
                        ee_s32 digit = *valstring - '0';
                        if (digit>9)
                        if (digit>9)
                                digit=10+*valstring-'a';
                                digit = 10 + *valstring - 'a';
                        retval*=16;
                        retval*=16;
                        retval+=digit;
                        retval += digit;
                        valstring++;
                        valstring++;
                }
                }
        } else {
        } else {
                while ((*valstring >= '0') && (*valstring <= '9')) {
                while ((*valstring >= '0') && (*valstring <= '9')) {
                        ee_s32 digit=*valstring-'0';
                        ee_s32 digit = *valstring - '0';
                        retval*=10;
                        retval*=10;
                        retval+=digit;
                        retval += digit;
                        valstring++;
                        valstring++;
                }
                }
        }
        }
        /* now add qualifiers */
        /* now add qualifiers */
        if (*valstring=='K')
        if (*valstring == 'K')
                retval*=1024;
                retval *= 1024;
        if (*valstring=='M')
        if (*valstring == 'M')
                retval*=1024*1024;
                retval *= 1024 * 1024;
 
 
        retval*=neg;
        retval *= neg;
        return retval;
        return retval;
}
}
 
 
ee_s32 get_seed_args(int i, int argc, char *argv[]) {
ee_s32 get_seed_args(int i, int argc, char *argv[])
 
{
        if (argc>i)
        if (argc>i)
                return parseval(argv[i]);
                return parseval(argv[i]);
        return 0;
        return 0;
}
}
 
 
#elif (SEED_METHOD==SEED_FUNC)
#elif (SEED_METHOD==SEED_FUNC)
/* If using OS based function, you must define and implement the functions below in core_portme.h and core_portme.c ! */
/* If using OS based function, you must define and implement the functions below in core_portme.h and core_portme.c ! */
ee_s32 get_seed_32(int i) {
ee_s32 get_seed_32(int i)
 
{
        ee_s32 retval;
        ee_s32 retval;
        switch (i) {
        switch (i) {
                case 1:
        case 1:
                        retval=portme_sys1();
                retval = portme_sys1();
                        break;
                break;
                case 2:
        case 2:
                        retval=portme_sys2();
                retval = portme_sys2();
                        break;
                break;
                case 3:
        case 3:
                        retval=portme_sys3();
                retval = portme_sys3();
                        break;
                break;
                case 4:
        case 4:
                        retval=portme_sys4();
                retval = portme_sys4();
                        break;
                break;
                case 5:
        case 5:
                        retval=portme_sys5();
                retval = portme_sys5();
                        break;
                break;
                default:
        default:
                        retval=0;
                retval = 0;
                        break;
                break;
        }
        }
        return retval;
        return retval;
}
}
#endif
#endif
 
 
/* Function: crc*
/* Function: crc*
        Service functions to calculate 16b CRC code.
        Service functions to calculate 16b CRC code.
 
 
*/
*/
ee_u16 crcu8(ee_u8 data, ee_u16 crc )
ee_u16 crcu8(ee_u8 data, ee_u16 crc)
{
{
        ee_u8 i=0,x16=0,carry=0;
        ee_u8 i = 0, x16 = 0, carry = 0;
 
 
        for (i = 0; i < 8; i++)
        for (i = 0; i < 8; i++) {
    {
 
                x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1));
                x16 = (ee_u8)((data & 1) ^ ((ee_u8)crc & 1));
                data >>= 1;
                data >>= 1;
 
 
                if (x16 == 1)
                if (x16 == 1) {
                {
 
                   crc ^= 0x4002;
                   crc ^= 0x4002;
                   carry = 1;
                   carry = 1;
                }
                } else
                else
 
                        carry = 0;
                        carry = 0;
                crc >>= 1;
                crc >>= 1;
                if (carry)
                if (carry)
                   crc |= 0x8000;
                        crc |= 0x8000;
                else
                else
                   crc &= 0x7fff;
                        crc &= 0x7fff;
    }
        }
        return crc;
        return crc;
}
}
ee_u16 crcu16(ee_u16 newval, ee_u16 crc) {
 
 
ee_u16 crcu16(ee_u16 newval, ee_u16 crc)
 
{
        crc=crcu8( (ee_u8) (newval)                             ,crc);
        crc=crcu8( (ee_u8) (newval)                             ,crc);
        crc=crcu8( (ee_u8) ((newval)>>8)        ,crc);
        crc = crcu8((ee_u8) ((newval) >> 8), crc);
        return crc;
        return crc;
}
}
ee_u16 crcu32(ee_u32 newval, ee_u16 crc) {
 
 
ee_u16 crcu32(ee_u32 newval, ee_u16 crc)
 
{
        crc=crc16((ee_s16) newval               ,crc);
        crc=crc16((ee_s16) newval               ,crc);
        crc=crc16((ee_s16) (newval>>16) ,crc);
        crc = crc16((ee_s16) (newval >> 16), crc);
        return crc;
        return crc;
}
}
ee_u16 crc16(ee_s16 newval, ee_u16 crc) {
 
 
ee_u16 crc16(ee_s16 newval, ee_u16 crc)
 
{
        return crcu16((ee_u16)newval, crc);
        return crcu16((ee_u16)newval, crc);
}
}
 
 
ee_u8 check_data_types() {
ee_u8 check_data_types()
 
{
        ee_u8 retval=0;
        ee_u8 retval=0;
        if (sizeof(ee_u8) != 1) {
        if (sizeof(ee_u8) != 1) {
                ee_printf("ERROR: ee_u8 is not an 8b datatype!\n");
                ee_printf("ERROR: ee_u8 is not an 8b datatype!\n");
                retval++;
                retval++;
        }
        }
        if (sizeof(ee_u16) != 2) {
        if (sizeof(ee_u16) != 2) {
                ee_printf("ERROR: ee_u16 is not a 16b datatype!\n");
                ee_printf("ERROR: ee_u16 is not a 16b datatype!\n");
                retval++;
                retval++;
        }
        }
        if (sizeof(ee_s16) != 2) {
        if (sizeof(ee_s16) != 2) {
                ee_printf("ERROR: ee_s16 is not a 16b datatype!\n");
                ee_printf("ERROR: ee_s16 is not a 16b datatype!\n");
                retval++;
                retval++;
        }
        }
        if (sizeof(ee_s32) != 4) {
        if (sizeof(ee_s32) != 4) {
                ee_printf("ERROR: ee_s32 is not a 32b datatype!\n");
                ee_printf("ERROR: ee_s32 is not a 32b datatype!\n");
                retval++;
                retval++;
        }
        }
        if (sizeof(ee_u32) != 4) {
        if (sizeof(ee_u32) != 4) {
                ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
                ee_printf("ERROR: ee_u32 is not a 32b datatype!\n");
                retval++;
                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");
                ee_printf
 
                    ("ERROR: ee_ptr_int is not a datatype that holds an int pointer!\n");
                retval++;
                retval++;
        }
        }
        if (retval>0) {
        if (retval>0) {
                ee_printf("ERROR: Please modify the datatypes in core_portme.h!\n");
                ee_printf
 
                    ("ERROR: Please modify the datatypes in core_portme.h!\n");
        }
        }
        return retval;
        return retval;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.