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 double 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] = Double.NaN;
101 a1[1] = Double.POSITIVE_INFINITY;
102 a1[2] = Double.NEGATIVE_INFINITY;
103 a1[3] = Double.MAX_VALUE;
104 a1[4] = Double.MIN_VALUE;
105 a1[5] = Double.MIN_NORMAL;
106
107 a2[6] = a1[0];
108 a2[7] = a1[1];
322 errn += verify("test_divv_n: ", 5, a0[5], (Double.MIN_NORMAL/(-VALUE)));
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], (Double.NaN/(-VALUE)));
328 errn += verify("test_diva_n: ", 1, a0[1], (Double.POSITIVE_INFINITY/(-VALUE)));
329 errn += verify("test_diva_n: ", 2, a0[2], (Double.NEGATIVE_INFINITY/(-VALUE)));
330 errn += verify("test_diva_n: ", 3, a0[3], (Double.MAX_VALUE/(-VALUE)));
331 errn += verify("test_diva_n: ", 4, a0[4], (Double.MIN_VALUE/(-VALUE)));
332 errn += verify("test_diva_n: ", 5, a0[5], (Double.MIN_NORMAL/(-VALUE)));
333 errn += verify("test_diva_n: ", 6, a0[6], ((ADD_INIT+6)/(-Double.NaN)));
334 errn += verify("test_diva_n: ", 7, a0[7], ((ADD_INIT+7)/(-Double.POSITIVE_INFINITY)));
335 errn += verify("test_diva_n: ", 8, a0[8], ((ADD_INIT+8)/(-Double.NEGATIVE_INFINITY)));
336 errn += verify("test_diva_n: ", 9, a0[9], ((ADD_INIT+9)/(-Double.MAX_VALUE)));
337 errn += verify("test_diva_n: ", 10, a0[10], ((ADD_INIT+10)/(-Double.MIN_VALUE)));
338 errn += verify("test_diva_n: ", 11, a0[11], ((ADD_INIT+11)/(-Double.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 }
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 double test_sum(double[] a1) {
476 double 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(double[] a0, double[] a1) {
484 for (int i = 0; i < a0.length; i+=1) {
485 a0[i] = (a1[i]+VALUE);
486 }
487 }
488 static void test_addv(double[] a0, double[] a1, double 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(double[] a0, double[] 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(double[] a0, double[] a1) {
542 for (int i = 0; i < a0.length; i+=1) {
543 a0[i] = (a1[i]/(-VALUE));
544 }
545 }
546 static void test_divv(double[] a0, double[] a1, double b) {
547 for (int i = 0; i < a0.length; i+=1) {
548 a0[i] = (a1[i]/b);
549 }
550 }
551 static void test_diva(double[] a0, double[] a1, double[] 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, double elem, double val) {
558 if (elem != val && !(Double.isNaN(elem) && Double.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 double 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] = Double.NaN;
102 a1[1] = Double.POSITIVE_INFINITY;
103 a1[2] = Double.NEGATIVE_INFINITY;
104 a1[3] = Double.MAX_VALUE;
105 a1[4] = Double.MIN_VALUE;
106 a1[5] = Double.MIN_NORMAL;
107
108 a2[6] = a1[0];
109 a2[7] = a1[1];
323 errn += verify("test_divv_n: ", 5, a0[5], (Double.MIN_NORMAL/(-VALUE)));
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], (Double.NaN/(-VALUE)));
329 errn += verify("test_diva_n: ", 1, a0[1], (Double.POSITIVE_INFINITY/(-VALUE)));
330 errn += verify("test_diva_n: ", 2, a0[2], (Double.NEGATIVE_INFINITY/(-VALUE)));
331 errn += verify("test_diva_n: ", 3, a0[3], (Double.MAX_VALUE/(-VALUE)));
332 errn += verify("test_diva_n: ", 4, a0[4], (Double.MIN_VALUE/(-VALUE)));
333 errn += verify("test_diva_n: ", 5, a0[5], (Double.MIN_NORMAL/(-VALUE)));
334 errn += verify("test_diva_n: ", 6, a0[6], ((ADD_INIT+6)/(-Double.NaN)));
335 errn += verify("test_diva_n: ", 7, a0[7], ((ADD_INIT+7)/(-Double.POSITIVE_INFINITY)));
336 errn += verify("test_diva_n: ", 8, a0[8], ((ADD_INIT+8)/(-Double.NEGATIVE_INFINITY)));
337 errn += verify("test_diva_n: ", 9, a0[9], ((ADD_INIT+9)/(-Double.MAX_VALUE)));
338 errn += verify("test_diva_n: ", 10, a0[10], ((ADD_INIT+10)/(-Double.MIN_VALUE)));
339 errn += verify("test_diva_n: ", 11, a0[11], ((ADD_INIT+11)/(-Double.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 test_negc(a0, a1);
344 errn += verify("test_negc: ", 0, a0[0], (Double.NaN));
345 errn += verify("test_negc: ", 1, a0[1], (Double.NEGATIVE_INFINITY));
346 errn += verify("test_negc: ", 2, a0[2], (Double.POSITIVE_INFINITY));
347 errn += verify("test_negc: ", 3, a0[3], (double)(-Double.MAX_VALUE));
348 errn += verify("test_negc: ", 4, a0[4], (double)(-Double.MIN_VALUE));
349 errn += verify("test_negc: ", 5, a0[5], (double)(-Double.MIN_NORMAL));
350 for (int i=6; i<ARRLEN; i++) {
351 errn += verify("test_negc: ", i, a0[i], (double)(-((double)(ADD_INIT+i))));
352 }
353
354 }
355
356 if (errn > 0)
357 return errn;
358
359 System.out.println("Time");
360 long start, end;
361
362 start = System.currentTimeMillis();
363 for (int i=0; i<ITERS; i++) {
364 test_sum(a1);
365 }
366 end = System.currentTimeMillis();
367 System.out.println("test_sum: " + (end - start));
368
369 start = System.currentTimeMillis();
370 for (int i=0; i<ITERS; i++) {
371 test_addc(a0, a1);
372 }
463
464 start = System.currentTimeMillis();
465 for (int i=0; i<ITERS; i++) {
466 test_divc_n(a0, a1);
467 }
468 end = System.currentTimeMillis();
469 System.out.println("test_divc_n: " + (end - start));
470 start = System.currentTimeMillis();
471 for (int i=0; i<ITERS; i++) {
472 test_divv(a0, a1, -VALUE);
473 }
474 end = System.currentTimeMillis();
475 System.out.println("test_divv_n: " + (end - start));
476 start = System.currentTimeMillis();
477 for (int i=0; i<ITERS; i++) {
478 test_diva(a0, a1, a3);
479 }
480 end = System.currentTimeMillis();
481 System.out.println("test_diva_n: " + (end - start));
482
483 start = System.currentTimeMillis();
484 for (int i=0; i<ITERS; i++) {
485 test_negc(a0, a1);
486 }
487 end = System.currentTimeMillis();
488 System.out.println("test_negc_n: " + (end - start));
489
490 return errn;
491 }
492
493 static double test_sum(double[] a1) {
494 double sum = 0;
495 for (int i = 0; i < a1.length; i+=1) {
496 sum += a1[i];
497 }
498 return sum;
499 }
500
501 static void test_addc(double[] a0, double[] a1) {
502 for (int i = 0; i < a0.length; i+=1) {
503 a0[i] = (a1[i]+VALUE);
504 }
505 }
506 static void test_addv(double[] a0, double[] a1, double b) {
507 for (int i = 0; i < a0.length; i+=1) {
508 a0[i] = (a1[i]+b);
509 }
552 }
553
554 static void test_divc(double[] a0, double[] a1) {
555 for (int i = 0; i < a0.length; i+=1) {
556 a0[i] = (a1[i]/VALUE);
557 }
558 }
559 static void test_divc_n(double[] a0, double[] a1) {
560 for (int i = 0; i < a0.length; i+=1) {
561 a0[i] = (a1[i]/(-VALUE));
562 }
563 }
564 static void test_divv(double[] a0, double[] a1, double b) {
565 for (int i = 0; i < a0.length; i+=1) {
566 a0[i] = (a1[i]/b);
567 }
568 }
569 static void test_diva(double[] a0, double[] a1, double[] a2) {
570 for (int i = 0; i < a0.length; i+=1) {
571 a0[i] = (a1[i]/a2[i]);
572 }
573 }
574 static void test_negc(double[] a0, double[] a1) {
575 for (int i = 0; i < a0.length; i+=1) {
576 a0[i] = (double)(-((double)a1[i]));
577 }
578 }
579
580 static int verify(String text, int i, double elem, double val) {
581 if (elem != val && !(Double.isNaN(elem) && Double.isNaN(val))) {
582 System.err.println(text + "[" + i + "] = " + elem + " != " + val);
583 return 1;
584 }
585 return 0;
586 }
587 }
|