Search
lxdream.org :: lxdream/test/randmath.c
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
view annotate diff log raw
     1 #include <stdlib.h>
     2 #include <stdio.h>
     4 typedef unsigned char uint8_t;
     5 typedef signed char int8_t;
     6 typedef unsigned short uint16_t;
     7 typedef signed short int16_t;
     8 typedef unsigned int uint32_t;
     9 typedef signed int int32_t;
    10 typedef unsigned long long uint64_t;
    11 typedef signed long long int64_t;
    13 #define TEST_REPS 64
    15 void printuint8_t(uint8_t a) { printf( "%08X ", (unsigned int)a ); }
    16 void printint8_t(int8_t a) { printf( "%08X ", (unsigned int)(uint8_t)a ); }
    17 void printuint16_t(uint16_t a) { printf( "%08X ", (unsigned int)a ); }
    18 void printint16_t(int16_t a) { printf( "%08X ", (unsigned int)(uint16_t)a ); }
    19 void printuint32_t(uint32_t a) { printf( "%08X ", (unsigned int)a ); }
    20 void printint32_t(int32_t a) { printf( "%08X ", (unsigned int)a ); }
    21 void printuint64_t(uint64_t a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
    22 void printint64_t(int64_t a) { printf( "%08X%08X ", (unsigned int)(a>>32),(unsigned int)a ); }
    24 #define TEST_TYPE(T) \
    25 void test##T() { \
    26     T a, b, c, d, e, f; \
    27     read(0,&a,sizeof(a)); read(0,&b,sizeof(b)); read(0,&c,sizeof(c)); read(0,&d,sizeof(d)); \
    28     e = a * b - c * d;\
    29     if( b != 0 && c != 0 ) { f = a / b + 1/c;  }\
    30     T g = e - f / 2  + (uint32_t)b;\
    31     T h = b * c / d; T i = a / -d; \
    32     printf( "%d| ", sizeof(a) ); \
    33     print##T(a); print##T(b); print##T(c); print##T(d); \
    34     printf( ": " ); print##T(e); print##T(f); print##T(g); \
    35     print##T(h); print##T(i); \
    36     printf( "\n" ); \
    37 }
    39 TEST_TYPE(uint8_t);
    40 TEST_TYPE(int8_t);
    41 TEST_TYPE(uint16_t);
    42 TEST_TYPE(int16_t);
    43 TEST_TYPE(uint32_t);
    44 TEST_TYPE(int32_t);
    45 TEST_TYPE(uint64_t);
    46 TEST_TYPE(int64_t);
    48 int main(int argc, char *argv[]) {
    49   unsigned i;
    51   for(i=0;i<TEST_REPS;i++ ) { testuint64_t(); }
    52   for(i=0;i<TEST_REPS;i++ ) { testint64_t(); }
    53   for(i=0;i<TEST_REPS;i++ ) { testuint32_t(); }
    54   for(i=0;i<TEST_REPS;i++ ) { testint32_t(); }
    55   for(i=0;i<TEST_REPS;i++ ) { testuint16_t(); }
    56   for(i=0;i<TEST_REPS;i++ ) { testint16_t(); }
    57   for(i=0;i<TEST_REPS;i++ ) { testuint8_t(); }
    58   for(i=0;i<TEST_REPS;i++ ) { testint8_t(); }
    59   return 0;
    60 }
.