Search
lxdream.org :: lxdream/test/randmath.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/randmath.c
changeset 1131:4727c2006e0f
next1169:23a9613aceb1
author nkeynes
date Wed Oct 06 08:47:13 2010 +1000 (11 years ago)
permissions -rw-r--r--
last change Add missing files for the randmath test, and update .hgignore
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/randmath.c Wed Oct 06 08:47:13 2010 +1000
1.3 @@ -0,0 +1,60 @@
1.4 +#include <stdlib.h>
1.5 +#include <stdio.h>
1.6 +
1.7 +typedef unsigned char uint8_t;
1.8 +typedef signed char int8_t;
1.9 +typedef unsigned short uint16_t;
1.10 +typedef signed short int16_t;
1.11 +typedef unsigned int uint32_t;
1.12 +typedef signed int int32_t;
1.13 +typedef unsigned long long uint64_t;
1.14 +typedef signed long long int64_t;
1.15 +
1.16 +#define TEST_REPS 64
1.17 +
1.18 +void printuint8_t(uint8_t a) { printf( "%08X ", (unsigned int)a ); }
1.19 +void printint8_t(int8_t a) { printf( "%08X ", (unsigned int)(uint8_t)a ); }
1.20 +void printuint16_t(uint16_t a) { printf( "%08X ", (unsigned int)a ); }
1.21 +void printint16_t(int16_t a) { printf( "%08X ", (unsigned int)(uint16_t)a ); }
1.22 +void printuint32_t(uint32_t a) { printf( "%08X ", (unsigned int)a ); }
1.23 +void printint32_t(int32_t a) { printf( "%08X ", (unsigned int)a ); }
1.24 +void printuint64_t(uint64_t a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
1.25 +void printint64_t(int64_t a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
1.26 +
1.27 +#define TEST_TYPE(T) \
1.28 +void test##T() { \
1.29 + T a, b, c, d, e, f; \
1.30 + read(0,&a,sizeof(a)); read(0,&b,sizeof(b)); read(0,&c,sizeof(c)); read(0,&d,sizeof(d)); \
1.31 + e = a * b - c * d;\
1.32 + if( b != 0 && c != 0 ) { f = a / b + 1/c; }\
1.33 + T g = e - f / 2 + (uint32_t)b;\
1.34 + T h = b * c / d; T i = a / -d; \
1.35 + printf( "%d| ", sizeof(a) ); \
1.36 + print##T(a); print##T(b); print##T(c); print##T(d); \
1.37 + printf( ": " ); print##T(e); print##T(f); print##T(g); \
1.38 + print##T(h); print##T(i); \
1.39 + printf( "\n" ); \
1.40 +}
1.41 +
1.42 +TEST_TYPE(uint8_t);
1.43 +TEST_TYPE(int8_t);
1.44 +TEST_TYPE(uint16_t);
1.45 +TEST_TYPE(int16_t);
1.46 +TEST_TYPE(uint32_t);
1.47 +TEST_TYPE(int32_t);
1.48 +TEST_TYPE(uint64_t);
1.49 +TEST_TYPE(int64_t);
1.50 +
1.51 +int main(int argc, char *argv[]) {
1.52 + unsigned i;
1.53 +
1.54 + for(i=0;i<TEST_REPS;i++ ) { testuint64_t(); }
1.55 + for(i=0;i<TEST_REPS;i++ ) { testint64_t(); }
1.56 + for(i=0;i<TEST_REPS;i++ ) { testuint32_t(); }
1.57 + for(i=0;i<TEST_REPS;i++ ) { testint32_t(); }
1.58 + for(i=0;i<TEST_REPS;i++ ) { testuint16_t(); }
1.59 + for(i=0;i<TEST_REPS;i++ ) { testint16_t(); }
1.60 + for(i=0;i<TEST_REPS;i++ ) { testuint8_t(); }
1.61 + for(i=0;i<TEST_REPS;i++ ) { testint8_t(); }
1.62 + return 0;
1.63 +}
.