root/trunk/libffado/tests/test-bufferops.cpp

Revision 847, 3.4 kB (checked in by ppalmers, 15 years ago)

use SSE2 for byteswaps (20% faster than ntohl())

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "debugmodule/debugmodule.h"
25
26 DECLARE_GLOBAL_DEBUG_MODULE;
27
28 #include "libutil/ByteSwap.h"
29 #include "libutil/SystemTimeSource.h"
30 #include <inttypes.h>
31
32 #include <emmintrin.h>
33 /*
34 void test() {
35     vSInt16     *in, *out; //must be 16 byte aligned
36
37     for( x = 0; x < array_bytes / sizeof( vSInt16); x++ )
38     {
39         vSInt16 v = in[x]; //load 16 bytes
40         v = _mm_or_si128( _mm_slli_epi16( v, 8 ), _mm_srli_epi16( v, 8 ) ); //swap it
41         out[x] = v; //store it out
42     }
43 }*/
44
45 #define NB_QUADLETS (4096 * 4096)
46 #define NB_TESTS 10
47 int
48 main(int argc, char **argv) {
49     quadlet_t *buffer_1;
50     quadlet_t *buffer_ref;
51     int i=0;
52    
53     Util::SystemTimeSource time;
54     ffado_microsecs_t start;
55     ffado_microsecs_t elapsed;
56    
57     setDebugLevel(DEBUG_LEVEL_NORMAL);
58    
59     buffer_1 = new quadlet_t[NB_QUADLETS];
60     buffer_ref = new quadlet_t[NB_QUADLETS];
61    
62     debugOutput(DEBUG_LEVEL_NORMAL, "Generating test data...\n");
63     for (i=0; i<NB_QUADLETS; i++) {
64         byte_t tmp = i & 0xFF;
65         buffer_1[i]   = tmp << 24;
66         tmp = (i + 1) & 0xFF;
67         buffer_1[i]   |= tmp << 16;
68         tmp = (i + 2) & 0xFF;
69         buffer_1[i]   |= tmp << 8;
70         tmp = (i + 3) & 0xFF;
71         buffer_1[i]   |= tmp;
72     }
73    
74     // do reference conversion
75    
76     for (i=0; i<NB_QUADLETS; i++) {
77         buffer_ref[i] = htonl(buffer_1[i]);
78     }
79    
80     debugOutput(DEBUG_LEVEL_NORMAL, "Performing byte-swap...\n");
81    
82     int test=0;
83     for (test=0; test<NB_TESTS; test++) {
84         for (i=0; i<NB_QUADLETS; i++) {
85             byte_t tmp = i & 0xFF;
86             buffer_1[i]   = tmp << 24;
87             tmp = (i + 1) & 0xFF;
88             buffer_1[i]   |= tmp << 16;
89             tmp = (i + 2) & 0xFF;
90             buffer_1[i]   |= tmp << 8;
91             tmp = (i + 3) & 0xFF;
92             buffer_1[i]   |= tmp;
93         }
94
95         start = time.getCurrentTimeAsUsecs();
96         byteSwapToBus(buffer_1, NB_QUADLETS);
97         elapsed = time.getCurrentTimeAsUsecs() - start;
98         debugOutput(DEBUG_LEVEL_NORMAL, " took %lluusec...\n", elapsed);
99        
100     }
101
102     // check
103     debugOutput(DEBUG_LEVEL_NORMAL, "Checking results...\n");
104     bool all_ok=true;
105     for (i=0; i<NB_QUADLETS; i++) {
106         if (buffer_1[i] != buffer_ref[i]) {
107             debugOutput(DEBUG_LEVEL_NORMAL, " bad result: %08X should be %08X\n",
108                         buffer_1[i], buffer_ref[i]);
109             all_ok=false;
110         } else {
111             //debugOutput(DEBUG_LEVEL_VERBOSE, "good result: %08X should be %08X\n",
112             //            buffer_1[i], buffer_ref[i]);
113         }
114     }
115
116     delete[] buffer_1;
117     delete[] buffer_ref;
118    
119     return 0;
120 }
Note: See TracBrowser for help on using the browser.