3 * Copyright (c) 2009, Sun Microsystems, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * - Neither the name of Sun Microsystems, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
31 * xdr_float_vax.c, XDR floating point routines for vax.
33 * Copyright (C) 1984, Sun Microsystems, Inc.
35 * These are the "floating point" xdr routines used to (de)serialize
36 * most common data items. See xdr.h for more info on the interface to
40 #error "Must be included from xdr_float.c"
43 /* What IEEE single precision floating point looks like on a Vax */
46 unsigned int mantissa
:23;
51 /* Vax single precision floating point */
54 unsigned int mantissa1
:7;
57 unsigned int mantissa2
:16;
60 # define VAX_SNG_BIAS 0x81
61 # define IEEE_SNG_BIAS 0x7f
65 static struct sgl_limits
68 struct ieee_single ieee
;
72 {0x7f, 0xff, 0x0, 0xffff}, /* Max Vax */
73 {0x0, 0xff, 0x0} /* Max IEEE */
76 {0x0, 0x0, 0x0, 0x0}, /* Min Vax */
77 {0x0, 0x0, 0x0} /* Min IEEE */
84 xdr_float (XDR
* xdrs
,
87 struct ieee_single is
;
88 struct vax_single vs
, *vsp
;
89 struct sgl_limits
*lim
;
95 vs
= *((struct vax_single
*) fp
);
96 for (i
= 0, lim
= sgl_limits
;
97 i
< sizeof (sgl_limits
) / sizeof (struct sgl_limits
); i
++, lim
++)
99 if ((vs
.mantissa2
== lim
->s
.mantissa2
) &&
100 (vs
.exp
== lim
->s
.exp
) && (vs
.mantissa1
== lim
->s
.mantissa1
))
106 is
.exp
= vs
.exp
- VAX_SNG_BIAS
+ IEEE_SNG_BIAS
;
107 is
.mantissa
= (vs
.mantissa1
<< 16) | vs
.mantissa2
;
110 return (XDR_PUTINT32 (xdrs
, (int32_t *) & is
));
113 vsp
= (struct vax_single
*) fp
;
114 if (!XDR_GETINT32 (xdrs
, (int32_t *) & is
))
116 for (i
= 0, lim
= sgl_limits
;
117 i
< sizeof (sgl_limits
) / sizeof (struct sgl_limits
); i
++, lim
++)
119 if ((is
.exp
== lim
->ieee
.exp
) &&
120 (is
.mantissa
== lim
->ieee
.mantissa
))
126 vsp
->exp
= is
.exp
- IEEE_SNG_BIAS
+ VAX_SNG_BIAS
;
127 vsp
->mantissa2
= is
.mantissa
;
128 vsp
->mantissa1
= (is
.mantissa
>> 16);
139 #if !defined(_DOUBLE_IS_32BITS)
141 /* What IEEE double precision floating point looks like on a Vax */
144 unsigned int mantissa1
:20;
147 unsigned int mantissa2
:32;
150 /* Vax double precision floating point */
153 unsigned int mantissa1
:7;
156 unsigned int mantissa2
:16;
157 unsigned int mantissa3
:16;
158 unsigned int mantissa4
:16;
161 # define VAX_DBL_BIAS 0x81
162 # define IEEE_DBL_BIAS 0x3ff
163 # define MASK(nbits) ((1 << nbits) - 1)
167 static struct dbl_limits
170 struct ieee_double ieee
;
174 {0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff}, /* Max Vax */
175 {0x0, 0x7ff, 0x0, 0x0} /* Max IEEE */
178 {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* Min Vax */
179 {0x0, 0x0, 0x0, 0x0} /* Min IEEE */
186 xdr_double (XDR
* xdrs
,
190 struct ieee_double id
;
191 struct vax_double vd
;
192 struct dbl_limits
*lim
;
199 vd
= *((struct vax_double
*) dp
);
200 for (i
= 0, lim
= dbl_limits
;
201 i
< sizeof (dbl_limits
) / sizeof (struct dbl_limits
); i
++, lim
++)
203 if ((vd
.mantissa4
== lim
->d
.mantissa4
) &&
204 (vd
.mantissa3
== lim
->d
.mantissa3
) &&
205 (vd
.mantissa2
== lim
->d
.mantissa2
) &&
206 (vd
.mantissa1
== lim
->d
.mantissa1
) && (vd
.exp
== lim
->d
.exp
))
212 id
.exp
= vd
.exp
- VAX_DBL_BIAS
+ IEEE_DBL_BIAS
;
213 id
.mantissa1
= (vd
.mantissa1
<< 13) | (vd
.mantissa2
>> 3);
214 id
.mantissa2
= ((vd
.mantissa2
& MASK (3)) << 29) |
215 (vd
.mantissa3
<< 13) | ((vd
.mantissa4
>> 3) & MASK (13));
218 lp
= (int32_t *) & id
;
219 return (XDR_PUTINT32 (xdrs
, lp
++) && XDR_PUTINT32 (xdrs
, lp
));
222 lp
= (int32_t *) & id
;
223 if (!XDR_GETINT32 (xdrs
, lp
++) || !XDR_GETINT32 (xdrs
, lp
))
225 for (i
= 0, lim
= dbl_limits
;
226 i
< sizeof (dbl_limits
) / sizeof (struct dbl_limits
); i
++, lim
++)
228 if ((id
.mantissa2
== lim
->ieee
.mantissa2
) &&
229 (id
.mantissa1
== lim
->ieee
.mantissa1
) &&
230 (id
.exp
== lim
->ieee
.exp
))
236 vd
.exp
= id
.exp
- IEEE_DBL_BIAS
+ VAX_DBL_BIAS
;
237 vd
.mantissa1
= (id
.mantissa1
>> 13);
238 vd
.mantissa2
= ((id
.mantissa1
& MASK (13)) << 3) | (id
.mantissa2
>> 29);
239 vd
.mantissa3
= (id
.mantissa2
>> 13);
240 vd
.mantissa4
= (id
.mantissa2
<< 3);
243 *dp
= *((double *) &vd
);
251 #endif /* !_DOUBLE_IS_32BITS */