annotate tests/fptest.c @ 866:49fc8d8a0b9c

Re-do some portability things.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Jan 2015 03:41:35 +0200
parents b111cccf45fc
children 5e1d67f33dec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include <stdio.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #define FP_DW_SIZE 8
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #define FP_W0_SIZE 4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
36
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
7 void check(const char *str, DMFixedPoint v, Sint64 dw)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 DMFixedPoint *q = (DMFixedPoint *) &dw;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
11 printf("%-15s = ", str); FP_PRINTF64(v); printf("\n");
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
12 printf("should be = "); FP_PRINTF64((*q)); printf("\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 if (v.dw != dw)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 printf("ERROR! A test value differs from expected!\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 DMFixedPoint a, b, delta;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 char *s;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 (void) argc;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 (void) argv;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 // Check host characteristics
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 switch (SDL_BYTEORDER)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 case SDL_BIG_ENDIAN: s = "big endian"; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 case SDL_LIL_ENDIAN: s = "little endian"; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 default: s = "unknown?"; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 printf(
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 "SDL byte order = %s (%d)\n\n", s, SDL_BYTEORDER);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 printf(
866
49fc8d8a0b9c Re-do some portability things.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
42 "sizeof(DMFixedPoint) = %" PRId64 " bytes\n"
49fc8d8a0b9c Re-do some portability things.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
43 "sizeof(DMFixedPoint.dw) = %" PRId64 " bytes (should be %d)\n"
49fc8d8a0b9c Re-do some portability things.
Matti Hamalainen <ccr@tnsp.org>
parents: 864
diff changeset
44 "sizeof(DMFixedPoint.w[0]) = %" PRId64 " bytes (should be %d)\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 sizeof(a), sizeof(a.dw), FP_DW_SIZE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 sizeof(a.w[0]), FP_W0_SIZE);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 if (sizeof(a.dw) != FP_DW_SIZE || sizeof(a.w[0]) != FP_W0_SIZE)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 printf("ERROR! Some type sizes DO NOT MATCH!\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 return -1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 // TEST #1
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 printf("\nTEST #1: set initial values\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 FP_SETHL(a, 55, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 check("a", a, 0x0000003700000000ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 FP_CONV(b, 178);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 check("b", b, 0x00000000000000b2ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 FP_DIV_R(delta, a, b);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 check("delta", delta, 0x000000004f19e33cULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 // Test #2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 printf("\nTEST #2: 50 x (a + delta)\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 for (i = 0; i < 50; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 FP_ADD(a, delta);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 check("a end", a, 0x00000046730e61b8ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 // Test #3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 printf("\nTEST #3: 50 x (a - delta)\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 for (i = 0; i < 50; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 FP_SUB(a, delta);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 check("a end", a, 0x0000003700000000ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 // Test #4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 printf("\nTEST #4: 5 x (a * delta)\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 for (i = 0; i < 5; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 FP_MUL(a, delta);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 check("a end", a, 0xd644e40000000000ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 // Test #5
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 printf("\nTEST #4: 2 x (a / delta)\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 for (i = 0; i < 2; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 FP_DIV(a, delta);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 check("a end", a, 8ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }