Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 14 files changed
  • 0 comments
  • 1 contributor
5  software/bios/Makefile
@@ -18,7 +18,10 @@ bios.elf: linker.ld $(OBJECTS) libs
18 18
 bios-rescue.elf: linker-rescue.ld $(OBJECTS) libs
19 19
 
20 20
 %.elf:
21  
-	$(LD) $(LDFLAGS) -T $< -N -o $@ $(OBJECTS) -L$(M2DIR)/software/libbase -lbase
  21
+	$(LD) $(LDFLAGS) -T $< -N -o $@ $(OBJECTS) \
  22
+		-L$(M2DIR)/software/libbase \
  23
+		-L$(CRTDIR) \
  24
+		-lbase -lcompiler_rt
22 25
 	chmod -x $@
23 26
 
24 27
 libs:
4  software/include/base/limits.h
... ...
@@ -1,8 +1,8 @@
1 1
 #ifndef __LIMITS_H
2 2
 #define __LIMITS_H
3 3
 
4  
-#define INT_MIN 0x7fffffff
5  
-#define INT_MAX 0x80000000
  4
+#define INT_MIN 0x80000000
  5
+#define INT_MAX 0x7fffffff
6 6
 
7 7
 #define SHRT_MIN 0x8000
8 8
 #define SHRT_MAX 0x7fff
2  software/include/base/string.h
@@ -39,4 +39,6 @@ void *memmove(void *dest, const void *src, size_t count);
39 39
 char *strstr(const char *s1, const char *s2);
40 40
 void *memchr(const void *s, int c, size_t n);
41 41
 
  42
+char *strerror(int errnum);
  43
+
42 44
 #endif /* __STRING_H */
2  software/libbase/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/common.mak
3 3
 
4  
-OBJECTS=divsi3.o setjmp.o libc.o crc16.o crc32.o console.o timer.o system.o board.o uart.o softfloat.o softfloat-glue.o vsnprintf.o strtod.o
  4
+OBJECTS=setjmp.o libc.o errno.o crc16.o crc32.o console.o timer.o system.o board.o uart.o vsnprintf.o strtod.o
5 5
 
6 6
 all: libbase.a
7 7
 
55  software/libbase/divsi3.c
... ...
@@ -1,55 +0,0 @@
1  
-#define divnorm(num, den, sign) 		\
2  
-{						\
3  
-  if(num < 0) 					\
4  
-    {						\
5  
-      num = -num;				\
6  
-      sign = 1;					\
7  
-    }						\
8  
-  else 						\
9  
-    {						\
10  
-      sign = 0;					\
11  
-    }						\
12  
-						\
13  
-  if(den < 0) 					\
14  
-    {						\
15  
-      den = - den;				\
16  
-      sign = 1 - sign;				\
17  
-    } 						\
18  
-}
19  
-
20  
-#define exitdiv(sign, res) if (sign) { res = - res;} return res;
21  
-
22  
-long __divsi3 (long numerator, long denominator);
23  
-long __divsi3 (long numerator, long denominator)
24  
-{
25  
-	int sign;
26  
-	long dividend;
27  
-
28  
-	divnorm(numerator, denominator, sign);
29  
-
30  
-	dividend = (unsigned int)numerator/(unsigned int)denominator;
31  
-	exitdiv(sign, dividend);
32  
-}
33  
-
34  
-long __modsi3 (long numerator, long denominator);
35  
-long __modsi3 (long numerator, long denominator)
36  
-{
37  
-	int sign;
38  
-	long res;
39  
-
40  
-	if(numerator < 0) {
41  
-		numerator = -numerator;
42  
-		sign = 1;
43  
-	} else
44  
-		sign = 0;
45  
-
46  
-	if(denominator < 0)
47  
-		denominator = -denominator;
48  
-
49  
-	res = (unsigned int)numerator % (unsigned int)denominator;
50  
-
51  
-	if(sign)
52  
-		return -res;
53  
-	else
54  
-		return res;
55  
-}
208  software/libbase/errno.c
... ...
@@ -0,0 +1,208 @@
  1
+#include <string.h>
  2
+#include <errno.h>
  3
+
  4
+int errno;
  5
+
  6
+/************************************************************************
  7
+ * Based on: lib/string/lib_strerror.c
  8
+ *
  9
+ *   Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
  10
+ *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  11
+ *
  12
+ * Redistribution and use in source and binary forms, with or without
  13
+ * modification, are permitted provided that the following conditions
  14
+ * are met:
  15
+ *
  16
+ * 1. Redistributions of source code must retain the above copyright
  17
+ *    notice, this list of conditions and the following disclaimer.
  18
+ * 2. Redistributions in binary form must reproduce the above copyright
  19
+ *    notice, this list of conditions and the following disclaimer in
  20
+ *    the documentation and/or other materials provided with the
  21
+ *    distribution.
  22
+ * 3. Neither the name NuttX nor the names of its contributors may be
  23
+ *    used to endorse or promote products derived from this software
  24
+ *    without specific prior written permission.
  25
+ *
  26
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  33
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  34
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37
+ * POSSIBILITY OF SUCH DAMAGE.
  38
+ *
  39
+ ************************************************************************/
  40
+
  41
+struct errno_strmap_s
  42
+{
  43
+  int errnum;
  44
+  char *str;
  45
+};
  46
+
  47
+/* This table maps all error numbers to descriptive strings.
  48
+ * The only assumption that the code makes with regard to this
  49
+ * this table is that it is order by error number.
  50
+ *
  51
+ * The size of this table is quite large.  Its size can be
  52
+ * reduced by eliminating some of the more obscure error
  53
+ * strings.
  54
+ */
  55
+
  56
+struct errno_strmap_s g_errnomap[] =
  57
