-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_debug.c
723 lines (595 loc) · 22.1 KB
/
math_debug.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/*
The MIT License (MIT)
Copyright (c) 2015 Lachlan Tychsen-Smith ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "math_neon.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#ifdef WIN32
#include <time.h>
#else
#include <sys/time.h>
#include <sys/resource.h>
#endif
#define randf() (rand() / (RAND_MAX + 1.0f))
struct test1_s {
const char* name;
float (*func)(float); //the function
float (*bench)(float); //the function to benchmark against.
float rng0, rng1;
int num;
float emaxabs;
float xmaxabs;
float emaxrel;
float xmaxrel;
float erms;
int time; //time to execute num functions;
};
struct test2_s {
const char* name;
float (*func)(float, float); //the function
float (*bench)(float, float); //the function to benchmark against.
float rng0, rng1;
int num;
float emaxabs;
float xmaxabs;
float emaxrel;
float xmaxrel;
float erms;
int time; //time to execute num functions;
};
float invsqrtf(float x){
return (1.0f / sqrtf(x));
}
typedef struct test1_s test1_t;
typedef struct test2_s test2_t;
test1_t test1[51] =
{
{"sinf ", sinf, sinf, -M_PI, M_PI, 500000},
{"sinf_c ", sinf_c, sinf, -M_PI, M_PI, 500000},
{"sinf_neon ", sinf_neon, sinf, -M_PI, M_PI, 500000},
{"cosf ", cosf, cosf, -M_PI, M_PI, 500000},
{"cosf_c ", cosf_c, cosf, -M_PI, M_PI, 500000},
{"cosf_neon ", cosf_neon, cosf, -M_PI, M_PI, 500000},
{"tanf ", tanf, tanf, -M_PI_4, M_PI_4, 500000, 0, 0, 0},
{"tanf_c ", tanf_c, tanf, -M_PI_4, M_PI_4, 500000, 0, 0, 0},
{"tanf_neon ", tanf_neon, tanf, -M_PI_4, M_PI_4, 500000, 0, 0, 0},
{"asinf ", asinf, asinf, -1, 1, 500000, 0, 0, 0},
{"asinf_c ", asinf_c, asinf, -1, 1, 500000, 0, 0, 0},
{"asinf_neon ", asinf_neon, asinf, -1, 1, 500000, 0, 0, 0},
{"acosf ", acosf, acosf, -1, 1, 500000, 0, 0, 0},
{"acosf_c ", acosf_c, acosf, -1, 1, 500000, 0, 0, 0},
{"acosf_neon ", acosf_neon, acosf, -1, 1, 500000, 0, 0, 0},
{"atanf ", atanf, atanf, -1, 1, 500000, 0, 0, 0},
{"atanf_c ", atanf_c, atanf, -1, 1, 500000, 0, 0, 0},
{"atanf_neon ", atanf_neon, atanf, -1, 1, 500000, 0, 0, 0},
{"sinhf ", sinhf, sinhf, -M_PI, M_PI, 500000, 0, 0, 0},
{"sinhf_c ", sinhf_c, sinhf, -M_PI, M_PI, 500000, 0, 0, 0},
{"sinhf_neon ", sinhf_neon, sinhf, -M_PI, M_PI, 500000, 0, 0, 0},
{"coshf ", coshf, coshf, -M_PI, M_PI, 500000, 0, 0, 0},
{"coshf_c ", coshf_c, coshf, -M_PI, M_PI, 500000, 0, 0, 0},
{"coshf_neon ", coshf_neon, coshf, -M_PI, M_PI, 500000, 0, 0, 0},
{"tanhf ", tanhf, tanhf, -M_PI, M_PI, 500000, 0, 0, 0},
{"tanhf_c ", tanhf_c, tanhf, -M_PI, M_PI, 500000, 0, 0, 0},
{"tanhf_neon ", tanhf_neon, tanhf, -M_PI, M_PI, 500000, 0, 0, 0},
{"expf ", expf, expf, 0, 10, 500000, 0, 0, 0},
{"expf_c ", expf_c, expf, 0, 10, 500000, 0, 0, 0},
{"expf_neon ", expf_neon, expf, 0, 10, 500000, 0, 0, 0},
{"logf ", logf, logf, 1, 1000, 500000, 0, 0, 0},
{"logf_c ", logf_c, logf, 1, 1000, 500000, 0, 0, 0},
{"logf_neon ", logf_neon, logf, 1, 1000, 500000, 0, 0, 0},
{"log10f ", log10f, log10f, 1, 1000, 500000, 0, 0, 0},
{"log10f_c ", log10f_c, log10f, 1, 1000, 500000, 0, 0, 0},
{"log10f_neon ", log10f_neon,log10f, 1, 1000, 500000, 0, 0, 0},
{"floorf ", floorf, floorf, 1, 1000, 5000000, 0, 0, 0},
{"floorf_c ", floorf_c, floorf, 1, 1000, 5000000, 0, 0, 0},
{"floorf_neon", floorf_neon,floorf, 1, 1000, 5000000, 0, 0, 0},
{"ceilf ", ceilf, ceilf, 1, 1000, 5000000, 0, 0, 0},
{"ceilf_c ", ceilf_c, ceilf, 1, 1000, 5000000, 0, 0, 0},
{"ceilf_neon", ceilf_neon, ceilf, 1, 1000, 5000000, 0, 0, 0},
{"fabsf ", fabsf, fabsf, 1, 1000, 5000000, 0, 0, 0},
{"fabsf_c ", fabsf_c, fabsf, 1, 1000, 5000000, 0, 0, 0},
{"fabsf_neon", fabsf_neon, fabsf, 1, 1000, 5000000, 0, 0, 0},
{"sqrtf ", sqrtf, sqrtf, 1, 1000, 500000, 0, 0, 0},
{"sqrtf_c ", sqrtf_c, sqrtf, 1, 1000, 500000, 0, 0, 0},
{"sqrtf_neon ", sqrtf_neon, sqrtf, 1, 1000, 500000, 0, 0, 0},
{"invsqrtf ", invsqrtf, invsqrtf, 1, 1000, 500000, 0, 0, 0},
{"invsqrtf_c ", invsqrtf_c, invsqrtf, 1, 1000, 500000, 0, 0, 0},
{"invsqrtf_neon ", invsqrtf_neon, invsqrtf, 1, 1000, 500000, 0, 0, 0},
};
test2_t test2[9] =
{
{"atan2f ", atan2f, atan2f, 0.1, 10, 10000, 0, 0, 0},
{"atan2f_c ", atan2f_c, atan2f, 0.1, 10, 10000, 0, 0, 0},
{"atan2f_neon ", atan2f_neon,atan2f, 0.1, 10, 10000, 0, 0, 0},
{"powf ", powf, powf, 1, 10, 10000, 0, 0, 0},
{"powf_c ", powf_c, powf, 1, 10, 10000, 0, 0, 0},
{"powf_neon ", powf_neon, powf, 1, 10, 10000, 0, 0, 0},
{"fmodf ", fmodf, fmodf, 1, 10, 10000, 0, 0, 0},
{"fmodf_c ", fmodf_c, fmodf, 1, 10, 10000, 0, 0, 0},
{"fmodf_neon ", fmodf_neon, fmodf, 1, 10, 10000, 0, 0, 0},
};
void
test_mathfunc1(test1_t *tst)
{
float x;
float dx = (tst->rng1 - tst->rng0) / ((float)tst->num);
#ifndef WIN32
struct rusage ru;
#endif
tst->emaxabs = tst->xmaxabs = 0;
tst->emaxrel = tst->xmaxrel = 0;
tst->erms = 0;
for(x = tst->rng0; x < tst->rng1 ; x += dx){
float r = (tst->func)((float)x);
float rr = (tst->bench)((float)x);
float dr = fabs(r - rr);
float drr = dr * (100.0f / rr);
tst->erms += dr*dr;
if (dr > tst->emaxabs){
tst->emaxabs = dr;
tst->xmaxabs = x;
}
if (drr > tst->emaxrel){
tst->emaxrel = drr;
tst->xmaxrel = x;
}
}
tst->erms = sqrt(tst->erms / ((float) tst->num));
#ifdef WIN32
tst->time = (1000 * clock()) / (CLOCKS_PER_SEC / 1000);
#else
getrusage(RUSAGE_SELF, &ru);
tst->time = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
#endif
for(x = tst->rng0; x < tst->rng1 ; x += dx){
(tst->func)((float)x);
}
#ifdef WIN32
tst->time = (1000 * clock()) / (CLOCKS_PER_SEC / 1000) - tst->time;
#else
getrusage(RUSAGE_SELF, &ru);
tst->time = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec - tst->time;
#endif
}
void
test_mathfunc2(test2_t *tst)
{
float x, y;
float rng = tst->rng1 - tst->rng0;
float d = (rng * rng) / ((float) tst->num);
#ifndef WIN32
struct rusage ru;
#endif
tst->emaxabs = tst->xmaxabs = 0;
tst->emaxrel = tst->xmaxrel = 0;
for(y = (tst->rng0); y < (tst->rng1) ; y += d){
for(x = (tst->rng0); x < (tst->rng1); x += d){
float r = (tst->func)((float)x, y);
float rr = (tst->bench)((float)x, y);
float dr = fabs(r - rr);
float drr = dr * (100.0f / rr);
if (dr > tst->emaxabs){
tst->emaxabs = dr;
tst->xmaxabs = x;
}
if (drr > tst->emaxrel && fabsf(rr) > 0.0001){
tst->emaxrel = drr;
tst->xmaxrel = x;
}
}
}
#ifdef WIN32
tst->time = (1000 * clock()) / (CLOCKS_PER_SEC / 1000) ;
#else
getrusage(RUSAGE_SELF, &ru);
tst->time = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
#endif
for(y = tst->rng0; y < tst->rng1 ; y += d){
for(x = tst->rng0; x < tst->rng1 ; x += d){
(tst->func)((float)x, (float)y);
}
}
#ifdef WIN32
tst->time = (1000 * clock()) / (CLOCKS_PER_SEC / 1000) - tst->time;
#else
getrusage(RUSAGE_SELF, &ru);
tst->time = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec - tst->time;
#endif
}
void test_vectorfunc()
{
float v0[4], v1[4], d[4];
for(int i=0;i<4;i++)
{
v0[i] = 10*randf() - 5;
v1[i] = 10*randf() - 5;
d[i] = 10*randf() - 5;
}
int testnum = 5000000;
struct rusage ru;
int v2t[3], v3t[3], v4t[3];
float r;
printf("\n");
//dot 2
getrusage(RUSAGE_SELF, &ru);
v2t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
r = dot2_c(v0, v1);
};
getrusage(RUSAGE_SELF, &ru);
v2t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
r = dot2_neon(v0, v1);
};
getrusage(RUSAGE_SELF, &ru);
v2t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
r = dot2_c(v0, v1);
printf("dot2_c = %f\n", r);
r = dot2_neon(v0, v1);
printf("dot2_neon = %f\n", r);
printf("dot2: c=%i \t neon=%i \t rate=%.2f \n", v2t[1] - v2t[0], v2t[2] - v2t[1],
(float)(v2t[1] - v2t[0]) / (float)(v2t[2] - v2t[1]));
//normalize 2
getrusage(RUSAGE_SELF, &ru);
v2t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
normalize2_c(v0, d);
};
getrusage(RUSAGE_SELF, &ru);
v2t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
normalize2_neon(v0, d);
};
getrusage(RUSAGE_SELF, &ru);
v2t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
normalize2_c(v0, d);
printf("normalize2_c = [%.2f, %.2f]\n", d[0], d[1]);
normalize2_neon(v0, d);
printf("normalize2_neon = [%.2f, %.2f]\n", d[0], d[1]);
printf("normalize2: c=%i \t neon=%i \t rate=%.2f \n", v2t[1] - v2t[0], v2t[2] - v2t[1],
(float)(v2t[1] - v2t[0]) / (float)(v2t[2] - v2t[1]));
printf("\n");
//dot 3
getrusage(RUSAGE_SELF, &ru);
v3t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
r = dot3_c(v0, v1);
};
getrusage(RUSAGE_SELF, &ru);
v3t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
r = dot3_neon(v0, v1);
};
getrusage(RUSAGE_SELF, &ru);
v3t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
r = dot3_c(v0, v1);
printf("dot3_c = %f\n", r);
r = dot3_neon(v0, v1);
printf("dot3_neon = %f\n", r);
printf("dot3: c=%i \t neon=%i \t rate=%.2f \n", v3t[1] - v3t[0], v3t[2] - v3t[1],
(float)(v3t[1] - v3t[0]) / (float)(v3t[2] - v3t[1]));
//normalize 3
getrusage(RUSAGE_SELF, &ru);
v3t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
normalize3_c(v0, d);
};
getrusage(RUSAGE_SELF, &ru);
v3t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
normalize3_neon(v0, d);
};
getrusage(RUSAGE_SELF, &ru);
v3t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
normalize3_c(v0, d);
printf("normalize3_c = [%.2f, %.2f, %.2f]\n", d[0], d[1], d[2]);
normalize3_neon(v0, d);
printf("normalize3_neon = [%.2f, %.2f, %.2f]\n", d[0], d[1], d[2]);
printf("normalize3: c=%i \t neon=%i \t rate=%.2f \n", v3t[1] - v3t[0], v3t[2] - v3t[1],
(float)(v3t[1] - v3t[0]) / (float)(v3t[2] - v3t[1]));
//cross 3
getrusage(RUSAGE_SELF, &ru);
v3t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
cross3_c(v0, v1, d);
};
getrusage(RUSAGE_SELF, &ru);
v3t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
cross3_neon(v0, v1, d);
};
getrusage(RUSAGE_SELF, &ru);
v3t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
cross3_c(v0, v1, d);
printf("cross3_c = [%.2f, %.2f, %.2f]\n", d[0], d[1], d[2]);
cross3_neon(v0, v1, d);
printf("cross3_neon = [%.2f, %.2f, %.2f]\n", d[0], d[1], d[2]);
printf("cross3: c=%i \t neon=%i \t rate=%.2f \n", v3t[1] - v3t[0], v3t[2] - v3t[1],
(float)(v3t[1] - v3t[0]) / (float)(v3t[2] - v3t[1]));
printf("\n");
//dot 4
getrusage(RUSAGE_SELF, &ru);
v4t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
r = dot4_c(v0, v1);
};
getrusage(RUSAGE_SELF, &ru);
v4t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
r = dot4_neon(v0, v1);
};
getrusage(RUSAGE_SELF, &ru);
v4t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
r = dot4_c(v0, v1);
printf("dot4_c = %f\n", r);
r = dot4_neon(v0, v1);
printf("dot4_neon = %f\n", r);
printf("dot4: c=%i \t neon=%i \t rate=%.2f \n", v4t[1] - v4t[0], v4t[2] - v4t[1],
(float)(v4t[1] - v4t[0]) / (float)(v4t[2] - v4t[1]));
//normalize 4
getrusage(RUSAGE_SELF, &ru);
v4t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
normalize4_c(v0, d);
};
getrusage(RUSAGE_SELF, &ru);
v4t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(int i=0;i < testnum; i++)
{
normalize4_neon(v0, d);
};
getrusage(RUSAGE_SELF, &ru);
v4t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
normalize4_c(v0, d);
printf("normalize4_c = [%.2f, %.2f, %.2f, %.2f]\n", d[0], d[1], d[2], d[3]);
normalize4_neon(v0, d);
printf("normalize4_neon = [%.2f, %.2f, %.2f, %.2f]\n", d[0], d[1], d[2], d[3]);
printf("normalize4: c=%i \t neon=%i \t rate=%.2f \n", v4t[1] - v4t[0], v4t[2] - v4t[1],
(float)(v4t[1] - v4t[0]) / (float)(v4t[2] - v4t[1]));
printf("\n");
}
void test_matrixfunc()
{
float m0[16], m1[16], m2[16];
int m2t[3], m3t[3], m4t[3];
int i;
int testnum = 1000000;
struct rusage ru;
for(int i=0;i<16;i++)
{
m0[i] = 10.0f * randf() - 5.0f;
m1[i] = 10.0f * randf() - 5.0f;
m2[i] = 10.0f * randf() - 5.0f;
}
//matmul2
getrusage(RUSAGE_SELF, &ru);
m2t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matmul2_c(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m2t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matmul2_neon(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m2t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
matmul2_c(m0, m1, m2);
printf("matmul2_c = \n");
printf("\t\t\t|%.2f, %.2f|\n", m2[0], m2[2]);
printf("\t\t\t|%.2f, %.2f|\n", m2[1], m2[3]);
matmul2_neon(m0, m1, m2);
printf("matmul2_neon = \n");
printf("\t\t\t|%.2f, %.2f|\n", m2[0], m2[2]);
printf("\t\t\t|%.2f, %.2f|\n", m2[1], m2[3]);
printf("matmul2: c=%i \t neon=%i \t rate=%.2f \n", m2t[1] - m2t[0], m2t[2] - m2t[1],
(float)(m2t[1] - m2t[0]) / (float)(m2t[2] - m2t[1]));
//matvec2
getrusage(RUSAGE_SELF, &ru);
m2t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matvec2_c(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m2t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matvec2_neon(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m2t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
memset(m2, 0, 4*sizeof(float));
matvec2_c(m0, m1, m2);
printf("matvec2_c = |%.2f, %.2f|\n", m2[0], m2[1]);
memset(m2, 0, 4*sizeof(float));
matvec2_neon(m0, m1, m2);
printf("matvec2_neon = |%.2f, %.2f|\n", m2[0], m2[1]);
printf("matvec2: c=%i \t neon=%i \t rate=%.2f \n", m2t[1] - m2t[0], m2t[2] - m2t[1],
(float)(m2t[1] - m2t[0]) / (float)(m2t[2] - m2t[1]));
//MAT3
getrusage(RUSAGE_SELF, &ru);
m3t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matmul3_c(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m3t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matmul3_neon(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m3t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
memset(m2, 0, 9*sizeof(float));
matmul3_c(m0, m1, m2);
printf("matmul3_c =\n");
printf("\t\t\t|%.2f, %.2f, %.2f|\n", m2[0], m2[3], m2[6]);
printf("\t\t\t|%.2f, %.2f, %.2f|\n", m2[1], m2[4], m2[7]);
printf("\t\t\t|%.2f, %.2f, %.2f|\n", m2[2], m2[5], m2[8]);
memset(m2, 0, 9*sizeof(float));
matmul3_neon(m0, m1, m2);
printf("matmul3_neon =\n");
printf("\t\t\t|%.2f, %.2f, %.2f|\n", m2[0], m2[3], m2[6]);
printf("\t\t\t|%.2f, %.2f, %.2f|\n", m2[1], m2[4], m2[7]);
printf("\t\t\t|%.2f, %.2f, %.2f|\n", m2[2], m2[5], m2[8]);
printf("matmul3: c=%i \t neon=%i \t rate=%.2f \n", m3t[1] - m3t[0], m3t[2] - m3t[1],
(float)(m3t[1] - m3t[0]) / (float)(m3t[2] - m3t[1]));
//matvec3
getrusage(RUSAGE_SELF, &ru);
m3t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matvec3_c(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m3t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matvec3_neon(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m3t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
memset(m2, 0, 4*sizeof(float));
matvec3_c(m0, m1, m2);
printf("matvec3_c = |%.2f, %.2f, %.2f|\n", m2[0], m2[1], m2[2]);
memset(m2, 0, 4*sizeof(float));
matvec3_neon(m0, m1, m2);
printf("matvec3_neon = |%.2f, %.2f, %.2f|\n", m2[0], m2[1], m2[2]);
printf("matvec3: c=%i \t neon=%i \t rate=%.2f \n", m2t[1] - m2t[0], m2t[2] - m2t[1],
(float)(m2t[1] - m2t[0]) / (float)(m2t[2] - m2t[1]));
//MAT4
getrusage(RUSAGE_SELF, &ru);
m4t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matmul4_c(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m4t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matmul4_neon(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m4t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
memset(m2, 0, 16*sizeof(float));
matmul4_c(m0, m1, m2);
printf("matmul4_c =\n");
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[0], m2[4], m2[8], m2[12]);
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[1], m2[5], m2[9], m2[13]);
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[2], m2[6], m2[10], m2[14]);
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[3], m2[7], m2[11], m2[15]);
memset(m2, 0, 16*sizeof(float));
matmul4_neon(m0, m1, m2);
printf("matmul4_neon =\n");
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[0], m2[4], m2[8], m2[12]);
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[1], m2[5], m2[9], m2[13]);
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[2], m2[6], m2[10], m2[14]);
printf("\t\t\t|%.2f, %.2f, %.2f, %.2f|\n", m2[3], m2[7], m2[11], m2[15]);
printf("matmul4: c=%i \t neon=%i \t rate=%.2f \n", m4t[1] - m4t[0], m4t[2] - m4t[1],
(float)(m4t[1] - m4t[0]) / (float)(m4t[2] - m4t[1]));
//matvec4
getrusage(RUSAGE_SELF, &ru);
m4t[0] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matvec4_c(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m4t[1] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
for(i = 0; i < testnum; i++){
matvec4_neon(m0, m1, m2);
}
getrusage(RUSAGE_SELF, &ru);
m4t[2] = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
memset(m2, 0, 4*sizeof(float));
matvec4_c(m0, m1, m2);
printf("matvec4_c = |%.2f, %.2f, %.2f, %f|\n", m2[0], m2[1], m2[2], m2[3]);
memset(m2, 0, 4*sizeof(float));
matvec4_neon(m0, m1, m2);
printf("matvec4_neon = |%.2f, %.2f, %.2f, %f|\n", m2[0], m2[1], m2[2], m2[3]);
printf("matvec4: c=%i \t neon=%i \t rate=%.2f \n", m2t[1] - m2t[0], m2t[2] - m2t[1],
(float)(m2t[1] - m2t[0]) / (float)(m2t[2] - m2t[1]));
}
int main(int argc, char** argv)
{
int i, ii;
if (argc > 1 && strcmp(argv[1], "-norunfast") == 0){
printf("RUNFAST: Disabled \n");
}else {
printf("RUNFAST: Enabled \n");
enable_runfast();
}
srand(time(NULL));
#if 1
//test single argument functions:
printf("------------------------------------------------------------------------------------------------------\n");
printf("MATRIX FUNCTION TESTS \n");
printf("------------------------------------------------------------------------------------------------------\n");
test_matrixfunc();
test_vectorfunc();
printf("------------------------------------------------------------------------------------------------------\n");
printf("CMATH FUNCTION TESTS \n");
printf("------------------------------------------------------------------------------------------------------\n");
printf("Function\tRange\t\tNumber\tABS Max Error\tREL Max Error\tRMS Error\tTime\tRate\n");
printf("------------------------------------------------------------------------------------------------------\n");
for(i = 0; i < 51; i++){
test_mathfunc1(&test1[i]);
ii = i - (i % 3);
printf("%s\t", test1[i].name);
printf("[%.2f, %.2f]\t", test1[i].rng0, test1[i].rng1);
printf("%i\t", test1[i].num);
printf("%.2e\t", test1[i].emaxabs);
printf("%.2e%%\t", test1[i].emaxrel);
printf("%.2e\t", test1[i].erms);
printf("%i\t", test1[i].time);
printf("x%.2f\t", (float)test1[ii].time / test1[i].time);
printf("\n");
}
for(i = 0; i < 9; i++){
test_mathfunc2(&test2[i]);
ii = i - (i % 3);
printf("%s\t", test2[i].name);
printf("[%.2f, %.2f]\t", test2[i].rng0, test2[i].rng1);
printf("%i\t", test2[i].num);
printf("%.2e\t", test2[i].emaxabs);
printf("%.2e%%\t", test2[i].emaxrel);
printf("%.2e\t", test2[i].erms);
printf("%i\t", test2[i].time);
printf("x%.2f\t", (float)test2[ii].time / test2[i].time);
printf("\n");
}
#else
float x = 0;
for(x = -M_PI_2; x < M_PI_2; x+= 0.01)
{
printf("x=%.2f\t in=%.2f\t c=%.2f\t neon=%.2f \n", x, sinhf(x), sinhf_c(x), sinhf_neon(x));
}
#endif
return 0;
}