1 /*
2  * Copyright (c) 2000,2001,2004 Sasha Vasko <sasha at aftercode.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 
20 #define LOCAL_DEBUG
21 #define DO_CLOCKING
22 #ifdef NO_DEBUG_OUTPUT
23 #undef DEBUG_RECTS
24 #undef DEBUG_RECTS2
25 #endif
26 
27 #ifdef _WIN32
28 #include "win32/config.h"
29 #else
30 #include "config.h"
31 #endif
32 
33 
34 #include <string.h>
35 #ifdef DO_CLOCKING
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
38 # include <time.h>
39 #else
40 # if HAVE_SYS_TIME_H
41 #  include <sys/time.h>
42 # else
43 #  include <time.h>
44 # endif
45 #endif
46 #endif
47 #ifdef HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
50 #ifdef HAVE_STDLIB_H
51 #include <stdlib.h>
52 #endif
53 #ifdef HAVE_STDARG_H
54 #include <stdarg.h>
55 #endif
56 
57 #ifdef HAVE_MMX
58 #include <mmintrin.h>
59 #include <xmmintrin.h>
60 #endif
61 
62 #ifdef _WIN32
63 # include "win32/afterbase.h"
64 #else
65 # include "afterbase.h"
66 #endif
67 #include "asvisual.h"
68 #include "blender.h"
69 #include "asimage.h"
70 #include "imencdec.h"
71 
72 #define TEST_PADDD
73 #define USE_PREFETCH
74 
75 #ifdef DO_CLOCKING
76 #define MIN_TEST_LEN 15000000
77 #define MAX_TEST_LEN 15000001
78 #define MAX_REPS 1
79 #else
80 #define MIN_TEST_LEN 1
81 #define MAX_TEST_LEN 10001
82 #define MAX_REPS 1
83 #endif
84 
85 static CARD32 rnd32_seed = 345824357;
86 
87 #define MAX_MY_RND32		0x00ffffffff
88 #ifdef WORD64
89 #define MY_RND32() \
90 (rnd32_seed = ((1664525L*rnd32_seed)&MAX_MY_RND32)+1013904223L)
91 #else
92 #define MY_RND32() \
93 (rnd32_seed = (1664525L*rnd32_seed)+1013904223L)
94 #endif
95 
96 
main()97 int main()
98 {
99 	int test_len ;
100 	CARD32 *test_set1 ;
101 	CARD32 *test_set2 ;
102 	CARD32 *control_data ;
103 	int i, reps ;
104 
105 	for( test_len = MIN_TEST_LEN ; test_len < MAX_TEST_LEN ; ++test_len )
106 	{
107 		test_set1 = safemalloc( (test_len + (test_len&0x01))* sizeof(CARD32) );
108 		test_set2 = safemalloc( (test_len + (test_len&0x01))* sizeof(CARD32) );
109 		control_data = safemalloc( (test_len + (test_len&0x01))* sizeof(CARD32) );
110 		for( i = 0 ; i < test_len ; ++i )
111 		{
112 			test_set1[i] = MY_RND32()& 0x00FFFFFF ;
113 			test_set2[i] = MY_RND32()& 0x00FFFFFF ;
114 		}
115 		{
116 			START_TIME(int_math);
117 			for( reps = 0 ; reps < MAX_REPS ; ++reps )
118 			{
119 				for( i = 0 ; i < test_len ; ++i )
120 				{
121 #ifdef TEST_PADDD
122 					control_data[i] = test_set1[i] + test_set2[i] ;
123 #else
124 					control_data[i] = test_set2[i] >> 1 ;
125 #endif
126 				}
127 			}
128 			SHOW_TIME("Standard int math : ", int_math);
129 		}
130 		{
131 			START_TIME(mmx_math);
132 			for( reps = 0 ; reps < MAX_REPS ; ++reps )
133 			{
134 				int len = test_len + (test_len&0x00000001);
135 				__m64  *vdst = (__m64*)&(test_set1[0]);
136 				__m64  *vinc = (__m64*)&(test_set2[0]);
137 				__m64  *vsrc = (__m64*)&(test_set2[0]);
138 				len = len>>1;
139 				i = 0 ;
140 				do{
141 #ifdef TEST_PADDD
142 					vdst[i] = _mm_add_pi32(vdst[i],vinc[i]);  /* paddd */
143 #ifdef USE_PREFETCH
144 					_mm_prefetch( &vinc[i+16], _MM_HINT_NTA );
145 #endif
146 #else
147 					vdst[i] = _mm_srli_pi32(vsrc[i],1);  /* psrld */
148 #endif
149 				}while( ++i < len );
150 			}
151 			SHOW_TIME("MMX int math : ", mmx_math);
152 		}
153 		for( i = 0 ; i < test_len ; ++i )
154 			if( control_data[i] != test_set1[i] )
155 				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] );
156 //			else	fprintf( stderr, "test %d: position %d same    - %8.8lX	and %8.8lX\n", test_len, i, control_data[i], test_set1[i] );
157 
158 		free( control_data );
159 		free( test_set2 );
160 		free( test_set1 );
161 	}
162 }
163