This repository has been archived by the owner on Jun 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
executable file
·2637 lines (2229 loc) · 60 KB
/
main.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
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*============================================================================
bandwidth 1.1, a benchmark to estimate memory transfer bandwidth.
Copyright (C) 2005-2014 by Zack T Smith.
Copyright (c) 2015 Raptor Engineering
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Zack Smith may be reached at veritas@comcast.net.
*===========================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <wchar.h>
#include <math.h>
#include <sys/ioctl.h>
#include <netdb.h> // gethostbyname
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define GRAPH_WIDTH 1440
#define GRAPH_HEIGHT 900
#include "defs.h"
#include "BMP.h"
#include "BMPGraphing.h"
#if defined(__x86_64__) || defined(__i386__)
#define TITLE_MEMORY_NET "Network benchmark results from bandwidth " RELEASE " by Zack Smith, http://zsmith.co"
#define TITLE_MEMORY_GRAPH "Memory benchmark results from bandwidth " RELEASE " by Zack Smith, http://zsmith.co"
#else
#define TITLE_MEMORY_NET "Network benchmark results from bandwidth " RELEASE " by Zack Smith and Raptor Engineering"
#define TITLE_MEMORY_GRAPH "Memory benchmark results from bandwidth " RELEASE " by Zack Smith and Raptor Engineering"
#endif
#ifdef __WIN32__
#include <windows.h>
#endif
#ifdef __linux__
#include <linux/fb.h>
#include <sys/mman.h>
#endif
static int network_port = NETWORK_DEFAULT_PORTNUM;
enum {
NO_SSE2,
SSE2,
SSE2_BYPASS,
AVX,
AVX_BYPASS,
VSX,
LODSQ,
LODSD,
LODSW,
LODSB
};
static BMPGraph *graph = NULL;
static bool use_sse2 = true;
static bool use_sse4 = true;
static bool is_intel = false;
static bool is_amd = false;
static uint32_t cpu_has_mmx = 0;
static uint32_t cpu_has_sse = 0;
static uint32_t cpu_has_sse2 = 0;
static uint32_t cpu_has_sse3 = 0;
static uint32_t cpu_has_ssse3 = 0;
static uint32_t cpu_has_sse4a = 0;
static uint32_t cpu_has_sse41 = 0;
static uint32_t cpu_has_sse42 = 0;
static uint32_t cpu_has_aes = 0;
static uint32_t cpu_has_avx = 0;
static uint32_t cpu_has_avx2 = 0;
static uint32_t cpu_has_vsx = 0;
static uint32_t cpu_has_64bit = 0;
static uint32_t cpu_has_xd = 0;
//----------------------------------------
// Parameters for the tests.
//
static long usec_per_test = 5000000; // 5 seconds per memory test.
static int chunk_sizes[] = {
128,
256,
384,
512,
640,
768,
896,
1024,
1280,
2048,
3072,
4096,
6144,
8192, // Some processors' L1 data caches are only 8kB.
12288,
16384,
20480,
24576,
28672,
32768, // Common L1 data cache size.
34*1024,
36*1024,
40960,
49152,
65536,
131072, // Old L2 cache size.
192 * 1024,
256 * 1024, // Old L2 cache size.
320 * 1024,
384 * 1024,
512 * 1024, // Old L2 cache size.
768 * 1024,
1 << 20, // 1 MB = common L2 cache size.
(1024 + 256) * 1024, // 1.25
(1024 + 512) * 1024, // 1.5
(1024 + 768) * 1024, // 1.75
1 << 21, // 2 MB = common L2 cache size.
(2048 + 256) * 1024, // 2.25
(2048 + 512) * 1024, // 2.5
(2048 + 768) * 1024, // 2.75
3072 * 1024, // 3 MB = common L2 cache size.
3407872, // 3.25 MB
3 * 1024 * 1024 + 1024 * 512, // 3.5 MB
1 << 22, // 4 MB
5242880, // 5 megs
6291456, // 6 megs (common L2 cache size)
7 * 1024 * 1024,
8 * 1024 * 1024, // Xeon E3's often has 8MB L3
9 * 1024 * 1024,
10 * 1024 * 1024, // Xeon E5-2609 has 10MB L3
12 * 1024 * 1024,
14 * 1024 * 1024,
15 * 1024 * 1024, // Xeon E6-2630 has 15MB L3
16 * 1024 * 1024,
20 * 1024 * 1024, // Xeon E5-2690 has 20MB L3
21 * 1024 * 1024,
32 * 1024 * 1024,
48 * 1024 * 1024,
64 * 1024 * 1024,
72 * 1024 * 1024,
96 * 1024 * 1024,
128 * 1024 * 1024,
#if defined(__PPC64__)
256 * 1024 * 1024,
512 * 1024 * 1024,
1024 * 1024 * 1024,
#endif
0
};
static double chunk_sizes_log2 [sizeof(chunk_sizes)/sizeof(int)];
//----------------------------------------------------------------------------
// Name: error
// Purpose: Complain and exit.
//----------------------------------------------------------------------------
void error (char *s)
{
#ifndef __WIN32__
fprintf (stderr, "Error: %s\n", s);
exit (1);
#else
wchar_t tmp [200];
int i;
for (i = 0; s[i]; i++)
tmp[i] = s[i];
tmp[i] = 0;
MessageBoxW (0, tmp, L"Error", 0);
ExitProcess (0);
#endif
}
//============================================================================
// Output buffer logic.
// This is somewhat vestigial code, originating with Windows Mobile ARM port.
//============================================================================
#define MSGLEN 10000
static wchar_t msg [MSGLEN];
void print (wchar_t *s)
{
wcsncat (msg, s, MSGLEN-1);
}
void newline ()
{
wcsncat (msg, L"\n", MSGLEN-1);
}
void println (wchar_t *s)
{
wcsncat (msg, s, MSGLEN-1);
newline ();
}
void print_int (int d)
{
swprintf (msg + wcslen (msg), MSGLEN, L"%d", d);
}
void print_uint (unsigned int d)
{
swprintf (msg + wcslen (msg), MSGLEN, L"%lu", d);
}
void println_int (int d)
{
print_int (d);
newline ();
}
void print_result (long double result)
{
swprintf (msg + wcslen (msg), MSGLEN, L"%.1Lf MB/s", result);
}
void dump (FILE *f)
{
if (!f)
f = stdout;
int i = 0;
while (msg[i]) {
char ch = (char) msg[i];
fputc (ch, f);
i++;
}
msg [0] = 0;
}
void flush ()
{
dump (NULL);
fflush (stdout);
}
void print_size (unsigned long size)
{
if (size < 1536) {
print_int (size);
print (L" B");
}
else if (size < (1<<20)) {
print_int (size >> 10);
print (L" kB");
} else {
print_int (size >> 20);
switch ((size >> 18) & 3) {
case 1: print (L".25"); break;
case 2: print (L".5"); break;
case 3: print (L".75"); break;
}
print (L" MB");
}
}
//============================================================================
// Timing logic.
//============================================================================
//----------------------------------------------------------------------------
// Name: mytime
// Purpose: Reports time in microseconds.
//----------------------------------------------------------------------------
unsigned long mytime ()
{
#ifndef __WIN32__
struct timeval tv;
struct timezone tz;
memset (&tz, 0, sizeof(struct timezone));
gettimeofday (&tv, &tz);
return 1000000 * tv.tv_sec + tv.tv_usec;
#else
return 1000 * GetTickCount (); // accurate enough.
#endif
}
//----------------------------------------------------------------------------
// Name: calculate_result
// Purpose: Calculates and prints a result.
// Returns: 10 times the number of megabytes per second.
//----------------------------------------------------------------------------
int
calculate_result (unsigned long chunk_size, long long total_loops, long diff)
{
if (!diff)
error ("Zero time difference.");
// printf ("\nIn calculate_result, chunk_size=%ld, total_loops=%lld, diff=%ld\n", chunk_size, total_loops, diff);
long double result = (long double) chunk_size;
result *= (long double) total_loops;
result *= 1000000.; // Convert to microseconds.
result /= 1048576.;
result /= (long double) diff;
print_result (result);
return (long) (10.0 * result);
}
//============================================================================
// Tests.
//============================================================================
//----------------------------------------------------------------------------
// Name: do_write
// Purpose: Performs write on chunk of memory of specified size.
//----------------------------------------------------------------------------
int
do_write (unsigned long size, int mode, bool random)
{
unsigned char *chunk;
unsigned char *chunk0;
unsigned long loops;
unsigned long long total_count=0;
#if defined(__x86_64__) || defined(__PPC64__)
unsigned long value = 0x1234567689abcdef;
#else
unsigned long value = 0x12345678;
#endif
unsigned long diff=0, t0;
unsigned long tmp;
unsigned long **chunk_ptrs = NULL;
if (size & 127)
error ("do_write(): chunk size is not multiple of 128.");
//-------------------------------------------------
#if defined(__PPC64__)
// Align to 128-bit boundaries
chunk0 = malloc (size+256);
chunk = chunk0;
if (!chunk)
error ("Out of memory");
tmp = (unsigned long) chunk;
if (tmp & 127) {
tmp -= (tmp & 127);
tmp += 128;
chunk = (unsigned char*) tmp;
}
#else
// Align to 32-bit boundaries
chunk0 = malloc (size+64);
chunk = chunk0;
if (!chunk)
error ("Out of memory");
tmp = (unsigned long) chunk;
if (tmp & 31) {
tmp -= (tmp & 31);
tmp += 32;
chunk = (unsigned char*) tmp;
}
#endif
//----------------------------------------
// Set up random pointers to chunks.
//
if (random) {
tmp = size/256;
chunk_ptrs = (unsigned long**) malloc (sizeof (unsigned long*) * tmp);
if (!chunk_ptrs)
error ("Out of memory.");
//----------------------------------------
// Store pointers to all chunks into array.
//
int i;
for (i = 0; i < tmp; i++) {
chunk_ptrs [i] = (unsigned long*) (chunk + 256 * i);
}
//----------------------------------------
// Randomize the array of chunk pointers.
//
int k = 100;
while (k--) {
for (i = 0; i < tmp; i++) {
int j = rand() % tmp;
if (i != j) {
unsigned long *ptr = chunk_ptrs [i];
chunk_ptrs [i] = chunk_ptrs [j];
chunk_ptrs [j] = ptr;
}
}
}
}
//-------------------------------------------------
if (random)
print (L"Random write ");
else
print (L"Sequential write ");
switch (mode) {
case SSE2:
print (L"(128-bit), size = ");
break;
case AVX:
print (L"(256-bit), size = ");
break;
case VSX:
print (L"(128-bit), size = ");
break;
case AVX_BYPASS:
print (L"bypassing cache (256-bit), size = ");
break;
case SSE2_BYPASS:
print (L"bypassing cache (128-bit), size = ");
break;
default:
#if defined(__x86_64__) || defined(__PPC64__)
print (L"(64-bit), size = ");
#else
print (L"(32-bit), size = ");
#endif
}
print_size (size);
print (L", ");
loops = (1 << 26) / size;// XX need to adjust for CPU MHz
if (loops < 1)
loops = 1;
t0 = mytime ();
while (diff < usec_per_test) {
total_count += loops;
switch (mode) {
#if defined(__x86_64__) || defined(__i386__)
case SSE2:
if (random)
RandomWriterSSE2 (chunk_ptrs, size/256, loops, value);
else {
if (size & 128)
WriterSSE2_128bytes (chunk, size, loops, value);
else
WriterSSE2 (chunk, size, loops, value);
}
break;
case SSE2_BYPASS:
if (random)
RandomWriterSSE2_bypass (chunk_ptrs, size/256, loops, value);
else {
if (size & 128)
WriterSSE2_128bytes_bypass (chunk, size, loops, value);
else
WriterSSE2_bypass (chunk, size, loops, value);
}
break;
case AVX:
if (!random) {
WriterAVX (chunk, size, loops, value);
}
break;
case AVX_BYPASS:
if (!random) {
WriterAVX_bypass (chunk, size, loops, value);
}
break;
#endif
#if defined(__PPC64__)
case VSX:
if (random)
RandomWriterVSX (chunk_ptrs, size/256, loops, value);
else
WriterVSX (chunk, size, loops, value);
break;
#endif
default:
if (random)
RandomWriter (chunk_ptrs, size/256, loops, value);
else {
if (size & 128)
Writer_128bytes (chunk, size, loops, value);
else
Writer (chunk, size, loops, value);
}
}
diff = mytime () - t0;
}
print (L"loops = ");
print_uint (total_count);
print (L", ");
flush ();
int result = calculate_result (size, total_count, diff);
newline ();
flush ();
free ((void*)chunk0);
if (chunk_ptrs)
free (chunk_ptrs);
return result;
}
//----------------------------------------------------------------------------
// Name: do_read
// Purpose: Performs sequential read on chunk of memory of specified size.
//----------------------------------------------------------------------------
int
do_read (unsigned long size, int mode, bool random)
{
unsigned long loops;
unsigned long long total_count = 0;
unsigned long t0, diff=0;
unsigned char *chunk;
unsigned char *chunk0;
unsigned long tmp;
unsigned long **chunk_ptrs = NULL;
if (size & 127)
error ("do_read(): chunk size is not multiple of 128.");
//-------------------------------------------------
#if defined(__PPC64__)
// Align to 128-bit boundaries
chunk0 = chunk = malloc (size+256);
if (!chunk)
error ("Out of memory");
memset (chunk, 0, size);
tmp = (unsigned long) chunk;
if (tmp & 127) {
tmp -= (tmp & 127);
tmp += 128;
chunk = (unsigned char*) tmp;
}
#else
// Align to 32-bit boundaries
chunk0 = chunk = malloc (size+64);
if (!chunk)
error ("Out of memory");
memset (chunk, 0, size);
tmp = (unsigned long) chunk;
if (tmp & 31) {
tmp -= (tmp & 31);
tmp += 32;
chunk = (unsigned char*) tmp;
}
#endif
//----------------------------------------
// Set up random pointers to chunks.
//
if (random) {
int tmp = size/256;
chunk_ptrs = (unsigned long**) malloc (sizeof (unsigned long*) * tmp);
if (!chunk_ptrs)
error ("Out of memory.");
//----------------------------------------
// Store pointers to all chunks into array.
//
int i;
for (i = 0; i < tmp; i++) {
chunk_ptrs [i] = (unsigned long*) (chunk + 256 * i);
}
//----------------------------------------
// Randomize the array of chunk pointers.
//
int k = 100;
while (k--) {
for (i = 0; i < tmp; i++) {
int j = rand() % tmp;
if (i != j) {
unsigned long *ptr = chunk_ptrs [i];
chunk_ptrs [i] = chunk_ptrs [j];
chunk_ptrs [j] = ptr;
}
}
}
}
//-------------------------------------------------
if (random)
print (L"Random read ");
else
print (L"Sequential read ");
switch (mode) {
case SSE2:
print (L"(128-bit), size = ");
break;
case LODSB:
print (L"(8-bit LODSB), size = ");
break;
case LODSW:
print (L"(16-bit LODSW), size = ");
break;
case LODSD:
print (L"(32-bit LODSD), size = ");
break;
case LODSQ:
print (L"(64-bit LODSQ), size = ");
break;
case AVX:
print (L"(256-bit), size = ");
break;
case VSX:
print (L"(128-bit), size = ");
break;
case AVX_BYPASS:
print (L"bypassing cache (256-bit), size = ");
break;
case SSE2_BYPASS:
print (L"bypassing cache (128-bit), size = ");
break;
default:
#if defined(__x86_64__) || defined(__PPC64__)
print (L"(64-bit), size = ");
#else
print (L"(32-bit), size = ");
#endif
}
print_size (size);
print (L", ");
flush ();
loops = (1 << 26) / size; // XX need to adjust for CPU MHz
if (loops < 1)
loops = 1;
t0 = mytime ();
while (diff < usec_per_test) {
total_count += loops;
switch (mode) {
#if defined(__x86_64__) || defined(__i386__)
case SSE2:
if (random)
RandomReaderSSE2 (chunk_ptrs, size/256, loops);
else {
if (size & 128)
ReaderSSE2_128bytes (chunk, size, loops);
else
ReaderSSE2 (chunk, size, loops);
}
break;
case SSE2_BYPASS:
// No random reader for bypass.
//
if (random)
RandomReaderSSE2_bypass (chunk_ptrs, size/256, loops);
else {
if (size & 128)
ReaderSSE2_128bytes_bypass (chunk, size, loops);
else
ReaderSSE2_bypass (chunk, size, loops);
}
break;
case AVX:
if (!random) {
ReaderAVX (chunk, size, loops);
}
break;
#endif
#if defined(__PPC64__)
case VSX:
if (random)
RandomReaderVSX (chunk_ptrs, size/256, loops);
else
ReaderVSX (chunk, size, loops);
break;
#endif
case LODSB:
if (!random) {
ReaderLODSB (chunk, size, loops);
}
break;
case LODSW:
if (!random) {
ReaderLODSW (chunk, size, loops);
}
break;
case LODSD:
if (!random) {
ReaderLODSD (chunk, size, loops);
}
break;
case LODSQ:
if (!random) {
ReaderLODSQ (chunk, size, loops);
}
break;
default:
if (random) {
RandomReader (chunk_ptrs, size/256, loops);
} else {
if (size & 128)
Reader_128bytes (chunk, size, loops);
else
Reader (chunk, size, loops);
}
}
diff = mytime () - t0;
}
print (L"loops = ");
print_uint (total_count);
print (L", ");
int result = calculate_result (size, total_count, diff);
newline ();
flush ();
free (chunk0);
if (chunk_ptrs)
free (chunk_ptrs);
return result;
}
#if defined(__x86_64__) || defined(__i386__)
//----------------------------------------------------------------------------
// Name: do_copy
// Purpose: Performs sequential memory copy.
//----------------------------------------------------------------------------
int
do_copy (unsigned long size, int mode)
{
unsigned long loops;
unsigned long long total_count = 0;
unsigned long t0, diff=0;
unsigned char *chunk_src;
unsigned char *chunk_dest;
unsigned char *chunk_src0;
unsigned char *chunk_dest0;
unsigned long tmp;
if (size & 127)
error ("do_copy(): chunk size is not multiple of 128.");
//-------------------------------------------------
#if defined(__PPC64__)
// Align to 128-bit boundaries
chunk_src0 = chunk_src = malloc (size+256);
if (!chunk_src)
error ("Out of memory");
chunk_dest0 = chunk_dest = malloc (size+256);
if (!chunk_dest)
error ("Out of memory");
memset (chunk_src, 100, size);
memset (chunk_dest, 200, size);
tmp = (unsigned long) chunk_src;
if (tmp & 127) {
tmp -= (tmp & 127);
tmp += 128;
chunk_src = (unsigned char*) tmp;
}
tmp = (unsigned long) chunk_dest;
if (tmp & 127) {
tmp -= (tmp & 127);
tmp += 128;
chunk_dest = (unsigned char*) tmp;
}
#else
// Align to 32-bit boundaries
chunk_src0 = chunk_src = malloc (size+64);
if (!chunk_src)
error ("Out of memory");
chunk_dest0 = chunk_dest = malloc (size+64);
if (!chunk_dest)
error ("Out of memory");
memset (chunk_src, 100, size);
memset (chunk_dest, 200, size);
tmp = (unsigned long) chunk_src;
if (tmp & 31) {
tmp -= (tmp & 31);
tmp += 32;
chunk_src = (unsigned char*) tmp;
}
tmp = (unsigned long) chunk_dest;
if (tmp & 31) {
tmp -= (tmp & 31);
tmp += 32;
chunk_dest = (unsigned char*) tmp;
}
#endif
//-------------------------------------------------
print (L"Sequential copy ");
if (mode == SSE2) {
print (L"(128-bit), size = ");
}
else if (mode == AVX) {
print (L"(256-bit), size = ");
}
else {
#if defined(__x86_64__) || defined(__PPC64__)
print (L"(64-bit), size = ");
#else
print (L"(32-bit), size = ");
#endif
}
print_size (size);
print (L", ");
flush ();
loops = (1 << 26) / size; // XX need to adjust for CPU MHz
if (loops < 1)
loops = 1;
t0 = mytime ();
while (diff < usec_per_test) {
total_count += loops;
if (mode == SSE2) {
#if defined(__x86_64__)
if (size & 128)
CopySSE_128bytes (chunk_dest, chunk_src, size, loops);
else
CopySSE (chunk_dest, chunk_src, size, loops);
#else
CopySSE (chunk_dest, chunk_src, size, loops);
#endif
}
else if (mode == AVX) {
if (!(size & 128))
CopyAVX (chunk_dest, chunk_src, size, loops);
}
diff = mytime () - t0;
}
print (L"loops = ");
print_uint (total_count);
print (L", ");
int result = calculate_result (size, total_count, diff);
newline ();
flush ();
free (chunk_src0);
free (chunk_dest0);
return result;
}
#endif
//----------------------------------------------------------------------------
// Name: fb_readwrite
// Purpose: Performs sequential read & write tests on framebuffer memory.
//----------------------------------------------------------------------------
#if defined(__linux__) && defined(FBIOGET_FSCREENINFO)
void
fb_readwrite (bool use_sse2)
{
unsigned long counter, total_count;
unsigned long length;
unsigned long diff, t0;
static struct fb_fix_screeninfo fi;
static struct fb_var_screeninfo vi;
unsigned long *fb = NULL;
unsigned long datum;
int fd;
register unsigned long foo;
#if defined(__x86_64__) || defined(__PPC64__)
unsigned long value = 0x1234567689abcdef;
#else
unsigned long value = 0x12345678;
#endif
//-------------------------------------------------
fd = open ("/dev/fb0", O_RDWR);
if (fd < 0)
fd = open ("/dev/fb/0", O_RDWR);
if (fd < 0) {
println (L"Cannot open framebuffer device.");
return;
}
if (ioctl (fd, FBIOGET_FSCREENINFO, &fi)) {
close (fd);
println (L"Cannot get framebuffer info");
return;
}
else
if (ioctl (fd, FBIOGET_VSCREENINFO, &vi)) {
close (fd);
println (L"Cannot get framebuffer info");
return;
}
else
{
if (fi.visual != FB_VISUAL_TRUECOLOR &&
fi.visual != FB_VISUAL_DIRECTCOLOR ) {
close (fd);
println (L"Need direct/truecolor framebuffer device.");
return;
} else {
unsigned long fblen;
print (L"Framebuffer resolution: ");
print_int (vi.xres);
print (L"x");
print_int (vi.yres);
print (L", ");
print_int (vi.bits_per_pixel);
println (L" bpp\n");
fb = (unsigned long*) fi.smem_start;
fblen = fi.smem_len;
fb = mmap (fb, fblen,
PROT_WRITE | PROT_READ,
MAP_SHARED, fd, 0);
if (fb == MAP_FAILED) {
close (fd);
println (L"Cannot access framebuffer memory.");
return;
}
}
}
//-------------------
// Use only the upper half of the display.
//
length = FB_SIZE;
//-------------------
// READ
//
print (L"Framebuffer memory sequential read ");
flush ();