| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include <stdlib.h> |
| 34 |
#include <stdarg.h> |
| 35 |
#include <string.h> |
| 36 |
#include <stdio.h> |
| 37 |
#include <time.h> |
| 38 |
#include "milieu.h" |
| 39 |
#include "softfloat.h" |
| 40 |
|
| 41 |
enum { |
| 42 |
minIterations = 1000 |
| 43 |
}; |
| 44 |
|
| 45 |
void fail( const char *message, ... ) |
| 46 |
{ |
| 47 |
va_list varArgs; |
| 48 |
|
| 49 |
fputs( "timesoftfloat: ", stderr ); |
| 50 |
va_start( varArgs, message ); |
| 51 |
vfprintf( stderr, message, varArgs ); |
| 52 |
va_end( varArgs ); |
| 53 |
fputs( ".\n", stderr ); |
| 54 |
exit( EXIT_FAILURE ); |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
static char *functionName, *roundingModeName, *tininessModeName; |
| 59 |
|
| 60 |
static void reportTime( int32 count, long clocks ) |
| 61 |
{ |
| 62 |
|
| 63 |
printf( |
| 64 |
"%8.1f kops/s: %s", |
| 65 |
( count / ( ( (float) clocks ) / CLOCKS_PER_SEC ) ) / 1000, |
| 66 |
functionName |
| 67 |
); |
| 68 |
if ( roundingModeName ) { |
| 69 |
fputs( ", rounding ", stdout ); |
| 70 |
fputs( roundingModeName, stdout ); |
| 71 |
if ( tininessModeName ) { |
| 72 |
fputs( ", tininess ", stdout ); |
| 73 |
fputs( tininessModeName, stdout ); |
| 74 |
fputs( " rounding", stdout ); |
| 75 |
} |
| 76 |
} |
| 77 |
fputc( '\n', stdout ); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
enum { |
| 82 |
numInputs_int32 = 32 |
| 83 |
}; |
| 84 |
|
| 85 |
static const int32 inputs_int32[ numInputs_int32 ] = { |
| 86 |
0xFFFFBB79, 0x405CF80F, 0x00000000, 0xFFFFFD04, |
| 87 |
0xFFF20002, 0x0C8EF795, 0xF00011FF, 0x000006CA, |
| 88 |
0x00009BFE, 0xFF4862E3, 0x9FFFEFFE, 0xFFFFFFB7, |
| 89 |
0x0BFF7FFF, 0x0000F37A, 0x0011DFFE, 0x00000006, |
| 90 |
0xFFF02006, 0xFFFFF7D1, 0x10200003, 0xDE8DF765, |
| 91 |
0x00003E02, 0x000019E8, 0x0008FFFE, 0xFFFFFB5C, |
| 92 |
0xFFDF7FFE, 0x07C42FBF, 0x0FFFE3FF, 0x040B9F13, |
| 93 |
0xBFFFFFF8, 0x0001BF56, 0x000017F6, 0x000A908A |
| 94 |
}; |
| 95 |
|
| 96 |
static void time_a_int32_z_float32( float32 function( int32 ) ) |
| 97 |
{ |
| 98 |
clock_t startClock, endClock; |
| 99 |
int32 count, i; |
| 100 |
int8 inputNum; |
| 101 |
|
| 102 |
count = 0; |
| 103 |
inputNum = 0; |
| 104 |
startClock = clock(); |
| 105 |
do { |
| 106 |
for ( i = minIterations; i; --i ) { |
| 107 |
function( inputs_int32[ inputNum ] ); |
| 108 |
inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 ); |
| 109 |
} |
| 110 |
count += minIterations; |
| 111 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 112 |
inputNum = 0; |
| 113 |
startClock = clock(); |
| 114 |
for ( i = count; i; --i ) { |
| 115 |
function( inputs_int32[ inputNum ] ); |
| 116 |
inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 ); |
| 117 |
} |
| 118 |
endClock = clock(); |
| 119 |
reportTime( count, endClock - startClock ); |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
static void time_a_int32_z_float64( float64 function( int32 ) ) |
| 124 |
{ |
| 125 |
clock_t startClock, endClock; |
| 126 |
int32 count, i; |
| 127 |
int8 inputNum; |
| 128 |
|
| 129 |
count = 0; |
| 130 |
inputNum = 0; |
| 131 |
startClock = clock(); |
| 132 |
do { |
| 133 |
for ( i = minIterations; i; --i ) { |
| 134 |
function( inputs_int32[ inputNum ] ); |
| 135 |
inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 ); |
| 136 |
} |
| 137 |
count += minIterations; |
| 138 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 139 |
inputNum = 0; |
| 140 |
startClock = clock(); |
| 141 |
for ( i = count; i; --i ) { |
| 142 |
function( inputs_int32[ inputNum ] ); |
| 143 |
inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 ); |
| 144 |
} |
| 145 |
endClock = clock(); |
| 146 |
reportTime( count, endClock - startClock ); |
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
enum { |
| 151 |
numInputs_float32 = 32 |
| 152 |
}; |
| 153 |
|
| 154 |
static const float32 inputs_float32[ numInputs_float32 ] = { |
| 155 |
0x4EFA0000, 0xC1D0B328, 0x80000000, 0x3E69A31E, |
| 156 |
0xAF803EFF, 0x3F800000, 0x17BF8000, 0xE74A301A, |
| 157 |
0x4E010003, 0x7EE3C75D, 0xBD803FE0, 0xBFFEFF00, |
| 158 |
0x7981F800, 0x431FFFFC, 0xC100C000, 0x3D87EFFF, |
| 159 |
0x4103FEFE, 0xBC000007, 0xBF01F7FF, 0x4E6C6B5C, |
| 160 |
0xC187FFFE, 0xC58B9F13, 0x4F88007F, 0xDF004007, |
| 161 |
0xB7FFD7FE, 0x7E8001FB, 0x46EFFBFF, 0x31C10000, |
| 162 |
0xDB428661, 0x33F89B1F, 0xA3BFEFFF, 0x537BFFBE |
| 163 |
}; |
| 164 |
|
| 165 |
static void time_a_float32_z_int32( int32 function( float32 ) ) |
| 166 |
{ |
| 167 |
clock_t startClock, endClock; |
| 168 |
int32 count, i; |
| 169 |
int8 inputNum; |
| 170 |
|
| 171 |
count = 0; |
| 172 |
inputNum = 0; |
| 173 |
startClock = clock(); |
| 174 |
do { |
| 175 |
for ( i = minIterations; i; --i ) { |
| 176 |
function( inputs_float32[ inputNum ] ); |
| 177 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 178 |
} |
| 179 |
count += minIterations; |
| 180 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 181 |
inputNum = 0; |
| 182 |
startClock = clock(); |
| 183 |
for ( i = count; i; --i ) { |
| 184 |
function( inputs_float32[ inputNum ] ); |
| 185 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 186 |
} |
| 187 |
endClock = clock(); |
| 188 |
reportTime( count, endClock - startClock ); |
| 189 |
|
| 190 |
} |
| 191 |
|
| 192 |
static void time_a_float32_z_float64( float64 function( float32 ) ) |
| 193 |
{ |
| 194 |
clock_t startClock, endClock; |
| 195 |
int32 count, i; |
| 196 |
int8 inputNum; |
| 197 |
|
| 198 |
count = 0; |
| 199 |
inputNum = 0; |
| 200 |
startClock = clock(); |
| 201 |
do { |
| 202 |
for ( i = minIterations; i; --i ) { |
| 203 |
function( inputs_float32[ inputNum ] ); |
| 204 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 205 |
} |
| 206 |
count += minIterations; |
| 207 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 208 |
inputNum = 0; |
| 209 |
startClock = clock(); |
| 210 |
for ( i = count; i; --i ) { |
| 211 |
function( inputs_float32[ inputNum ] ); |
| 212 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 213 |
} |
| 214 |
endClock = clock(); |
| 215 |
reportTime( count, endClock - startClock ); |
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
static void time_az_float32( float32 function( float32 ) ) |
| 220 |
{ |
| 221 |
clock_t startClock, endClock; |
| 222 |
int32 count, i; |
| 223 |
int8 inputNum; |
| 224 |
|
| 225 |
count = 0; |
| 226 |
inputNum = 0; |
| 227 |
startClock = clock(); |
| 228 |
do { |
| 229 |
for ( i = minIterations; i; --i ) { |
| 230 |
function( inputs_float32[ inputNum ] ); |
| 231 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 232 |
} |
| 233 |
count += minIterations; |
| 234 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 235 |
inputNum = 0; |
| 236 |
startClock = clock(); |
| 237 |
for ( i = count; i; --i ) { |
| 238 |
function( inputs_float32[ inputNum ] ); |
| 239 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 240 |
} |
| 241 |
endClock = clock(); |
| 242 |
reportTime( count, endClock - startClock ); |
| 243 |
|
| 244 |
} |
| 245 |
|
| 246 |
static void time_ab_float32_z_flag( flag function( float32, float32 ) ) |
| 247 |
{ |
| 248 |
clock_t startClock, endClock; |
| 249 |
int32 count, i; |
| 250 |
int8 inputNumA, inputNumB; |
| 251 |
|
| 252 |
count = 0; |
| 253 |
inputNumA = 0; |
| 254 |
inputNumB = 0; |
| 255 |
startClock = clock(); |
| 256 |
do { |
| 257 |
for ( i = minIterations; i; --i ) { |
| 258 |
function( |
| 259 |
inputs_float32[ inputNumA ], inputs_float32[ inputNumB ] ); |
| 260 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float32 - 1 ); |
| 261 |
if ( inputNumA == 0 ) ++inputNumB; |
| 262 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float32 - 1 ); |
| 263 |
} |
| 264 |
count += minIterations; |
| 265 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 266 |
inputNumA = 0; |
| 267 |
inputNumB = 0; |
| 268 |
startClock = clock(); |
| 269 |
for ( i = count; i; --i ) { |
| 270 |
function( |
| 271 |
inputs_float32[ inputNumA ], inputs_float32[ inputNumB ] ); |
| 272 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float32 - 1 ); |
| 273 |
if ( inputNumA == 0 ) ++inputNumB; |
| 274 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float32 - 1 ); |
| 275 |
} |
| 276 |
endClock = clock(); |
| 277 |
reportTime( count, endClock - startClock ); |
| 278 |
|
| 279 |
} |
| 280 |
|
| 281 |
static void time_abz_float32( float32 function( float32, float32 ) ) |
| 282 |
{ |
| 283 |
clock_t startClock, endClock; |
| 284 |
int32 count, i; |
| 285 |
int8 inputNumA, inputNumB; |
| 286 |
|
| 287 |
count = 0; |
| 288 |
inputNumA = 0; |
| 289 |
inputNumB = 0; |
| 290 |
startClock = clock(); |
| 291 |
do { |
| 292 |
for ( i = minIterations; i; --i ) { |
| 293 |
function( |
| 294 |
inputs_float32[ inputNumA ], inputs_float32[ inputNumB ] ); |
| 295 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float32 - 1 ); |
| 296 |
if ( inputNumA == 0 ) ++inputNumB; |
| 297 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float32 - 1 ); |
| 298 |
} |
| 299 |
count += minIterations; |
| 300 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 301 |
inputNumA = 0; |
| 302 |
inputNumB = 0; |
| 303 |
startClock = clock(); |
| 304 |
for ( i = count; i; --i ) { |
| 305 |
function( |
| 306 |
inputs_float32[ inputNumA ], inputs_float32[ inputNumB ] ); |
| 307 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float32 - 1 ); |
| 308 |
if ( inputNumA == 0 ) ++inputNumB; |
| 309 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float32 - 1 ); |
| 310 |
} |
| 311 |
endClock = clock(); |
| 312 |
reportTime( count, endClock - startClock ); |
| 313 |
|
| 314 |
} |
| 315 |
|
| 316 |
static const float32 inputs_float32_pos[ numInputs_float32 ] = { |
| 317 |
0x4EFA0000, 0x41D0B328, 0x00000000, 0x3E69A31E, |
| 318 |
0x2F803EFF, 0x3F800000, 0x17BF8000, 0x674A301A, |
| 319 |
0x4E010003, 0x7EE3C75D, 0x3D803FE0, 0x3FFEFF00, |
| 320 |
0x7981F800, 0x431FFFFC, 0x4100C000, 0x3D87EFFF, |
| 321 |
0x4103FEFE, 0x3C000007, 0x3F01F7FF, 0x4E6C6B5C, |
| 322 |
0x4187FFFE, 0x458B9F13, 0x4F88007F, 0x5F004007, |
| 323 |
0x37FFD7FE, 0x7E8001FB, 0x46EFFBFF, 0x31C10000, |
| 324 |
0x5B428661, 0x33F89B1F, 0x23BFEFFF, 0x537BFFBE |
| 325 |
}; |
| 326 |
|
| 327 |
static void time_az_float32_pos( float32 function( float32 ) ) |
| 328 |
{ |
| 329 |
clock_t startClock, endClock; |
| 330 |
int32 count, i; |
| 331 |
int8 inputNum; |
| 332 |
|
| 333 |
count = 0; |
| 334 |
inputNum = 0; |
| 335 |
startClock = clock(); |
| 336 |
do { |
| 337 |
for ( i = minIterations; i; --i ) { |
| 338 |
function( inputs_float32_pos[ inputNum ] ); |
| 339 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 340 |
} |
| 341 |
count += minIterations; |
| 342 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 343 |
inputNum = 0; |
| 344 |
startClock = clock(); |
| 345 |
for ( i = count; i; --i ) { |
| 346 |
function( inputs_float32_pos[ inputNum ] ); |
| 347 |
inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 ); |
| 348 |
} |
| 349 |
endClock = clock(); |
| 350 |
reportTime( count, endClock - startClock ); |
| 351 |
|
| 352 |
} |
| 353 |
|
| 354 |
enum { |
| 355 |
numInputs_float64 = 32 |
| 356 |
}; |
| 357 |
|
| 358 |
static const struct { |
| 359 |
bits32 high, low; |
| 360 |
} inputs_float64[ numInputs_float64 ] = { |
| 361 |
{ 0x422FFFC0, 0x08000000 }, |
| 362 |
{ 0xB7E00004, 0x80000000 }, |
| 363 |
{ 0xF3FD2546, 0x120B7935 }, |
| 364 |
{ 0x3FF00000, 0x00000000 }, |
| 365 |
{ 0xCE07F766, 0xF09588D6 }, |
| 366 |
{ 0x80000000, 0x00000000 }, |
| 367 |
{ 0x3FCE0004, 0x00000000 }, |
| 368 |
{ 0x8313B60F, 0x0032BED8 }, |
| 369 |
{ 0xC1EFFFFF, 0xC0002000 }, |
| 370 |
{ 0x3FB3C75D, 0x224F2B0F }, |
| 371 |
{ 0x7FD00000, 0x004000FF }, |
| 372 |
{ 0xA12FFF80, 0x00001FFF }, |
| 373 |
{ 0x3EE00000, 0x00FE0000 }, |
| 374 |
{ 0x00100000, 0x80000004 }, |
| 375 |
{ 0x41CFFFFE, 0x00000020 }, |
| 376 |
{ 0x40303FFF, 0xFFFFFFFD }, |
| 377 |
{ 0x3FD00000, 0x3FEFFFFF }, |
| 378 |
{ 0xBFD00000, 0x10000000 }, |
| 379 |
{ 0xB7FC6B5C, 0x16CA55CF }, |
| 380 |
{ 0x413EEB94, 0x0B9D1301 }, |
| 381 |
{ 0xC7E00200, 0x001FFFFF }, |
| 382 |
{ 0x47F00021, 0xFFFFFFFE }, |
| 383 |
{ 0xBFFFFFFF, 0xF80000FF }, |
| 384 |
{ 0xC07FFFFF, 0xE00FFFFF }, |
| 385 |
{ 0x001497A6, 0x3740C5E8 }, |
| 386 |
{ 0xC4BFFFE0, 0x001FFFFF }, |
| 387 |
{ 0x96FFDFFE, 0xFFFFFFFF }, |
| 388 |
{ 0x403FC000, 0x000001FE }, |
| 389 |
{ 0xFFD00000, 0x000001F6 }, |
| 390 |
{ 0x06404000, 0x02000000 }, |
| 391 |
{ 0x479CEE1E, 0x4F789FE0 }, |
| 392 |
{ 0xC237FFFF, 0xFFFFFDFE } |
| 393 |
}; |
| 394 |
|
| 395 |
static void time_a_float64_z_int32( int32 function( float64 ) ) |
| 396 |
{ |
| 397 |
clock_t startClock, endClock; |
| 398 |
int32 count, i; |
| 399 |
int8 inputNum; |
| 400 |
float64 a; |
| 401 |
|
| 402 |
count = 0; |
| 403 |
inputNum = 0; |
| 404 |
startClock = clock(); |
| 405 |
do { |
| 406 |
for ( i = minIterations; i; --i ) { |
| 407 |
a.low = inputs_float64[ inputNum ].low; |
| 408 |
a.high = inputs_float64[ inputNum ].high; |
| 409 |
function( a ); |
| 410 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 411 |
} |
| 412 |
count += minIterations; |
| 413 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 414 |
inputNum = 0; |
| 415 |
startClock = clock(); |
| 416 |
for ( i = count; i; --i ) { |
| 417 |
a.low = inputs_float64[ inputNum ].low; |
| 418 |
a.high = inputs_float64[ inputNum ].high; |
| 419 |
function( a ); |
| 420 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 421 |
} |
| 422 |
endClock = clock(); |
| 423 |
reportTime( count, endClock - startClock ); |
| 424 |
|
| 425 |
} |
| 426 |
|
| 427 |
static void time_a_float64_z_float32( float32 function( float64 ) ) |
| 428 |
{ |
| 429 |
clock_t startClock, endClock; |
| 430 |
int32 count, i; |
| 431 |
int8 inputNum; |
| 432 |
float64 a; |
| 433 |
|
| 434 |
count = 0; |
| 435 |
inputNum = 0; |
| 436 |
startClock = clock(); |
| 437 |
do { |
| 438 |
for ( i = minIterations; i; --i ) { |
| 439 |
a.low = inputs_float64[ inputNum ].low; |
| 440 |
a.high = inputs_float64[ inputNum ].high; |
| 441 |
function( a ); |
| 442 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 443 |
} |
| 444 |
count += minIterations; |
| 445 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 446 |
inputNum = 0; |
| 447 |
startClock = clock(); |
| 448 |
for ( i = count; i; --i ) { |
| 449 |
a.low = inputs_float64[ inputNum ].low; |
| 450 |
a.high = inputs_float64[ inputNum ].high; |
| 451 |
function( a ); |
| 452 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 453 |
} |
| 454 |
endClock = clock(); |
| 455 |
reportTime( count, endClock - startClock ); |
| 456 |
|
| 457 |
} |
| 458 |
|
| 459 |
static void time_az_float64( float64 function( float64 ) ) |
| 460 |
{ |
| 461 |
clock_t startClock, endClock; |
| 462 |
int32 count, i; |
| 463 |
int8 inputNum; |
| 464 |
float64 a; |
| 465 |
|
| 466 |
count = 0; |
| 467 |
inputNum = 0; |
| 468 |
startClock = clock(); |
| 469 |
do { |
| 470 |
for ( i = minIterations; i; --i ) { |
| 471 |
a.low = inputs_float64[ inputNum ].low; |
| 472 |
a.high = inputs_float64[ inputNum ].high; |
| 473 |
function( a ); |
| 474 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 475 |
} |
| 476 |
count += minIterations; |
| 477 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 478 |
inputNum = 0; |
| 479 |
startClock = clock(); |
| 480 |
for ( i = count; i; --i ) { |
| 481 |
a.low = inputs_float64[ inputNum ].low; |
| 482 |
a.high = inputs_float64[ inputNum ].high; |
| 483 |
function( a ); |
| 484 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 485 |
} |
| 486 |
endClock = clock(); |
| 487 |
reportTime( count, endClock - startClock ); |
| 488 |
|
| 489 |
} |
| 490 |
|
| 491 |
static void time_ab_float64_z_flag( flag function( float64, float64 ) ) |
| 492 |
{ |
| 493 |
clock_t startClock, endClock; |
| 494 |
int32 count, i; |
| 495 |
int8 inputNumA, inputNumB; |
| 496 |
float64 a, b; |
| 497 |
|
| 498 |
count = 0; |
| 499 |
inputNumA = 0; |
| 500 |
inputNumB = 0; |
| 501 |
startClock = clock(); |
| 502 |
do { |
| 503 |
for ( i = minIterations; i; --i ) { |
| 504 |
a.low = inputs_float64[ inputNumA ].low; |
| 505 |
a.high = inputs_float64[ inputNumA ].high; |
| 506 |
b.low = inputs_float64[ inputNumB ].low; |
| 507 |
b.high = inputs_float64[ inputNumB ].high; |
| 508 |
function( a, b ); |
| 509 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float64 - 1 ); |
| 510 |
if ( inputNumA == 0 ) ++inputNumB; |
| 511 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float64 - 1 ); |
| 512 |
} |
| 513 |
count += minIterations; |
| 514 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 515 |
inputNumA = 0; |
| 516 |
inputNumB = 0; |
| 517 |
startClock = clock(); |
| 518 |
for ( i = count; i; --i ) { |
| 519 |
a.low = inputs_float64[ inputNumA ].low; |
| 520 |
a.high = inputs_float64[ inputNumA ].high; |
| 521 |
b.low = inputs_float64[ inputNumB ].low; |
| 522 |
b.high = inputs_float64[ inputNumB ].high; |
| 523 |
function( a, b ); |
| 524 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float64 - 1 ); |
| 525 |
if ( inputNumA == 0 ) ++inputNumB; |
| 526 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float64 - 1 ); |
| 527 |
} |
| 528 |
endClock = clock(); |
| 529 |
reportTime( count, endClock - startClock ); |
| 530 |
|
| 531 |
} |
| 532 |
|
| 533 |
static void time_abz_float64( float64 function( float64, float64 ) ) |
| 534 |
{ |
| 535 |
clock_t startClock, endClock; |
| 536 |
int32 count, i; |
| 537 |
int8 inputNumA, inputNumB; |
| 538 |
float64 a, b; |
| 539 |
|
| 540 |
count = 0; |
| 541 |
inputNumA = 0; |
| 542 |
inputNumB = 0; |
| 543 |
startClock = clock(); |
| 544 |
do { |
| 545 |
for ( i = minIterations; i; --i ) { |
| 546 |
a.low = inputs_float64[ inputNumA ].low; |
| 547 |
a.high = inputs_float64[ inputNumA ].high; |
| 548 |
b.low = inputs_float64[ inputNumB ].low; |
| 549 |
b.high = inputs_float64[ inputNumB ].high; |
| 550 |
function( a, b ); |
| 551 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float64 - 1 ); |
| 552 |
if ( inputNumA == 0 ) ++inputNumB; |
| 553 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float64 - 1 ); |
| 554 |
} |
| 555 |
count += minIterations; |
| 556 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 557 |
inputNumA = 0; |
| 558 |
inputNumB = 0; |
| 559 |
startClock = clock(); |
| 560 |
for ( i = count; i; --i ) { |
| 561 |
a.low = inputs_float64[ inputNumA ].low; |
| 562 |
a.high = inputs_float64[ inputNumA ].high; |
| 563 |
b.low = inputs_float64[ inputNumB ].low; |
| 564 |
b.high = inputs_float64[ inputNumB ].high; |
| 565 |
function( a, b ); |
| 566 |
inputNumA = ( inputNumA + 1 ) & ( numInputs_float64 - 1 ); |
| 567 |
if ( inputNumA == 0 ) ++inputNumB; |
| 568 |
inputNumB = ( inputNumB + 1 ) & ( numInputs_float64 - 1 ); |
| 569 |
} |
| 570 |
endClock = clock(); |
| 571 |
reportTime( count, endClock - startClock ); |
| 572 |
|
| 573 |
} |
| 574 |
|
| 575 |
static const struct { |
| 576 |
bits32 high, low; |
| 577 |
} inputs_float64_pos[ numInputs_float64 ] = { |
| 578 |
{ 0x422FFFC0, 0x08000000 }, |
| 579 |
{ 0x37E00004, 0x80000000 }, |
| 580 |
{ 0x73FD2546, 0x120B7935 }, |
| 581 |
{ 0x3FF00000, 0x00000000 }, |
| 582 |
{ 0x4E07F766, 0xF09588D6 }, |
| 583 |
{ 0x00000000, 0x00000000 }, |
| 584 |
{ 0x3FCE0004, 0x00000000 }, |
| 585 |
{ 0x0313B60F, 0x0032BED8 }, |
| 586 |
{ 0x41EFFFFF, 0xC0002000 }, |
| 587 |
{ 0x3FB3C75D, 0x224F2B0F }, |
| 588 |
{ 0x7FD00000, 0x004000FF }, |
| 589 |
{ 0x212FFF80, 0x00001FFF }, |
| 590 |
{ 0x3EE00000, 0x00FE0000 }, |
| 591 |
{ 0x00100000, 0x80000004 }, |
| 592 |
{ 0x41CFFFFE, 0x00000020 }, |
| 593 |
{ 0x40303FFF, 0xFFFFFFFD }, |
| 594 |
{ 0x3FD00000, 0x3FEFFFFF }, |
| 595 |
{ 0x3FD00000, 0x10000000 }, |
| 596 |
{ 0x37FC6B5C, 0x16CA55CF }, |
| 597 |
{ 0x413EEB94, 0x0B9D1301 }, |
| 598 |
{ 0x47E00200, 0x001FFFFF }, |
| 599 |
{ 0x47F00021, 0xFFFFFFFE }, |
| 600 |
{ 0x3FFFFFFF, 0xF80000FF }, |
| 601 |
{ 0x407FFFFF, 0xE00FFFFF }, |
| 602 |
{ 0x001497A6, 0x3740C5E8 }, |
| 603 |
{ 0x44BFFFE0, 0x001FFFFF }, |
| 604 |
{ 0x16FFDFFE, 0xFFFFFFFF }, |
| 605 |
{ 0x403FC000, 0x000001FE }, |
| 606 |
{ 0x7FD00000, 0x000001F6 }, |
| 607 |
{ 0x06404000, 0x02000000 }, |
| 608 |
{ 0x479CEE1E, 0x4F789FE0 }, |
| 609 |
{ 0x4237FFFF, 0xFFFFFDFE } |
| 610 |
}; |
| 611 |
|
| 612 |
static void time_az_float64_pos( float64 function( float64 ) ) |
| 613 |
{ |
| 614 |
clock_t startClock, endClock; |
| 615 |
int32 count, i; |
| 616 |
int8 inputNum; |
| 617 |
float64 a; |
| 618 |
|
| 619 |
count = 0; |
| 620 |
inputNum = 0; |
| 621 |
startClock = clock(); |
| 622 |
do { |
| 623 |
for ( i = minIterations; i; --i ) { |
| 624 |
a.low = inputs_float64_pos[ inputNum ].low; |
| 625 |
a.high = inputs_float64_pos[ inputNum ].high; |
| 626 |
function( a ); |
| 627 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 628 |
} |
| 629 |
count += minIterations; |
| 630 |
} while ( clock() - startClock < CLOCKS_PER_SEC ); |
| 631 |
inputNum = 0; |
| 632 |
startClock = clock(); |
| 633 |
for ( i = count; i; --i ) { |
| 634 |
a.low = inputs_float64_pos[ inputNum ].low; |
| 635 |
a.high = inputs_float64_pos[ inputNum ].high; |
| 636 |
function( a ); |
| 637 |
inputNum = ( inputNum + 1 ) & ( numInputs_float64 - 1 ); |
| 638 |
} |
| 639 |
endClock = clock(); |
| 640 |
reportTime( count, endClock - startClock ); |
| 641 |
|
| 642 |
} |
| 643 |
|
| 644 |
enum { |
| 645 |
INT32_TO_FLOAT32 = 1, |
| 646 |
INT32_TO_FLOAT64, |
| 647 |
FLOAT32_TO_INT32, |
| 648 |
FLOAT32_TO_INT32_ROUND_TO_ZERO, |
| 649 |
FLOAT32_TO_FLOAT64, |
| 650 |
FLOAT32_ROUND_TO_INT, |
| 651 |
FLOAT32_ADD, |
| 652 |
FLOAT32_SUB, |
| 653 |
FLOAT32_MUL, |
| 654 |
FLOAT32_DIV, |
| 655 |
FLOAT32_REM, |
| 656 |
FLOAT32_SQRT, |
| 657 |
FLOAT32_EQ, |
| 658 |
FLOAT32_LE, |
| 659 |
FLOAT32_LT, |
| 660 |
FLOAT32_EQ_SIGNALING, |
| 661 |
FLOAT32_LE_QUIET, |
| 662 |
FLOAT32_LT_QUIET, |
| 663 |
FLOAT64_TO_INT32, |
| 664 |
FLOAT64_TO_INT32_ROUND_TO_ZERO, |
| 665 |
FLOAT64_TO_FLOAT32, |
| 666 |
FLOAT64_ROUND_TO_INT, |
| 667 |
FLOAT64_ADD, |
| 668 |
FLOAT64_SUB, |
| 669 |
FLOAT64_MUL, |
| 670 |
FLOAT64_DIV, |
| 671 |
FLOAT64_REM, |
| 672 |
FLOAT64_SQRT, |
| 673 |
FLOAT64_EQ, |
| 674 |
FLOAT64_LE, |
| 675 |
FLOAT64_LT, |
| 676 |
FLOAT64_EQ_SIGNALING, |
| 677 |
FLOAT64_LE_QUIET, |
| 678 |
FLOAT64_LT_QUIET, |
| 679 |
NUM_FUNCTIONS |
| 680 |
}; |
| 681 |
|
| 682 |
static struct { |
| 683 |
char *name; |
| 684 |
int8 numInputs; |
| 685 |
flag roundingMode, tininessMode; |
| 686 |
} functions[ NUM_FUNCTIONS ] = { |
| 687 |
{ 0, 0, 0, 0 }, |
| 688 |
{ "int32_to_float32", 1, TRUE, FALSE }, |
| 689 |
{ "int32_to_float64", 1, FALSE, FALSE }, |
| 690 |
{ "float32_to_int32", 1, TRUE, FALSE }, |
| 691 |
{ "float32_to_int32_round_to_zero", 1, FALSE, FALSE }, |
| 692 |
{ "float32_to_float64", 1, FALSE, FALSE }, |
| 693 |
{ "float32_round_to_int", 1, TRUE, FALSE }, |
| 694 |
{ "float32_add", 2, TRUE, FALSE }, |
| 695 |
{ "float32_sub", 2, TRUE, FALSE }, |
| 696 |
{ "float32_mul", 2, TRUE, TRUE, }, |
| 697 |
{ "float32_div", 2, TRUE, FALSE }, |
| 698 |
{ "float32_rem", 2, FALSE, FALSE }, |
| 699 |
{ "float32_sqrt", 1, TRUE, FALSE }, |
| 700 |
{ "float32_eq", 2, FALSE, FALSE }, |
| 701 |
{ "float32_le", 2, FALSE, FALSE }, |
| 702 |
{ "float32_lt", 2, FALSE, FALSE }, |
| 703 |
{ "float32_eq_signaling", 2, FALSE, FALSE }, |
| 704 |
{ "float32_le_quiet", 2, FALSE, FALSE }, |
| 705 |
{ "float32_lt_quiet", 2, FALSE, FALSE }, |
| 706 |
{ "float64_to_int32", 1, TRUE, FALSE }, |
| 707 |
{ "float64_to_int32_round_to_zero", 1, FALSE, FALSE }, |
| 708 |
{ "float64_to_float32", 1, TRUE, TRUE, }, |
| 709 |
{ "float64_round_to_int", 1, TRUE, FALSE }, |
| 710 |
{ "float64_add", 2, TRUE, FALSE }, |
| 711 |
{ "float64_sub", 2, TRUE, FALSE }, |
| 712 |
{ "float64_mul", 2, TRUE, TRUE, }, |
| 713 |
{ "float64_div", 2, TRUE, FALSE }, |
| 714 |
{ "float64_rem", 2, FALSE, FALSE }, |
| 715 |
{ "float64_sqrt", 1, TRUE, FALSE }, |
| 716 |
{ "float64_eq", 2, FALSE, FALSE }, |
| 717 |
{ "float64_le", 2, FALSE, FALSE }, |
| 718 |
{ "float64_lt", 2, FALSE, FALSE }, |
| 719 |
{ "float64_eq_signaling", 2, FALSE, FALSE }, |
| 720 |
{ "float64_le_quiet", 2, FALSE, FALSE }, |
| 721 |
{ "float64_lt_quiet", 2, FALSE, FALSE } |
| 722 |
}; |
| 723 |
|
| 724 |
enum { |
| 725 |
ROUND_NEAREST_EVEN = 1, |
| 726 |
ROUND_TO_ZERO, |
| 727 |
ROUND_DOWN, |
| 728 |
ROUND_UP, |
| 729 |
NUM_ROUNDINGMODES |
| 730 |
}; |
| 731 |
enum { |
| 732 |
TININESS_BEFORE_ROUNDING = 1, |
| 733 |
TININESS_AFTER_ROUNDING, |
| 734 |
NUM_TININESSMODES |
| 735 |
}; |
| 736 |
|
| 737 |
static void |
| 738 |
timeFunctionVariety( |
| 739 |
uint8 functionCode, int8 roundingMode, int8 tininessMode ) |
| 740 |
{ |
| 741 |
uint8 roundingCode; |
| 742 |
int8 tininessCode; |
| 743 |
|
| 744 |
functionName = functions[ functionCode ].name; |
| 745 |
switch ( roundingMode ) { |
| 746 |
case 0: |
| 747 |
roundingModeName = 0; |
| 748 |
roundingCode = float_round_nearest_even; |
| 749 |
break; |
| 750 |
case ROUND_NEAREST_EVEN: |
| 751 |
roundingModeName = "nearest_even"; |
| 752 |
roundingCode = float_round_nearest_even; |
| 753 |
break; |
| 754 |
case ROUND_TO_ZERO: |
| 755 |
roundingModeName = "to_zero"; |
| 756 |
roundingCode = float_round_to_zero; |
| 757 |
break; |
| 758 |
case ROUND_DOWN: |
| 759 |
roundingModeName = "down"; |
| 760 |
roundingCode = float_round_down; |
| 761 |
break; |
| 762 |
case ROUND_UP: |
| 763 |
roundingModeName = "up"; |
| 764 |
roundingCode = float_round_up; |
| 765 |
break; |
| 766 |
} |
| 767 |
float_rounding_mode = roundingCode; |
| 768 |
switch ( tininessMode ) { |
| 769 |
case 0: |
| 770 |
tininessModeName = 0; |
| 771 |
tininessCode = float_tininess_after_rounding; |
| 772 |
break; |
| 773 |
case TININESS_BEFORE_ROUNDING: |
| 774 |
tininessModeName = "before"; |
| 775 |
tininessCode = float_tininess_before_rounding; |
| 776 |
break; |
| 777 |
case TININESS_AFTER_ROUNDING: |
| 778 |
tininessModeName = "after"; |
| 779 |
tininessCode = float_tininess_after_rounding; |
| 780 |
break; |
| 781 |
} |
| 782 |
float_detect_tininess = tininessCode; |
| 783 |
switch ( functionCode ) { |
| 784 |
case INT32_TO_FLOAT32: |
| 785 |
time_a_int32_z_float32( int32_to_float32 ); |
| 786 |
break; |
| 787 |
case INT32_TO_FLOAT64: |
| 788 |
time_a_int32_z_float64( int32_to_float64 ); |
| 789 |
break; |
| 790 |
case FLOAT32_TO_INT32: |
| 791 |
time_a_float32_z_int32( float32_to_int32 ); |
| 792 |
break; |
| 793 |
case FLOAT32_TO_INT32_ROUND_TO_ZERO: |
| 794 |
time_a_float32_z_int32( float32_to_int32_round_to_zero ); |
| 795 |
break; |
| 796 |
case FLOAT32_TO_FLOAT64: |
| 797 |
time_a_float32_z_float64( float32_to_float64 ); |
| 798 |
break; |
| 799 |
case FLOAT32_ROUND_TO_INT: |
| 800 |
time_az_float32( float32_round_to_int ); |
| 801 |
break; |
| 802 |
case FLOAT32_ADD: |
| 803 |
time_abz_float32( float32_add ); |
| 804 |
break; |
| 805 |
case FLOAT32_SUB: |
| 806 |
time_abz_float32( float32_sub ); |
| 807 |
break; |
| 808 |
case FLOAT32_MUL: |
| 809 |
time_abz_float32( float32_mul ); |
| 810 |
break; |
| 811 |
case FLOAT32_DIV: |
| 812 |
time_abz_float32( float32_div ); |
| 813 |
break; |
| 814 |
case FLOAT32_REM: |
| 815 |
time_abz_float32( float32_rem ); |
| 816 |
break; |
| 817 |
case FLOAT32_SQRT: |
| 818 |
time_az_float32_pos( float32_sqrt ); |
| 819 |
break; |
| 820 |
case FLOAT32_EQ: |
| 821 |
time_ab_float32_z_flag( float32_eq ); |
| 822 |
break; |
| 823 |
case FLOAT32_LE: |
| 824 |
time_ab_float32_z_flag( float32_le ); |
| 825 |
break; |
| 826 |
case FLOAT32_LT: |
| 827 |
time_ab_float32_z_flag( float32_lt ); |
| 828 |
break; |
| 829 |
case FLOAT32_EQ_SIGNALING: |
| 830 |
time_ab_float32_z_flag( float32_eq_signaling ); |
| 831 |
break; |
| 832 |
case FLOAT32_LE_QUIET: |
| 833 |
time_ab_float32_z_flag( float32_le_quiet ); |
| 834 |
break; |
| 835 |
case FLOAT32_LT_QUIET: |
| 836 |
time_ab_float32_z_flag( float32_lt_quiet ); |
| 837 |
break; |
| 838 |
case FLOAT64_TO_INT32: |
| 839 |
time_a_float64_z_int32( float64_to_int32 ); |
| 840 |
break; |
| 841 |
case FLOAT64_TO_INT32_ROUND_TO_ZERO: |
| 842 |
time_a_float64_z_int32( float64_to_int32_round_to_zero ); |
| 843 |
break; |
| 844 |
case FLOAT64_TO_FLOAT32: |
| 845 |
time_a_float64_z_float32( float64_to_float32 ); |
| 846 |
break; |
| 847 |
case FLOAT64_ROUND_TO_INT: |
| 848 |
time_az_float64( float64_round_to_int ); |
| 849 |
break; |
| 850 |
case FLOAT64_ADD: |
| 851 |
time_abz_float64( float64_add ); |
| 852 |
break; |
| 853 |
case FLOAT64_SUB: |
| 854 |
time_abz_float64( float64_sub ); |
| 855 |
break; |
| 856 |
case FLOAT64_MUL: |
| 857 |
time_abz_float64( float64_mul ); |
| 858 |
break; |
| 859 |
case FLOAT64_DIV: |
| 860 |
time_abz_float64( float64_div ); |
| 861 |
break; |
| 862 |
case FLOAT64_REM: |
| 863 |
time_abz_float64( float64_rem ); |
| 864 |
break; |
| 865 |
case FLOAT64_SQRT: |
| 866 |
time_az_float64_pos( float64_sqrt ); |
| 867 |
break; |
| 868 |
case FLOAT64_EQ: |
| 869 |
time_ab_float64_z_flag( float64_eq ); |
| 870 |
break; |
| 871 |
case FLOAT64_LE: |
| 872 |
time_ab_float64_z_flag( float64_le ); |
| 873 |
break; |
| 874 |
case FLOAT64_LT: |
| 875 |
time_ab_float64_z_flag( float64_lt ); |
| 876 |
break; |
| 877 |
case FLOAT64_EQ_SIGNALING: |
| 878 |
time_ab_float64_z_flag( float64_eq_signaling ); |
| 879 |
break; |
| 880 |
case FLOAT64_LE_QUIET: |
| 881 |
time_ab_float64_z_flag( float64_le_quiet ); |
| 882 |
break; |
| 883 |
case FLOAT64_LT_QUIET: |
| 884 |
time_ab_float64_z_flag( float64_lt_quiet ); |
| 885 |
break; |
| 886 |
} |
| 887 |
|
| 888 |
} |
| 889 |
|
| 890 |
static void |
| 891 |
timeFunction( uint8 functionCode, int8 roundingModeIn, int8 tininessModeIn ) |
| 892 |
{ |
| 893 |
int8 roundingMode, tininessMode; |
| 894 |
|
| 895 |
for ( roundingMode = 1; |
| 896 |
roundingMode < NUM_ROUNDINGMODES; |
| 897 |
++roundingMode |
| 898 |
) { |
| 899 |
if ( ! functions[ functionCode ].roundingMode ) { |
| 900 |
roundingMode = 0; |
| 901 |
} |
| 902 |
else if ( roundingModeIn ) { |
| 903 |
roundingMode = roundingModeIn; |
| 904 |
} |
| 905 |
for ( tininessMode = 1; |
| 906 |
tininessMode < NUM_TININESSMODES; |
| 907 |
++tininessMode |
| 908 |
) { |
| 909 |
if ( ! functions[ functionCode ].tininessMode ) { |
| 910 |
tininessMode = 0; |
| 911 |
} |
| 912 |
else if ( tininessModeIn ) { |
| 913 |
tininessMode = tininessModeIn; |
| 914 |
} |
| 915 |
timeFunctionVariety( functionCode, roundingMode, tininessMode ); |
| 916 |
if ( tininessModeIn || ! tininessMode ) break; |
| 917 |
} |
| 918 |
if ( roundingModeIn || ! roundingMode ) break; |
| 919 |
} |
| 920 |
|
| 921 |
} |
| 922 |
|
| 923 |
main( int argc, char **argv ) |
| 924 |
{ |
| 925 |
char *argPtr; |
| 926 |
flag functionArgument; |
| 927 |
uint8 functionCode; |
| 928 |
int8 operands, roundingMode, tininessMode; |
| 929 |
|
| 930 |
if ( argc <= 1 ) goto writeHelpMessage; |
| 931 |
functionArgument = FALSE; |
| 932 |
functionCode = 0; |
| 933 |
operands = 0; |
| 934 |
roundingMode = 0; |
| 935 |
tininessMode = 0; |
| 936 |
--argc; |
| 937 |
++argv; |
| 938 |
while ( argc && ( argPtr = argv[ 0 ] ) ) { |
| 939 |
if ( argPtr[ 0 ] == '-' ) ++argPtr; |
| 940 |
if ( strcmp( argPtr, "help" ) == 0 ) { |
| 941 |
writeHelpMessage: |
| 942 |
fputs( |
| 943 |
"timesoftfloat [<option>...] <function>\n" |
| 944 |
" <option>: (* is default)\n" |
| 945 |
" -help --Write this message and exit.\n" |
| 946 |
" -nearesteven --Only time rounding to nearest/even.\n" |
| 947 |
" -tozero --Only time rounding to zero.\n" |
| 948 |
" -down --Only time rounding down.\n" |
| 949 |
" -up --Only time rounding up.\n" |
| 950 |
" -tininessbefore --Only time underflow tininess before rounding.\n" |
| 951 |
" -tininessafter --Only time underflow tininess after rounding.\n" |
| 952 |
" <function>:\n" |
| 953 |
" int32_to_<float> <float>_add <float>_eq\n" |
| 954 |
" <float>_to_int32 <float>_sub <float>_le\n" |
| 955 |
" <float>_to_int32_round_to_zero <float>_mul <float>_lt\n" |
| 956 |
" <float>_to_<float> <float>_div <float>_eq_signaling\n" |
| 957 |
" <float>_round_to_int <float>_rem <float>_le_quiet\n" |
| 958 |
" <float>_sqrt <float>_lt_quiet\n" |
| 959 |
" -all1 --All 1-operand functions.\n" |
| 960 |
" -all2 --All 2-operand functions.\n" |
| 961 |
" -all --All functions.\n" |
| 962 |
" <float>:\n" |
| 963 |
" float32 --Single precision.\n" |
| 964 |
" float64 --Double precision.\n", |
| 965 |
stdout |
| 966 |
); |
| 967 |
return EXIT_SUCCESS; |
| 968 |
} |
| 969 |
else if ( ( strcmp( argPtr, "nearesteven" ) == 0 ) |
| 970 |
|| ( strcmp( argPtr, "nearest_even" ) == 0 ) ) { |
| 971 |
roundingMode = ROUND_NEAREST_EVEN; |
| 972 |
} |
| 973 |
else if ( ( strcmp( argPtr, "tozero" ) == 0 ) |
| 974 |
|| ( strcmp( argPtr, "to_zero" ) == 0 ) ) { |
| 975 |
roundingMode = ROUND_TO_ZERO; |
| 976 |
} |
| 977 |
else if ( strcmp( argPtr, "down" ) == 0 ) { |
| 978 |
roundingMode = ROUND_DOWN; |
| 979 |
} |
| 980 |
else if ( strcmp( argPtr, "up" ) == 0 ) { |
| 981 |
roundingMode = ROUND_UP; |
| 982 |
} |
| 983 |
else if ( strcmp( argPtr, "tininessbefore" ) == 0 ) { |
| 984 |
tininessMode = TININESS_BEFORE_ROUNDING; |
| 985 |
} |
| 986 |
else if ( strcmp( argPtr, "tininessafter" ) == 0 ) { |
| 987 |
tininessMode = TININESS_AFTER_ROUNDING; |
| 988 |
} |
| 989 |
else if ( strcmp( argPtr, "all1" ) == 0 ) { |
| 990 |
functionArgument = TRUE; |
| 991 |
functionCode = 0; |
| 992 |
operands = 1; |
| 993 |
} |
| 994 |
else if ( strcmp( argPtr, "all2" ) == 0 ) { |
| 995 |
functionArgument = TRUE; |
| 996 |
functionCode = 0; |
| 997 |
operands = 2; |
| 998 |
} |
| 999 |
else if ( strcmp( argPtr, "all" ) == 0 ) { |
| 1000 |
functionArgument = TRUE; |
| 1001 |
functionCode = 0; |
| 1002 |
operands = 0; |
| 1003 |
} |
| 1004 |
else { |
| 1005 |
for ( functionCode = 1; |
| 1006 |
functionCode < NUM_FUNCTIONS; |
| 1007 |
++functionCode |
| 1008 |
) { |
| 1009 |
if ( strcmp( argPtr, functions[ functionCode ].name ) == 0 ) { |
| 1010 |
break; |
| 1011 |
} |
| 1012 |
} |
| 1013 |
if ( functionCode == NUM_FUNCTIONS ) { |
| 1014 |
fail( "Invalid option or function `%s'", argv[ 0 ] ); |
| 1015 |
} |
| 1016 |
functionArgument = TRUE; |
| 1017 |
} |
| 1018 |
--argc; |
| 1019 |
++argv; |
| 1020 |
} |
| 1021 |
if ( ! functionArgument ) fail( "Function argument required" ); |
| 1022 |
if ( functionCode ) { |
| 1023 |
timeFunction( functionCode, roundingMode, tininessMode ); |
| 1024 |
} |
| 1025 |
else if ( operands == 1 ) { |
| 1026 |
for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode |
| 1027 |
) { |
| 1028 |
if ( functions[ functionCode ].numInputs == 1 ) { |
| 1029 |
timeFunction( functionCode, roundingMode, tininessMode ); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
else if ( operands == 2 ) { |
| 1034 |
for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode |
| 1035 |
) { |
| 1036 |
if ( functions[ functionCode ].numInputs == 2 ) { |
| 1037 |
timeFunction( functionCode, roundingMode, tininessMode ); |
| 1038 |
} |
| 1039 |
} |
| 1040 |
} |
| 1041 |
else { |
| 1042 |
for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode |
| 1043 |
) { |
| 1044 |
timeFunction( functionCode, roundingMode, tininessMode ); |
| 1045 |
} |
| 1046 |
} |
| 1047 |
return EXIT_SUCCESS; |
| 1048 |
|
| 1049 |
} |
| 1050 |
|