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
|
//#include "../bench/lmbench.h"
/* link with */
/* link with : "" */
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <pwd.h>
#include <sys/types.h>
#include <assert.h>
#include <pthread.h>
#include <sys/wait.h>
#include <list>
//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }
// g++ -Wall -O3 -lm -lpthread -lasound `gtk-config --cflags --libs` test.cpp -o test
//-------------------------------------------------------------------
// Generic min and max using c++ inline
//-------------------------------------------------------------------
inline int max (unsigned int a, unsigned int b) { return (a>b) ? a : b; }
inline int max (int a, int b) { return (a>b) ? a : b; }
inline long max (long a, long b) { return (a>b) ? a : b; }
inline long max (int a, long b) { return (a>b) ? a : b; }
inline long max (long a, int b) { return (a>b) ? a : b; }
inline float max (float a, float b) { return (a>b) ? a : b; }
inline float max (int a, float b) { return (a>b) ? a : b; }
inline float max (float a, int b) { return (a>b) ? a : b; }
inline float max (long a, float b) { return (a>b) ? a : b; }
inline float max (float a, long b) { return (a>b) ? a : b; }
inline double max (double a, double b) { return (a>b) ? a : b; }
inline double max (int a, double b) { return (a>b) ? a : b; }
inline double max (double a, int b) { return (a>b) ? a : b; }
inline double max (long a, double b) { return (a>b) ? a : b; }
inline double max (double a, long b) { return (a>b) ? a : b; }
inline double max (float a, double b) { return (a>b) ? a : b; }
inline double max (double a, float b) { return (a>b) ? a : b; }
inline int min (int a, int b) { return (a<b) ? a : b; }
inline long min (long a, long b) { return (a<b) ? a : b; }
inline long min (int a, long b) { return (a<b) ? a : b; }
inline long min (long a, int b) { return (a<b) ? a : b; }
inline float min (float a, float b) { return (a<b) ? a : b; }
inline float min (int a, float b) { return (a<b) ? a : b; }
inline float min (float a, int b) { return (a<b) ? a : b; }
inline float min (long a, float b) { return (a<b) ? a : b; }
inline float min (float a, long b) { return (a<b) ? a : b; }
inline double min (double a, double b) { return (a<b) ? a : b; }
inline double min (int a, double b) { return (a<b) ? a : b; }
inline double min (double a, int b) { return (a<b) ? a : b; }
inline double min (long a, double b) { return (a<b) ? a : b; }
inline double min (double a, long b) { return (a<b) ? a : b; }
inline double min (float a, double b) { return (a<b) ? a : b; }
inline double min (double a, float b) { return (a<b) ? a : b; }
inline int lsr (int x, int n) { return int(((unsigned int)x) >> n); }
bool setRealtimePriority ()
{
struct passwd * pw;
int err;
uid_t uid;
struct sched_param param;
uid = getuid ();
pw = getpwnam ("root");
setuid (pw->pw_uid);
param.sched_priority = 50; /* 0 to 99 */
err = sched_setscheduler(0, SCHED_RR, ¶m);
setuid (uid);
return (err != -1);
}
/******************************************************************************
*******************************************************************************
VECTOR INTRINSICS
*******************************************************************************
*******************************************************************************/
<<includeIntrinsic>>
/******************************************************************************
*******************************************************************************
ABSTRACT USER INTERFACE
*******************************************************************************
*******************************************************************************/
class UI
{
bool fStopped;
public:
UI() : fStopped(false) {}
virtual ~UI() {}
virtual void addButton(char* label, float* zone) = 0;
virtual void addToggleButton(char* label, float* zone) = 0;
virtual void addCheckButton(char* label, float* zone) = 0;
virtual void addVerticalSlider(char* label, float* zone, float init, float min, float max, float step) = 0;
virtual void addHorizontalSlider(char* label, float* zone, float init, float min, float max, float step) = 0;
virtual void addNumEntry(char* label, float* zone, float init, float min, float max, float step) = 0;
// -- passive widgets
virtual void addNumDisplay(char* label, float* zone, int precision) = 0;
virtual void addTextDisplay(char* label, float* zone, char* names[], float min, float max) = 0;
virtual void addHorizontalBargraph(char* label, float* zone, float min, float max) = 0;
virtual void addVerticalBargraph(char* label, float* zone, float min, float max) = 0;
virtual void openFrameBox(char* label) = 0;
virtual void openTabBox(char* label) = 0;
virtual void openHorizontalBox(char* label) = 0;
virtual void openVerticalBox(char* label) = 0;
virtual void closeBox() = 0;
virtual void run() = 0;
void stop() { fStopped = true; }
bool stopped() { return fStopped; }
};
/******************************************************************************
*******************************************************************************
DSP
*******************************************************************************
*******************************************************************************/
//----------------------------------------------------------------
// d�inition du processeur de signal
//----------------------------------------------------------------
class dsp {
protected:
int fSamplingFreq;
public:
dsp() {}
virtual ~dsp() {}
virtual int getNumInputs() = 0;
virtual int getNumOutputs() = 0;
virtual void buildUserInterface(UI* interface) = 0;
virtual void init(int samplingRate) = 0;
virtual void compute(int len, float** inputs, float** outputs) = 0;
};
<<includeclass>>
mydsp DSP;
static __inline__ unsigned long long int rdtsc(void)
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
#define CHRONO(title,test) \
{ \
unsigned long long int t0, t1, t2; \
\
printf("Test %s... ", title); \
test; \
t0 = rdtsc (); \
t1 = rdtsc (); \
test; \
t2 = rdtsc (); \
printf("elapsed time: %ld cycles\n", long(t2-t1 - (t1-t0))); \
}
#define BSIZE 128
void bench()
{
int numInChan = DSP.getNumInputs();
int numOutChan = DSP.getNumOutputs();
assert (numInChan < 256);
assert (numOutChan < 256);
float* inChannel[256];
float* outChannel[256];
// allocate input buffers (initialized with white noise)
int R0_0 = 0;
for (int i = 0; i < numInChan; i++) {
inChannel[i] = (float*) aligned_calloc (BSIZE, sizeof(float));
for (int j = 0; j < BSIZE; j++) {
int R0temp0 = (12345 + (1103515245 * R0_0));
inChannel[i][j] = 4.656613e-10f*R0temp0;
R0_0 = R0temp0;
}
}
// allocate output buffers (not initialized)
for (int i = 0; i < numOutChan; i++) outChannel[i] = (float*) aligned_calloc (BSIZE, sizeof(float));
// init the dsp with a resoneable sampling rate)
DSP.init(48000);
// compute one block of BSIZE samples
//CHRONO("Faust generated code ", DSP.compute(BSIZE,inChannel,outChannel));
// search minimal execution time stable for at least 20 runs
int stab = 0;
unsigned long long int tmin, t, t1, t2;
t1 = rdtsc ();
DSP.compute(BSIZE,inChannel,outChannel);
t2 = rdtsc ();
tmin = t2-t1;
do {
t1 = rdtsc ();
DSP.compute(BSIZE,inChannel,outChannel);
t2 = rdtsc ();
t = t2-t1;
if (tmin <= t) {
stab++;
} else {
tmin = t;
stab = 0;
}
} while (stab < 100);
printf("\t%ld cycles\n", long(tmin)); \
}
//-------------------------------------------------------------------------
// MAIN
//-------------------------------------------------------------------------
// lopt : Scan Command Line long int Arguments
long lopt (int argc, char *argv[], char* longname, char* shortname, long def)
{
for (int i=2; i<argc; i++)
if ( strcmp(argv[i-1], shortname) == 0 || strcmp(argv[i-1], longname) == 0 )
return atoi(argv[i]);
return def;
}
int main(int argc, char *argv[] )
{
bool rt = setRealtimePriority();
//printf(rt?"RealTime Set\n":"RealTime Not Set\n");
bench();
return 0;
}
|