+{
  58
+  { EPERM,               EPERM_STR           },
  59
+  { ENOENT,              ENOENT_STR          },
  60
+  { ESRCH,               ESRCH_STR           },
  61
+  { EINTR,               EINTR_STR           },
  62
+  { EIO,                 EIO_STR             },
  63
+  { ENXIO,               ENXIO_STR           },
  64
+  { E2BIG,               E2BIG_STR           },
  65
+  { ENOEXEC,             ENOEXEC_STR         },
  66
+  { EBADF,               EBADF_STR           },
  67
+  { ECHILD,              ECHILD_STR          },
  68
+  { EAGAIN,              EAGAIN_STR          },
  69
+  { ENOMEM,              ENOMEM_STR          },
  70
+  { EACCES,              EACCES_STR          },
  71
+  { EFAULT,              EFAULT_STR          },
  72
+  { ENOTBLK,             ENOTBLK_STR         },
  73
+  { EBUSY,               EBUSY_STR           },
  74
+  { EEXIST,              EEXIST_STR          },
  75
+  { EXDEV,               EXDEV_STR           },
  76
+  { ENODEV,              ENODEV_STR          },
  77
+  { ENOTDIR,             ENOTDIR_STR         },
  78
+  { EISDIR,              EISDIR_STR          },
  79
+  { EINVAL,              EINVAL_STR          },
  80
+  { ENFILE,              ENFILE_STR          },
  81
+  { EMFILE,              EMFILE_STR          },
  82
+  { ENOTTY,              ENOTTY_STR          },
  83
+  { ETXTBSY,             ETXTBSY_STR         },
  84
+  { EFBIG,               EFBIG_STR           },
  85
+  { ENOSPC,              ENOSPC_STR          },
  86
+  { ESPIPE,              ESPIPE_STR          },
  87
+  { EROFS,               EROFS_STR           },
  88
+  { EMLINK,              EMLINK_STR          },
  89
+  { EPIPE,               EPIPE_STR           },
  90
+  { EDOM,                EDOM_STR            },
  91
+  { ERANGE,              ERANGE_STR          },
  92
+  { EDEADLK,             EDEADLK_STR         },
  93
+  { ENAMETOOLONG,        ENAMETOOLONG_STR    },
  94
+  { ENOLCK,              ENOLCK_STR          },
  95
+  { ENOSYS,              ENOSYS_STR          },
  96
+  { ENOTEMPTY,           ENOTEMPTY_STR       },
  97
+  { ELOOP,               ELOOP_STR           },
  98
+  { ENOMSG,              ENOMSG_STR          },
  99
+  { EIDRM,               EIDRM_STR           },
  100
+  { ECHRNG,              ECHRNG_STR          },
  101
+  { EL2NSYNC,            EL2NSYNC_STR        },
  102
+  { EL3HLT,              EL3HLT_STR          },
  103
+  { EL3RST,              EL3RST_STR          },
  104
+  { ELNRNG,              ELNRNG_STR          },
  105
+  { EUNATCH,             EUNATCH_STR         },
  106
+  { ENOCSI,              ENOCSI_STR          },
  107
+  { EL2HLT,              EL2HLT_STR          },
  108
+  { EBADE,               EBADE_STR           },
  109
+  { EBADR,               EBADR_STR           },
  110
+  { EXFULL,              EXFULL_STR          },
  111
+  { ENOANO,              ENOANO_STR          },
  112
+  { EBADRQC,             EBADRQC_STR         },
  113
+  { EBADSLT,             EBADSLT_STR         },
  114
+  { EBFONT,              EBFONT_STR          },
  115
+  { ENOSTR,              ENOSTR_STR          },
  116
+  { ENODATA,             ENODATA_STR         },
  117
+  { ETIME,               ETIME_STR           },
  118
+  { ENOSR,               ENOSR_STR           },
  119
+  { ENONET,              ENONET_STR          },
  120
+  { ENOPKG,              ENOPKG_STR          },
  121
+  { EREMOTE,             EREMOTE_STR         },
  122
+  { ENOLINK,             ENOLINK_STR         },
  123
+  { EADV,                EADV_STR            },
  124
+  { ESRMNT,              ESRMNT_STR          },
  125
+  { ECOMM,               ECOMM_STR           },
  126
+  { EPROTO,              EPROTO_STR          },
  127
+  { EMULTIHOP,           EMULTIHOP_STR       },
  128
+  { EDOTDOT,             EDOTDOT_STR         },
  129
+  { EBADMSG,             EBADMSG_STR         },
  130
+  { EOVERFLOW,           EOVERFLOW_STR       },
  131
+  { ENOTUNIQ,            ENOTUNIQ_STR        },
  132
+  { EBADFD,              EBADFD_STR          },
  133
+  { EREMCHG,             EREMCHG_STR         },
  134
+  { ELIBACC,             ELIBACC_STR         },
  135
+  { ELIBBAD,             ELIBBAD_STR         },
  136
+  { ELIBSCN,             ELIBSCN_STR         },
  137
+  { ELIBMAX,             ELIBMAX_STR         },
  138
+  { ELIBEXEC,            ELIBEXEC_STR        },
  139
+  { EILSEQ,              EILSEQ_STR          },
  140
+  { ERESTART,            ERESTART_STR        },
  141
+  { ESTRPIPE,            ESTRPIPE_STR        },
  142
+  { EUSERS,              EUSERS_STR          },
  143
+  { ENOTSOCK,            ENOTSOCK_STR        },
  144
+  { EDESTADDRREQ,        EDESTADDRREQ_STR    },
  145
+  { EMSGSIZE,            EMSGSIZE_STR        },
  146
+  { EPROTOTYPE,          EPROTOTYPE_STR      },
  147
+  { ENOPROTOOPT,         ENOPROTOOPT_STR     },
  148
+  { EPROTONOSUPPORT,     EPROTONOSUPPORT_STR },
  149
+  { ESOCKTNOSUPPORT,     ESOCKTNOSUPPORT_STR },
  150
+  { EOPNOTSUPP,          EOPNOTSUPP_STR      },
  151
+  { EPFNOSUPPORT,        EPFNOSUPPORT_STR    },
  152
+  { EAFNOSUPPORT,        EAFNOSUPPORT_STR    },
  153
+  { EADDRINUSE,          EADDRINUSE_STR      },
  154
+  { EADDRNOTAVAIL,       EADDRNOTAVAIL_STR   },
  155
+  { ENETDOWN,            ENETDOWN_STR        },
  156
+  { ENETUNREACH,         ENETUNREACH_STR     },
  157
+  { ENETRESET,           ENETRESET_STR       },
  158
+  { ECONNABORTED,        ECONNABORTED_STR    },
  159
+  { ECONNRESET,          ECONNRESET_STR      },
  160
+  { ENOBUFS,             ENOBUFS_STR         },
  161
+  { EISCONN,             EISCONN_STR         },
  162
+  { ENOTCONN,            ENOTCONN_STR        },
  163
+  { ESHUTDOWN,           ESHUTDOWN_STR       },
  164
+  { ETOOMANYREFS,        ETOOMANYREFS_STR    },
  165
+  { ETIMEDOUT,           ETIMEDOUT_STR       },
  166
+  { ECONNREFUSED,        ECONNREFUSED_STR    },
  167
+  { EHOSTDOWN,           EHOSTDOWN_STR       },
  168
+  { EHOSTUNREACH,        EHOSTUNREACH_STR    },
  169
+  { EALREADY,            EALREADY_STR        },
  170
+  { EINPROGRESS,         EINPROGRESS_STR     },
  171
+  { ESTALE,              ESTALE_STR          },
  172
+  { EUCLEAN,             EUCLEAN_STR         },
  173
+  { ENOTNAM,             ENOTNAM_STR         },
  174
+  { ENAVAIL,             ENAVAIL_STR         },
  175
+  { EISNAM,              EISNAM_STR          },
  176
+  { EREMOTEIO,           EREMOTEIO_STR       },
  177
+  { EDQUOT,              EDQUOT_STR          },
  178
+  { ENOMEDIUM,           ENOMEDIUM_STR       },
  179
+  { EMEDIUMTYPE,         EMEDIUMTYPE_STR     }
  180
+};
  181
+
  182
+#define NERRNO_STRS (sizeof(g_errnomap) / sizeof(struct errno_strmap_s))
  183
+
  184
+char *strerror(int errnum)
  185
+{
  186
+  int ndxlow = 0;
  187
+  int ndxhi  = NERRNO_STRS - 1;
  188
+  int ndxmid;
  189
+
  190
+  do
  191
+    {
  192
+      ndxmid = (ndxlow + ndxhi) >> 1;
  193
+      if (errnum > g_errnomap[ndxmid].errnum)
  194
+        {
  195
+          ndxlow = ndxmid + 1;
  196
+        }
  197
+      else if (errnum < g_errnomap[ndxmid].errnum)
  198
+        {
  199
+          ndxhi = ndxmid - 1;
  200
+        }
  201
+      else
  202
+        {
  203
+          return g_errnomap[ndxmid].str;
  204
+        }
  205
+    }
  206
+  while (ndxlow <= ndxhi);
  207
+  return "Unknown error";
  208
+}
2  software/libbase/libc.c
@@ -23,8 +23,6 @@
23 23
 #include <string.h>
24 24
 #include <limits.h>
25 25
 
