xdr_float.c (0cc39166733d7a7eee94bd8aa573237a90d9838e) xdr_float.c (1ad08a09e9732e9e6e44f069c55f4abe27ed392a)
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC";*/
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC";*/
33static char *rcsid = "$Id: xdr_float.c,v 1.1 1993/10/27 05:41:10 paul Exp $";
33static char *rcsid = "$Id: xdr_float.c,v 1.2 1995/05/30 05:42:04 rgrimes Exp $";
34#endif
35
36/*
37 * xdr_float.c, Generic XDR routines impelmentation.
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * These are the "floating point" xdr routines used to (de)serialize

--- 4 unchanged lines hidden (view full) ---

46#include <stdio.h>
47#include <sys/types.h>
48#include <sys/param.h>
49#include <rpc/types.h>
50#include <rpc/xdr.h>
51
52/*
53 * NB: Not portable.
34#endif
35
36/*
37 * xdr_float.c, Generic XDR routines impelmentation.
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * These are the "floating point" xdr routines used to (de)serialize

--- 4 unchanged lines hidden (view full) ---

46#include <stdio.h>
47#include <sys/types.h>
48#include <sys/param.h>
49#include <rpc/types.h>
50#include <rpc/xdr.h>
51
52/*
53 * NB: Not portable.
54 * This routine works on Suns (Sky / 68000's), i386's, MIPS, NS32k and Vaxen.
54 * This routine works on machines with IEEE754 FP and Vaxen.
55 */
56
55 */
56
57#if defined(mc68000)||defined(sparc)||defined(i386)||defined(mips)||defined(ns32000)
57#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \
58 defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \
59 defined(__arm32__) || defined(__ppc__)
60#include <machine/endian.h>
58#define IEEEFP
59#endif
60
61#ifdef vax
62
63/* What IEEE single precision floating point looks like on a Vax */
64struct ieee_single {
65 unsigned int mantissa: 23;

--- 23 unchanged lines hidden (view full) ---

89};
90#endif /* vax */
91
92bool_t
93xdr_float(xdrs, fp)
94 register XDR *xdrs;
95 register float *fp;
96{
61#define IEEEFP
62#endif
63
64#ifdef vax
65
66/* What IEEE single precision floating point looks like on a Vax */
67struct ieee_single {
68 unsigned int mantissa: 23;

--- 23 unchanged lines hidden (view full) ---

92};
93#endif /* vax */
94
95bool_t
96xdr_float(xdrs, fp)
97 register XDR *xdrs;
98 register float *fp;
99{
97#ifndef IEEEFP
100#ifdef IEEEFP
101 bool_t rv;
102 long tmpl;
103#else
98 struct ieee_single is;
99 struct vax_single vs, *vsp;
100 struct sgl_limits *lim;
101 int i;
102#endif
103 switch (xdrs->x_op) {
104
105 case XDR_ENCODE:
104 struct ieee_single is;
105 struct vax_single vs, *vsp;
106 struct sgl_limits *lim;
107 int i;
108#endif
109 switch (xdrs->x_op) {
110
111 case XDR_ENCODE:
106#ifdef IEEEFP
107 return (XDR_PUTLONG(xdrs, (long *)fp));
112#ifdef IEEEFP
113 tmpl = *(int32_t *)fp;
114 return (XDR_PUTLONG(xdrs, &tmpl));
108#else
109 vs = *((struct vax_single *)fp);
110 for (i = 0, lim = sgl_limits;
111 i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
112 i++, lim++) {
113 if ((vs.mantissa2 == lim->s.mantissa2) &&
114 (vs.exp == lim->s.exp) &&
115 (vs.mantissa1 == lim->s.mantissa1)) {

--- 5 unchanged lines hidden (view full) ---

121 is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
122 shipit:
123 is.sign = vs.sign;
124 return (XDR_PUTLONG(xdrs, (long *)&is));
125#endif
126
127 case XDR_DECODE:
128#ifdef IEEEFP
115#else
116 vs = *((struct vax_single *)fp);
117 for (i = 0, lim = sgl_limits;
118 i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
119 i++, lim++) {
120 if ((vs.mantissa2 == lim->s.mantissa2) &&
121 (vs.exp == lim->s.exp) &&
122 (vs.mantissa1 == lim->s.mantissa1)) {

--- 5 unchanged lines hidden (view full) ---

128 is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
129 shipit:
130 is.sign = vs.sign;
131 return (XDR_PUTLONG(xdrs, (long *)&is));
132#endif
133
134 case XDR_DECODE:
135#ifdef IEEEFP
129 return (XDR_GETLONG(xdrs, (long *)fp));
136 rv = XDR_GETLONG(xdrs, &tmpl);
137 *(int32_t *)fp = tmpl;
138 return (rv);
130#else
131 vsp = (struct vax_single *)fp;
132 if (!XDR_GETLONG(xdrs, (long *)&is))
133 return (FALSE);
134 for (i = 0, lim = sgl_limits;
135 i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
136 i++, lim++) {
137 if ((is.exp == lim->ieee.exp) &&

--- 11 unchanged lines hidden (view full) ---

149#endif
150
151 case XDR_FREE:
152 return (TRUE);
153 }
154 return (FALSE);
155}
156
139#else
140 vsp = (struct vax_single *)fp;
141 if (!XDR_GETLONG(xdrs, (long *)&is))
142 return (FALSE);
143 for (i = 0, lim = sgl_limits;
144 i < sizeof(sgl_limits)/sizeof(struct sgl_limits);
145 i++, lim++) {
146 if ((is.exp == lim->ieee.exp) &&

--- 11 unchanged lines hidden (view full) ---

158#endif
159
160 case XDR_FREE:
161 return (TRUE);
162 }
163 return (FALSE);
164}
165
157/*
158 * This routine works on Suns (Sky / 68000's), i386's, MIPS and Vaxen.
159 */
160
161#ifdef vax
162/* What IEEE double precision floating point looks like on a Vax */
163struct ieee_double {
164 unsigned int mantissa1 : 20;
165 unsigned int exp : 11;
166 unsigned int sign : 1;
167 unsigned int mantissa2 : 32;
168};

--- 25 unchanged lines hidden (view full) ---

194#endif /* vax */
195
196
197bool_t
198xdr_double(xdrs, dp)
199 register XDR *xdrs;
200 double *dp;
201{
166#ifdef vax
167/* What IEEE double precision floating point looks like on a Vax */
168struct ieee_double {
169 unsigned int mantissa1 : 20;
170 unsigned int exp : 11;
171 unsigned int sign : 1;
172 unsigned int mantissa2 : 32;
173};

--- 25 unchanged lines hidden (view full) ---

199#endif /* vax */
200
201
202bool_t
203xdr_double(xdrs, dp)
204 register XDR *xdrs;
205 double *dp;
206{
207#ifdef IEEEFP
208 register int32_t *i32p;
209 bool_t rv;
210 long tmpl;
211#else
202 register long *lp;
212 register long *lp;
203#ifndef IEEEFP
204 struct ieee_double id;
205 struct vax_double vd;
206 register struct dbl_limits *lim;
207 int i;
208#endif
209
210 switch (xdrs->x_op) {
211
212 case XDR_ENCODE:
213#ifdef IEEEFP
213 struct ieee_double id;
214 struct vax_double vd;
215 register struct dbl_limits *lim;
216 int i;
217#endif
218
219 switch (xdrs->x_op) {
220
221 case XDR_ENCODE:
222#ifdef IEEEFP
214 lp = (long *)dp;
223 i32p = (int32_t *)dp;
215#if BYTE_ORDER == BIG_ENDIAN
224#if BYTE_ORDER == BIG_ENDIAN
216 return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
225 tmpl = *i32p++;
226 rv = XDR_PUTLONG(xdrs, &tmpl);
227 if (!rv)
228 return (rv);
229 tmpl = *i32p;
230 rv = XDR_PUTLONG(xdrs, &tmpl);
217#else
231#else
218 return (XDR_PUTLONG(xdrs, lp+1) && XDR_PUTLONG(xdrs, lp));
232 tmpl = *(i32p+1);
233 rv = XDR_PUTLONG(xdrs, &tmpl);
234 if (!rv)
235 return (rv);
236 tmpl = *i32p;
237 rv = XDR_PUTLONG(xdrs, &tmpl);
219#endif
238#endif
239 return (rv);
220#else
221 vd = *((struct vax_double *)dp);
222 for (i = 0, lim = dbl_limits;
223 i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
224 i++, lim++) {
225 if ((vd.mantissa4 == lim->d.mantissa4) &&
226 (vd.mantissa3 == lim->d.mantissa3) &&
227 (vd.mantissa2 == lim->d.mantissa2) &&

--- 11 unchanged lines hidden (view full) ---

239 shipit:
240 id.sign = vd.sign;
241 lp = (long *)&id;
242 return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
243#endif
244
245 case XDR_DECODE:
246#ifdef IEEEFP
240#else
241 vd = *((struct vax_double *)dp);
242 for (i = 0, lim = dbl_limits;
243 i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
244 i++, lim++) {
245 if ((vd.mantissa4 == lim->d.mantissa4) &&
246 (vd.mantissa3 == lim->d.mantissa3) &&
247 (vd.mantissa2 == lim->d.mantissa2) &&

--- 11 unchanged lines hidden (view full) ---

259 shipit:
260 id.sign = vd.sign;
261 lp = (long *)&id;
262 return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
263#endif
264
265 case XDR_DECODE:
266#ifdef IEEEFP
247 lp = (long *)dp;
267 i32p = (int32_t *)dp;
248#if BYTE_ORDER == BIG_ENDIAN
268#if BYTE_ORDER == BIG_ENDIAN
249 return (XDR_GETLONG(xdrs, lp++) && XDR_GETLONG(xdrs, lp));
269 rv = XDR_GETLONG(xdrs, &tmpl);
270 *i32p++ = tmpl;
271 if (!rv)
272 return (rv);
273 rv = XDR_GETLONG(xdrs, &tmpl);
274 *i32p = tmpl;
250#else
275#else
251 return (XDR_GETLONG(xdrs, lp+1) && XDR_GETLONG(xdrs, lp));
276 rv = XDR_GETLONG(xdrs, &tmpl);
277 *(i32p+1) = tmpl;
278 if (!rv)
279 return (rv);
280 rv = XDR_GETLONG(xdrs, &tmpl);
281 *i32p = tmpl;
252#endif
282#endif
283 return (rv);
253#else
254 lp = (long *)&id;
255 if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))
256 return (FALSE);
257 for (i = 0, lim = dbl_limits;
258 i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
259 i++, lim++) {
260 if ((id.mantissa2 == lim->ieee.mantissa2) &&

--- 23 unchanged lines hidden ---
284#else
285 lp = (long *)&id;
286 if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))
287 return (FALSE);
288 for (i = 0, lim = dbl_limits;
289 i < sizeof(dbl_limits)/sizeof(struct dbl_limits);
290 i++, lim++) {
291 if ((id.mantissa2 == lim->ieee.mantissa2) &&

--- 23 unchanged lines hidden ---