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