]>
git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cryptkit/ckutils/giantAsmBench/giantAsmBench.c
2 * Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <security_cryptkit/giantPortCommon.h>
26 #include <security_cryptkit/feeDebug.h>
27 #include <security_cryptkit/feeFunctions.h>
29 #include "ckutilsPlatform.h"
33 #define LOOPS_DEF 10000
34 #define MIN_SIZE_DEF 1 /* mix digits for vectorMultiply test */
35 #define MAX_SIZE_DEF 8 /* max digits */
38 static void usage(char **argv
)
40 printf("usage: %s [options]\n", argv
[0]);
41 printf(" Options:\n");
42 printf(" l=loops (default = %d)\n", LOOPS_DEF
);
43 printf(" n=maxDigits (default = %d)\n", MIN_SIZE_DEF
);
44 printf(" x=maxDigits (default = %d)\n", MAX_SIZE_DEF
);
51 * Fill buffer with random data. Assumes giantDigits is native int size.
53 static void randDigits(unsigned numDigits
,
58 for(i
=0; i
<numDigits
; i
++) {
59 /* RAND() only returns 31 bits on Unix.... */
60 digits
[i
]= RAND() + ((RAND() & 1) << 31);
66 int main(int argc
, char **argv
)
70 giantDigit
*digit1
; // mallocd arrays
74 giantDigit
*dig1p
; // ptr into mallocd arrays
83 giantDigit scr1
; // op result
84 giantDigit scr2
; // op result
85 int loops
= LOOPS_DEF
;
88 unsigned maxSize
= MAX_SIZE_DEF
;
89 unsigned minSize
= MIN_SIZE_DEF
;
94 argc
= ccommand(&argv
);
97 for(arg
=1; arg
<argc
; arg
++) {
101 maxSize
= atoi(&argp
[2]);
104 minSize
= atoi(&argp
[2]);
107 loops
= atoi(&argp
[2]);
110 seed
= atoi(&argp
[2]);
122 seed
= (unsigned)tim
;
127 * Scratch digits, big enough for anything. Malloc here, init with
128 * random data before each test.
130 digit1
= malloc(sizeof(giantDigit
) * loops
* 2);
131 digit2
= malloc(sizeof(giantDigit
) * loops
* 2);
133 /* vect1 and vect2 are arrays of giantDigit arrays */
134 vect1
= malloc(sizeof(giantDigit
) * loops
* maxSize
);
135 vect2
= malloc(sizeof(giantDigit
) * loops
* maxSize
);
137 if((digit1
== NULL
) || (digit1
== NULL
) ||
138 (vect1
== NULL
) || (vect2
== NULL
)) {
139 printf("malloc error\n");
143 printf("Starting giantAsm test: seed %d\n", seed
);
145 /* giantAddDigits test */
146 randDigits(loops
, digit1
);
147 randDigits(loops
, digit2
);
150 PLAT_GET_TIME(startTime
);
151 for(i
=0; i
<loops
; i
++) {
152 scr1
= giantAddDigits(*dig1p
++, *dig2p
++, &scr2
);
154 PLAT_GET_TIME(endTime
);
155 elapsed
= PLAT_GET_NS(startTime
, endTime
);
156 printf("giantAddDigits: %f ns\n",
157 (double)elapsed
/ (double)loops
);
159 /* giantAddDouble test */
160 randDigits(loops
, digit1
);
161 randDigits(loops
* 2, digit2
);
164 PLAT_GET_TIME(startTime
);
165 for(i
=0; i
<loops
; i
++) {
166 giantAddDouble(dig2p
, dig2p
+1, *dig1p
++);
169 PLAT_GET_TIME(endTime
);
170 elapsed
= PLAT_GET_NS(startTime
, endTime
);
171 printf("giantAddDouble: %f ns\n",
172 (double)elapsed
/ (double)loops
);
174 /* giantSubDigits test */
175 randDigits(loops
, digit1
);
176 randDigits(loops
, digit2
);
179 PLAT_GET_TIME(startTime
);
180 for(i
=0; i
<loops
; i
++) {
181 scr1
= giantSubDigits(*dig1p
++, *dig2p
++, &scr2
);
183 PLAT_GET_TIME(endTime
);
184 elapsed
= PLAT_GET_NS(startTime
, endTime
);
185 printf("giantSubDigits: %f ns\n",
186 (double)elapsed
/ (double)loops
);
188 /* giantMulDigits test */
189 randDigits(loops
, digit1
);
190 randDigits(loops
, digit2
);
193 PLAT_GET_TIME(startTime
);
194 for(i
=0; i
<loops
; i
++) {
195 giantMulDigits(*dig1p
++, *dig2p
++, &scr1
, &scr2
);
197 PLAT_GET_TIME(endTime
);
198 elapsed
= PLAT_GET_NS(startTime
, endTime
);
199 printf("giantMulDigits: %f ns\n",
200 (double)elapsed
/ (double)loops
);
202 printf("\nvectorMultiply:\n");
203 for(numDigits
=minSize
; numDigits
<=maxSize
; numDigits
*=2) {
205 randDigits(loops
, digit1
); // plierDigit
206 randDigits(loops
* numDigits
, vect1
); // candVector
207 randDigits(loops
* numDigits
, vect2
); // prodVector
212 PLAT_GET_TIME(startTime
);
213 for(i
=0; i
<loops
; i
++) {
214 scr1
= VectorMultiply(*dig1p
++, // plierDigit
215 vect1p
, // candVector
217 vect2p
); // prodVector
221 PLAT_GET_TIME(endTime
);
222 elapsed
= PLAT_GET_NS(startTime
, endTime
);
223 printf(" bits = %4d : %f ns\n",
224 numDigits
* GIANT_BITS_PER_DIGIT
,
225 (double)elapsed
/ (double)loops
);
227 } /* for numDigits */