⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.c

📁 EP9315开发板的Wince6.0的BSP包文件
💻 C
字号:
/**********************************************************************
#                                                                      
# Filename: demo.c
#                                                                      
# Description:
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Use of this source code is subject to the terms of the Cirrus end-user
# license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
# If you did not accept the terms of the EULA, you are not authorized to 
# use this source code. For a copy of the EULA, please see the 
# EULA.RTF on your install media.
#
# Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
#                                                                      
#**********************************************************************/

#include <stdio.h>
#include <windows.h>
#include "vec_single.h"
#include "vec_double.h"

typedef double (*pfndd)(double);
typedef float (*pfnff)(float);
typedef float (*pfnfff)(float,float);
typedef double (*pfnddd)(double,double);


struct function_node
{
    char* crunchfunc;
    char* softfloatfunc;
    WCHAR* fname;    
    char * ftype;    
    int loopcount;
    int iCrunchTime;
    int iSoftFloatTime;    
};

struct function_node function_table[]=
{
    {(char*)ceilf   ,(char *)0, L"ceilf"   , "ff",  10, 0, 0},
    {(char*)fabsf   ,(char *)0, L"fabsf"   , "ff",  10, 0, 0},
    {(char*)floorf  ,(char *)0, L"floorf"  , "ff",  10, 0, 0},
    {(char*)sqrtf   ,(char *)0, L"sqrtf"   , "ff",  10, 0, 0},
    {(char*)fmodf   ,(char *)0, L"fmodf"   , "fff", 10, 0, 0}, 
    {(char*)acos    ,(char *)0, L"acos"    , "dd",  10, 0, 0},
    {(char*)asin    ,(char *)0, L"asin"    , "dd",  10, 0, 0},
    {(char*)atan    ,(char *)0, L"atan"    , "dd",  10, 0, 0},
    {(char*)cos     ,(char *)0, L"cos"     , "dd",  10, 0, 0},
    {(char*)cosh    ,(char *)0, L"cosh"    , "dd",  10, 0, 0},
    {(char*)exp     ,(char *)0, L"exp"     , "dd",  10, 0, 0},
    {(char*)fabs    ,(char *)0, L"fabs"    , "dd",  10, 0, 0},
    {(char*)log     ,(char *)0, L"log"     , "dd",  10, 0, 0},
    {(char*)log10   ,(char *)0, L"log10"   , "dd",  10, 0, 0},
    {(char*)sin     ,(char *)0, L"sin"     , "dd",  10, 0, 0},
    {(char*)sinh    ,(char *)0, L"sinh"    , "dd",  10, 0, 0},
    {(char*)sqrt    ,(char *)0, L"sqrt"    , "dd",  10, 0, 0},
    {(char*)tan     ,(char *)0, L"tan"     , "dd",  10, 0, 0},
    {(char*)tanh    ,(char *)0, L"tanh"    , "dd",  10, 0, 0},
    {(char*)ceil    ,(char *)0, L"ceil"    , "dd",  10, 0, 0},
    {(char*)floor   ,(char *)0, L"floor"   , "dd",  10, 0, 0},
    {(char*)_y0     ,(char *)0, L"_y0"     , "dd",  10, 0, 0},
    {(char*)_y1     ,(char *)0, L"_y1"     , "dd",  10, 0, 0},
    {(char*)atan2   ,(char *)0, L"atan2"   , "ddd", 10, 0, 0}, 
    {(char*)fmod    ,(char *)0, L"fmod"    , "ddd", 10, 0, 0}, 
    {(char*)pow     ,(char *)0, L"pow"     , "ddd", 10, 0, 0}, 
    {0, 0, 0, 0, 0, 0}, 
};

//****************************************************************************
// GetFuncTime
//****************************************************************************
// Gets the functions time for perform a certain number of iterations.
// 
// returns the time it takes to execute.
//
int GetFuncTime(char * func, char * args, int interations)
{
    int         iStartTime, iEndTime;
    register int         i,j;
    register double_t    arg_t;
    register single_t    arg_ts;
    double result;
    float  results;


    if (strcmp(args,"dd")==0)
    {
        iStartTime = GetTickCount();
        for(j=0 ; j<interations ; j++)
        {
            for(i=0;i<VEC_DOUBLE_LENGTH;i++)
            {
                arg_t.n.dwlow=vec_doubles[i].dwlow;
                arg_t.n.dwhigh=vec_doubles[i].dwhigh;
                result = ((pfndd)(func))(arg_t.value);
            }
        }
        iEndTime   = GetTickCount();
    }
    else if (strcmp(args,"ff")==0)
    {
        iStartTime = GetTickCount();
        for(j=0 ; j<interations ; j++)
        {
            for(i=0;i<VEC_SINGLES_LENGTH;i++)
            {
                arg_ts.n=vec_singles[i];
                results = ((pfnff)(func))(arg_ts.value);
            }
        }
        iEndTime   = GetTickCount();
    }
    else if (strcmp(args,"fff")==0)
    {
        iStartTime = GetTickCount();
        for(j=0 ; j<interations ; j++)
        {
            for(i=0;i<VEC_SINGLES_LENGTH;i++)
            {
                arg_ts.n=vec_singles[i];
                results = ((pfnfff)(func))(arg_ts.value,1.2f);
            }
        }
        iEndTime  = GetTickCount();
    }
    else if (strcmp(args,"ddd")==0)
    {
        iStartTime = GetTickCount();
        for(j=0 ; j<interations ; j++)
        {
            for(i=0;i<VEC_DOUBLE_LENGTH;i++)
            {
                arg_t.n.dwlow=vec_doubles[i].dwlow;
                arg_t.n.dwhigh=vec_doubles[i].dwhigh;
                result = ((pfnddd)(func))(arg_t.value,1.2);
            }
        }
        iEndTime   = GetTickCount();
    }

    return iEndTime - iStartTime; 
}



//****************************************************************************
// test_performance
//****************************************************************************
// 
// 
//

void test_performance()
{
    int iCrunchTime, iSoftFloatTime;
    struct function_node * p=(struct function_node*)function_table;



    //
    // Print Header information.
    //
    printf("-------------------------------------------------------------------------\r\n");
    printf("func name       total           soft-float      crunch-float    percentage of\r\n");
    printf("                iterations      total time      total time      time saved\r\n"); 
    printf("-------------------------------------------------------------------------\r\n");



    while(1)
    {
        if(p->crunchfunc==0) 
            break;

        //
        // Get the time it takes to execute the crunch and soft float functions.
        //
        iCrunchTime = GetFuncTime
        (
            p->crunchfunc,
            p->ftype,
            p->loopcount
        );

        iSoftFloatTime = GetFuncTime
        (
            p->softfloatfunc,
            p->ftype,
            p->loopcount
        );

        //
        // Print out the results.
        //
        wprintf
        (
            L"%6s:         %3d             %4d  ms        %3d  ms          %2d%%\r\n",
            p->fname,
            p->loopcount,
            iSoftFloatTime,
            iCrunchTime,
            100 - ((iCrunchTime * 100 )/ iSoftFloatTime)
        );

        p++;
    }   
}



//****************************************************************************
// FillTable
//****************************************************************************
// Fills in the table with the function pointers to the softfloat library.
//
// returns TRUE  - Success
//         FALSE - Failure
// 
//
void FillTable(HINSTANCE *phCoredll)
{
    FARPROC pfunc;
    int     i;
    *phCoredll = LoadLibrary(L"coredll.dll");

    if(!(*phCoredll))
    {
        printf("  *  ERROR: Cannot load coredll.dll\r\n");
        exit(1);
    }

    for(i = 0 ; ; i++)
    {
        //
        // Check to see if we are at the end of the loop.
        //
        if(function_table[i].crunchfunc == 0)
            break;

        //
        // Get the function address.
        //
        pfunc = GetProcAddress
        (
            *phCoredll, 
            function_table[i].fname
        );

        //
        // Check to make sure that a NULL pointer was not returned.
        //
        if(!pfunc)
        {
            wsprintf
            (
                L"  *  ERROR: Cannot get a pointer to coredll.dll::%s\r\n", 
                function_table[i].fname
            );
            exit(1);
        }

        function_table[i].softfloatfunc = (char *)pfunc;
    }

    return;
}


//****************************************************************************
// main
//****************************************************************************
//  Main function.
// 
//
int main(int argc, char *argv[])
{
    HINSTANCE h;

    FillTable(&h);

    test_performance();

    //
    // Free the handle to the library before quitting.
    //
    FreeLibrary( h);

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -