annotate tests/fptest.c @ 2390:88be5cf55caf

Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Jan 2020 20:37:54 +0200
parents 186cf6a7d634
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include <stdio.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #define FP_DW_SIZE 8
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #define FP_W0_SIZE 4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
2390
88be5cf55caf Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
10
36
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
11 void check(const char *str, DMFixedPoint v, Sint64 dw)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 DMFixedPoint *q = (DMFixedPoint *) &dw;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
15 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
16 printf("should be = "); FP_PRINTF64((*q)); printf("\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 if (v.dw != dw)
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 printf("ERROR! A test value differs from expected!\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 }
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
1610
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
24
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
25 void header(const char *msg)
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
26 {
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
27 test_number++;
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
28 printf("\nTEST #%d: %s\n", test_number, msg);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
29 }
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
30
2390
88be5cf55caf Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
31
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
2390
88be5cf55caf Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
34 DMFixedPoint a, b, delta;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 char *s;
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 (void) argc;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 (void) argv;
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 // Check host characteristics
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 switch (SDL_BYTEORDER)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 case SDL_BIG_ENDIAN: s = "big endian"; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 case SDL_LIL_ENDIAN: s = "little endian"; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 default: s = "unknown?"; break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1610
diff changeset
48
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 printf(
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 "SDL byte order = %s (%d)\n\n", s, SDL_BYTEORDER);
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1610
diff changeset
51
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 printf(
2390
88be5cf55caf Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
53 "sizeof(DMFixedPoint) = %" DM_PRIu_SIZE_T " bytes\n"
88be5cf55caf Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
54 "sizeof(DMFixedPoint.dw) = %" DM_PRIu_SIZE_T " bytes (should be %d)\n"
88be5cf55caf Use correct format specifier DM_PRIu_SIZE_T instead of DM_PRId64.
Matti Hamalainen <ccr@tnsp.org>
parents: 2046
diff changeset
55 "sizeof(DMFixedPoint.w[0]) = %" DM_PRIu_SIZE_T " bytes (should be %d)\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 sizeof(a), sizeof(a.dw), FP_DW_SIZE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 sizeof(a.w[0]), FP_W0_SIZE);
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1610
diff changeset
58
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 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
60 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 printf("ERROR! Some type sizes DO NOT MATCH!\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 return -1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 }
2046
186cf6a7d634 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1610
diff changeset
64
1610
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
65 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
66 header("set initial values");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 FP_SETHL(a, 55, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 check("a", a, 0x0000003700000000ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 FP_CONV(b, 178);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 check("b", b, 0x00000000000000b2ULL);
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 FP_DIV_R(delta, a, b);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 check("delta", delta, 0x000000004f19e33cULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
1610
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
76 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
77 header("50 x (a + delta)");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 for (i = 0; i < 50; i++)
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 FP_ADD(a, delta);
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 check("a end", a, 0x00000046730e61b8ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
1610
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
84 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
85 header("50 x (a - delta)");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 for (i = 0; i < 50; i++)
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 FP_SUB(a, delta);
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 check("a end", a, 0x0000003700000000ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
1610
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
92 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
93 header("5 x (a * delta)");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 for (i = 0; i < 5; i++)
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 FP_MUL(a, delta);
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 check("a end", a, 0xd644e40000000000ULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
1610
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
100 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
101 header("a / 2");
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
102 FP_CONV(delta, 2);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
103 FP_DIV(a, delta);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
104 check("a end", a, 0xeb22720000000000ULL);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
105
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
106 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
107 header("a / 2");
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
108 FP_DIV(a, delta);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
109 check("a end", a, 0xf591390000000000ULL);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
110
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
111 //-----------------------------------------------
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
112 header("");
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
113 FP_SETHL(a, -200, 50);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
114 FP_CONV(b, 15);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
115 FP_DIV(a, b);
61246926756a Slight improvements to fptest.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
116 check("a end", a, 0xfffffff2aaaaaaaeULL);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }