test_mmx.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000,2001,2004 Sasha Vasko <sasha at aftercode.net>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 
00020 #define LOCAL_DEBUG
00021 #define DO_CLOCKING
00022 #ifdef NO_DEBUG_OUTPUT
00023 #undef DEBUG_RECTS
00024 #undef DEBUG_RECTS2
00025 #endif
00026 
00027 #ifdef _WIN32
00028 #include "win32/config.h"
00029 #else
00030 #include "config.h"
00031 #endif
00032 
00033 
00034 #include <string.h>
00035 #ifdef DO_CLOCKING
00036 #if TIME_WITH_SYS_TIME
00037 # include <sys/time.h>
00038 # include <time.h>
00039 #else
00040 # if HAVE_SYS_TIME_H
00041 #  include <sys/time.h>
00042 # else
00043 #  include <time.h>
00044 # endif
00045 #endif
00046 #endif
00047 #ifdef HAVE_UNISTD_H
00048 #include <unistd.h>
00049 #endif
00050 #ifdef HAVE_STDLIB_H
00051 #include <stdlib.h>
00052 #endif
00053 #ifdef HAVE_STDARG_H
00054 #include <stdarg.h>
00055 #endif
00056 
00057 #ifdef HAVE_MMX
00058 #include <mmintrin.h>
00059 #include <xmmintrin.h>
00060 #endif
00061 
00062 #ifdef _WIN32
00063 # include "win32/afterbase.h"
00064 #else
00065 # include "afterbase.h"
00066 #endif
00067 #include "asvisual.h"
00068 #include "blender.h"
00069 #include "asimage.h"
00070 #include "imencdec.h"
00071 
00072 #define TEST_PADDD
00073 #define USE_PREFETCH
00074 
00075 #ifdef DO_CLOCKING
00076 #define MIN_TEST_LEN 15000000
00077 #define MAX_TEST_LEN 15000001
00078 #define MAX_REPS 1
00079 #else
00080 #define MIN_TEST_LEN 1
00081 #define MAX_TEST_LEN 10001
00082 #define MAX_REPS 1
00083 #endif
00084 
00085 static CARD32 rnd32_seed = 345824357;
00086 
00087 #define MAX_MY_RND32            0x00ffffffff
00088 #ifdef WORD64
00089 #define MY_RND32() \
00090 (rnd32_seed = ((1664525L*rnd32_seed)&MAX_MY_RND32)+1013904223L)
00091 #else
00092 #define MY_RND32() \
00093 (rnd32_seed = (1664525L*rnd32_seed)+1013904223L)
00094 #endif
00095 
00096 
00097 int main()
00098 {
00099         int test_len ; 
00100         CARD32 *test_set1 ;
00101         CARD32 *test_set2 ;     
00102         CARD32 *control_data ;  
00103         int i, reps ; 
00104 
00105         for( test_len = MIN_TEST_LEN ; test_len < MAX_TEST_LEN ; ++test_len ) 
00106         {
00107                 test_set1 = safemalloc( (test_len + (test_len&0x01))* sizeof(CARD32) ); 
00108                 test_set2 = safemalloc( (test_len + (test_len&0x01))* sizeof(CARD32) );
00109                 control_data = safemalloc( (test_len + (test_len&0x01))* sizeof(CARD32) );                      
00110                 for( i = 0 ; i < test_len ; ++i ) 
00111                 {
00112                         test_set1[i] = MY_RND32()& 0x00FFFFFF ;
00113                         test_set2[i] = MY_RND32()& 0x00FFFFFF ;
00114                 }
00115                 {
00116                         START_TIME(int_math);
00117                         for( reps = 0 ; reps < MAX_REPS ; ++reps ) 
00118                         {
00119                                 for( i = 0 ; i < test_len ; ++i ) 
00120                                 {
00121 #ifdef TEST_PADDD                               
00122                                         control_data[i] = test_set1[i] + test_set2[i] ; 
00123 #else
00124                                         control_data[i] = test_set2[i] >> 1 ; 
00125 #endif
00126                                 }               
00127                         }
00128                         SHOW_TIME("Standard int math : ", int_math);
00129                 }
00130                 {
00131                         START_TIME(mmx_math);
00132                         for( reps = 0 ; reps < MAX_REPS ; ++reps ) 
00133                         {
00134                                 int len = test_len + (test_len&0x00000001); 
00135                                 __m64  *vdst = (__m64*)&(test_set1[0]);
00136                                 __m64  *vinc = (__m64*)&(test_set2[0]);
00137                                 __m64  *vsrc = (__m64*)&(test_set2[0]);
00138                                 len = len>>1;
00139                                 i = 0 ; 
00140                                 do{
00141 #ifdef TEST_PADDD                               
00142                                         vdst[i] = _mm_add_pi32(vdst[i],vinc[i]);  /* paddd */
00143 #ifdef USE_PREFETCH
00144                                         _mm_prefetch( &vinc[i+16], _MM_HINT_NTA );
00145 #endif
00146 #else
00147                                         vdst[i] = _mm_srli_pi32(vsrc[i],1);  /* psrld */
00148 #endif 
00149                                 }while( ++i < len );
00150                         }
00151                         SHOW_TIME("MMX int math : ", mmx_math);
00152                 }
00153                 for( i = 0 ; i < test_len ; ++i ) 
00154                         if( control_data[i] != test_set1[i] ) 
00155                                 fprintf( stderr, "test %d: position %d differs - %8.8lX and %8.8lX, set2 = %8.8lX\n", test_len, i, control_data[i], test_set1[i], test_set2[i] );
00156 //                      else    fprintf( stderr, "test %d: position %d same    - %8.8lX and %8.8lX\n", test_len, i, control_data[i], test_set1[i] );
00157                 
00158                 free( control_data );
00159                 free( test_set2 );
00160                 free( test_set1 );
00161         }
00162 }

Generated on Tue Jul 5 14:13:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1