Mercurial > hg > dmlib
annotate tests/fptest.c @ 2294:7f6ba3b32f54
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 03 Jul 2019 10:28:43 +0300 |
parents | 186cf6a7d634 |
children | 88be5cf55caf |
rev | line source |
---|---|
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1147
diff
changeset
|
1 #include "dmtool.h" |
0 | 2 #include "dmlib.h" |
3 #include <stdio.h> | |
4 | |
5 #define FP_DW_SIZE 8 | |
6 #define FP_W0_SIZE 4 | |
7 | |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
8 static int test_number = 0; |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
9 |
36
f3407a58e01e
Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
10 void check(const char *str, DMFixedPoint v, Sint64 dw) |
0 | 11 { |
12 DMFixedPoint *q = (DMFixedPoint *) &dw; | |
13 | |
809
eba3b87f3f84
Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents:
653
diff
changeset
|
14 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
|
15 printf("should be = "); FP_PRINTF64((*q)); printf("\n"); |
0 | 16 |
17 if (v.dw != dw) | |
18 { | |
19 printf("ERROR! A test value differs from expected!\n"); | |
20 } | |
21 } | |
22 | |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
23 |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
24 void header(const char *msg) |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
25 { |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
26 test_number++; |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
27 printf("\nTEST #%d: %s\n", test_number, msg); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
28 } |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
29 |
0 | 30 int main(int argc, char *argv[]) |
31 { | |
32 int i; | |
33 DMFixedPoint a, b, delta; | |
34 char *s; | |
35 | |
36 (void) argc; | |
37 (void) argv; | |
38 | |
39 // Check host characteristics | |
40 switch (SDL_BYTEORDER) | |
41 { | |
42 case SDL_BIG_ENDIAN: s = "big endian"; break; | |
43 case SDL_LIL_ENDIAN: s = "little endian"; break; | |
44 default: s = "unknown?"; break; | |
45 } | |
2046 | 46 |
0 | 47 printf( |
48 "SDL byte order = %s (%d)\n\n", s, SDL_BYTEORDER); | |
2046 | 49 |
0 | 50 printf( |
1147
5e1d67f33dec
Use DM_PRI* format specifiers here.
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
51 "sizeof(DMFixedPoint) = %" DM_PRId64 " bytes\n" |
5e1d67f33dec
Use DM_PRI* format specifiers here.
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
52 "sizeof(DMFixedPoint.dw) = %" DM_PRId64 " bytes (should be %d)\n" |
5e1d67f33dec
Use DM_PRI* format specifiers here.
Matti Hamalainen <ccr@tnsp.org>
parents:
866
diff
changeset
|
53 "sizeof(DMFixedPoint.w[0]) = %" DM_PRId64 " bytes (should be %d)\n", |
0 | 54 sizeof(a), sizeof(a.dw), FP_DW_SIZE, |
55 sizeof(a.w[0]), FP_W0_SIZE); | |
2046 | 56 |
0 | 57 if (sizeof(a.dw) != FP_DW_SIZE || sizeof(a.w[0]) != FP_W0_SIZE) |
58 { | |
59 printf("ERROR! Some type sizes DO NOT MATCH!\n"); | |
60 return -1; | |
61 } | |
2046 | 62 |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
63 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
64 header("set initial values"); |
0 | 65 FP_SETHL(a, 55, 0); |
66 check("a", a, 0x0000003700000000ULL); | |
67 | |
68 FP_CONV(b, 178); | |
69 check("b", b, 0x00000000000000b2ULL); | |
70 | |
71 FP_DIV_R(delta, a, b); | |
72 check("delta", delta, 0x000000004f19e33cULL); | |
73 | |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
74 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
75 header("50 x (a + delta)"); |
0 | 76 for (i = 0; i < 50; i++) |
77 { | |
78 FP_ADD(a, delta); | |
79 } | |
80 check("a end", a, 0x00000046730e61b8ULL); | |
81 | |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
82 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
83 header("50 x (a - delta)"); |
0 | 84 for (i = 0; i < 50; i++) |
85 { | |
86 FP_SUB(a, delta); | |
87 } | |
88 check("a end", a, 0x0000003700000000ULL); | |
89 | |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
90 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
91 header("5 x (a * delta)"); |
0 | 92 for (i = 0; i < 5; i++) |
93 { | |
94 FP_MUL(a, delta); | |
95 } | |
96 check("a end", a, 0xd644e40000000000ULL); | |
97 | |
1610
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
98 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
99 header("a / 2"); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
100 FP_CONV(delta, 2); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
101 FP_DIV(a, delta); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
102 check("a end", a, 0xeb22720000000000ULL); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
103 |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
104 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
105 header("a / 2"); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
106 FP_DIV(a, delta); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
107 check("a end", a, 0xf591390000000000ULL); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
108 |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
109 //----------------------------------------------- |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
110 header(""); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
111 FP_SETHL(a, -200, 50); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
112 FP_CONV(b, 15); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
113 FP_DIV(a, b); |
61246926756a
Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
114 check("a end", a, 0xfffffff2aaaaaaaeULL); |
0 | 115 |
116 return 0; | |
117 } |