69 for (int i=0; i<ITERS; i++) {
70 test_sum(a1);
71 test_addc(a0, a1);
72 test_addv(a0, a1, VALUE);
73 test_adda(a0, a1, a2);
74 test_subc(a0, a1);
75 test_subv(a0, a1, VALUE);
76 test_suba(a0, a1, a2);
77 test_mulc(a0, a1);
78 test_mulv(a0, a1, VALUE);
79 test_mula(a0, a1, a2);
80 test_divc(a0, a1);
81 test_divv(a0, a1, VALUE);
82 test_diva(a0, a1, a2);
83 test_mulc_n(a0, a1);
84 test_mulv(a0, a1, -VALUE);
85 test_mula(a0, a1, a3);
86 test_divc_n(a0, a1);
87 test_divv(a0, a1, -VALUE);
88 test_diva(a0, a1, a3);
89 }
90 // Test and verify results
91 System.out.println("Verification");
92 int errn = 0;
93 {
94 float sum = test_sum(a1);
95 if (sum != gold_sum) {
96 System.err.println("test_sum: " + sum + " != " + gold_sum);
97 errn++;
98 }
99 // Overwrite with NaN values
100 a1[0] = Float.NaN;
101 a1[1] = Float.POSITIVE_INFINITY;
102 a1[2] = Float.NEGATIVE_INFINITY;
103 a1[3] = Float.MAX_VALUE;
104 a1[4] = Float.MIN_VALUE;
105 a1[5] = Float.MIN_NORMAL;
106
107 a2[6] = a1[0];
108 a2[7] = a1[1];
323 for (int i=6; i<ARRLEN; i++) {
324 errn += verify("test_divv_n: ", i, a0[i], ((ADD_INIT+i)/(-VALUE)));
325 }
326 test_diva(a0, a1, a3);
327 errn += verify("test_diva_n: ", 0, a0[0], (Float.NaN/(-VALUE)));
328 errn += verify("test_diva_n: ", 1, a0[1], (Float.POSITIVE_INFINITY/(-VALUE)));
329 errn += verify("test_diva_n: ", 2, a0[2], (Float.NEGATIVE_INFINITY/(-VALUE)));
330 errn += verify("test_diva_n: ", 3, a0[3], (Float.MAX_VALUE/(-VALUE)));
331 errn += verify("test_diva_n: ", 4, a0[4], (Float.MIN_VALUE/(-VALUE)));
332 errn += verify("test_diva_n: ", 5, a0[5], (Float.MIN_NORMAL/(-VALUE)));
333 errn += verify("test_diva_n: ", 6, a0[6], ((ADD_INIT+6)/(-Float.NaN)));
334 errn += verify("test_diva_n: ", 7, a0[7], ((ADD_INIT+7)/(-Float.POSITIVE_INFINITY)));
335 errn += verify("test_diva_n: ", 8, a0[8], ((ADD_INIT+8)/(-Float.NEGATIVE_INFINITY)));
336 errn += verify("test_diva_n: ", 9, a0[9], ((ADD_INIT+9)/(-Float.MAX_VALUE)));
337 errn += verify("test_diva_n: ", 10, a0[10], ((ADD_INIT+10)/(-Float.MIN_VALUE)));
338 errn += verify("test_diva_n: ", 11, a0[11], ((ADD_INIT+11)/(-Float.MIN_NORMAL)));
339 for (int i=12; i<ARRLEN; i++) {
340 errn += verify("test_diva_n: ", i, a0[i], ((ADD_INIT+i)/(-VALUE)));
341 }
342
343 }
344
345 if (errn > 0)
346 return errn;
347
348 System.out.println("Time");
349 long start, end;
350
351 start = System.currentTimeMillis();
352 for (int i=0; i<ITERS; i++) {
353 test_sum(a1);
354 }
355 end = System.currentTimeMillis();
356 System.out.println("test_sum: " + (end - start));
357
358 start = System.currentTimeMillis();
359 for (int i=0; i<ITERS; i++) {
360 test_addc(a0, a1);
361 }
362 end = System.currentTimeMillis();
452
453 start = System.currentTimeMillis();
454 for (int i=0; i<ITERS; i++) {
455 test_divc_n(a0, a1);
456 }
457 end = System.currentTimeMillis();
458 System.out.println("test_divc_n: " + (end - start));
459 start = System.currentTimeMillis();
460 for (int i=0; i<ITERS; i++) {
461 test_divv(a0, a1, -VALUE);
462 }
463 end = System.currentTimeMillis();
464 System.out.println("test_divv_n: " + (end - start));
465 start = System.currentTimeMillis();
466 for (int i=0; i<ITERS; i++) {
467 test_diva(a0, a1, a3);
468 }
469 end = System.currentTimeMillis();
470 System.out.println("test_diva_n: " + (end - start));
471
472 return errn;
473 }
474
475 static float test_sum(float[] a1) {
476 float sum = 0;
477 for (int i = 0; i < a1.length; i+=1) {
478 sum += a1[i];
479 }
480 return sum;
481 }
482
483 static void test_addc(float[] a0, float[] a1) {
484 for (int i = 0; i < a0.length; i+=1) {
485 a0[i] = (a1[i]+VALUE);
486 }
487 }
488 static void test_addv(float[] a0, float[] a1, float b) {
489 for (int i = 0; i < a0.length; i+=1) {
490 a0[i] = (a1[i]+b);
491 }
534 }
535
536 static void test_divc(float[] a0, float[] a1) {
537 for (int i = 0; i < a0.length; i+=1) {
538 a0[i] = (a1[i]/VALUE);
539 }
540 }
541 static void test_divc_n(float[] a0, float[] a1) {
542 for (int i = 0; i < a0.length; i+=1) {
543 a0[i] = (a1[i]/(-VALUE));
544 }
545 }
546 static void test_divv(float[] a0, float[] a1, float b) {
547 for (int i = 0; i < a0.length; i+=1) {
548 a0[i] = (a1[i]/b);
549 }
550 }
551 static void test_diva(float[] a0, float[] a1, float[] a2) {
552 for (int i = 0; i < a0.length; i+=1) {
553 a0[i] = (a1[i]/a2[i]);
554 }
555 }
556
557 static int verify(String text, int i, float elem, float val) {
558 if (elem != val && !(Float.isNaN(elem) && Float.isNaN(val))) {
559 System.err.println(text + "[" + i + "] = " + elem + " != " + val);
560 return 1;
561 }
562 return 0;
563 }
564 }
|
69 for (int i=0; i<ITERS; i++) {
70 test_sum(a1);
71 test_addc(a0, a1);
72 test_addv(a0, a1, VALUE);
73 test_adda(a0, a1, a2);
74 test_subc(a0, a1);
75 test_subv(a0, a1, VALUE);
76 test_suba(a0, a1, a2);
77 test_mulc(a0, a1);
78 test_mulv(a0, a1, VALUE);
79 test_mula(a0, a1, a2);
80 test_divc(a0, a1);
81 test_divv(a0, a1, VALUE);
82 test_diva(a0, a1, a2);
83 test_mulc_n(a0, a1);
84 test_mulv(a0, a1, -VALUE);
85 test_mula(a0, a1, a3);
86 test_divc_n(a0, a1);
87 test_divv(a0, a1, -VALUE);
88 test_diva(a0, a1, a3);
89 test_negc(a0, a1);
90 }
91 // Test and verify results
92 System.out.println("Verification");
93 int errn = 0;
94 {
95 float sum = test_sum(a1);
96 if (sum != gold_sum) {
97 System.err.println("test_sum: " + sum + " != " + gold_sum);
98 errn++;
99 }
100 // Overwrite with NaN values
101 a1[0] = Float.NaN;
102 a1[1] = Float.POSITIVE_INFINITY;
103 a1[2] = Float.NEGATIVE_INFINITY;
104 a1[3] = Float.MAX_VALUE;
105 a1[4] = Float.MIN_VALUE;
106 a1[5] = Float.MIN_NORMAL;
107
108 a2[6] = a1[0];
109 a2[7] = a1[1];
324 for (int i=6; i<ARRLEN; i++) {
325 errn += verify("test_divv_n: ", i, a0[i], ((ADD_INIT+i)/(-VALUE)));
326 }
327 test_diva(a0, a1, a3);
328 errn += verify("test_diva_n: ", 0, a0[0], (Float.NaN/(-VALUE)));
329 errn += verify("test_diva_n: ", 1, a0[1], (Float.POSITIVE_INFINITY/(-VALUE)));
330 errn += verify("test_diva_n: ", 2, a0[2], (Float.NEGATIVE_INFINITY/(-VALUE)));
331 errn += verify("test_diva_n: ", 3, a0[3], (Float.MAX_VALUE/(-VALUE)));
332 errn += verify("test_diva_n: ", 4, a0[4], (Float.MIN_VALUE/(-VALUE)));
333 errn += verify("test_diva_n: ", 5, a0[5], (Float.MIN_NORMAL/(-VALUE)));
334 errn += verify("test_diva_n: ", 6, a0[6], ((ADD_INIT+6)/(-Float.NaN)));
335 errn += verify("test_diva_n: ", 7, a0[7], ((ADD_INIT+7)/(-Float.POSITIVE_INFINITY)));
336 errn += verify("test_diva_n: ", 8, a0[8], ((ADD_INIT+8)/(-Float.NEGATIVE_INFINITY)));
337 errn += verify("test_diva_n: ", 9, a0[9], ((ADD_INIT+9)/(-Float.MAX_VALUE)));
338 errn += verify("test_diva_n: ", 10, a0[10], ((ADD_INIT+10)/(-Float.MIN_VALUE)));
339 errn += verify("test_diva_n: ", 11, a0[11], ((ADD_INIT+11)/(-Float.MIN_NORMAL)));
340 for (int i=12; i<ARRLEN; i++) {
341 errn += verify("test_diva_n: ", i, a0[i], ((ADD_INIT+i)/(-VALUE)));
342 }
343
344 test_negc(a0, a1);
345 errn += verify("test_negc: ", 0, a0[0], (Float.NaN));
346 errn += verify("test_negc: ", 1, a0[1], (Float.NEGATIVE_INFINITY));
347 errn += verify("test_negc: ", 2, a0[2], (Float.POSITIVE_INFINITY));
348 errn += verify("test_negc: ", 3, a0[3], (float)(-Float.MAX_VALUE));
349 errn += verify("test_negc: ", 4, a0[4], (float)(-Float.MIN_VALUE));
350 errn += verify("test_negc: ", 5, a0[5], (float)(-Float.MIN_NORMAL));
351 for (int i=6; i<ARRLEN; i++) {
352 errn += verify("test_negc: ", i, a0[i], (float)(-((float)(ADD_INIT+i))));
353 }
354
355 }
356
357 if (errn > 0)
358 return errn;
359
360 System.out.println("Time");
361 long start, end;
362
363 start = System.currentTimeMillis();
364 for (int i=0; i<ITERS; i++) {
365 test_sum(a1);
366 }
367 end = System.currentTimeMillis();
368 System.out.println("test_sum: " + (end - start));
369
370 start = System.currentTimeMillis();
371 for (int i=0; i<ITERS; i++) {
372 test_addc(a0, a1);
373 }
374 end = System.currentTimeMillis();
464
465 start = System.currentTimeMillis();
466 for (int i=0; i<ITERS; i++) {
467 test_divc_n(a0, a1);
468 }
469 end = System.currentTimeMillis();
470 System.out.println("test_divc_n: " + (end - start));
471 start = System.currentTimeMillis();
472 for (int i=0; i<ITERS; i++) {
473 test_divv(a0, a1, -VALUE);
474 }
475 end = System.currentTimeMillis();
476 System.out.println("test_divv_n: " + (end - start));
477 start = System.currentTimeMillis();
478 for (int i=0; i<ITERS; i++) {
479 test_diva(a0, a1, a3);
480 }
481 end = System.currentTimeMillis();
482 System.out.println("test_diva_n: " + (end - start));
483
484 start = System.currentTimeMillis();
485 for (int i=0; i<ITERS; i++) {
486 test_negc(a0, a1);
487 }
488 end = System.currentTimeMillis();
489 System.out.println("test_negc_n: " + (end - start));
490
491 return errn;
492 }
493
494 static float test_sum(float[] a1) {
495 float sum = 0;
496 for (int i = 0; i < a1.length; i+=1) {
497 sum += a1[i];
498 }
499 return sum;
500 }
501
502 static void test_addc(float[] a0, float[] a1) {
503 for (int i = 0; i < a0.length; i+=1) {
504 a0[i] = (a1[i]+VALUE);
505 }
506 }
507 static void test_addv(float[] a0, float[] a1, float b) {
508 for (int i = 0; i < a0.length; i+=1) {
509 a0[i] = (a1[i]+b);
510 }
553 }
554
555 static void test_divc(float[] a0, float[] a1) {
556 for (int i = 0; i < a0.length; i+=1) {
557 a0[i] = (a1[i]/VALUE);
558 }
559 }
560 static void test_divc_n(float[] a0, float[] a1) {
561 for (int i = 0; i < a0.length; i+=1) {
562 a0[i] = (a1[i]/(-VALUE));
563 }
564 }
565 static void test_divv(float[] a0, float[] a1, float b) {
566 for (int i = 0; i < a0.length; i+=1) {
567 a0[i] = (a1[i]/b);
568 }
569 }
570 static void test_diva(float[] a0, float[] a1, float[] a2) {
571 for (int i = 0; i < a0.length; i+=1) {
572 a0[i] = (a1[i]/a2[i]);
573 }
574 }
575
576 static void test_negc(float[] a0, float[] a1) {
577 for (int i = 0; i < a0.length; i+=1) {
578 a0[i] = (float)(-((float)a1[i]));
579 }
580 }
581
582 static int verify(String text, int i, float elem, float val) {
583 if (elem != val && !(Float.isNaN(elem) && Float.isNaN(val))) {
584 System.err.println(text + "[" + i + "] = " + elem + " != " + val);
585 return 1;
586 }
587 return 0;
588 }
589 }
|