1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 SOLARIS is
not defined
23 # if !(defined(_WIN32)) && !(defined(__linux)) && !(defined(__FreeBSD__))
26 __linux
, or __FreeBSD__ is defined
44 #if defined(__APPLE__)
51 /************************************************************************/
53 /* Generate cpucfg.h */
57 # define INT64 _PRInt64
65 # define INT64 long long
81 struct align_PRInt64
{
85 struct align_fakelonglong
{
99 struct align_pointer
{
104 #define ALIGN_OF(type) (((char*)&(((struct align_##type*)0)->a)) - ((char*)0))
108 /* Used if shell doesn't support redirection. By default, assume it does. */
111 static int Log2(int n
) {
118 log2
+= 16, n
>>= 16;
135 /* We assume that int's are 32 bits */
136 static void do64(void) {
143 if (u
.c
[0] == 0x01) {
144 fprintf(stream
, "#undef IS_LITTLE_ENDIAN\n");
145 fprintf(stream
, "#define IS_BIG_ENDIAN 1\n\n");
147 fprintf(stream
, "#define IS_LITTLE_ENDIAN 1\n");
148 fprintf(stream
, "#undef IS_BIG_ENDIAN\n\n");
152 static void do32(void) {
159 if (u
.c
[0] == 0x01) {
160 fprintf(stream
, "#undef IS_LITTLE_ENDIAN\n");
161 fprintf(stream
, "#define IS_BIG_ENDIAN 1\n\n");
163 fprintf(stream
, "#define IS_LITTLE_ENDIAN 1\n");
164 fprintf(stream
, "#undef IS_BIG_ENDIAN\n\n");
169 ** Concievably this could actually be used; but there is lots of code out
170 ** there with and's and shift's in it that assumes a byte is 8 bits, so
171 ** forget about porting THIS code to those non 8 bit byte machines.
173 static void BitsPerByte(void) { bpb
= 8; }
175 int main(int argc
, char** argv
) {
178 /* If we got a command line argument, try to use it as the stream. */
181 if (!(stream
= fopen(*argv
, "wt"))) {
182 fprintf(stderr
, "Could not write to output file %s.\n", *argv
);
189 fprintf(stream
, "#ifndef nspr_cpucfg___\n");
190 fprintf(stream
, "#define nspr_cpucfg___\n\n");
192 fprintf(stream
, "/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
194 if (sizeof(long) == 8) {
199 fprintf(stream
, "#define PR_BYTES_PER_BYTE %d\n", sizeof(char));
200 fprintf(stream
, "#define PR_BYTES_PER_SHORT %d\n", sizeof(short));
201 fprintf(stream
, "#define PR_BYTES_PER_INT %d\n", sizeof(int));
202 fprintf(stream
, "#define PR_BYTES_PER_INT64 %d\n", 8);
203 fprintf(stream
, "#define PR_BYTES_PER_LONG %d\n", sizeof(long));
204 fprintf(stream
, "#define PR_BYTES_PER_FLOAT %d\n", sizeof(float));
205 fprintf(stream
, "#define PR_BYTES_PER_DOUBLE %d\n\n", sizeof(double));
207 fprintf(stream
, "#define PR_BITS_PER_BYTE %d\n", bpb
);
208 fprintf(stream
, "#define PR_BITS_PER_SHORT %d\n", bpb
* sizeof(short));
209 fprintf(stream
, "#define PR_BITS_PER_INT %d\n", bpb
* sizeof(int));
210 fprintf(stream
, "#define PR_BITS_PER_INT64 %d\n", bpb
* 8);
211 fprintf(stream
, "#define PR_BITS_PER_LONG %d\n", bpb
* sizeof(long));
212 fprintf(stream
, "#define PR_BITS_PER_FLOAT %d\n", bpb
* sizeof(float));
213 fprintf(stream
, "#define PR_BITS_PER_DOUBLE %d\n\n", bpb
* sizeof(double));
215 fprintf(stream
, "#define PR_BITS_PER_BYTE_LOG2 %d\n", Log2(bpb
));
216 fprintf(stream
, "#define PR_BITS_PER_SHORT_LOG2 %d\n",
217 Log2(bpb
* sizeof(short)));
218 fprintf(stream
, "#define PR_BITS_PER_INT_LOG2 %d\n",
219 Log2(bpb
* sizeof(int)));
220 fprintf(stream
, "#define PR_BITS_PER_INT64_LOG2 %d\n", 6);
221 fprintf(stream
, "#define PR_BITS_PER_LONG_LOG2 %d\n",
222 Log2(bpb
* sizeof(long)));
223 fprintf(stream
, "#define PR_BITS_PER_FLOAT_LOG2 %d\n",
224 Log2(bpb
* sizeof(float)));
225 fprintf(stream
, "#define PR_BITS_PER_DOUBLE_LOG2 %d\n\n",
226 Log2(bpb
* sizeof(double)));
228 fprintf(stream
, "#define PR_ALIGN_OF_SHORT %d\n", ALIGN_OF(short));
229 fprintf(stream
, "#define PR_ALIGN_OF_INT %d\n", ALIGN_OF(int));
230 fprintf(stream
, "#define PR_ALIGN_OF_LONG %d\n", ALIGN_OF(long));
231 if (sizeof(INT64
) < 8) {
232 /* this machine doesn't actually support PRInt64's */
233 fprintf(stream
, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(fakelonglong
));
235 fprintf(stream
, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(PRInt64
));
237 fprintf(stream
, "#define PR_ALIGN_OF_FLOAT %d\n", ALIGN_OF(float));
238 fprintf(stream
, "#define PR_ALIGN_OF_DOUBLE %d\n", ALIGN_OF(double));
239 fprintf(stream
, "#define PR_ALIGN_OF_POINTER %d\n\n", ALIGN_OF(pointer
));
241 fprintf(stream
, "#endif /* nspr_cpucfg___ */\n");