26  
-int errno;
27  
-
28 26
 /**
29 27
  * strchr - Find the first occurrence of a character in a string
30 28
  * @s: The string to be searched
112  software/libbase/milieu.h
... ...
@@ -1,112 +0,0 @@
1  
-
2  
-/*============================================================================
3  
-
4  
-This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
5  
-Package, Release 2b.
6  
-
7  
-Written by John R. Hauser.  This work was made possible in part by the
8  
-International Computer Science Institute, located at Suite 600, 1947 Center
9  
-Street, Berkeley, California 94704.  Funding was partially provided by the
10  
-National Science Foundation under grant MIP-9311980.  The original version
11  
-of this code was written as part of a project to build a fixed-point vector
12  
-processor in collaboration with the University of California at Berkeley,
13  
-overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
14  
-is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
15  
-arithmetic/SoftFloat.html'.
16  
-
17  
-THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort has
18  
-been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
19  
-RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
20  
-AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
21  
-COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
22  
-EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
23  
-INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
24  
-OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
25  
-
26  
-Derivative works are acceptable, even for commercial purposes, so long as
27  
-(1) the source code for the derivative work includes prominent notice that
28  
-the work is derivative, and (2) the source code includes prominent notice with
29  
-these four paragraphs for those parts of this code that are retained.
30  
-
31  
-=============================================================================*/
32  
-
33  
-/*----------------------------------------------------------------------------
34  
-| Include common integer types and flags.
35  
-*----------------------------------------------------------------------------*/
36  
-
37  
-/*----------------------------------------------------------------------------
38  
-| One of the macros `BIGENDIAN' or `LITTLEENDIAN' must be defined.
39  
-*----------------------------------------------------------------------------*/
40  
-#define BIGENDIAN
41  
-
42  
-/*----------------------------------------------------------------------------
43  
-| The macro `BITS64' can be defined to indicate that 64-bit integer types are
44  
-| supported by the compiler.
45  
-*----------------------------------------------------------------------------*/
46  
-//#define BITS64
47  
-
48  
-/*----------------------------------------------------------------------------
49  
-| Each of the following `typedef's defines the most convenient type that holds
50  
-| integers of at least as many bits as specified.  For example, `uint8' should
51  
-| be the most convenient type that can hold unsigned integers of as many as
52  
-| 8 bits.  The `flag' type must be able to hold either a 0 or 1.  For most
53  
-| implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
54  
-| to the same as `int'.
55  
-*----------------------------------------------------------------------------*/
56  
-typedef int flag;
57  
-typedef int uint8;
58  
-typedef int int8;
59  
-typedef int uint16;
60  
-typedef int int16;
61  
-typedef unsigned int uint32;
62  
-typedef signed int int32;
63  
-#ifdef BITS64
64  
-typedef unsigned long long int uint64;
65  
-typedef signed long long int int64;
66  
-#endif
67  
-
68  
-/*----------------------------------------------------------------------------
69  
-| Each of the following `typedef's defines a type that holds integers
70  
-| of _exactly_ the number of bits specified.  For instance, for most
71  
-| implementation of C, `bits16' and `sbits16' should be `typedef'ed to
72  
-| `unsigned short int' and `signed short int' (or `short int'), respectively.
73  
-*----------------------------------------------------------------------------*/
74  
-typedef unsigned char bits8;
75  
-typedef signed char sbits8;
76  
-typedef unsigned short int bits16;
77  
-typedef signed short int sbits16;
78  
-typedef unsigned int bits32;
79  
-typedef signed int sbits32;
80  
-#ifdef BITS64
81  
-typedef unsigned long long int bits64;
82  
-typedef signed long long int sbits64;
83  
-#endif
84  
-
85  
-#ifdef BITS64
86  
-/*----------------------------------------------------------------------------
87  
-| The `LIT64' macro takes as its argument a textual integer literal and
88  
-| if necessary ``marks'' the literal as having a 64-bit integer type.
89  
-| For example, the GNU C Compiler (`gcc') requires that 64-bit literals be
90  
-| appended with the letters `LL' standing for `long long', which is `gcc's
91  
-| name for the 64-bit integer type.  Some compilers may allow `LIT64' to be
92  
-| defined as the identity macro:  `#define LIT64( a ) a'.
93  
-*----------------------------------------------------------------------------*/
94  
-#define LIT64( a ) a##LL
95  
-#endif
96  
-
97  
-/*----------------------------------------------------------------------------
98  
-| The macro `INLINE' can be used before functions that should be inlined.  If
99  
-| a compiler does not support explicit inlining, this macro should be defined
100  
-| to be `static'.
101  
-*----------------------------------------------------------------------------*/
102  
-#define INLINE extern inline
103  
-
104  
-
105  
-/*----------------------------------------------------------------------------
106  
-| Symbolic Boolean literals.
107  
-*----------------------------------------------------------------------------*/
108  
-enum {
109  
-    FALSE = 0,
110  
-    TRUE  = 1
111  
-};
112  
-
274  software/libbase/softfloat-glue.c
... ...
@@ -1,274 +0,0 @@
1  
-/*	$NetBSD: fplib_glue.c,v 1.2 2000/02/22 01:18:28 mycroft Exp $	*/
2  
-
3  
-/*-
4  
- * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  
- * All rights reserved.
6  
- *
7  
- * This code is derived from software contributed to The NetBSD Foundation
8  
- * by Neil A. Carson and Mark Brinicombe
9  
- *
10  
- * Redistribution and use in source and binary forms, with or without
11  
- * modification, are permitted provided that the following conditions
12  
- * are met:
13  
- * 1. Redistributions of source code must retain the above copyright
14  
- *    notice, this list of conditions and the following disclaimer.
15  
- * 2. Redistributions in binary form must reproduce the above copyright
16  
- *    notice, this list of conditions and the following disclaimer in the
17  
- *    documentation and/or other materials provided with the distribution.
18  
- * 3. All advertising materials mentioning features or use of this software
19  
- *    must display the following acknowledgement:
20  
- *	This product includes software developed by the NetBSD
21  
- *	Foundation, Inc. and its contributors.
22  
- * 4. Neither the name of The NetBSD Foundation nor the names of its
23  
- *    contributors may be used to endorse or promote products derived
24  
- *    from this software without specific prior written permission.
25  
- *
26  
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  
- * POSSIBILITY OF SUCH DAMAGE.
37  
- */
38  
-
39  
-#include "milieu.h"
40  
-#include "softfloat.h"
41  
-
42  
-int __eqsf2(float32 a,float32 b);
43  
-int __eqdf2(float64 a,float64 b);
44  
-int __nesf2(float32 a,float32 b);
45  
-int __nedf2(float64 a,float64 b);
46  
-int __gtsf2(float32 a,float32 b);
47  
-int __gtdf2(float64 a,float64 b);
48  
-int __gesf2(float32 a,float32 b);
49  
-int __gedf2(float64 a,float64 b);
50  
-int __ltsf2(float32 a,float32 b);
51  
-int __ltdf2(float64 a,float64 b);
52  
-int __lesf2(float32 a,float32 b);
53  
-int __ledf2(float64 a,float64 b);
54  
-float32 __negsf2(float32 a);
55  
-float64 __negdf2(float64 a);
56  
-
57  
-/********************************* COMPARISONS ********************************/
58  
-
59  
-/*
60  
- * 'Equal' wrapper. This returns 0 if the numbers are equal, or (1 | -1)
61  
- * otherwise. So we need to invert the output.
62  
- */
63  
-
64  
-int __eqsf2(float32 a,float32 b) {
65  
-	return float32_eq(a,b)?0:1;
66  
-}
67  
-
68  
-int __eqdf2(float64 a,float64 b) {
69  
-	return float64_eq(a,b)?0:1;
70  
-}
71  
-
72  
-/*
73  
- * 'Not Equal' wrapper. This returns -1 or 1 (say, 1!) if the numbers are
74  
- * not equal, 0 otherwise. However no not equal call is provided, so we have
75  
- * to use an 'equal' call and invert the result. The result is already
76  
- * inverted though! Confusing?!
77  
- */
78  
-int __nesf2(float32 a,float32 b) {
79  
-	return float32_eq(a,b)?0:-1;
80  
-}
81  
-
82  
-int __nedf2(float64 a,float64 b) {
83  
-	return float64_eq(a,b)?0:-1;
84  
-}
85  
-
86  
-/*
87  
- * 'Greater Than' wrapper. This returns 1 if the number is greater, 0
88  
- * or -1 otherwise. Unfortunately, no such function exists. We have to
89  
- * instead compare the numbers using the 'less than' calls in order to
90  
- * make up our mind. This means that we can call 'less than or equal' and
91  
- * invert the result.
92  
- */
93  
-int __gtsf2(float32 a,float32 b) {
94  
-	return float32_le(a,b)?0:1;
95  
-}
96  
-
97  
-int __gtdf2(float64 a,float64 b) {
98  
-	return float64_le(a,b)?0:1;
99  
-}
100  
-
101  
-/*
102  
- * 'Greater Than or Equal' wrapper. We emulate this by inverting the result
103  
- * of a 'less than' call.
104  
- */
105  
-int __gesf2(float32 a,float32 b) {
106  
-	return float32_lt(a,b)?-1:0;
107  
-}
108  
-
109  
-int __gedf2(float64 a,float64 b) {
110  
-	return float64_lt(a,b)?-1:0;
111  
-}
112  
-
113  
-/*
114  
- * 'Less Than' wrapper. A 1 from the ARM code needs to be turned into -1.
115  
- */
116  
-int __ltsf2(float32 a,float32 b) {
117  
-	return float32_lt(a,b)?-1:0;
118  
-}
119  
-
120  
-int __ltdf2(float64 a,float64 b) {
121  
-	return float64_lt(a,b)?-1:0;
122  
-}
123  
-
124  
-/*
125  
- * 'Less Than or Equal' wrapper. A 0 must turn into a 1, and a 1 into a 0.
126  
- */
127  
-int __lesf2(float32 a,float32 b) {
128  
-	return float32_le(a,b)?0:1;
129  
-}
130  
-
131  
-int __ledf2(float64 a,float64 b) {
132  
-	return float64_le(a,b)?0:1;
133  
-}
134  
-
135  
-/*
136  
- * Float negate... This isn't provided by the library, but it's hardly the
137  
- * hardest function in the world to write... :) In fact, because of the
138  
- * position in the registers of arguments, the double precision version can
139  
- * go here too ;-)
140  
- */
141  
-float32 __negsf2(float32 a) {
142  
-	return (a ^ 0x80000000);
143  
-}
144  
-
145  
-float64 __negdf2(float64 a) {
146  
-	a.high ^= 0x80000000;
147  
-	return a;
148  
-}
149  
-
150  
-/*
151  
- * 32-bit operations. This is not BSD code.
152  
- */
153  
-float32 __addsf3(float32 a, float32 b);
154  
-float32 __addsf3(float32 a, float32 b)
155  
-{
156  
-	return float32_add(a, b);
157  
-}
158  
-
159  
-float32 __subsf3(float32 a, float32 b);
160  
-float32 __subsf3(float32 a, float32 b)
161  
-{
162  
-	return float32_sub(a, b);
163  
-}
164  
-
165  
-float32 __mulsf3(float32 a, float32 b);
166  
-float32 __mulsf3(float32 a, float32 b)
167  
-{
168  
-	return float32_mul(a, b);
169  
-}
170  
-
171  
-float32 __divsf3(float32 a, float32 b);
172  
-float32 __divsf3(float32 a, float32 b)
173  
-{
174  
-	return float32_div(a, b);
175  
-}
176  
-
177  
-float32 __floatsisf(int32 x);
178  
-float32 __floatsisf(int32 x)
179  
-{
180  
-	return int32_to_float32(x);
181  
-}
182  
-
183  
-float32 __floatunsisf(int32 x);
184  
-float32 __floatunsisf(int32 x)
185  
-{
186  
-	return int32_to_float32(x); // XXX
187  
-}
188  
-
189  
-int32 __fixsfsi(float32 x);
190  
-int32 __fixsfsi(float32 x)
191  
-{
192  
-	return float32_to_int32_round_to_zero(x);
193  
-}
194  
-
195  
-uint32 __fixunssfsi(float32 x);
196  
-uint32 __fixunssfsi(float32 x)
197  
-{
198  
-	return float32_to_int32_round_to_zero(x); // XXX
199  
-}
200  
-
201  
-flag __unordsf2(float32 a, float32 b);
202  
-flag __unordsf2(float32 a, float32 b)
203  
-{
204  
-	/*
205  
-	 * The comparison is unordered if either input is a NaN.
206  
-	 * Test for this by comparing each operand with itself.
207  
-	 * We must perform both comparisons to correctly check for
208  
-	 * signalling NaNs.
209  
-	 */
210  
-	return 1 ^ (float32_eq(a, a) & float32_eq(b, b));
211  
-}
212  
-
213  
-/*
214  
- * 64-bit operations. This is not BSD code.
215  
- */
216  
-float64 __adddf3(float64 a, float64 b);
217  
-float64 __adddf3(float64 a, float64 b)
218  
-{
219  
-	return float64_add(a, b);
220  
-}
221  
-
222  
-float64 __subdf3(float64 a, float64 b);
223  
-float64 __subdf3(float64 a, float64 b)
224  
-{
225  
-	return float64_sub(a, b);
226  
-}
227  
-
228  
-float64 __muldf3(float64 a, float64 b);
229  
-float64 __muldf3(float64 a, float64 b)
230  
-{
231  
-	return float64_mul(a, b);
232  
-}
233  
-
234  
-float64 __divdf3(float64 a, float64 b);
235  
-float64 __divdf3(float64 a, float64 b)
236  
-{
237  
-	return float64_div(a, b);
238  
-}
239  
-
240  
-float64 __floatsidf(int32 x);
241  
-float64 __floatsidf(int32 x)
242  
-{
243  
-	return int32_to_float64(x);
244  
-}
245  
-
246  
-float64 __floatunsidf(int32 x);
247  
-float64 __floatunsidf(int32 x)
248  
-{
249  
-	return int32_to_float64(x); // XXX
250  
-}
251  
-
252  
-int32 __fixdfsi(float64 x);
253  
-int32 __fixdfsi(float64 x)
254  
-{
255  
-	return float64_to_int32_round_to_zero(x);
256  
-}
257  
-
258  
-uint32 __fixunsdfsi(float64 x);
259  
-uint32 __fixunsdfsi(float64 x)
260  
-{
261  
-	return float64_to_int32_round_to_zero(x); // XXX
262  
-}
263  
-
264  
-flag __unorddf2(float64 a, float64 b);
265  
-flag __unorddf2(float64 a, float64 b)
266  
-{
267  
-	/*
268  
-	 * The comparison is unordered if either input is a NaN.
269  
-	 * Test for this by comparing each operand with itself.
270  
-	 * We must perform both comparisons to correctly check for
271  
-	 * signalling NaNs.
272  
-	 */
273  
-	return 1 ^ (float64_eq(a, a) & float64_eq(b, b));
274  
-}
627  software/libbase/softfloat-macros.h
... ...
@@ -1,627 +0,0 @@
1  
-
2  
-/*============================================================================
3  
-
4  
-This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
5  
-Arithmetic Package, Release 2b.
6  
-
7  
-Written by John R. Hauser.  This work was made possible in part by the
8  
-International Computer Science Institute, located at Suite 600, 1947 Center
9  
-Street, Berkeley, California 94704.  Funding was partially provided by the
10  
-National Science Foundation under grant MIP-9311980.  The original version
11  
-of this code was written as part of a project to build a fixed-point vector
12  
-processor in collaboration with the University of California at Berkeley,
13  
-overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
14  
-is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
15  
-arithmetic/SoftFloat.html'.
16  
-
17  
-THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort has
18  
-been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
19  
-RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
20  
-AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
21  
-COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
22  
-EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
23  
-INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
24  
-OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
25  
-
26  
-Derivative works are acceptable, even for commercial purposes, so long as
27  
-(1) the source code for the derivative work includes prominent notice that
28  
-the work is derivative, and (2) the source code includes prominent notice with
29  
-these four paragraphs for those parts of this code that are retained.
30  
-
31  
-=============================================================================*/
32  
-
33  
-/*----------------------------------------------------------------------------
34  
-| Shifts `a' right by the number of bits given in `count'.  If any nonzero
35  
-| bits are shifted off, they are ``jammed'' into the least significant bit of
36  
-| the result by setting the least significant bit to 1.  The value of `count'
37  
-| can be arbitrarily large; in particular, if `count' is greater than 32, the
38  
-| result will be either 0 or 1, depending on whether `a' is zero or nonzero.
39  
-| The result is stored in the location pointed to by `zPtr'.
40  
-*----------------------------------------------------------------------------*/
41  
-
42  
-INLINE void shift32RightJamming( bits32 a, int16 count, bits32 *zPtr )
43  
-{
44  
-    bits32 z;
45  
-
46  
-    if ( count == 0 ) {
47  
-        z = a;
48  
-    }
49  
-    else if ( count < 32 ) {
50  
-        z = ( a>>count ) | ( ( a<<( ( - count ) & 31 ) ) != 0 );
51  
-    }
52  
-    else {
53  
-        z = ( a != 0 );
54  
-    }
55  
-    *zPtr = z;
56  
-
57  
-}
58  
-
59  
-/*----------------------------------------------------------------------------
60  
-| Shifts the 64-bit value formed by concatenating `a0' and `a1' right by the
61  
-| number of bits given in `count'.  Any bits shifted off are lost.  The value
62  
-| of `count' can be arbitrarily large; in particular, if `count' is greater
63  
-| than 64, the result will be 0.  The result is broken into two 32-bit pieces
64  
-| which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.
65  
-*----------------------------------------------------------------------------*/
66  
-
67  
-INLINE void
68  
- shift64Right(
69  
-     bits32 a0, bits32 a1, int16 count, bits32 *z0Ptr, bits32 *z1Ptr )
70  
-{
71  
-    bits32 z0, z1;
72  
-    int8 negCount = ( - count ) & 31;
73  
-
74  
-    if ( count == 0 ) {
75  
-        z1 = a1;
76  
-        z0 = a0;
77  
-    }
78  
-    else if ( count < 32 ) {
79  
-        z1 = ( a0<<negCount ) | ( a1>>count );
80  
-        z0 = a0>>count;
81  
-    }
82  
-    else {
83  
-        z1 = ( count < 64 ) ? ( a0>>( count & 31 ) ) : 0;
84  
-        z0 = 0;
85  
-    }
86  
-    *z1Ptr = z1;
87  
-    *z0Ptr = z0;
88  
-
89  
-}
90  
-
91  
-/*----------------------------------------------------------------------------
92  
-| Shifts the 64-bit value formed by concatenating `a0' and `a1' right by the
93  
-| number of bits given in `count'.  If any nonzero bits are shifted off, they
94  
-| are ``jammed'' into the least significant bit of the result by setting the
95  
-| least significant bit to 1.  The value of `count' can be arbitrarily large;
96  
-| in particular, if `count' is greater than 64, the result will be either 0
97  
-| or 1, depending on whether the concatenation of `a0' and `a1' is zero or
98  
-| nonzero.  The result is broken into two 32-bit pieces which are stored at
99  
-| the locations pointed to by `z0Ptr' and `z1Ptr'.
100  
-*----------------------------------------------------------------------------*/
101  
-
102  
-INLINE void
103  
- shift64RightJamming(
104  
-     bits32 a0, bits32 a1, int16 count, bits32 *z0Ptr, bits32 *z1Ptr )
105  
-{
106  
-    bits32 z0, z1;
107  
-    int8 negCount = ( - count ) & 31;
108  
-
109  
-    if ( count == 0 ) {
110  
-        z1 = a1;
111  
-        z0 = a0;
112  
-    }
113  
-    else if ( count < 32 ) {
114  
-        z1 = ( a0<<negCount ) | ( a1>>count ) | ( ( a1<<negCount ) != 0 );
115  
-        z0 = a0>>count;
116  
-    }
117  
-    else {
118  
-        if ( count == 32 ) {
119  
-            z1 = a0 | ( a1 != 0 );
120  
-        }
121  
-        else if ( count < 64 ) {
122  
-            z1 = ( a0>>( count & 31 ) ) | ( ( ( a0<<negCount ) | a1 ) != 0 );
123  
-        }
124  
-        else {
125  
-            z1 = ( ( a0 | a1 ) != 0 );
126  
-        }
127  
-        z0 = 0;
128  
-    }
129  
-    *z1Ptr = z1;
130  
-    *z0Ptr = z0;
131  
-
132  
-}
133  
-
134  
-/*----------------------------------------------------------------------------
135  
-| Shifts the 96-bit value formed by concatenating `a0', `a1', and `a2' right
136  
-| by 32 _plus_ the number of bits given in `count'.  The shifted result is
137  
-| at most 64 nonzero bits; these are broken into two 32-bit pieces which are
138  
-| stored at the locations pointed to by `z0Ptr' and `z1Ptr'.  The bits shifted
139  
-| off form a third 32-bit result as follows:  The _last_ bit shifted off is
140  
-| the most-significant bit of the extra result, and the other 31 bits of the
141  
-| extra result are all zero if and only if _all_but_the_last_ bits shifted off
142  
-| were all zero.  This extra result is stored in the location pointed to by
143  
-| `z2Ptr'.  The value of `count' can be arbitrarily large.
144  
-|     (This routine makes more sense if `a0', `a1', and `a2' are considered
145  
-| to form a fixed-point value with binary point between `a1' and `a2'.  This
146  
-| fixed-point value is shifted right by the number of bits given in `count',
147  
-| and the integer part of the result is returned at the locations pointed to
148  
-| by `z0Ptr' and `z1Ptr'.  The fractional part of the result may be slightly
149  
-| corrupted as described above, and is returned at the location pointed to by
150  
-| `z2Ptr'.)
151  
-*----------------------------------------------------------------------------*/
152  
-
153  
-INLINE void
154  
- shift64ExtraRightJamming(
155  
-     bits32 a0,
156  
-     bits32 a1,
157  
-     bits32 a2,
158  
-     int16 count,
159  
-     bits32 *z0Ptr,
160  
-     bits32 *z1Ptr,
161  
-     bits32 *z2Ptr
162  
- )
163  
-{
164  
-    bits32 z0, z1, z2;
165  
-    int8 negCount = ( - count ) & 31;
166  
-
167  
-    if ( count == 0 ) {
168  
-        z2 = a2;
169  
-        z1 = a1;
170  
-        z0 = a0;
171  
-    }
172  
-    else {
173  
-        if ( count < 32 ) {
174  
-            z2 = a1<<negCount;
175  
-            z1 = ( a0<<negCount ) | ( a1>>count );
176  
-            z0 = a0>>count;
177  
-        }
178  
-        else {
179  
-            if ( count == 32 ) {
180  
-                z2 = a1;
181  
-                z1 = a0;
182  
-            }
183  
-            else {
184  
-                a2 |= a1;
185  
-                if ( count < 64 ) {
186  
-                    z2 = a0<<negCount;
187  
-                    z1 = a0>>( count & 31 );
188  
-                }
189  
-                else {
190  
-                    z2 = ( count == 64 ) ? a0 : ( a0 != 0 );
191  
-                    z1 = 0;
192  
-                }
193  
-            }
194  
-            z0 = 0;
195  
-        }
196  
-        z2 |= ( a2 != 0 );
197  
-    }
198  
-    *z2Ptr = z2;
199  
-    *z1Ptr = z1;
200  
-    *z0Ptr = z0;
201  
-
202  
-}
203  
-
204  
-/*----------------------------------------------------------------------------
205  
-| Shifts the 64-bit value formed by concatenating `a0' and `a1' left by the
206  
-| number of bits given in `count'.  Any bits shifted off are lost.  The value
207  
-| of `count' must be less than 32.  The result is broken into two 32-bit
208  
-| pieces which are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.
209  
-*----------------------------------------------------------------------------*/
210  
-
211  
-INLINE void
212  
- shortShift64Left(
213  
-     bits32 a0, bits32 a1, int16 count, bits32 *z0Ptr, bits32 *z1Ptr )
214  
-{
215  
-
216  
-    *z1Ptr = a1<<count;
217  
-    *z0Ptr =
218  
-        ( count == 0 ) ? a0 : ( a0<<count ) | ( a1>>( ( - count ) & 31 ) );
219  
-
220  
-}
221  
-
222  
-/*----------------------------------------------------------------------------
223  
-| Shifts the 96-bit value formed by concatenating `a0', `a1', and `a2' left
224  
-| by the number of bits given in `count'.  Any bits shifted off are lost.
225  
-| The value of `count' must be less than 32.  The result is broken into three
226  
-| 32-bit pieces which are stored at the locations pointed to by `z0Ptr',
227  
-| `z1Ptr', and `z2Ptr'.
228  
-*----------------------------------------------------------------------------*/
229  
-
230  
-INLINE void
231  
- shortShift96Left(
232  
-     bits32 a0,
233  
-     bits32 a1,
234  
-     bits32 a2,
235  
-     int16 count,
236  
-     bits32 *z0Ptr,
237  
-     bits32 *z1Ptr,
238  
-     bits32 *z2Ptr
239  
- )
240  
-{
241  
-    bits32 z0, z1, z2;
242  
-    int8 negCount;
243  
-
244  
-    z2 = a2<<count;
245  
-    z1 = a1<<count;
246  
-    z0 = a0<<count;
247  
-    if ( 0 < count ) {
248  
-        negCount = ( ( - count ) & 31 );
249  
-        z1 |= a2>>negCount;
250  
-        z0 |= a1>>negCount;
251  
-    }
252  
-    *z2Ptr = z2;
253  
-    *z1Ptr = z1;
254  
-    *z0Ptr = z0;
255  
-
256  
-}
257  
-
258  
-/*----------------------------------------------------------------------------
259  
-| Adds the 64-bit value formed by concatenating `a0' and `a1' to the 64-bit
260  
-| value formed by concatenating `b0' and `b1'.  Addition is modulo 2^64, so
261  
-| any carry out is lost.  The result is broken into two 32-bit pieces which
262  
-| are stored at the locations pointed to by `z0Ptr' and `z1Ptr'.
263  
-*----------------------------------------------------------------------------*/
264  
-
265  
-INLINE void
266  
- add64(
267  
-     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr )
268  
-{
269  
-    bits32 z1;
270  
-
271  
-    z1 = a1 + b1;
272  
-    *z1Ptr = z1;
273  
-    *z0Ptr = a0 + b0 + ( z1 < a1 );
274  
-
275  
-}
276  
-
277  
-/*----------------------------------------------------------------------------
278  
-| Adds the 96-bit value formed by concatenating `a0', `a1', and `a2' to the
279  
-| 96-bit value formed by concatenating `b0', `b1', and `b2'.  Addition is
280  
-| modulo 2^96, so any carry out is lost.  The result is broken into three
281  
-| 32-bit pieces which are stored at the locations pointed to by `z0Ptr',
282  
-| `z1Ptr', and `z2Ptr'.
283  
-*----------------------------------------------------------------------------*/
284  
-
285  
-INLINE void
286  
- add96(
287  
-     bits32 a0,
288  
-     bits32 a1,
289  
-     bits32 a2,
290  
-     bits32 b0,
291  
-     bits32 b1,
292  
-     bits32 b2,
293  
-     bits32 *z0Ptr,
294  
-     bits32 *z1Ptr,
295  
-     bits32 *z2Ptr
296  
- )
297  
-{
298  
-    bits32 z0, z1, z2;
299  
-    int8 carry0, carry1;
300  
-
301  
-    z2 = a2 + b2;
302  
-    carry1 = ( z2 < a2 );
303  
-    z1 = a1 + b1;
304  
-    carry0 = ( z1 < a1 );
305  
-    z0 = a0 + b0;
306  
-    z1 += carry1;
307  
-    z0 += ( z1 < carry1 );
308  
-    z0 += carry0;
309  
-    *z2Ptr = z2;
310  
-    *z1Ptr = z1;
311  
-    *z0Ptr = z0;
312  
-
313  
-}
314  
-
315  
-/*----------------------------------------------------------------------------
316  
-| Subtracts the 64-bit value formed by concatenating `b0' and `b1' from the
317  
-| 64-bit value formed by concatenating `a0' and `a1'.  Subtraction is modulo
318  
-| 2^64, so any borrow out (carry out) is lost.  The result is broken into two
319  
-| 32-bit pieces which are stored at the locations pointed to by `z0Ptr' and
320  
-| `z1Ptr'.
321  
-*----------------------------------------------------------------------------*/
322  
-
323  
-INLINE void
324  
- sub64(
325  
-     bits32 a0, bits32 a1, bits32 b0, bits32 b1, bits32 *z0Ptr, bits32 *z1Ptr )
326  
-{
327  
-
328  
-    *z1Ptr = a1 - b1;
329  
-    *z0Ptr = a0 - b0 - ( a1 < b1 );
330  
-
331  
-}
332  
-
333  
-/*----------------------------------------------------------------------------
334  
-| Subtracts the 96-bit value formed by concatenating `b0', `b1', and `b2' from
335  
-| the 96-bit value formed by concatenating `a0', `a1', and `a2'.  Subtraction
336  
-| is modulo 2^96, so any borrow out (carry out) is lost.  The result is broken
337  
-| into three 32-bit pieces which are stored at the locations pointed to by
338  
-| `z0Ptr', `z1Ptr', and `z2Ptr'.
339  
-*----------------------------------------------------------------------------*/
340  
-
341  
-INLINE void
342  
- sub96(
343  
-     bits32 a0,
344  
-     bits32 a1,
345  
-     bits32 a2,
346  
-     bits32 b0,
347  
-     bits32 b1,
348  
-     bits32 b2,
349  
-     bits32 *z0Ptr,
350  
-     bits32 *z1Ptr,
351  
-     bits32 *z2Ptr
352  
- )
353  
-{
354  
-    bits32 z0, z1, z2;
355  
-    int8 borrow0, borrow1;
356  
-
357  
-    z2 = a2 - b2;
358  
-    borrow1 = ( a2 < b2 );
359  
-    z1 = a1 - b1;
360  
-    borrow0 = ( a1 < b1 );
361  
-    z0 = a0 - b0;
362  
-    z0 -= ( z1 < borrow1 );
363  
-    z1 -= borrow1;
364  
-    z0 -= borrow0;
365  
-    *z2Ptr = z2;
366  
-    *z1Ptr = z1;
367  
-    *z0Ptr = z0;
368  
-
369  
-}
370  
-
371  
-/*----------------------------------------------------------------------------
372  
-| Multiplies `a' by `b' to obtain a 64-bit product.  The product is broken
373  
-| into two 32-bit pieces which are stored at the locations pointed to by
374  
-| `z0Ptr' and `z1Ptr'.
375  
-*----------------------------------------------------------------------------*/
376  
-
377  
-INLINE void mul32To64( bits32 a, bits32 b, bits32 *z0Ptr, bits32 *z1Ptr )
378  
-{
379  
-    bits16 aHigh, aLow, bHigh, bLow;
380  
-    bits32 z0, zMiddleA, zMiddleB, z1;
381  
-
382  
-    aLow = a;
383  
-    aHigh = a>>16;
384  
-    bLow = b;
385  
-    bHigh = b>>16;
386  
-    z1 = ( (bits32) aLow ) * bLow;
387  
-    zMiddleA = ( (bits32) aLow ) * bHigh;
388  
-    zMiddleB = ( (bits32) aHigh ) * bLow;
389  
-    z0 = ( (bits32) aHigh ) * bHigh;
390  
-    zMiddleA += zMiddleB;
391  
-    z0 += ( ( (bits32) ( zMiddleA < zMiddleB ) )<<16 ) + ( zMiddleA>>16 );
392  
-    zMiddleA <<= 16;
393  
-    z1 += zMiddleA;
394  
-    z0 += ( z1 < zMiddleA );
395  
-    *z1Ptr = z1;
396  
-    *z0Ptr = z0;
397  
-
398  
-}
399  
-
400  
-/*----------------------------------------------------------------------------
401  
-| Multiplies the 64-bit value formed by concatenating `a0' and `a1' by `b'
402  
-| to obtain a 96-bit product.  The product is broken into three 32-bit pieces
403  
-| which are stored at the locations pointed to by `z0Ptr', `z1Ptr', and
404  
-| `z2Ptr'.
405  
-*----------------------------------------------------------------------------*/
406  
-
407  
-INLINE void
408  
- mul64By32To96(
409  
-     bits32 a0,
410  
-     bits32 a1,
411  
-     bits32 b,
412  
-     bits32 *z0Ptr,
413  
-     bits32 *z1Ptr,
414  
-     bits32 *z2Ptr
415  
- )
416  
-{
417  
-    bits32 z0, z1, z2, more1;
418  
-
419  
-    mul32To64( a1, b, &z1, &z2 );
420  
-    mul32To64( a0, b, &z0, &more1 );
421  
-    add64( z0, more1, 0, z1, &z0, &z1 );
422  
-    *z2Ptr = z2;
423  
-    *z1Ptr = z1;
424  
-    *z0Ptr = z0;
425  
-
426  
-}
427  
-
428  
-/*----------------------------------------------------------------------------
429  
-| Multiplies the 64-bit value formed by concatenating `a0' and `a1' to the
430  
-| 64-bit value formed by concatenating `b0' and `b1' to obtain a 128-bit
431  
-| product.  The product is broken into four 32-bit pieces which are stored at
432  
-| the locations pointed to by `z0Ptr', `z1Ptr', `z2Ptr', and `z3Ptr'.
433  
-*----------------------------------------------------------------------------*/
434  
-
435  
-INLINE void
436  
- mul64To128(
437  
-     bits32 a0,
438  
-     bits32 a1,
439  
-     bits32 b0,
440  
-     bits32 b1,
441  
-     bits32 *z0Ptr,
442  
-     bits32 *z1Ptr,
443  
-     bits32 *z2Ptr,
444  
-     bits32 *z3Ptr
445  
- )
446  
-{
447  
-    bits32 z0, z1, z2, z3;
448  
-    bits32 more1, more2;
449  
-
450  
-    mul32To64( a1, b1, &z2, &z3 );
451  
-    mul32To64( a1, b0, &z1, &more2 );
452  
-    add64( z1, more2, 0, z2, &z1, &z2 );
453  
-    mul32To64( a0, b0, &z0, &more1 );
454  
-    add64( z0, more1, 0, z1, &z0, &z1 );
455  
-    mul32To64( a0, b1, &more1, &more2 );
456  
-    add64( more1, more2, 0, z2, &more1, &z2 );
457  
-    add64( z0, z1, 0, more1, &z0, &z1 );
458  
-    *z3Ptr = z3;
459  
-    *z2Ptr = z2;
460  
-    *z1Ptr = z1;
461  
-    *z0Ptr = z0;
462  
-
463  
-}
464  
-
465  
-/*----------------------------------------------------------------------------
466  
-| Returns an approximation to the 32-bit integer quotient obtained by dividing
467  
-| `b' into the 64-bit value formed by concatenating `a0' and `a1'.  The
468  
-| divisor `b' must be at least 2^31.  If q is the exact quotient truncated
469  
-| toward zero, the approximation returned lies between q and q + 2 inclusive.
470  
-| If the exact quotient q is larger than 32 bits, the maximum positive 32-bit
471  
-| unsigned integer is returned.
472  
-*----------------------------------------------------------------------------*/
473  
-
474  
-static bits32 estimateDiv64To32( bits32 a0, bits32 a1, bits32 b )
475  
-{
476  
-    bits32 b0, b1;
477  
-    bits32 rem0, rem1, term0, term1;
478  
-    bits32 z;
479  
-
480  
-    if ( b <= a0 ) return 0xFFFFFFFF;
481  
-    b0 = b>>16;
482  
-    z = ( b0<<16 <= a0 ) ? 0xFFFF0000 : ( a0 / b0 )<<16;
483  
-    mul32To64( b, z, &term0, &term1 );
484  
-    sub64( a0, a1, term0, term1, &rem0, &rem1 );
485  
-    while ( ( (sbits32) rem0 ) < 0 ) {
486  
-        z -= 0x10000;
487  
-        b1 = b<<16;
488  
-        add64( rem0, rem1, b0, b1, &rem0, &rem1 );
489  
-    }
490  
-    rem0 = ( rem0<<16 ) | ( rem1>>16 );
491  
-    z |= ( b0<<16 <= rem0 ) ? 0xFFFF : rem0 / b0;
492  
-    return z;
493  
-
494  
-}
495  
-
496  
-/*----------------------------------------------------------------------------
497  
-| Returns an approximation to the square root of the 32-bit significand given
498  
-| by `a'.  Considered as an integer, `a' must be at least 2^31.  If bit 0 of
499  
-| `aExp' (the least significant bit) is 1, the integer returned approximates
500  
-| 2^31*sqrt(`a'/2^31), where `a' is considered an integer.  If bit 0 of `aExp'
501  
-| is 0, the integer returned approximates 2^31*sqrt(`a'/2^30).  In either
502  
-| case, the approximation returned lies strictly within +/-2 of the exact
503  
-| value.
504  
-*----------------------------------------------------------------------------*/
505  
-
506  
-static bits32 estimateSqrt32( int16 aExp, bits32 a )
507  
-{
508  
-    static const bits16 sqrtOddAdjustments[] = {
509  
-        0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,
510  
-        0x039C, 0x0468, 0x0545, 0x0631, 0x072B, 0x0832, 0x0946, 0x0A67
511  
-    };
512  
-    static const bits16 sqrtEvenAdjustments[] = {
513  
-        0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E,
514  
-        0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002
515  
-    };
516  
-    int8 index;
517  
-    bits32 z;
518  
-
519  
-    index = ( a>>27 ) & 15;
520  
-    if ( aExp & 1 ) {
521  
-        z = 0x4000 + ( a>>17 ) - sqrtOddAdjustments[ index ];
522  
-        z = ( ( a / z )<<14 ) + ( z<<15 );
523  
-        a >>= 1;
524  
-    }
525  
-    else {
526  
-        z = 0x8000 + ( a>>17 ) - sqrtEvenAdjustments[ index ];
527  
-        z = a / z + z;
528  
-        z = ( 0x20000 <= z ) ? 0xFFFF8000 : ( z<<15 );
529  
-        if ( z <= a ) return (bits32) ( ( (sbits32) a )>>1 );
530  
-    }
531  
-    return ( ( estimateDiv64To32( a, 0, z ) )>>1 ) + ( z>>1 );
532  
-
533  
-}
534  
-
535  
-/*----------------------------------------------------------------------------
536  
-| Returns the number of leading 0 bits before the most-significant 1 bit of
537  
-| `a'.  If `a' is zero, 32 is returned.
538  
-*----------------------------------------------------------------------------*/
539  
-
540  
-static int8 countLeadingZeros32( bits32 a )
541  
-{
542  
-    static const int8 countLeadingZerosHigh[] = {
543  
-        8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
544  
-        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
545  
-        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
546  
-        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
547  
-        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
548  
-        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
549  
-        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
550  
-        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
551  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
552  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
553  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
554  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
555  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
556  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
557  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
558  
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
559  
-    };
560  
-    int8 shiftCount;
561  
-
562  
-    shiftCount = 0;
563  
-    if ( a < 0x10000 ) {
564  
-        shiftCount += 16;
565  
-        a <<= 16;
566  
-    }
567  
-    if ( a < 0x1000000 ) {
568  
-        shiftCount += 8;
569  
-        a <<= 8;
570  
-    }
571  
-    shiftCount += countLeadingZerosHigh[ a>>24 ];
572  
-    return shiftCount;
573  
-
574  
-}
575  
-
576  
-/*----------------------------------------------------------------------------
577  
-| Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is
578  
-| equal to the 64-bit value formed by concatenating `b0' and `b1'.  Otherwise,
579  
-| returns 0.
580  
-*----------------------------------------------------------------------------*/
581  
-
582  
-INLINE flag eq64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )
583  
-{
584  
-
585  
-    return ( a0 == b0 ) && ( a1 == b1 );
586  
-
587  
-}
588  
-
589  
-/*----------------------------------------------------------------------------
590  
-| Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is less
591  
-| than or equal to the 64-bit value formed by concatenating `b0' and `b1'.
592  
-| Otherwise, returns 0.
593  
-*----------------------------------------------------------------------------*/
594  
-
595  
-INLINE flag le64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )
596  
-{
597  
-
598  
-    return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 <= b1 ) );
599  
-
600  
-}
601  
-
602  
-/*----------------------------------------------------------------------------
603  
-| Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is less
604  
-| than the 64-bit value formed by concatenating `b0' and `b1'.  Otherwise,
605  
-| returns 0.
606  
-*----------------------------------------------------------------------------*/
607  
-
608  
-INLINE flag lt64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )
609  
-{
610  
-
611  
-    return ( a0 < b0 ) || ( ( a0 == b0 ) && ( a1 < b1 ) );
612  
-
613  
-}
614  
-
615  
-/*----------------------------------------------------------------------------
616  
-| Returns 1 if the 64-bit value formed by concatenating `a0' and `a1' is not
617  
-| equal to the 64-bit value formed by concatenating `b0' and `b1'.  Otherwise,
618  
-| returns 0.
619  
-*----------------------------------------------------------------------------*/
620  
-
621  
-INLINE flag ne64( bits32 a0, bits32 a1, bits32 b0, bits32 b1 )
622  
-{
623  
-
624  
-    return ( a0 != b0 ) || ( a1 != b1 );
625  
-
626  
-}
627  
-
242  software/libbase/softfloat-specialize.h
... ...
@@ -1,242 +0,0 @@
1  
-
2  
-/*============================================================================
3  
-
4  
-This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
5  
-Arithmetic Package, Release 2b.
6  
-
7  
-Written by John R. Hauser.  This work was made possible in part by the
8  
-International Computer Science Institute, located at Suite 600, 1947 Center
9  
-Street, Berkeley, California 94704.  Funding was partially provided by the
10  
-National Science Foundation under grant MIP-9311980.  The original version
11  
-of this code was written as part of a project to build a fixed-point vector
12  
-processor in collaboration with the University of California at Berkeley,
13  
-overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
14  
-is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
15  
-arithmetic/SoftFloat.html'.
16  
-
17  
-THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort has
18  
-been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
19  
-RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
20  
-AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
21  
-COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
22  
-EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
23  
-INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
24  
-OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
25  
-
26  
-Derivative works are acceptable, even for commercial purposes, so long as
27  
-(1) the source code for the derivative work includes prominent notice that
28  
-the work is derivative, and (2) the source code includes prominent notice with
29  
-these four paragraphs for those parts of this code that are retained.
30  
-
31  
-=============================================================================*/
32  
-
33  
-/*----------------------------------------------------------------------------
34  
-| Underflow tininess-detection mode, statically initialized to default value.
35  
-| (The declaration in `softfloat.h' must match the `int8' type here.)
36  
-*----------------------------------------------------------------------------*/
37  
-int8 float_detect_tininess = float_tininess_after_rounding;
38  
-
39  
-/*----------------------------------------------------------------------------
40  
-| Raises the exceptions specified by `flags'.  Floating-point traps can be
41  
-| defined here if desired.  It is currently not possible for such a trap
42  
-| to substitute a result value.  If traps are not implemented, this routine
43  
-| should be simply `float_exception_flags |= flags;'.
44  
-*----------------------------------------------------------------------------*/
45  
-
46  
-void float_raise( int8 flags )
47  
-{
48  
-
49  
-    float_exception_flags |= flags;
50  
-
51  
-}
52  
-
53  
-/*----------------------------------------------------------------------------
54  
-| Internal canonical NaN format.
55  
-*----------------------------------------------------------------------------*/
56  
-typedef struct {
57  
-    flag sign;
58  
-    bits32 high, low;
59  
-} commonNaNT;
60  
-
61  
-/*----------------------------------------------------------------------------
62  
-| The pattern for a default generated single-precision NaN.
63  
-*----------------------------------------------------------------------------*/
64  
-enum {
65  
-    float32_default_nan = 0xFFFFFFFF
66  
-};
67  
-
68  
-/*----------------------------------------------------------------------------
69  
-| Returns 1 if the single-precision floating-point value `a' is a NaN;
70  
-| otherwise returns 0.
71  
-*----------------------------------------------------------------------------*/
72  
-
73  
-flag float32_is_nan( float32 a )
74  
-{
75  
-
76  
-    return ( 0xFF000000 < (bits32) ( a<<1 ) );
77  
-
78  
-}
79  
-
80  
-/*----------------------------------------------------------------------------
81  
-| Returns 1 if the single-precision floating-point value `a' is a signaling
82  
-| NaN; otherwise returns 0.
83  
-*----------------------------------------------------------------------------*/
84  
-
85  
-flag float32_is_signaling_nan( float32 a )
86  
-{
87  
-
88  
-    return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
89  
-
90  
-}
91  
-
92  
-/*----------------------------------------------------------------------------
93  
-| Returns the result of converting the single-precision floating-point NaN
94  
-| `a' to the canonical NaN format.  If `a' is a signaling NaN, the invalid
95  
-| exception is raised.
96  
-*----------------------------------------------------------------------------*/
97  
-
98  
-static commonNaNT float32ToCommonNaN( float32 a )
99  
-{
100  
-    commonNaNT z;
101  
-
102  
-    if ( float32_is_signaling_nan( a ) ) float_raise( float_flag_invalid );
103  
-    z.sign = a>>31;
104  
-    z.low = 0;
105  
-    z.high = a<<9;
106  
-    return z;
107  
-
108  
-}
109  
-
110  
-/*----------------------------------------------------------------------------
111  
-| Returns the result of converting the canonical NaN `a' to the single-
112  
-| precision floating-point format.
113  
-*----------------------------------------------------------------------------*/
114  
-
115  
-static float32 commonNaNToFloat32( commonNaNT a )
116  
-{
117  
-
118  
-    return ( ( (bits32) a.sign )<<31 ) | 0x7FC00000 | ( a.high>>9 );
119  
-
120  
-}
121  
-
122  
-/*----------------------------------------------------------------------------
123  
-| Takes two single-precision floating-point values `a' and `b', one of which
124  
-| is a NaN, and returns the appropriate NaN result.  If either `a' or `b' is a
125  
-| signaling NaN, the invalid exception is raised.
126  
-*----------------------------------------------------------------------------*/
127  
-
128  
-static float32 propagateFloat32NaN( float32 a, float32 b )
129  
-{
130  
-    flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
131  
-
132