5 #include "SDL_endian.h"
6 #include "SDL_cpuinfo.h"
9 * Watcom C flags these as Warning 201: "Unreachable code" if you just
10 * compare them directly, so we push it through a function to keep the
11 * compiler quiet. --ryan.
13 static int badsize(size_t sizeoftype
, size_t hardcodetype
)
15 return sizeoftype
!= hardcodetype
;
18 int TestTypes(SDL_bool verbose
)
22 if ( badsize(sizeof(Uint8
), 1) ) {
24 printf("sizeof(Uint8) != 1, instead = %ul\n",
28 if ( badsize(sizeof(Uint16
), 2) ) {
30 printf("sizeof(Uint16) != 2, instead = %ul\n",
34 if ( badsize(sizeof(Uint32
), 4) ) {
36 printf("sizeof(Uint32) != 4, instead = %ul\n",
40 #ifdef SDL_HAS_64BIT_TYPE
41 if ( badsize(sizeof(Uint64
), 8) ) {
43 printf("sizeof(Uint64) != 8, instead = %ul\n",
49 printf("WARNING: No 64-bit datatype on this platform\n");
52 if ( verbose
&& !error
)
53 printf("All data types are the expected size.\n");
55 return( error
? 1 : 0 );
58 int TestEndian(SDL_bool verbose
)
61 Uint16 value
= 0x1234;
63 Uint16 value16
= 0xCDAB;
64 Uint16 swapped16
= 0xABCD;
65 Uint32 value32
= 0xEFBEADDE;
66 Uint32 swapped32
= 0xDEADBEEF;
67 #ifdef SDL_HAS_64BIT_TYPE
68 Uint64 value64
, swapped64
;
71 value64
|= 0xCDAB3412;
72 swapped64
= 0x1234ABCD;
74 swapped64
|= 0xDEADBEEF;
78 printf("Detected a %s endian machine.\n",
79 (SDL_BYTEORDER
== SDL_LIL_ENDIAN
) ? "little" : "big");
81 if ( (*((char *)&value
) >> 4) == 0x1 ) {
82 real_byteorder
= SDL_BIG_ENDIAN
;
84 real_byteorder
= SDL_LIL_ENDIAN
;
86 if ( real_byteorder
!= SDL_BYTEORDER
) {
88 printf("Actually a %s endian machine!\n",
89 (real_byteorder
== SDL_LIL_ENDIAN
) ? "little" : "big");
94 printf("Value 16 = 0x%X, swapped = 0x%X\n", value16
, SDL_Swap16(value16
));
96 if ( SDL_Swap16(value16
) != swapped16
) {
98 printf("16 bit value swapped incorrectly!\n");
103 printf("Value 32 = 0x%X, swapped = 0x%X\n", value32
, SDL_Swap32(value32
));
105 if ( SDL_Swap32(value32
) != swapped32
) {
107 printf("32 bit value swapped incorrectly!\n");
111 #ifdef SDL_HAS_64BIT_TYPE
114 printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64
, SDL_Swap64(value64
));
116 printf("Value 64 = 0x%llX, swapped = 0x%llX\n", value64
, SDL_Swap64(value64
));
119 if ( SDL_Swap64(value64
) != swapped64
) {
121 printf("64 bit value swapped incorrectly!\n");
126 return( error
? 1 : 0 );
130 int TestCPUInfo(SDL_bool verbose
)
133 printf("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
134 printf("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
135 printf("MMX Ext %s\n", SDL_HasMMXExt() ? "detected" : "not detected");
136 printf("3DNow %s\n", SDL_Has3DNow() ? "detected" : "not detected");
137 printf("3DNow Ext %s\n", SDL_Has3DNowExt() ? "detected" : "not detected");
138 printf("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
139 printf("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
140 printf("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
145 int main(int argc
, char *argv
[])
147 SDL_bool verbose
= SDL_TRUE
;
150 if ( argv
[1] && (SDL_strcmp(argv
[1], "-q") == 0) ) {
154 printf("This system is running %s\n",
198 "an unknown operating system! (see SDL_platform.h)"
203 status
+= TestTypes(verbose
);
204 status
+= TestEndian(verbose
);
205 status
+= TestCPUInfo(verbose
);