1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/tsrc/examples/memcpy-speed/src/memcpy-speed.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,157 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include <stdio.h>
1.22 +#include <stdlib.h>
1.23 +#include <string.h>
1.24 +
1.25 +#define LOG_FILE "c:\\logs\\memcpy-speed_logs.txt"
1.26 +#include "std_log_result.h"
1.27 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.28 +
1.29 +void create_xml(int result)
1.30 +{
1.31 + if(result)
1.32 + assert_failed = 1;
1.33 +
1.34 + testResultXml("memcpy-speed");
1.35 + close_log_file();
1.36 +}
1.37 +
1.38 +#include <liboil/liboil.h>
1.39 +#include <liboil/liboilprofile.h>
1.40 +#include <liboil/liboilfunction.h>
1.41 +#include <liboil/globals.h>
1.42 +
1.43 +#define ALIGN(ptr,n) ((void *)((unsigned long)(ptr) & (~(unsigned long)(n-1))))
1.44 +
1.45 +int
1.46 +main(int argc, char *argv[])
1.47 +{
1.48 + char *s=NULL, *d=NULL;
1.49 + uint32_t *src, *dest;
1.50 + int16_t res=0;
1.51 + OilProfile prof;
1.52 + double ave, std;
1.53 + int i,j, cnt;
1.54 + double cpufreq;
1.55 + OilFunctionClass *klass;
1.56 + OilFunctionImpl *impl;
1.57 + int the_class;
1.58 +
1.59 + std_log(LOG_FILENAME_LINE,"Test Started memcpy-speed");
1.60 +
1.61 + oil_init ();
1.62 +
1.63 + s = malloc(512*1024+1024);
1.64 + d = malloc(512*1024+1024);
1.65 +// src = ((void *)((unsigned long)(s) | 0xFF ));
1.66 + //dest = ((void *)((unsigned long)(d) | 0xFF ));
1.67 + src = ((void *)((unsigned long)(s) ));
1.68 + dest = ((void *)((unsigned long)(d) ));
1.69 +
1.70 + for(the_class=0; the_class<3; the_class++)
1.71 + {
1.72 + cpufreq = 1788e6;
1.73 + switch(the_class) {
1.74 + case 0:
1.75 + klass = oil_class_get ("splat_u32_ns");
1.76 + break;
1.77 + case 1:
1.78 + klass = oil_class_get ("copy_u8");
1.79 + break;
1.80 + case 2:
1.81 + klass = oil_class_get ("sum_s16");
1.82 + break;
1.83 + }
1.84 +
1.85 + for(impl=klass->first_impl;impl;impl=impl->next) {
1.86 + std_log(LOG_FILENAME_LINE,"impl %s\n", impl->name);
1.87 +
1.88 + if (!oil_impl_is_usable(impl)) {
1.89 + std_log(LOG_FILENAME_LINE," not usable\n");
1.90 + continue;
1.91 + }
1.92 +
1.93 + oil_class_choose_by_name (klass, impl->name);
1.94 +
1.95 + for(i=10;i<20;i++){
1.96 + oil_profile_init (&prof);
1.97 + for(j=0;j<10;j++){
1.98 + switch(the_class) {
1.99 + case 0:
1.100 + oil_profile_start(&prof);
1.101 + oil_splat_u32_ns (dest, src, 1<<(i-2));
1.102 + oil_profile_stop(&prof);
1.103 + for(cnt=0; cnt<(1<<(i-2)); cnt++){
1.104 + if(dest[cnt]!=*src){
1.105 + std_log(LOG_FILENAME_LINE,"Failed at the_class=%d, cnt=%d, i=%d, j=%d, impl->name=%s\n", the_class, cnt, i, j, impl->name);
1.106 + assert_failed =1;
1.107 + }
1.108 + }
1.109 +
1.110 + break;
1.111 + case 1:
1.112 + oil_profile_start(&prof);
1.113 + oil_memcpy (dest, src, 1<<i);
1.114 + oil_profile_stop(&prof);
1.115 + for(cnt=0; cnt<(1<<(i-2)); cnt++){ //cnt is checked with 1<<(i-2) because dest & src are of type uint32_t*
1.116 + if(dest[cnt]!=src[cnt]){
1.117 + std_log(LOG_FILENAME_LINE,"Failed at the_class=%d, cnt=%d, i=%d, j=%d, impl->name=%s\n", the_class, cnt, i, j, impl->name);
1.118 + assert_failed =1;
1.119 + }
1.120 + }
1.121 +
1.122 + break;
1.123 + case 2:
1.124 + {
1.125 + int16_t* src1 = (int16_t*)src;
1.126 + int16_t* dest1 = (int16_t*)dest;
1.127 + oil_profile_start(&prof);
1.128 + oil_sum_s16 (dest1, src1, 1<<(i-1));
1.129 + oil_profile_stop(&prof);
1.130 + res=0;
1.131 + for(cnt=0; cnt<(1<<(i-1)); cnt++){
1.132 + res += src1[cnt];
1.133 + }
1.134 + if(*dest1 != res){
1.135 + std_log(LOG_FILENAME_LINE,"Failed at the_class=%d, impl->name=%s\n", the_class, impl->name);
1.136 + assert_failed =1;
1.137 + }
1.138 +
1.139 + }
1.140 + break;
1.141 + }
1.142 + }
1.143 + oil_profile_get_ave_std (&prof, &ave, &std);
1.144 + std_log(LOG_FILENAME_LINE,"%d: %10.4g %10.4g %10.4g\n", i, ave, std,
1.145 + ave/(1<<i));
1.146 +
1.147 + }
1.148 + }
1.149 +
1.150 + }
1.151 + free(s);
1.152 + free(d);
1.153 +
1.154 + if(!assert_failed)
1.155 + std_log(LOG_FILENAME_LINE, "Test Passed");
1.156 + else
1.157 + std_log(LOG_FILENAME_LINE, "Test Failed");
1.158 + create_xml(0);
1.159 + return 0;
1.160 +}