]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/ArithChk/arithchk.c
2 Program to generate an arith.h for use with the gdtoa binary to decimal and decimal to binary
5 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 Copyright (C) 1997, 1998 Lucent Technologies
17 Permission to use, copy, modify, and distribute this software and
18 its documentation for any purpose and without fee is hereby
19 granted, provided that the above copyright notice appear in all
20 copies and that both that the copyright notice and this
21 permission notice and warranty disclaimer appear in supporting
22 documentation, and that the name of Lucent or any of its entities
23 not be used in advertising or publicity pertaining to
24 distribution of the software without specific, written prior
27 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
28 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
29 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
30 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
32 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
33 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
36 NetBSD: arithchk.c,v 1.2 2006/01/25 15:27:42 kleink Exp
37 ****************************************************************/
38 #include <sys/EfiCdefs.h>
40 /* Try to deduce arith.h from arithmetic properties. */
46 typedef struct Akind
{
51 static Akind IEEE_LITTLE_ENDIAN
= { "IEEE_LITTLE_ENDIAN", 1 };
52 static Akind IEEE_BIG_ENDIAN
= { "IEEE_BIG_ENDIAN", 2 };
53 static Akind IBM
= { "IBM", 3 };
54 static Akind VAX
= { "VAX", 4 };
55 static Akind CRAY
= { "CRAY", 5};
69 if (sizeof(x
) > 2*(sizeof(double) + sizeof(long)))
73 if (u
.L
[0] == 1117925532 && u
.L
[1] == -448790528)
74 return &IEEE_BIG_ENDIAN
;
75 if (u
.L
[1] == 1117925532 && u
.L
[0] == -448790528)
76 return &IEEE_LITTLE_ENDIAN
;
77 if (u
.L
[0] == -2065213935 && u
.L
[1] == 10752)
79 if (u
.L
[0] == 1267827943 && u
.L
[1] == 704643072)
96 if (sizeof(x
) > 2*(sizeof(double) + sizeof(int)))
100 if (u
.L
[0] == 1117925532 && u
.L
[1] == -448790528)
101 return &IEEE_BIG_ENDIAN
;
102 if (u
.L
[1] == 1117925532 && u
.L
[0] == -448790528)
103 return &IEEE_LITTLE_ENDIAN
;
104 if (u
.L
[0] == -2065213935 && u
.L
[1] == 10752)
106 if (u
.L
[0] == 1267827943 && u
.L
[1] == 704643072)
111 char *emptyfmt
= ""; /* avoid possible warning message with printf("") */
122 /* Cray1 = 4617762693716115456 -- without overflow on non-Crays */
123 Cray1
= printf(emptyfmt
) < 0 ? 0 : 4617762;
124 if (printf(emptyfmt
, Cray1
) >= 0)
125 Cray1
= 1000000*Cray1
+ 693716;
126 if (printf(emptyfmt
, Cray1
) >= 0)
127 Cray1
= 1000000*Cray1
+ 115456;
142 for(i
= 155;; b
*= b
, i
>>= 1) {
160 #ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */
161 f
= fopen("arith.h", "w");
163 printf("Cannot open arith.h\n");
170 if (sizeof(double) == 2*sizeof(long))
172 else if (sizeof(double) == 2*sizeof(int)) {
176 else if (sizeof(double) == sizeof(long))
179 fprintf(f
, "#define %s\n#define Arith_Kind_ASL %d\n",
182 fprintf(f
, "#define Long int\n#define Intcast (int)(long)\n");
184 fprintf(f
, "#define Double_Align\n");
185 if (sizeof(char*) == 8)
186 fprintf(f
, "#define X64_bit_pointers\n");
188 if (sizeof(long long) < 8)
190 fprintf(f
, "#define NO_LONG_LONG\n");
191 if (a
->kind
<= 2 && fzcheck())
192 fprintf(f
, "#define Sudden_Underflow\n");
195 fprintf(f
, "/* Unknown arithmetic */\n");