Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. 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
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 43... Line 73...
43
 
73
 
44
 
74
 
45
#include <stdio.h>
75
#include <stdio.h>
46
#include "ossg.h"
76
#include "ossg.h"
47
 
77
 
48
#if defined (__TenDRA__)
78
#if defined(__TenDRA__)
49
#include "abstract.h"
79
#include "abstract.h"
50
#else
80
#else
51
#include "concrete.h"
81
#include "concrete.h"
52
#endif  /* defined(__TenDRA__) */
82
#endif  /* defined(__TenDRA__) */
53
 
83
 
54
 
84
 
55
#undef STATIC
85
#undef STATIC
56
#ifndef DEBUG
86
#ifndef DEBUG
57
#define STATIC static
87
#define STATIC static
58
#else
88
#else
59
#define STATIC
89
#define STATIC
60
#endif  /* ndef DEBUG */
90
#endif  /* ndef DEBUG */
61
 
91
 
62
#define UINT32_const(X) ((UINT32) (X))
92
#define UINT32_const(X)((UINT32)(X))
63
 
93
 
64
 
94
 
65
/* Error Treatments handling */
95
/* Error Treatments handling */
66
 
96
 
67
int __TDFerror;
97
int __TDFerror;
Line 76... Line 106...
76
 
106
 
77
 
107
 
78
 
108
 
79
/* Declarations of functions used internally */
109
/* Declarations of functions used internally */
80
 
110
 
81
static TDF_INT64	TDFUplus	PROTO_S ((TDF_INT64, TDF_INT64));
111
static TDF_INT64	TDFUplus(TDF_INT64, TDF_INT64);
82
static TDF_INT64	TDFUminus	PROTO_S ((TDF_INT64, TDF_INT64));
112
static TDF_INT64	TDFUminus(TDF_INT64, TDF_INT64);
83
static TDF_INT64	TDFUmult	PROTO_S ((TDF_INT64, TDF_INT64));
113
static TDF_INT64	TDFUmult(TDF_INT64, TDF_INT64);
84
static TDF_INT64	TDFUdiv_rem	PROTO_S ((TDF_INT64, TDF_INT64, UINT32));
114
static TDF_INT64	TDFUdiv_rem(TDF_INT64, TDF_INT64, UINT32);
85
static TDF_INT64	TDFUshr		PROTO_S ((TDF_INT64, UINT32));
115
static TDF_INT64	TDFUshr(TDF_INT64, UINT32);
86
 
116
 
87
 
117
 
88
 
118
 
89
/* Declarations of DEBUG functions */
119
/* Declarations of DEBUG functions */
90
 
120
 
91
#if DEBUG
121
#if DEBUG
92
INT64	make_INT64	PROTO_S ((INT32, UINT32));
122
INT64	make_INT64(INT32, UINT32);
93
UINT64	make_UINT64	PROTO_S ((UINT32, UINT32));
123
UINT64	make_UINT64(UINT32, UINT32);
94
void 	INT64_print	PROTO_S ((char *,  INT64, char *));
124
void 	INT64_print(char *,  INT64, char *);
95
void	UINT64_print	PROTO_S ((char *, UINT64, char *));
125
void	UINT64_print(char *, UINT64, char *);
96
#endif
126
#endif
97
 
127
 
98
 
128
 
99
/*  Forward declarations  */
129
/*  Forward declarations  */
100
 
130
 
101
INT64	__TDFUs_plus	PROTO_S ((INT64, INT64));
131
INT64	__TDFUs_plus(INT64, INT64);
102
INT64	__TDFUs_minus	PROTO_S ((INT64, INT64));
132
INT64	__TDFUs_minus(INT64, INT64);
103
INT64	__TDFUs_mult	PROTO_S ((INT64, INT64));
133
INT64	__TDFUs_mult(INT64, INT64);
104
INT64	__TDFUs_div1	PROTO_S ((INT64, INT64));
134
INT64	__TDFUs_div1(INT64, INT64);
105
INT64	__TDFUs_div2	PROTO_S ((INT64, INT64));
135
INT64	__TDFUs_div2(INT64, INT64);
106
INT64	__TDFUs_rem1	PROTO_S ((INT64, INT64));
136
INT64	__TDFUs_rem1(INT64, INT64);
107
INT64	__TDFUs_rem2	PROTO_S ((INT64, INT64));
137
INT64	__TDFUs_rem2(INT64, INT64);
108
INT64	__TDFUneg	PROTO_S ((INT64));
138
INT64	__TDFUneg(INT64);
109
INT64	__TDFUabs	PROTO_S ((INT64));
139
INT64	__TDFUabs(INT64);
110
INT64	__TDFUsswiden	PROTO_S ((INT32));
140
INT64	__TDFUsswiden(INT32);
111
INT64	__TDFUuswiden	PROTO_S ((UINT32));
141
INT64	__TDFUuswiden(UINT32);
112
INT32	__TDFUssshorten	PROTO_S ((INT64));
142
INT32	__TDFUssshorten(INT64);
113
INT32	__TDFUusshorten	PROTO_S ((UINT64));
143
INT32	__TDFUusshorten(UINT64);
114
INT64	__TDFUu642s64	PROTO_S ((UINT64));
144
INT64	__TDFUu642s64(UINT64);
115
INT64	__TDFUs_max	PROTO_S ((INT64, INT64));
145
INT64	__TDFUs_max(INT64, INT64);
116
INT64	__TDFUs_min	PROTO_S ((INT64, INT64));
146
INT64	__TDFUs_min(INT64, INT64);
117
int	__TDFUs_test	PROTO_S ((INT64, INT64));
147
int	__TDFUs_test(INT64, INT64);
118
 
148
 
119
UINT64	__TDFUu_plus	PROTO_S ((UINT64, UINT64));
149
UINT64	__TDFUu_plus(UINT64, UINT64);
120
UINT64	__TDFUu_minus	PROTO_S ((UINT64, UINT64));
150
UINT64	__TDFUu_minus(UINT64, UINT64);
121
UINT64	__TDFUu_mult	PROTO_S ((UINT64, UINT64));
151
UINT64	__TDFUu_mult(UINT64, UINT64);
122
UINT64	__TDFUu_div2	PROTO_S ((UINT64, UINT64));
152
UINT64	__TDFUu_div2(UINT64, UINT64);
123
UINT64	__TDFUu_rem2	PROTO_S ((UINT64, UINT64));
153
UINT64	__TDFUu_rem2(UINT64, UINT64);
124
UINT64	__TDFUu_shl	PROTO_S ((UINT64, UINT32));
154
UINT64	__TDFUu_shl(UINT64, UINT32);
125
UINT64	__TDFUu_shr	PROTO_S ((UINT64, UINT32));
155
UINT64	__TDFUu_shr(UINT64, UINT32);
126
UINT64	__TDFUuuwiden	PROTO_S ((UINT32));
156
UINT64	__TDFUuuwiden(UINT32);
127
UINT64	__TDFUsuwiden	PROTO_S ((INT32));
157
UINT64	__TDFUsuwiden(INT32);
128
UINT32	__TDFUsushorten	PROTO_S ((INT64));
158
UINT32	__TDFUsushorten(INT64);
129
UINT32	__TDFUuushorten	PROTO_S ((UINT64));
159
UINT32	__TDFUuushorten(UINT64);
130
UINT64	__TDFUs642u64	PROTO_S ((INT64));
160
UINT64	__TDFUs642u64(INT64);
131
UINT64	__TDFUu_max	PROTO_S ((UINT64, UINT64));
161
UINT64	__TDFUu_max(UINT64, UINT64);
132
UINT64	__TDFUu_min	PROTO_S ((UINT64, UINT64));
162
UINT64	__TDFUu_min(UINT64, UINT64);
133
int	__TDFUu_test	PROTO_S ((UINT64, UINT64));
163
int	__TDFUu_test(UINT64, UINT64);
134
UINT64	__TDFUand	PROTO_S ((UINT64, UINT64));
164
UINT64	__TDFUand(UINT64, UINT64);
135
UINT64	__TDFUor	PROTO_S ((UINT64, UINT64));
165
UINT64	__TDFUor(UINT64, UINT64);
136
UINT64	__TDFUxor	PROTO_S ((UINT64, UINT64));
166
UINT64	__TDFUxor(UINT64, UINT64);
137
UINT64	__TDFUnot	PROTO_S ((UINT64));
167
UINT64	__TDFUnot(UINT64);
138
 
168
 
139
 
169
 
140
 
170
 
141
#define TDFUis_positive(X)	((hi_32(X) >= 0))
171
#define TDFUis_positive(X)	((hi_32(X) >= 0))
142
#define TDFUis_negative(X)	((hi_32(X) < 0))
172
#define TDFUis_negative(X)	((hi_32(X) < 0))
143
#define TDFUis_zero(X)		((hi_32(X) == 0) && (lo_32(X) == 0))
173
#define TDFUis_zero(X)		((hi_32(X) == 0) && (lo_32(X) == 0))
144
#define TDFUis_nonzero(X)	((hi_32(X) != 0) || (lo_32(X) != 0))
174
#define TDFUis_nonzero(X)	((hi_32(X)!= 0) || (lo_32(X)!= 0))
145
 
175
 
146
 
176
 
147
/*
177
/*
148
** 	TDFUshl:
178
** 	TDFUshl:
149
**
179
**
Line 168... Line 198...
168
**  defined using the macro which produces the definition
198
**  defined using the macro which produces the definition
169
**  of the TDF token !!!  Got it ???
199
**  of the TDF token !!!  Got it ???
170
*/
200
*/
171
 
201
 
172
 
202
 
173
#define _TDFUshl(shifted_a,a,n) \
203
#define _TDFUshl(shifted_a,a,n)\
174
{ \
204
{ \
175
    if (n > 32)		/* assuming n <= 64 */ \
205
    if (n > 32)		/* assuming n <= 64 */ \
176
    { \
206
    { \
177
	hi_u32 (shifted_a) = lo_u32(a) << (n -32); \
207
	hi_u32(shifted_a) = lo_u32(a) << (n -32); \
178
	lo_u32 (shifted_a) = (UINT32) 0x00000000; \
208
	lo_u32(shifted_a) = (UINT32)0x00000000; \
179
    } \
209
    } \
180
    else	/*  (0 < n <= 32)  */ \
210
    else	/*  (0 < n <= 32)  */ \
181
    { \
211
    { \
182
	hi_u32 (shifted_a) = (lo_u32(a) >> (32-n)) | (hi_u32(a) << n); \
212
	hi_u32(shifted_a) = (lo_u32(a) >> (32-n)) | (hi_u32(a) << n); \
183
	lo_u32 (shifted_a) =  lo_u32(a) << n; \
213
	lo_u32(shifted_a) =  lo_u32(a) << n; \
184
    } \
214
    } \
185
}
215
}
186
 
216
 
187
#ifdef __TenDRA__
217
#ifdef __TenDRA__
188
 
218
 
189
/* Want to use this value in the .pl file */
219
/* Want to use this value in the .pl file */
190
 
220
 
191
#pragma token EXP rvalue : int : BIGEND_INT64 #
221
#pragma token EXP rvalue : int : BIGEND_INT64 #
192
#ifndef BIGENDIAN_INT64
222
#ifndef BIGENDIAN_INT64
193
#define BIGEND_INT64 0
223
#define BIGEND_INT64 0
194
#else
224
#else
195
#define BIGEND_INT64 BIGENDIAN_INT64
225
#define BIGEND_INT64 BIGENDIAN_INT64
196
#endif
226
#endif
197
 
227
 
198
 
228
 
199
 
229
 
200
/* Use a "procedure token" to implement TDFUshl */
230
/* Use a "procedure token" to implement TDFUshl */
201
 
231
 
202
#pragma token PROC (EXP lvalue : TDF_INT64 : , \
232
#pragma token PROC(EXP lvalue : TDF_INT64 : , \
203
		    EXP rvalue : TDF_INT64 : , \
233
		    EXP rvalue : TDF_INT64 : , \
204
		    EXP rvalue : UINT32 : ) \
234
		    EXP rvalue : UINT32 :)\
205
		STATEMENT TDFUshl #
235
		STATEMENT TDFUshl #
206
#define TDFUshl(shifted_a,a,n) _TDFUshl((shifted_a),(a),(n))
236
#define TDFUshl(shifted_a,a,n)_TDFUshl((shifted_a), (a), (n))
207
#else
237
#else
208
 
238
 
209
/* Use a macro (which calls a function) to implement TDFUshl */
239
/* Use a macro (which calls a function) to implement TDFUshl */
210
 
240
 
211
TDF_INT64 __TDFUshl PROTO_S ((TDF_INT64, UINT32));
241
TDF_INT64 __TDFUshl(TDF_INT64, UINT32);
212
TDF_INT64 __TDFUshl PROTO_N ((shifted_a, a, n))
-
 
213
	            PROTO_T (TDF_INT64 a X UINT32 n)
242
TDF_INT64 __TDFUshl(TDF_INT64 a, UINT32 n)
214
{
243
{
215
    TDF_INT64 tmp;
244
    TDF_INT64 tmp;
216
 
245
 
217
    _TDFUshl(tmp, a, n);
246
    _TDFUshl(tmp, a, n);
218
    return tmp;    
247
    return tmp;
219
}
248
}
220
#define TDFUshl(shifted_a,a,n) { shifted_a = __TDFUshl(a,n); }
249
#define TDFUshl(shifted_a,a,n) { shifted_a = __TDFUshl(a,n); }
221
#endif  /* __TenDRA__ */
250
#endif  /* __TenDRA__ */
222
 
251
 
223
 
252
 
224
 
253
 
225
 
254
 
226
/*  Function definitions  */
255
/*  Function definitions  */
227
 
256
 
228
 
257
 
229
 
258
 
230
/*
259
/*
231
**	TDFUplus:
260
**	TDFUplus:
232
**
261
**
233
**  Generic function to add two 64-bit integers,
262
**  Generic function to add two 64-bit integers,
234
**  interpretting each as an unsigned value.
263
**  interpretting each as an unsigned value.
235
*/
264
*/
236
 
265
 
237
static TDF_INT64 TDFUplus PROTO_N ((a, b))
266
static TDF_INT64
238
			  PROTO_T (TDF_INT64 a X TDF_INT64 b)
267
TDFUplus(TDF_INT64 a, TDF_INT64 b)
239
{
268
{
240
    TDF_INT64	sum;
269
    TDF_INT64	sum;
241
 
270
 
242
    lo_u32 (sum) = lo_u32(a) + lo_u32(b);
271
    lo_u32(sum) = lo_u32(a) + lo_u32(b);
243
    if (lo_u32(sum) < lo_u32(a)) {
272
    if (lo_u32(sum) < lo_u32(a)) {
244
	hi_u32 (sum) = hi_u32(a) + hi_u32(b) + 1;
273
	hi_u32(sum) = hi_u32(a) + hi_u32(b) + 1;
245
    }
-
 
246
    else {
274
    } else {
247
	hi_u32 (sum) = hi_u32(a) + hi_u32(b);
275
	hi_u32(sum) = hi_u32(a) + hi_u32(b);
248
    }
276
    }
249
    return sum;
277
    return sum;
250
}
278
}
251
 
279
 
252
 
280
 
253
 
281
 
254
/*
282
/*
255
**	__TDFUs_plus:
283
**	__TDFUs_plus:
256
**
284
**
257
**  Interpret signed numbers as unsigned, add them
285
**  Interpret signed numbers as unsigned, add them
258
**  as unsigned numbers, then reinterpret as signed.
286
**  as unsigned numbers, then reinterpret as signed.
259
**  Error handling if two positives produce a negative
287
**  Error handling if two positives produce a negative
260
**  or two negative produce a positive, else alright.
288
**  or two negative produce a positive, else alright.
261
*/
289
*/
262
 
290
 
263
INT64 __TDFUs_plus PROTO_N ((param_a, param_b))
291
INT64
264
		   PROTO_T (INT64 param_a X INT64 param_b)
292
__TDFUs_plus(INT64 param_a, INT64 param_b)
265
{
293
{
266
    TDF_INT64	sum, a, b;
294
    TDF_INT64	sum, a, b;
267
 
295
 
268
    PARAM(a) = param_a;
296
    PARAM(a) = param_a;
269
    PARAM(b) = param_b;
297
    PARAM(b) = param_b;
270
    CLEAR_ERRORS;
298
    CLEAR_ERRORS;
271
    sum = TDFUplus (a, b);	/* add as unsigned numbers */
299
    sum = TDFUplus (a, b);	/* add as unsigned numbers */
272
 
300
 
273
    if (TDFUis_positive(a)	&&	/* a >= 0 */
301
    if (TDFUis_positive(a)	&&	/* a >= 0 */
274
	TDFUis_positive(b)	&&	/* b >= 0 */
302
	TDFUis_positive(b)	&&	/* b >= 0 */
275
	TDFUis_negative(sum))		/* a+b < 0 */
303
	TDFUis_negative(sum)) {		/* a+b < 0 */
276
    {
-
 
277
	OVERFLOW_ERROR;
304
	OVERFLOW_ERROR;
278
    }
305
    }
279
    if (TDFUis_negative(a)	&&	/* a < 0 */
306
    if (TDFUis_negative(a)	&&	/* a < 0 */
280
	TDFUis_negative(b)	&&	/* b < 0 */
307
	TDFUis_negative(b)	&&	/* b < 0 */
281
	TDFUis_positive(sum))		/* a+b >= 0 */
308
	TDFUis_positive(sum)) {		/* a+b >= 0 */
282
    {
-
 
283
	OVERFLOW_ERROR;
309
	OVERFLOW_ERROR;
284
    }
310
    }
285
 
311
 
286
    return  PARAM(sum);
312
    return PARAM(sum);
287
}
313
}
288
 
314
 
289
 
315
 
290
 
316
 
291
/*
317
/*
292
**	__TDFUu_plus:
318
**	__TDFUu_plus:
293
**
319
**
294
**  Adds arguments, and tests to see if sum is less
320
**  Adds arguments, and tests to see if sum is less
295
**  than the first argument for error detection.
321
**  than the first argument for error detection.
296
*/
322
*/
297
 
323
 
298
UINT64 __TDFUu_plus PROTO_N ((param_a, param_b))
324
UINT64
299
		    PROTO_T (UINT64 param_a X UINT64 param_b)
325
__TDFUu_plus(UINT64 param_a, UINT64 param_b)
300
{
326
{
301
    TDF_INT64	sum, a, b;
327
    TDF_INT64	sum, a, b;
302
 
328
 
303
    UPARAM(a) = param_a;
329
    UPARAM(a) = param_a;
304
    UPARAM(b) = param_b;
330
    UPARAM(b) = param_b;
305
    CLEAR_ERRORS;
331
    CLEAR_ERRORS;
306
    sum = TDFUplus (a, b);
332
    sum = TDFUplus(a, b);
307
 
333
 
308
    if ((hi_u32(sum) <= hi_u32(a))	&&
334
    if ((hi_u32(sum) <= hi_u32(a))	&&
309
	(lo_u32(sum) < lo_u32(a)))	/* sum < a */
335
	(lo_u32(sum) < lo_u32(a))) {	/* sum < a */
310
    {
-
 
311
	OVERFLOW_ERROR;
336
	OVERFLOW_ERROR;
312
    }
337
    }
313
 
338
 
314
    return  UPARAM(sum);
339
    return UPARAM(sum);
315
}
340
}
316
 
341
 
317
 
342
 
318
 
343
 
319
/*
344
/*
320
**	TDFUminus:
345
**	TDFUminus:
321
**
346
**
322
**  Generic function to subtracting two 64-bit
347
**  Generic function to subtracting two 64-bit
323
**  integers, interpretting each as an unsigned value.
348
**  integers, interpretting each as an unsigned value.
324
*/
349
*/
325
 
350
 
326
static TDF_INT64 TDFUminus PROTO_N ((a, b))
351
static TDF_INT64
327
			   PROTO_T (TDF_INT64 a X TDF_INT64 b)
352
TDFUminus(TDF_INT64 a, TDF_INT64 b)
328
{
353
{
329
    TDF_INT64	sum;
354
    TDF_INT64	sum;
330
 
355
 
331
    lo_u32 (sum) = lo_u32(a) - lo_u32(b);
356
    lo_u32(sum) = lo_u32(a) - lo_u32(b);
332
    if (lo_u32(sum) > lo_u32(a)) {
357
    if (lo_u32(sum) > lo_u32(a)) {
333
	hi_u32 (sum) = hi_u32(a) - hi_u32(b) - 1;
358
	hi_u32(sum) = hi_u32(a) - hi_u32(b) - 1;
334
    }
-
 
335
    else {
359
    } else {
336
	hi_u32 (sum) = hi_u32(a) - hi_u32(b);
360
	hi_u32(sum) = hi_u32(a) - hi_u32(b);
337
    }
361
    }
338
    return sum;
362
    return sum;
339
}
363
}
340
 
364
 
341
 
365
 
342
 
366
 
343
/*
367
/*
344
**	__TDFUs_minus:
368
**	__TDFUs_minus:
345
**
369
**
346
**  Interpret signed numbers as unsigned, add them
370
**  Interpret signed numbers as unsigned, add them
347
**  as unsigned numbers, then reinterpret as signed.
371
**  as unsigned numbers, then reinterpret as signed.
348
**  Error handling if two positives produce a negative
372
**  Error handling if two positives produce a negative
349
**  or two negative produce a positive, else alright.
373
**  or two negative produce a positive, else alright.
350
*/
374
*/
351
 
375
 
352
INT64 __TDFUs_minus PROTO_N ((param_a, param_b))
376
INT64
353
		    PROTO_T (INT64 param_a X INT64 param_b)
377
__TDFUs_minus(INT64 param_a, INT64 param_b)
354
{
378
{
355
    TDF_INT64	diff, a, b;
379
    TDF_INT64	diff, a, b;
356
 
380
 
357
    PARAM(a) = param_a;
381
    PARAM(a) = param_a;
358
    PARAM(b) = param_b;
382
    PARAM(b) = param_b;
359
    CLEAR_ERRORS;
383
    CLEAR_ERRORS;
360
    diff = TDFUminus (a, b);	/* subtract as unsigned numbers */
384
    diff = TDFUminus (a, b);	/* subtract as unsigned numbers */
361
 
385
 
362
    if (TDFUis_positive(a)	&&	/* a >= 0 */
386
    if (TDFUis_positive(a)	&&	/* a >= 0 */
363
	TDFUis_negative(b)	&&	/* b < 0 */
387
	TDFUis_negative(b)	&&	/* b < 0 */
364
	TDFUis_negative(diff))		/* a-b < 0 */
388
	TDFUis_negative(diff)) {	/* a-b < 0 */
365
    {
-
 
366
	OVERFLOW_ERROR;
389
	OVERFLOW_ERROR;
367
    }
390
    }
368
    if (TDFUis_negative(a)	&&	/* a < 0 */
391
    if (TDFUis_negative(a)	&&	/* a < 0 */
369
	TDFUis_positive(b)	&&	/* b >= 0 */
392
	TDFUis_positive(b)	&&	/* b >= 0 */
370
	TDFUis_positive(diff))		/* a-b >= 0 */
393
	TDFUis_positive(diff)) {	/* a-b >= 0 */
371
    {
-
 
372
	OVERFLOW_ERROR;
394
	OVERFLOW_ERROR;
373
    }
395
    }
374
 
396
 
375
    return  PARAM(diff);
397
    return PARAM(diff);
376
}
398
}
377
 
399
 
378
 
400
 
379
 
401
 
380
/*
402
/*
381
**	__TDFUu_minus:
403
**	__TDFUu_minus:
382
**
404
**
383
**  Adds arguments, and tests to see if sum is less
405
**  Adds arguments, and tests to see if sum is less
384
**  than the first argument for error detection.
406
**  than the first argument for error detection.
385
*/
407
*/
386
 
408
 
387
UINT64 __TDFUu_minus PROTO_N ((param_a, param_b))
409
UINT64
388
		     PROTO_T (UINT64 param_a X UINT64 param_b)
410
__TDFUu_minus(UINT64 param_a, UINT64 param_b)
389
{
411
{
390
    TDF_INT64	diff, a, b;
412
    TDF_INT64	diff, a, b;
391
 
413
 
392
    UPARAM(a) = param_a;
414
    UPARAM(a) = param_a;
393
    UPARAM(b) = param_b;
415
    UPARAM(b) = param_b;
394
    CLEAR_ERRORS;
416
    CLEAR_ERRORS;
395
    diff = TDFUminus (a, b);
417
    diff = TDFUminus(a, b);
396
 
418
 
397
    if ((hi_u32(diff) >= hi_u32(a))	&&
419
    if ((hi_u32(diff) >= hi_u32(a))	&&
398
	(lo_u32(diff) > lo_u32(a)))	/* diff > a */
420
	(lo_u32(diff) > lo_u32(a))) {	/* diff > a */
399
    {
-
 
400
	OVERFLOW_ERROR;
421
	OVERFLOW_ERROR;
401
    }
422
    }
402
 
423
 
403
    return  UPARAM(diff);
424
    return UPARAM(diff);
404
}
425
}
405
 
426
 
406
 
427
 
407
 
428
 
408
 
429
 
409
 
430
 
410
 
431
 
411
 
432
 
412
 
433
 
413
 
434
 
414
/*
435
/*
415
**		a3	a2	a1	a0
436
**		a3	a2	a1	a0
416
**
437
**
417
**	X	b3	b2	b1	b0
438
**	X	b3	b2	b1	b0
418
**		--------------------------
439
**		--------------------------
419
**			     ----a0 X b0----	(STAGE1)
440
**			     ----a0 X b0----	(STAGE1)
420
**
441
**
421
**		     ----a1 X b0----		(STAGE2)
442
**		     ----a1 X b0----		(STAGE2)
422
**		     ----a0 X b1----
443
**		     ----a0 X b1----
423
**
444
**
424
**	     ----a2 X b0----			(STAGE3)
445
**	     ----a2 X b0----			(STAGE3)
425
**	     ----a1 X b1----
446
**	     ----a1 X b1----
Line 428... Line 449...
428
**   ----a3 X b0----				(STAGE4)
449
**   ----a3 X b0----				(STAGE4)
429
**   ----a2 X b1----
450
**   ----a2 X b1----
430
**   ----a1 X b2----
451
**   ----a1 X b2----
431
**   ----a0 X b3----
452
**   ----a0 X b3----
432
**
453
**
433
**
454
**
434
**  These are the only terms necessary to produce the answer.
455
**  These are the only terms necessary to produce the answer.
435
**  The other terms must all be used at error checking to
456
**  The other terms must all be used at error checking to
436
**  ensure that overflow does not occur.
457
**  ensure that overflow does not occur.
437
**
458
**
438
**  By adding the contributions in this order, it is possible
459
**  By adding the contributions in this order, it is possible
439
**  to control the size of the sum as each stage, i.e. only
460
**  to control the size of the sum as each stage, i.e. only
440
**  certain terms need to be considered, reducing the number
461
**  certain terms need to be considered, reducing the number
441
**  of steps in the addition.
462
**  of steps in the addition.
442
**
463
**
Line 444... Line 465...
444
**  is done: its value is reset to zero if non occur.
465
**  is done: its value is reset to zero if non occur.
445
*/
466
*/
446
 
467
 
447
 
468
 
448
#define hi_u16(X)	((X) >> 16)
469
#define hi_u16(X)	((X) >> 16)
449
#define lo_u16(X)	((X) & ((UINT32) 0xffff))
470
#define lo_u16(X)	((X) & ((UINT32)0xffff))
450
 
471
 
451
static TDF_INT64 TDFUmult PROTO_N ((a, b))
472
static TDF_INT64
452
			  PROTO_T (TDF_INT64 a X TDF_INT64 b)
473
TDFUmult(TDF_INT64 a, TDF_INT64 b)
453
{
474
{
454
    TDF_INT64	prod;
475
    TDF_INT64	prod;
455
    UINT32	a0, a1, a2, a3;
476
    UINT32	a0, a1, a2, a3;
456
    UINT32	b0, b1, b2, b3;
477
    UINT32	b0, b1, b2, b3;
457
    UINT32	work1, work2;
478
    UINT32	work1, work2;
458
 
479
 
459
    a0 = lo_u16 (lo_u32(a));
480
    a0 = lo_u16(lo_u32(a));
460
    a1 = hi_u16 (lo_u32(a));
481
    a1 = hi_u16(lo_u32(a));
461
    a2 = lo_u16 (hi_u32(a));
482
    a2 = lo_u16(hi_u32(a));
462
    a3 = hi_u16 (hi_u32(a));
483
    a3 = hi_u16(hi_u32(a));
463
 
484
 
464
    b0 = lo_u16 (lo_u32(b));
485
    b0 = lo_u16(lo_u32(b));
465
    b1 = hi_u16 (lo_u32(b));
486
    b1 = hi_u16(lo_u32(b));
466
    b2 = lo_u16 (hi_u32(b));
487
    b2 = lo_u16(hi_u32(b));
467
    b3 = hi_u16 (hi_u32(b));
488
    b3 = hi_u16(hi_u32(b));
468
 
489
 
469
    if ((a1 == 0) && (a2 == 0) && (a3 == 0) &&
490
    if ((a1 == 0) && (a2 == 0) && (a3 == 0) &&
470
	(b1 == 0) && (b2 == 0) && (b3 == 0))
491
	(b1 == 0) && (b2 == 0) && (b3 == 0)) {
471
    {
-
 
472
	hi_u32(prod) = 0;	/* result fits into 32 bits */
492
	hi_u32(prod) = 0;	/* result fits into 32 bits */
473
	lo_u32(prod) = a0 * b0;
493
	lo_u32(prod) = a0 * b0;
474
	return  prod;
494
	return prod;
475
    }
495
    }
476
 
496
 
477
/* Start STAGE1 */
497
/* Start STAGE1 */
478
 
498
 
479
    lo_u32(prod) = a0 * b0;
499
    lo_u32(prod) = a0 * b0;
Line 482... Line 502...
482
/* Start STAGE2 */
502
/* Start STAGE2 */
483
 
503
 
484
    work1 = a1 * b0;
504
    work1 = a1 * b0;
485
    work2 = work1 + (a0 * b1);
505
    work2 = work1 + (a0 * b1);
486
    if (work2 < work1) {
506
    if (work2 < work1) {
487
	hi_u32(prod) = ((UINT32) 0x10000);		/* set carry in result */
507
	hi_u32(prod) = ((UINT32) 0x10000);	/* set carry in result */
488
    }
-
 
489
    else {
508
    } else {
490
	hi_u32(prod) = 0;		/* must initialise somewhere */
509
	hi_u32(prod) = 0;		/* must initialise somewhere */
491
    }
510
    }
492
 
511
 
493
    work1 = lo_u16(work2);	/* lo-16 bits of sum */
512
    work1 = lo_u16(work2);	/* lo-16 bits of sum */
494
    work2 = hi_u16(work2);	/* hi-16 bits of sum */
513
    work2 = hi_u16(work2);	/* hi-16 bits of sum */
495
 
514
 
496
    lo_u32(prod) += (work1 << 16);
515
    lo_u32(prod) += (work1 << 16);
497
    if ((work1 << 16) > lo_u32(prod)) {	/* wrap */
516
    if ((work1 << 16) > lo_u32(prod)) {	/* wrap */
498
	hi_u32(prod) += (1 + work2);
517
	hi_u32(prod) += (1 + work2);
499
    }
-
 
500
    else {
518
    } else {
501
	hi_u32(prod) += work2;
519
	hi_u32(prod) += work2;
502
    }
520
    }
503
 
521
 
504
 
522
 
505
/* Start STAGE3 */
523
/* Start STAGE3 */
Line 518... Line 536...
518
    }
536
    }
519
 
537
 
520
    hi_u32(prod) += work1;
538
    hi_u32(prod) += work1;
521
 
539
 
522
    if (work1 > hi_u32(prod)) {
540
    if (work1 > hi_u32(prod)) {
523
	OVERFLOW_ERROR;
541
	OVERFLOW_ERROR;
524
    }
542
    }
525
 
543
 
526
 
544
 
527
/* Start STAGE4 */
545
/* Start STAGE4 */
528
 
546
 
529
    work1 = a3 * b0;
547
    work1 = a3 * b0;
530
    work2 = a2 * b1;
548
    work2 = a2 * b1;
531
 
549
 
532
    if ((work1 > ((UINT32) 0xffff)) ||
550
    if ((work1 > ((UINT32)0xffff)) ||
533
	(work2 > ((UINT32) 0xffff)))
551
	(work2 > ((UINT32)0xffff))) {
534
    {
-
 
535
	OVERFLOW_ERROR;
552
	OVERFLOW_ERROR;
536
    }
553
    }
537
 
554
 
538
    work1 = work1 + work2;
555
    work1 = work1 + work2;
539
    work2 = a1 * b2;
556
    work2 = a1 * b2;
540
 
557
 
541
    if (work2 > ((UINT32) 0xffff)) {
558
    if (work2 > ((UINT32)0xffff)) {
542
	OVERFLOW_ERROR;
559
	OVERFLOW_ERROR;
543
    }
560
    }
544
 
561
 
545
    work1 = work1 + work2;
562
    work1 = work1 + work2;
546
    work2 = a0 * b3;
563
    work2 = a0 * b3;
547
    work1 = work1 + work2;
564
    work1 = work1 + work2;
548
 
565
 
549
    if ((work1 > ((UINT32) 0xffff)) ||
566
    if ((work1 > ((UINT32)0xffff)) ||
550
	(work2 > ((UINT32) 0xffff)))
567
	(work2 > ((UINT32)0xffff))) {
551
    {
-
 
552
	OVERFLOW_ERROR;
568
	OVERFLOW_ERROR;
553
    }
569
    }
554
 
570
 
555
    work2 = work1 << 16;	/* We've made sure this will work */
571
    work2 = work1 << 16;	/* We've made sure this will work */
556
    hi_u32(prod) += work2;
572
    hi_u32(prod) += work2;
Line 559... Line 575...
559
	(a3 * b1 != 0)		||
575
	(a3 * b1 != 0)		||
560
	(a2 * b2 != 0)		||	/* Remaining contributions */
576
	(a2 * b2 != 0)		||	/* Remaining contributions */
561
	(a1 * b3 != 0)		||	/*    must all be zero     */
577
	(a1 * b3 != 0)		||	/*    must all be zero     */
562
	(a3 * b2 != 0)		||
578
	(a3 * b2 != 0)		||
563
	(a2 * b3 != 0)		||
579
	(a2 * b3 != 0)		||
564
	(a3 * b3 != 0))
580
	(a3 * b3 != 0)) {
565
    {
-
 
566
	OVERFLOW_ERROR;
581
	OVERFLOW_ERROR;
567
    }
582
    }
568
 
583
 
569
    return prod;
584
    return prod;
570
}
585
}
Line 573... Line 588...
573
 
588
 
574
 
589
 
575
 
590
 
576
/*
591
/*
577
**	__TDFUs_mult:
592
**	__TDFUs_mult:
578
**
593
**
579
**  Implements long multiplication in binary,
594
**  Implements long multiplication in binary,
580
**  checking for errors as it goes along.
595
**  checking for errors as it goes along.
581
*/
596
*/
582
 
597
 
583
 
598
 
584
INT64 __TDFUs_mult PROTO_N ((param_a, param_b))
599
INT64
585
		   PROTO_T (INT64 param_a X INT64 param_b)
600
__TDFUs_mult(INT64 param_a, INT64 param_b)
586
{
601
{
587
    TDF_INT64	prod, a, b;
602
    TDF_INT64	prod, a, b;
588
    int		sign;
603
    int		sign;
589
 
604
 
590
    PARAM(a) = param_a;
605
    PARAM(a) = param_a;
591
    PARAM(b) = param_b;
606
    PARAM(b) = param_b;
592
    CLEAR_ERRORS;
607
    CLEAR_ERRORS;
593
 
608
 
594
    sign = ((hi_32(a) ^ hi_32(b)) < 0);	/* sign of result */
609
    sign = ((hi_32(a) ^ hi_32(b)) < 0);	/* sign of result */
595
 
610
 
596
    PARAM(a) = __TDFUabs(param_a);
611
    PARAM(a) = __TDFUabs(param_a);
597
    PARAM(b) = __TDFUabs(param_b);
612
    PARAM(b) = __TDFUabs(param_b);
598
    prod = TDFUmult (a, b);				/* Any overflow will be flagged */
613
    prod = TDFUmult (a, b);		/* Any overflow will be flagged */
599
 
614
 
600
    if (hi_32(prod) < 0) {				/* definitely okay if this is false */
615
    if (hi_32(prod) < 0) {		/* definitely okay if this is false */
601
	if ((sign == 0) 			   || 	 /* positive int too big for INT_64 */
616
	if ((sign == 0) ||		/* positive int too big for INT_64 */
602
	    (hi_u32(prod) > ((UINT32) 0x80000000)) ||   /* signed int too big for INT_64 */
617
	    (hi_u32(prod) > ((UINT32) 0x80000000)) ||   /* signed int too big for INT_64 */
603
	    (lo_u32(prod) > ((UINT32) 0x00000000)))
618
	    (lo_u32(prod) > ((UINT32)0x00000000))) {
604
	{
-
 
605
	    OVERFLOW_ERROR;
619
	    OVERFLOW_ERROR;
606
	}
620
	}
607
    }
621
    }
608
 
622
 
609
    if ((sign == 0)				 ||	/* result is unsigned */
623
    if ((sign == 0)				 ||	/* result is unsigned */
610
	((hi_u32(prod) == ((UINT32) 0x80000000)) &&	/* - this number has the same     */
624
	((hi_u32(prod) == ((UINT32) 0x80000000)) &&	/* - this number has the same     */
611
	 (lo_u32(prod) != ((UINT32) 0x00000000))))	/* representation as its negation */
625
	 (lo_u32(prod) != ((UINT32) 0x00000000)))) {	/* representation as its negation */
612
    {
-
 
613
	return  PARAM(prod);
626
	return PARAM(prod);
614
    }
627
    }
615
    return  __TDFUneg(PARAM(prod));
628
    return __TDFUneg(PARAM(prod));
616
}
629
}
617
 
630
 
618
 
631
 
619
 
632
 
620
 
633
 
621
/*
634
/*
622
**	__TDFUu_mult:
635
**	__TDFUu_mult:
623
**
636
**
624
**  Implements long multiplication in binary,
637
**  Implements long multiplication in binary,
625
**  checking for errors as it goes along.
638
**  checking for errors as it goes along.
626
*/
639
*/
627
 
640
 
628
#if 0
641
#if 0
629
 
642
 
630
UINT64 __TDFUu_mult PROTO_N ((param_a, param_b))
643
UINT64
631
		    PROTO_T (UINT64 param_a X UINT64 param_b)
644
__TDFUu_mult(UINT64 param_a, UINT64 param_b)
632
{
645
{
633
    TDF_INT64	prod, a, b;
646
    TDF_INT64	prod, a, b;
634
 
647
 
635
    if (__TDFUu_test(param_b, UPARAM(const_u0)) == 0)  return UPARAM(const_u0);
648
    if (__TDFUu_test(param_b, UPARAM(const_u0)) == 0) return UPARAM(const_u0);
636
 
649
 
637
    UPARAM(a) = param_a;
650
    UPARAM(a) = param_a;
638
    UPARAM(b) = param_b;
651
    UPARAM(b) = param_b;
639
    prod = const_u0;
652
    prod = const_u0;
640
 
653
 
641
    while (__TDFUu_test(UPARAM(b), UPARAM(const_u1)) != 0)
654
    while (__TDFUu_test(UPARAM(b), UPARAM(const_u1))!= 0)
642
    {
655
    {
643
	if ((lo_u32(b) & 1) != 0) {
656
	if ((lo_u32(b) & 1)!= 0) {
644
	    prod = __TDFUu_plus (UPARAM(prod), UPARAM(a));	/* Any overflow will be flagged */
657
	    prod = __TDFUu_plus (UPARAM(prod), UPARAM(a));	/* Any overflow will be flagged */
645
	}
658
	}
646
	PARAM(a) = __TDFUu_shl (UPARAM(a), (UINT32) 1);
659
	PARAM(a) = __TDFUu_shl(UPARAM(a), (UINT32)1);
647
	PARAM(b) = __TDFUu_shr (UPARAM(b), (UINT32) 1);
660
	PARAM(b) = __TDFUu_shr(UPARAM(b), (UINT32)1);
648
    } 
661
    }
649
 
662
 
650
    return  UPARAM (__TDFUu_plus (prod, a));
663
    return UPARAM(__TDFUu_plus(prod, a));
651
}
664
}
652
 
665
 
653
#else
666
#else
654
 
667
 
655
UINT64 __TDFUu_mult PROTO_N ((param_a, param_b))
668
UINT64
656
		    PROTO_T (UINT64 param_a X UINT64 param_b)
669
__TDFUu_mult(UINT64 param_a, UINT64 param_b)
657
{
670
{
658
    TDF_INT64	prod, a, b;
671
    TDF_INT64	prod, a, b;
659
 
672
 
660
    UPARAM(a) = param_a;
673
    UPARAM(a) = param_a;
661
    UPARAM(b) = param_b;
674
    UPARAM(b) = param_b;
662
    CLEAR_ERRORS;
675
    CLEAR_ERRORS;
663
    prod = TDFUmult (a, b);	/* Any overflow will be flagged */
676
    prod = TDFUmult (a, b);	/* Any overflow will be flagged */
664
    return  UPARAM(prod);
677
    return UPARAM(prod);
665
}
678
}
666
 
679
 
667
#endif
680
#endif
668
 
681
 
669
 
682
 
Line 683... Line 696...
683
**	|a| = n * |b| + m,	(0 <= m < |b|)
696
**	|a| = n * |b| + m,	(0 <= m < |b|)
684
**
697
**
685
**  From this information, I believe the correct values
698
**  From this information, I believe the correct values
686
**  for the various functions can be deduced from the
699
**  for the various functions can be deduced from the
687
**  following table:
700
**  following table:
688
**
701
**
689
**
702
**
690
**	a	b	class	 |	div		rem
703
**	a	b	class	 |	div		rem
691
**    ======================================================
704
**    ======================================================
692
**	+	+	  1	 |	 n		 m
705
**	+	+	  1	 |	 n		 m
693
**	+	+	  2	 |	 n		 m
706
**	+	+	  2	 |	 n		 m
Line 695... Line 708...
695
**	+	-	  2	 |	-n		 m
708
**	+	-	  2	 |	-n		 m
696
**	-	+	  1	 | -n or -(n+1)	    0 or (b-m)
709
**	-	+	  1	 | -n or -(n+1)	    0 or (b-m)
697
**	-	+	  2	 |	-n		-m
710
**	-	+	  2	 |	-n		-m
698
**	-	-	  1	 |	 n		-m
711
**	-	-	  1	 |	 n		-m
699
**	-	-	  2	 |	 n		-m
712
**	-	-	  2	 |	 n		-m
700
*/
713
*/
701
 
714
 
702
 
715
 
703
 
716
 
704
 
717
 
705
/*
718
/*
706
**	TDFUdiv_rem:
719
**	TDFUdiv_rem:
707
**
720
**
708
**  Generic function to divide two 64-bit integers,
721
**  Generic function to divide two 64-bit integers,
709
**  interpretting each as an unsigned value.  Implements
722
**  interpretting each as an unsigned value.  Implements
710
**  the basic 'shift, compare and subtract' algorithm.
723
**  the basic 'shift, compare and subtract' algorithm.
711
**
724
**
712
**  Since the one function produces both the result and
725
**  Since the one function produces both the result and
Line 715... Line 728...
715
**  used for a signed-div0 call for which the arguments
728
**  used for a signed-div0 call for which the arguments
716
**  represent integers of different signs; in this case,
729
**  represent integers of different signs; in this case,
717
**  it is the result depends on the remainder (and so
730
**  it is the result depends on the remainder (and so
718
**  is adjusted according while this information is still
731
**  is adjusted according while this information is still
719
**  freely available.
732
**  freely available.
720
**
733
**
721
*/
734
*/
722
 
735
 
723
#define S_DIV1		((UINT32) 0)
736
#define S_DIV1		((UINT32)0)
724
#define S_DIV2		((UINT32) 2)
737
#define S_DIV2		((UINT32)2)
725
#define U_DIV2		((UINT32) 3)
738
#define U_DIV2		((UINT32)3)
726
#define S_REM1		((UINT32) 4)
739
#define S_REM1		((UINT32)4)
727
#define S_REM2		((UINT32) 6)
740
#define S_REM2		((UINT32)6)
728
#define U_REM2		((UINT32) 7)
741
#define U_REM2		((UINT32)7)
729
#define S_DIV1_0_1	((UINT32) 8)
742
#define S_DIV1_0_1	((UINT32)8)
730
 
743
 
731
#define is_signed(X)	(((X) & 1) == 0)
744
#define is_signed(X)	(((X) & 1) == 0)
732
#define is_class1(X)	(((X) & 2) == 0)
745
#define is_class1(X)	(((X) & 2) == 0)
733
#define is_div(X)	(((X) & 4) == 0)
746
#define is_div(X)	(((X) & 4) == 0)
734
 
747
 
735
static TDF_INT64 TDFUdiv_rem PROTO_N ((a, b, flags))
748
static TDF_INT64
736
			     PROTO_T (TDF_INT64 a X TDF_INT64 b X UINT32 flags)
749
TDFUdiv_rem(TDF_INT64 a, TDF_INT64 b, UINT32 flags)
737
{
750
{
738
    TDF_INT64	new_int, a_upper;
751
    TDF_INT64	new_int, a_upper;
739
    UINT32	i;
752
    UINT32	i;
740
 
753
 
741
    new_int = const_u0;
754
    new_int = const_u0;
742
    a_upper = const_u0;
755
    a_upper = const_u0;
743
 
756
 
744
    if (hi_u32(a) == 0) {
757
    if (hi_u32(a) == 0) {
745
	if (hi_u32(b) == 0) {	/* both a and b fit into 32 bits */
758
	if (hi_u32(b) == 0) {	/* both a and b fit into 32 bits */
746
	    lo_u32(new_int) = lo_u32(a) / lo_u32(b);
759
	    lo_u32(new_int) = lo_u32(a) / lo_u32(b);
747
	    lo_u32(a_upper) = lo_u32(a) % lo_u32(b);
760
	    lo_u32(a_upper) = lo_u32(a)% lo_u32(b);
748
	}
-
 
749
	else {			/* b > a */
761
	} else {			/* b > a */
750
	    lo_u32(new_int) = 0;
762
	    lo_u32(new_int) = 0;
751
	    a_upper = a;
763
	    a_upper = a;
752
	}
764
	}
753
    }
-
 
754
 
-
 
755
    else {
765
    } else {
756
	for (i = 64; i > 0; i--)
766
	for (i = 64; i > 0; i--) {
757
	{
-
 
758
	    TDFUshl (new_int, new_int, (UINT32) 1);
767
	    TDFUshl(new_int, new_int,(UINT32)1);
759
	    
768
 
760
	    TDFUshl (a_upper, a_upper, (UINT32) 1);
769
	    TDFUshl(a_upper, a_upper,(UINT32)1);
761
	    if ((hi_u32(a) >> 31) != 0)
770
	    if ((hi_u32(a) >> 31)!= 0) {
762
	    {
-
 
763
		hi_u32(a) &= ((UINT32) 0x7fffffff);	/* mask out for shift */
771
		hi_u32(a) &= ((UINT32) 0x7fffffff);	/* mask out for shift */
764
		lo_u32(a_upper) |= 1;	/* do carry */
772
		lo_u32(a_upper) |= 1;	/* do carry */
765
	    }
773
	    }
766
	    TDFUshl (a, a, (UINT32) 1);
774
	    TDFUshl(a, a,(UINT32)1);
767
	    
775
 
768
	    if (__TDFUu_test(UPARAM(a_upper), UPARAM(b)) >= 0) {
776
	    if (__TDFUu_test(UPARAM(a_upper), UPARAM(b)) >= 0) {
769
		UPARAM(a_upper) = __TDFUu_minus (UPARAM(a_upper), UPARAM(b));
777
		UPARAM(a_upper) = __TDFUu_minus(UPARAM(a_upper), UPARAM(b));
770
		lo_u32(new_int) |= 1;
778
		lo_u32(new_int) |= 1;
771
	    }
779
	    }
772
	} 
780
	}
773
	
781
 
774
    }
782
    }
775
 
783
 
776
    if (is_div(flags))		/* result of 'div' */
784
    if (is_div(flags)) {	/* result of 'div' */
777
    {
-
 
778
	if ((flags == S_DIV1_0_1)	&&
785
	if ((flags == S_DIV1_0_1)	&&
779
	    ((lo_32(a_upper) != 0)	||
786
	   ((lo_32(a_upper)!= 0)	||
780
	     (hi_32(a_upper) != 0)))
787
	    (hi_32(a_upper)!= 0))) {
781
	{
-
 
782
	    PARAM(new_int) = __TDFUs_plus(PARAM(new_int), PARAM(const_1));
788
	    PARAM(new_int) = __TDFUs_plus(PARAM(new_int), PARAM(const_1));
783
	}
789
	}
784
	return  new_int;
790
	return new_int;
785
    }
791
    }
786
 
792
 
787
    return  a_upper;		/* result of 'rem' */
793
    return a_upper;		/* result of 'rem' */
788
}
794
}
789
 
795
 
790
 
796
 
791
 
797
 
792
/*
798
/*
793
**	__TDFUs_div1:
799
**	__TDFUs_div1:
794
**
800
**
795
**  Division-by-zero is the only possible error.
801
**  Division-by-zero is the only possible error.
796
*/
802
*/
797
 
803
 
798
INT64 __TDFUs_div1 PROTO_N ((param_a, param_b))
804
INT64
799
		   PROTO_T (INT64 param_a X INT64 param_b)
805
__TDFUs_div1(INT64 param_a, INT64 param_b)
800
{
806
{
801
    TDF_INT64	quot, a, b;
807
    TDF_INT64	quot, a, b;
802
    int		is_neg;
808
    int		is_neg;
803
 
809
 
804
    PARAM(b) = param_b;
810
    PARAM(b) = param_b;
805
    if (TDFUis_zero(b))
811
    if (TDFUis_zero(b)) {
806
    {
-
 
807
	DIV_ZERO_ERROR;		/* Stop now - return anything */
812
	DIV_ZERO_ERROR;		/* Stop now - return anything */
808
	return param_b;
813
	return param_b;
809
    }
814
    }
810
    PARAM(a) = param_a;
815
    PARAM(a) = param_a;
811
 
816
 
812
    is_neg = ((hi_32(a) ^ hi_32(b)) < 0);		/* is result negative ? */
817
    is_neg = ((hi_32(a) ^ hi_32(b)) < 0);		/* is result negative ? */
813
    PARAM(a) = __TDFUabs(param_a);
818
    PARAM(a) = __TDFUabs(param_a);
814
    PARAM(b) = __TDFUabs(param_b);
819
    PARAM(b) = __TDFUabs(param_b);
815
 
820
 
816
    if (is_neg) {
821
    if (is_neg) {
817
	quot = TDFUdiv_rem (a, b, S_DIV1_0_1);
822
	quot = TDFUdiv_rem(a, b, S_DIV1_0_1);
818
	CLEAR_ERRORS;					/* May have been set by __TDFUabs */
823
	CLEAR_ERRORS;					/* May have been set by __TDFUabs */
819
	hi_32(quot) = hi_32(quot) ^ ( (INT32) 
824
	hi_32(quot) = hi_32(quot)^((INT32)
820
		((UINT32) 0xffffffff));		/* Avoid errors, don't call __TDFUneg */
825
		((UINT32) 0xffffffff));		/* Avoid errors, don't call __TDFUneg */
821
	lo_32(quot) = lo_32(quot) ^ UINT32_const(0xffffffff);
826
	lo_32(quot) = lo_32(quot)^ UINT32_const(0xffffffff);
822
	return  PARAM (TDFUplus (quot, const_1));
827
	return PARAM(TDFUplus(quot, const_1));
823
    }
828
    }
824
 
829
 
825
    quot = TDFUdiv_rem (a, b, S_DIV1);
830
    quot = TDFUdiv_rem(a, b, S_DIV1);
826
    CLEAR_ERRORS;	/* May have been set by __TDFUabs */
831
    CLEAR_ERRORS;	/* May have been set by __TDFUabs */
827
 
832
 
828
    if (TDFUis_negative(quot))		/* Only happens for INT_MAX+1 */
833
    if (TDFUis_negative(quot)) {	/* Only happens for INT_MAX+1 */
829
    {
-
 
830
	OVERFLOW_ERROR;
834
	OVERFLOW_ERROR;
831
    }
835
    }
832
    return  PARAM(quot);
836
    return PARAM(quot);
833
}
837
}
834
 
838
 
835
 
839
 
836
 
840
 
837
/*
841
/*
838
**	__TDFUs_div2:
842
**	__TDFUs_div2:
839
**
843
**
840
**  Division-by-zero is the only possible error.
844
**  Division-by-zero is the only possible error.
841
*/
845
*/
842
 
846
 
843
INT64 __TDFUs_div2 PROTO_N ((param_a, param_b))
847
INT64
844
		   PROTO_T (INT64 param_a X INT64 param_b)
848
__TDFUs_div2(INT64 param_a, INT64 param_b)
845
{
849
{
846
    TDF_INT64	quot, a, b;
850
    TDF_INT64	quot, a, b;
847
    int		is_neg;
851
    int		is_neg;
848
 
852
 
849
    PARAM(b) = param_b;
853
    PARAM(b) = param_b;
850
    if (TDFUis_zero(b))
854
    if (TDFUis_zero(b)) {
851
    {
-
 
852
	DIV_ZERO_ERROR;		/* Stop now - return anything */
855
	DIV_ZERO_ERROR;		/* Stop now - return anything */
853
	return param_b;
856
	return param_b;
854
    }
857
    }
855
    PARAM(a) = param_a;
858
    PARAM(a) = param_a;
856
 
859
 
857
    is_neg = ((hi_32(a) ^ hi_32(b)) < 0);	/* is result negative ? */
860
    is_neg = ((hi_32(a) ^ hi_32(b)) < 0);	/* is result negative ? */
858
    PARAM(a) = __TDFUabs(param_a);
861
    PARAM(a) = __TDFUabs(param_a);
859
    PARAM(b) = __TDFUabs(param_b);
862
    PARAM(b) = __TDFUabs(param_b);
860
 
863
 
861
    quot = TDFUdiv_rem (a, b, S_DIV2);
864
    quot = TDFUdiv_rem(a, b, S_DIV2);
862
    CLEAR_ERRORS;	/* May have been set by __TDFUabs */
865
    CLEAR_ERRORS;	/* May have been set by __TDFUabs */
863
 
866
 
864
    if (is_neg) {
867
    if (is_neg) {
865
	hi_32(quot) = hi_32(quot) ^
868
	hi_32(quot) = hi_32(quot)^
866
	   ( (INT32) ((UINT32) 0xffffffff)); /* Avoid errors, don't call __TDFUneg */
869
	   ( (INT32) ((UINT32) 0xffffffff)); /* Avoid errors, don't call __TDFUneg */
867
	lo_32(quot) = lo_32(quot) ^ ((UINT32) 0xffffffff);
870
	lo_32(quot) = lo_32(quot)^((UINT32)0xffffffff);
868
	return  PARAM(TDFUplus (quot, const_1));
871
	return PARAM(TDFUplus(quot, const_1));
869
    }
872
    }
870
 
873
 
871
    if (TDFUis_negative(quot))		/* Only happens for INT_MAX+1 */
874
    if (TDFUis_negative(quot)) {	/* Only happens for INT_MAX+1 */
872
    {
-
 
873
	OVERFLOW_ERROR;
875
	OVERFLOW_ERROR;
874
    }
876
    }
875
    return  PARAM(quot);
877
    return PARAM(quot);
876
}
878
}
877
 
879
 
878
 
880
 
879
 
881
 
880
/*
882
/*
881
**	__TDFUu_div2:
883
**	__TDFUu_div2:
882
**
884
**
883
**  Division-by-zero is the only possible error.
885
**  Division-by-zero is the only possible error.
884
*/
886
*/
885
 
887
 
886
UINT64 __TDFUu_div2 PROTO_N ((param_a, param_b))
888
UINT64
887
		    PROTO_T (UINT64 param_a X UINT64 param_b)
889
__TDFUu_div2(UINT64 param_a, UINT64 param_b)
888
{
890
{
889
    TDF_INT64	a, b;
891
    TDF_INT64	a, b;
890
 
892
 
891
    CLEAR_ERRORS;
893
    CLEAR_ERRORS;
892
 
894
 
893
    UPARAM(b) = param_b;
895
    UPARAM(b) = param_b;
894
    if (TDFUis_zero(b))
896
    if (TDFUis_zero(b)) {
895
    {
-
 
896
	DIV_ZERO_ERROR;		/* Stop now - return anything */
897
	DIV_ZERO_ERROR;		/* Stop now - return anything */
897
	return param_b;
898
	return param_b;
898
    }
899
    }
899
    UPARAM(a) = param_a;
900
    UPARAM(a) = param_a;
900
 
901
 
901
    return  UPARAM (TDFUdiv_rem (a, b, U_DIV2));
902
    return UPARAM(TDFUdiv_rem(a, b, U_DIV2));
902
}
903
}
903
 
904
 
904
 
905
 
905
/*
906
/*
906
**	__TDFUs_rem1:
907
**	__TDFUs_rem1:
907
**
908
**
908
**  Modulo-zero is the only possible error.
909
**  Modulo-zero is the only possible error.
909
*/
910
*/
910
 
911
 
911
INT64 __TDFUs_rem1 PROTO_N ((param_a, param_b))
912
INT64
912
		   PROTO_T (INT64 param_a X INT64 param_b)
913
__TDFUs_rem1(INT64 param_a, INT64 param_b)
913
{
914
{
914
    TDF_INT64	rem, a, b, abs_a, abs_b;
915
    TDF_INT64	rem, a, b, abs_a, abs_b;
915
    int		is_neg;
916
    int		is_neg;
916
 
917
 
917
    PARAM(b) = param_b;
918
    PARAM(b) = param_b;
918
    if (TDFUis_zero(b))
919
    if (TDFUis_zero(b)) {
919
    {
-
 
920
	DIV_ZERO_ERROR;		/* Stop now - return anything */
920
	DIV_ZERO_ERROR;		/* Stop now - return anything */
921
	return param_b;
921
	return param_b;
922
    }
922
    }
923
    PARAM(a) = param_a;
923
    PARAM(a) = param_a;
924
    PARAM(abs_a) = __TDFUabs(param_a);
924
    PARAM(abs_a) = __TDFUabs(param_a);
925
    PARAM(abs_b) = __TDFUabs(param_b);
925
    PARAM(abs_b) = __TDFUabs(param_b);
926
 
926
 
927
    is_neg = TDFUis_negative(b);	/* is result negative ? */
927
    is_neg = TDFUis_negative(b);	/* is result negative ? */
928
    rem = TDFUdiv_rem (abs_a, abs_b, S_REM1);
928
    rem = TDFUdiv_rem(abs_a, abs_b, S_REM1);
929
    CLEAR_ERRORS;		/* May have been set by __TDFUabs */
929
    CLEAR_ERRORS;		/* May have been set by __TDFUabs */
930
 
930
 
931
    if (TDFUis_positive(a)	&&
931
    if (TDFUis_positive(a)	&&
932
	TDFUis_negative(b)	&&
932
	TDFUis_negative(b)	&&
933
	TDFUis_nonzero(rem))
933
	TDFUis_nonzero(rem)) {
934
    {
-
 
935
	return  __TDFUs_plus (param_b, PARAM(rem));
934
	return __TDFUs_plus(param_b, PARAM(rem));
936
    }
935
    }
937
 
936
 
938
    if (TDFUis_negative(a)	&&
937
    if (TDFUis_negative(a)	&&
939
	TDFUis_positive(b)	&&
938
	TDFUis_positive(b)	&&
940
	TDFUis_nonzero(rem))
939
	TDFUis_nonzero(rem)) {
941
    {
-
 
942
	return  __TDFUs_minus (param_b, PARAM(rem));
940
	return __TDFUs_minus(param_b, PARAM(rem));
943
    }
941
    }
944
 
942
 
-
 
943
    if (is_neg) {
945
    if (is_neg) return  __TDFUneg(PARAM(rem));
944
	    return __TDFUneg(PARAM(rem));
-
 
945
    }
946
    return  PARAM(rem);
946
    return PARAM(rem);
947
}
947
}
948
 
948
 
949
 
949
 
950
 
950
 
951
/*
951
/*
952
**	__TDFUs_rem2:
952
**	__TDFUs_rem2:
953
**
953
**
954
**  Modulo-zero is the only possible error.
954
**  Modulo-zero is the only possible error.
955
*/
955
*/
956
 
956
 
957
INT64 __TDFUs_rem2 PROTO_N ((param_a, param_b))
957
INT64
958
		   PROTO_T (INT64 param_a X INT64 param_b)
958
__TDFUs_rem2(INT64 param_a, INT64 param_b)
959
{
959
{
960
    TDF_INT64	rem, a, b;
960
    TDF_INT64	rem, a, b;
961
    int		is_neg;
961
    int		is_neg;
962
 
962
 
963
    PARAM(b) = param_b;
963
    PARAM(b) = param_b;
964
    if (TDFUis_zero(b))
964
    if (TDFUis_zero(b)) {
965
    {
-
 
966
	DIV_ZERO_ERROR;		/* Stop now - return anything */
965
	DIV_ZERO_ERROR;		/* Stop now - return anything */
967
	return param_b;
966
	return param_b;
968
    }
967
    }
969
    PARAM(a) = param_a;
968
    PARAM(a) = param_a;
970
 
969
 
971
    is_neg = TDFUis_negative(a);	/* is result negative ? */
970
    is_neg = TDFUis_negative(a);	/* is result negative ? */
972
    PARAM(a) = __TDFUabs(param_a);
971
    PARAM(a) = __TDFUabs(param_a);
973
    PARAM(b) = __TDFUabs(param_b);
972
    PARAM(b) = __TDFUabs(param_b);
974
 
973
 
975
    rem = TDFUdiv_rem (a, b, S_REM2);
974
    rem = TDFUdiv_rem(a, b, S_REM2);
976
    CLEAR_ERRORS;		/* May have been set by __TDFUabs */
975
    CLEAR_ERRORS;		/* May have been set by __TDFUabs */
977
 
976
 
-
 
977
    if (is_neg) {
978
    if (is_neg) return  __TDFUneg(PARAM(rem));
978
	    return __TDFUneg(PARAM(rem));
-
 
979
    }
979
    return  PARAM(rem);
980
    return PARAM(rem);
980
}
981
}
981
 
982
 
982
 
983
 
983
 
984
 
984
/*
985
/*
985
**	__TDFUu_rem2:
986
**	__TDFUu_rem2:
986
**
987
**
987
**  Modulo-zero is the only possible error.
988
**  Modulo-zero is the only possible error.
988
*/
989
*/
989
 
990
 
990
UINT64 __TDFUu_rem2 PROTO_N ((param_a, param_b))
991
UINT64
991
		    PROTO_T (UINT64 param_a X UINT64 param_b)
992
__TDFUu_rem2(UINT64 param_a, UINT64 param_b)
992
{
993
{
993
    TDF_INT64	a, b;
994
    TDF_INT64	a, b;
994
 
995
 
995
    UPARAM(b) = param_b;
996
    UPARAM(b) = param_b;
996
    if (TDFUis_zero(b))
997
    if (TDFUis_zero(b)) {
997
    {
-
 
998
	DIV_ZERO_ERROR;		/* Stop now - return anything */
998
	DIV_ZERO_ERROR;		/* Stop now - return anything */
999
	return param_b;
999
	return param_b;
1000
    }
1000
    }
1001
    UPARAM(a) = param_a;
1001
    UPARAM(a) = param_a;
1002
 
1002
 
1003
    CLEAR_ERRORS;
1003
    CLEAR_ERRORS;
1004
    return  UPARAM (TDFUdiv_rem (a, b, U_REM2));
1004
    return UPARAM(TDFUdiv_rem(a, b, U_REM2));
1005
}
1005
}
1006
 
1006
 
1007
 
1007
 
1008
 
1008
 
1009
/*
1009
/*
Line 1011... Line 1011...
1011
**
1011
**
1012
**  Flip all bits and add 1, as for 2's complement.
1012
**  Flip all bits and add 1, as for 2's complement.
1013
**  Overflow error if original value was INT64_MIN.
1013
**  Overflow error if original value was INT64_MIN.
1014
*/
1014
*/
1015
 
1015
 
1016
INT64 __TDFUneg PROTO_N ((param_a))
1016
INT64
1017
		PROTO_T (INT64 param_a)
1017
__TDFUneg(INT64 param_a)
1018
{
1018
{
1019
    TDF_INT64	a;
1019
    TDF_INT64	a;
1020
 
1020
 
1021
    PARAM(a) = param_a;
1021
    PARAM(a) = param_a;
1022
    hi_32(a) = hi_32(a) ^ ((INT32) ((UINT32) 0xffffffff));
1022
    hi_32(a) = hi_32(a)^((INT32)((UINT32)0xffffffff));
1023
    lo_32(a) = lo_32(a) ^ ((UINT32) 0xffffffff);
1023
    lo_32(a) = lo_32(a)^((UINT32)0xffffffff);
1024
    return  __TDFUs_plus (PARAM(a), PARAM(const_1));	/* Should handle any errors */
1024
    return __TDFUs_plus(PARAM(a), PARAM(const_1));	/* Should handle any errors */
1025
}
1025
}
1026
 
1026
 
1027
 
1027
 
1028
 
1028
 
1029
 
1029
 
Line 1037... Line 1037...
1037
 
1037
 
1038
/*
1038
/*
1039
** 	__TDFUu_shl:
1039
** 	__TDFUu_shl:
1040
**
1040
**
1041
**  Does error checking.  If all is okay, returns the value.
1041
**  Does error checking.  If all is okay, returns the value.
1042
**  
1042
**
1043
*/
1043
*/
1044
 
1044
 
1045
UINT64 __TDFUu_shl PROTO_N ((param_a, n))
1045
UINT64
1046
		   PROTO_T (UINT64 param_a X UINT32 n)
1046
__TDFUu_shl(UINT64 param_a, UINT32 n)
1047
{
1047
{
1048
    TDF_INT64	a;
1048
    TDF_INT64	a;
1049
 
1049
 
1050
    CLEAR_ERRORS;
1050
    CLEAR_ERRORS;
1051
    if (n > 63) {
1051
    if (n > 63) {
1052
	OVERFLOW_ERROR;
1052
	OVERFLOW_ERROR;
1053
	return  UPARAM(const_u0);
1053
	return UPARAM(const_u0);
1054
    }
1054
    }
1055
 
1055
 
1056
    if (n == 0)	return param_a;
1056
    if (n == 0)	return param_a;
1057
 
1057
 
1058
    /* check that the result won't overflow */
1058
    /* check that the result won't overflow */
1059
 
1059
 
1060
    UPARAM(a) = param_a;
1060
    UPARAM(a) = param_a;
1061
    if (n > 32) {
1061
    if (n > 32) {
1062
	if (((lo_u32(a) >> (64-n)) != 0)	||
1062
	if (((lo_u32(a) >> (64-n))!= 0)	|| (hi_u32(a)!= 0)) {
1063
	    (hi_u32(a) != 0))
-
 
1064
	{
-
 
1065
	    OVERFLOW_ERROR;
1063
	    OVERFLOW_ERROR;
1066
	}
1064
	}
1067
    }
-
 
1068
    else if ((hi_u32(a) >> (32-n)) != 0)
1065
    } else if ((hi_u32(a) >> (32-n))!= 0) {
1069
    {
-
 
1070
	OVERFLOW_ERROR;
1066
	OVERFLOW_ERROR;
1071
    }
1067
    }
1072
 
1068
 
1073
    TDFUshl (a, a, n);
1069
    TDFUshl(a, a, n);
1074
    return  UPARAM(a);
1070
    return UPARAM(a);
1075
}
1071
}
1076
 
1072
 
1077
 
1073
 
1078
 
1074
 
1079
/*
1075
/*
Line 1081... Line 1077...
1081
**
1077
**
1082
**  2 cases: n > 32  - copy high 32-bits across and shift.
1078
**  2 cases: n > 32  - copy high 32-bits across and shift.
1083
**  	     n <= 32 - mask out two contributions and OR together.
1079
**  	     n <= 32 - mask out two contributions and OR together.
1084
*/
1080
*/
1085
 
1081
 
1086
static TDF_INT64 TDFUshr PROTO_N ((a, n))
1082
static TDF_INT64
1087
			 PROTO_T (TDF_INT64 a X UINT32 n)
1083
TDFUshr(TDF_INT64 a, UINT32 n)
1088
{
1084
{
1089
    TDF_INT64	shifted_a;
1085
    TDF_INT64	shifted_a;
1090
 
1086
 
1091
    CLEAR_ERRORS;
1087
    CLEAR_ERRORS;
1092
    if (n >= 32)	/* 32 <= n < 64 */
1088
    if (n >= 32) {	/* 32 <= n < 64 */
1093
    {
-
 
1094
	lo_u32 (shifted_a) = hi_u32(a) >> (n -32);
1089
	lo_u32(shifted_a) = hi_u32(a) >> (n -32);
1095
	hi_u32 (shifted_a) = (UINT32) 0x00000000;
1090
	hi_u32(shifted_a) = (UINT32)0x00000000;
1096
    }
-
 
1097
    else	/*  (0 < n <= 32)  */
1091
    } else {	/*  (0 < n <= 32)  */
1098
    {
-
 
1099
	lo_u32 (shifted_a) = (hi_u32(a) << (32-n)) | (lo_u32(a) >> n);
1092
	lo_u32(shifted_a) = (hi_u32(a) << (32-n)) | (lo_u32(a) >> n);
1100
	hi_u32 (shifted_a) =  hi_u32(a) >> n;
1093
	hi_u32(shifted_a) =  hi_u32(a) >> n;
1101
    }
1094
    }
1102
 
1095
 
1103
    return  shifted_a;
1096
    return shifted_a;
1104
}
1097
}
-
 
1098
 
-
 
1099
 
-
 
1100
 
-
 
1101
/*
-
 
1102
** 	__TDFUs_shr:
-
 
1103
**
-
 
1104
**  Best implemented in PL_TDF
-
 
1105
*/
1105
 
1106
 
1106
 
1107
 
1107
 
1108
 
1108
/*
1109
/*
1109
** 	__TDFUs_shr:
1110
** 	__TDFUu_shr:
1110
**
1111
**
1111
**  Best implemented in PL_TDF
-
 
1112
*/
-
 
1113
 
-
 
1114
 
-
 
1115
 
-
 
1116
/*
-
 
1117
** 	__TDFUu_shr:
-
 
1118
**
-
 
1119
**  Error occurs if n > 64 since the result is undefined.
1112
**  Error occurs if n > 64 since the result is undefined.
1120
*/
1113
*/
1121
 
1114
 
1122
UINT64 __TDFUu_shr PROTO_N ((param_a, n))
1115
UINT64
1123
		   PROTO_T (UINT64 param_a X UINT32 n)
1116
__TDFUu_shr(UINT64 param_a, UINT32 n)
1124
{
1117
{
1125
    TDF_INT64	a;
1118
    TDF_INT64	a;
1126
 
1119
 
1127
    CLEAR_ERRORS;
1120
    CLEAR_ERRORS;
1128
    if (n > 63) {	/* This is undefined */
1121
    if (n > 63) {	/* This is undefined */
1129
	OVERFLOW_ERROR;
1122
	OVERFLOW_ERROR;
1130
	return  UPARAM(const_u0);
1123
	return UPARAM(const_u0);
1131
    }
1124
    }
1132
 
1125
 
1133
    if (n == 0) return param_a;
1126
    if (n == 0) return param_a;
1134
    UPARAM(a) = param_a;
1127
    UPARAM(a) = param_a;
1135
    return  UPARAM (TDFUshr (a, n));
1128
    return UPARAM(TDFUshr(a, n));
1136
}
1129
}
1137
 
1130
 
1138
 
1131
 
1139
 
1132
 
1140
/*
1133
/*
1141
** 	__TDFUabs:
1134
** 	__TDFUabs:
1142
**
1135
**
1143
**  Checks for a negative quantity, for which it
1136
**  Checks for a negative quantity, for which it
1144
**  calls '__TDFUneg'.  Overflow for, as for __TDFUneg,
1137
**  calls '__TDFUneg'.  Overflow for, as for __TDFUneg,
1145
**  occurs when the value is INT32_MIN.
1138
**  occurs when the value is INT32_MIN.
1146
**  
1139
**
1147
*/
1140
*/
1148
 
1141
 
1149
INT64 __TDFUabs PROTO_N ((param_a))
1142
INT64
1150
		PROTO_T (INT64 param_a)
1143
__TDFUabs(INT64 param_a)
1151
{
1144
{
1152
    TDF_INT64	a;
1145
    TDF_INT64	a;
1153
 
1146
 
1154
    PARAM(a) = param_a;
1147
    PARAM(a) = param_a;
1155
    if (TDFUis_negative(a)) {
1148
    if (TDFUis_negative(a)) {
1156
	return  __TDFUneg (param_a);	/* This handles any errors */
1149
	return __TDFUneg (param_a);	/* This handles any errors */
1157
    }
1150
    }
1158
 
1151
 
1159
    CLEAR_ERRORS;
1152
    CLEAR_ERRORS;
1160
    return  param_a;
1153
    return param_a;
1161
}
1154
}
1162
 
1155
 
1163
 
1156
 
1164
/*
1157
/*
1165
** 	__TDFUsswiden:
1158
** 	__TDFUsswiden:
1166
**
1159
**
1167
**  Extends the sign bit, and returns the new int.
1160
**  Extends the sign bit, and returns the new int.
1168
**
1161
**
1169
*/
1162
*/
1170
 
1163
 
1171
INT64 __TDFUsswiden PROTO_N ((a))
1164
INT64
1172
		    PROTO_T (INT32 a)
1165
__TDFUsswiden(INT32 a)
1173
{
1166
{
1174
    TDF_INT64	ext_int;
1167
    TDF_INT64	ext_int;
1175
 
1168
 
1176
    CLEAR_ERRORS;
1169
    CLEAR_ERRORS;
1177
    hi_32(ext_int) = (INT32) ((a < 0) ? -1 : 0);	/* sign-extend a */
1170
    hi_32(ext_int) = (INT32) ((a < 0) ? -1 : 0);	/* sign-extend a */
1178
    lo_32(ext_int) = (UINT32) a;
1171
    lo_32(ext_int) = (UINT32)a;
1179
    return  PARAM(ext_int);
1172
    return PARAM(ext_int);
1180
}
1173
}
1181
 
1174
 
1182
 
1175
 
1183
/*
1176
/*
1184
** 	__TDFUsuwiden:
1177
** 	__TDFUsuwiden:
1185
**
1178
**
1186
**  Error if a is negative.
1179
**  Error if a is negative.
1187
**  Otherwise extends the sign bit (just to be safe)
1180
**  Otherwise extends the sign bit (just to be safe)
1188
*/
1181
*/
1189
 
1182
 
1190
UINT64 __TDFUsuwiden PROTO_N ((a))
1183
UINT64 __TDFUsuwiden(INT32 a)
1191
		     PROTO_T (INT32 a)
-
 
1192
{
1184
{
1193
    TDF_INT64	ext_int;
1185
    TDF_INT64	ext_int;
1194
 
1186
 
1195
    CLEAR_ERRORS;
1187
    CLEAR_ERRORS;
1196
    if (a < 0)
1188
    if (a < 0) {
1197
    {
-
 
1198
	OVERFLOW_ERROR;
1189
	OVERFLOW_ERROR;
1199
    }
1190
    }
1200
 
1191
 
1201
    hi_u32(ext_int) = (UINT32) ((a < 0) ? 0xffffffff : 0);
1192
    hi_u32(ext_int) = (UINT32)((a < 0)? 0xffffffff : 0);
1202
					/* sign-extend a */
1193
					/* sign-extend a */
1203
    lo_u32(ext_int) = (UINT32) a;
1194
    lo_u32(ext_int) = (UINT32)a;
1204
    return  UPARAM(ext_int);
1195
    return UPARAM(ext_int);
1205
}
1196
}
1206
 
1197
 
1207
 
1198
 
1208
/*
1199
/*
1209
** 	__TDFUuuwiden:
1200
** 	__TDFUuuwiden:
1210
**
1201
**
1211
**  Puts zero in bits 32-63 and returns
1202
**  Puts zero in bits 32-63 and returns
1212
*/
1203
*/
1213
 
1204
 
1214
UINT64 __TDFUuuwiden PROTO_N ((a))
1205
UINT64
1215
		     PROTO_T (UINT32 a)
1206
__TDFUuuwiden(UINT32 a)
1216
{
1207
{
1217
    TDF_INT64	ext_int;
1208
    TDF_INT64	ext_int;
1218
 
1209
 
1219
    CLEAR_ERRORS;
1210
    CLEAR_ERRORS;
1220
    hi_u32(ext_int) = 0;
1211
    hi_u32(ext_int) = 0;
1221
    lo_u32(ext_int) = a;
1212
    lo_u32(ext_int) = a;
1222
    return  UPARAM(ext_int);
1213
    return UPARAM(ext_int);
1223
}
1214
}
1224
 
1215
 
1225
 
1216
 
1226
/*
1217
/*
1227
** 	__TDFUuswiden:
1218
** 	__TDFUuswiden:
1228
**
1219
**
1229
**  Same as __TDFUuuswiden.
1220
**  Same as __TDFUuuswiden.
1230
**
1221
**
1231
*/
1222
*/
1232
 
1223
 
1233
INT64 __TDFUuswiden PROTO_N ((a))
1224
INT64
1234
		    PROTO_T (UINT32 a)
1225
__TDFUuswiden(UINT32 a)
1235
{
1226
{
1236
    TDF_INT64	ext_int;
1227
    TDF_INT64	ext_int;
1237
 
1228
 
1238
    CLEAR_ERRORS;
1229
    CLEAR_ERRORS;
1239
    hi_32(ext_int) = 0;
1230
    hi_32(ext_int) = 0;
1240
    lo_32(ext_int) = a;
1231
    lo_32(ext_int) = a;
1241
    return  PARAM(ext_int);
1232
    return PARAM(ext_int);
1242
}
1233
}
1243
 
1234
 
1244
 
1235
 
1245
/*
1236
/*
1246
** 	__TDFUssshorten:
1237
** 	__TDFUssshorten:
Line 1248... Line 1239...
1248
**  Check that bits 31-63 are all set/unset,
1239
**  Check that bits 31-63 are all set/unset,
1249
**  otherwise signal overflow.  Mask sign
1240
**  otherwise signal overflow.  Mask sign
1250
**  bit into bit-31.
1241
**  bit into bit-31.
1251
*/
1242
*/
1252
 
1243
 
1253
INT32 __TDFUssshorten PROTO_N ((param_a))
1244
INT32
1254
		      PROTO_T (INT64 param_a)
1245
__TDFUssshorten(INT64 param_a)
1255
{
1246
{
1256
    TDF_INT64	a;
1247
    TDF_INT64	a;
1257
 
1248
 
1258
    PARAM(a) = param_a;
1249
    PARAM(a) = param_a;
1259
    CLEAR_ERRORS;
1250
    CLEAR_ERRORS;
1260
    switch ((int) hi_32(a)) {
1251
    switch ((int)hi_32(a)) {
1261
      case 0:
1252
      case 0:
1262
	  if ((lo_32(a) & ((UINT32) 0x80000000)) != 0) {
1253
	  if ((lo_32(a) & ((UINT32)0x80000000))!= 0) {
1263
	      OVERFLOW_ERROR;
1254
	      OVERFLOW_ERROR;
1264
	  }
1255
	  }
1265
	  break;
1256
	  break;
1266
      case -1:
1257
      case -1:
1267
	  if ((lo_32(a) & ((UINT32) 0x80000000)) == 0) {
1258
	  if ((lo_32(a) & ((UINT32)0x80000000)) == 0) {
1268
	      OVERFLOW_ERROR;
1259
	      OVERFLOW_ERROR;
1269
	  }
1260
	  }
1270
	  break;
1261
	  break;
1271
      default:
1262
      default:
1272
	  OVERFLOW_ERROR;
1263
	  OVERFLOW_ERROR;
1273
    }
1264
    }
1274
 
1265
 
1275
    return  ((((INT32) lo_32(a)) & ((INT32) 0x7fffffff)) |
1266
    return ((((INT32)lo_32(a)) & ((INT32)0x7fffffff)) |
1276
		      (hi_32(a)  & ((INT32) ((UINT32) 0x80000000))));
1267
	    (hi_32(a) & ((INT32)((UINT32)0x80000000))));
1277
 
1268
 
1278
}
1269
}
1279
 
1270
 
1280
 
1271
 
1281
/*
1272
/*
Line 1284... Line 1275...
1284
**  Check that bits 32-63 are all zero
1275
**  Check that bits 32-63 are all zero
1285
**  otherwise signal overflow.  Answer
1276
**  otherwise signal overflow.  Answer
1286
**  is in bits 0-31.
1277
**  is in bits 0-31.
1287
*/
1278
*/
1288
 
1279
 
1289
UINT32 __TDFUsushorten PROTO_N ((param_a))
1280
UINT32
1290
		       PROTO_T (INT64 param_a)
1281
__TDFUsushorten(INT64 param_a)
1291
{
1282
{
1292
    TDF_INT64	a;
1283
    TDF_INT64	a;
1293
 
1284
 
1294
    PARAM(a) = param_a;
1285
    PARAM(a) = param_a;
1295
    CLEAR_ERRORS;
1286
    CLEAR_ERRORS;
1296
    if (hi_32(a) != 0)
1287
    if (hi_32(a) != 0) {
1297
    {
-
 
1298
	OVERFLOW_ERROR;
1288
	OVERFLOW_ERROR;
1299
    }
1289
    }
1300
 
1290
 
1301
    return  lo_32(a);
1291
    return lo_32(a);
1302
}
1292
}
1303
 
1293
 
1304
 
1294
 
1305
/*
1295
/*
1306
** 	__TDFUuushorten:
1296
** 	__TDFUuushorten:
1307
**
1297
**
1308
**  Error if bits 32-63 are not all zero.
1298
**  Error if bits 32-63 are not all zero.
1309
**  Return bits 0-31.
1299
**  Return bits 0-31.
1310
*/
1300
*/
1311
 
1301
 
1312
UINT32 __TDFUuushorten PROTO_N ((param_a))
1302
UINT32
1313
		       PROTO_T (UINT64 param_a)
1303
__TDFUuushorten(UINT64 param_a)
1314
{
1304
{
1315
    TDF_INT64	a;
1305
    TDF_INT64	a;
1316
 
1306
 
1317
    UPARAM(a) = param_a;
1307
    UPARAM(a) = param_a;
1318
    CLEAR_ERRORS;
1308
    CLEAR_ERRORS;
1319
    if (hi_u32(a) != 0)
1309
    if (hi_u32(a) != 0) {
1320
    {
-
 
1321
	OVERFLOW_ERROR;
1310
	OVERFLOW_ERROR;
1322
    }
1311
    }
1323
 
1312
 
1324
    return  lo_u32(a);
1313
    return lo_u32(a);
1325
}
1314
}
1326
 
1315
 
1327
 
1316
 
1328
/*
1317
/*
1329
** 	__TDFUusshorten:
1318
** 	__TDFUusshorten:
1330
**
1319
**
1331
**  Error if bits 31-63 are not all zero.
1320
**  Error if bits 31-63 are not all zero.
1332
**  Return bits 0-31.
1321
**  Return bits 0-31.
1333
*/
1322
*/
1334
 
1323
 
1335
INT32 __TDFUusshorten PROTO_N ((param_a))
1324
INT32
1336
		      PROTO_T (UINT64 param_a)
1325
__TDFUusshorten(UINT64 param_a)
1337
{
1326
{
1338
    TDF_INT64	a;
1327
    TDF_INT64	a;
1339
 
1328
 
1340
    UPARAM(a) = param_a;
1329
    UPARAM(a) = param_a;
1341
    CLEAR_ERRORS;
1330
    CLEAR_ERRORS;
1342
    if ((hi_u32(a) != 0)		||
1331
    if ((hi_u32(a)!= 0)	||
1343
	(((INT32) lo_u32(a)) < 0))	/* Must be an error - started off unsigned */
1332
	(((INT32) lo_u32(a)) < 0)) {	/* Must be an error - started off unsigned */
1344
    {
-
 
1345
	OVERFLOW_ERROR;
1333
	OVERFLOW_ERROR;
1346
    }
1334
    }
1347
 
1335
 
1348
    return  (INT32) lo_u32(a);
1336
    return (INT32)lo_u32(a);
1349
}
1337
}
1350
 
1338
 
1351
 
1339
 
1352
/*
1340
/*
1353
** 	__TDFUu642s64:
1341
** 	__TDFUu642s64:
1354
**
1342
**
1355
**  Error only if MSB of "a" is set.
1343
**  Error only if MSB of "a" is set.
1356
**  Return bits 0-31.
1344
**  Return bits 0-31.
1357
*/
1345
*/
1358
 
1346
 
1359
INT64 __TDFUu642s64 PROTO_N ((param_a))
1347
INT64
1360
		    PROTO_T (UINT64 param_a)
1348
__TDFUu642s64(UINT64 param_a)
1361
{
1349
{
1362
    TDF_INT64	a;
1350
    TDF_INT64	a;
1363
 
1351
 
1364
    UPARAM(a) = param_a;
1352
    UPARAM(a) = param_a;
1365
    CLEAR_ERRORS;
1353
    CLEAR_ERRORS;
1366
    if (TDFUis_negative(a))	/* Cast and check */
1354
    if (TDFUis_negative(a)) {	/* Cast and check */
1367
    {
-
 
1368
	OVERFLOW_ERROR;
1355
	OVERFLOW_ERROR;
1369
    }
1356
    }
1370
 
1357
 
1371
    return  PARAM(a);
1358
    return PARAM(a);
1372
}
1359
}
1373
 
1360
 
1374
 
1361
 
1375
/*
1362
/*
1376
** 	__TDFUs642u64:
1363
** 	__TDFUs642u64:
1377
**
1364
**
1378
**  Error only if "a" < 0.
1365
**  Error only if "a" < 0.
1379
**  Return bits 0-31.
1366
**  Return bits 0-31.
1380
*/
1367
*/
1381
 
1368
 
1382
UINT64 __TDFUs642u64 PROTO_N ((param_a))
1369
UINT64
1383
		     PROTO_T (INT64 param_a)
1370
__TDFUs642u64(INT64 param_a)
1384
{
1371
{
1385
    TDF_INT64	a;
1372
    TDF_INT64	a;
1386
 
1373
 
1387
    PARAM(a) = param_a;
1374
    PARAM(a) = param_a;
1388
    CLEAR_ERRORS;
1375
    CLEAR_ERRORS;
1389
    if (TDFUis_negative(a))	/* Check and cast */
1376
    if (TDFUis_negative(a)) {	/* Check and cast */
1390
    {
-
 
1391
	OVERFLOW_ERROR;
1377
	OVERFLOW_ERROR;
1392
    }
1378
    }
1393
 
1379
 
1394
    return  UPARAM(a);
1380
    return UPARAM(a);
1395
}
1381
}
1396
 
1382
 
1397
 
1383
 
1398
 
1384
 
1399
 
1385
 
Line 1402... Line 1388...
1402
**
1388
**
1403
**  Uses: (a>b) ? a : b		No errors.
1389
**  Uses: (a>b) ? a : b		No errors.
1404
**
1390
**
1405
*/
1391
*/
1406
 
1392
 
1407
INT64 __TDFUs_max PROTO_N ((param_a, param_b))
1393
INT64
1408
		  PROTO_T (INT64 param_a X INT64 param_b)
1394
__TDFUs_max(INT64 param_a, INT64 param_b)
1409
{
1395
{
1410
    CLEAR_ERRORS;
1396
    CLEAR_ERRORS;
1411
    if (__TDFUs_test(param_a, param_b) > 0) {
1397
    if (__TDFUs_test(param_a, param_b) > 0) {
1412
	 return param_a;			/* a = max(a,b) */
1398
	 return param_a;			/* a = max(a,b) */
1413
    }
1399
    }
1414
    return  param_b;				/* b = max(a,b) */
1400
    return param_b;				/* b = max(a,b) */
1415
}
1401
}
1416
 
1402
 
1417
 
1403
 
1418
/*
1404
/*
1419
** 	__TDFUu_max:
1405
** 	__TDFUu_max:
1420
**
1406
**
1421
**  Uses: (a>b) ? a : b		No errors.
1407
**  Uses: (a>b) ? a : b		No errors.
1422
**
1408
**
1423
*/
1409
*/
1424
 
1410
 
1425
UINT64 __TDFUu_max PROTO_N ((param_a, param_b))
1411
UINT64
1426
		   PROTO_T (UINT64 param_a X UINT64 param_b)
1412
__TDFUu_max(UINT64 param_a, UINT64 param_b)
1427
{
1413
{
1428
    if (__TDFUu_test(param_a, param_b) > 0) {
1414
    if (__TDFUu_test(param_a, param_b) > 0) {
1429
	 return param_a;			/* a = max(a,b) */
1415
	 return param_a;			/* a = max(a,b) */
1430
    }
1416
    }
1431
    return  param_b;				/* b = max(a,b) */
1417
    return param_b;				/* b = max(a,b) */
1432
}
1418
}
1433
 
1419
 
1434
 
1420
 
1435
/*
1421
/*
1436
** 	__TDFUs_min:
1422
** 	__TDFUs_min:
1437
**
1423
**
1438
**  Uses: (a<b) ? a : b		No errors.
1424
**  Uses: (a<b) ? a : b		No errors.
1439
**
1425
**
1440
*/
1426
*/
1441
 
1427
 
1442
INT64 __TDFUs_min PROTO_N ((param_a, param_b))
1428
INT64
1443
		  PROTO_T (INT64 param_a X INT64 param_b)
1429
__TDFUs_min(INT64 param_a, INT64 param_b)
1444
{
1430
{
1445
    if (__TDFUs_test(param_a, param_b) < 0) {
1431
    if (__TDFUs_test(param_a, param_b) < 0) {
1446
	return param_a;				/* a = min(a,b) */
1432
	return param_a;				/* a = min(a,b) */
1447
    }
1433
    }
1448
    return param_b;				/* b = min(a,b) */
1434
    return param_b;				/* b = min(a,b) */
Line 1454... Line 1440...
1454
**
1440
**
1455
**  Uses: (a<b) ? a : b		No errors.
1441
**  Uses: (a<b) ? a : b		No errors.
1456
**
1442
**
1457
*/
1443
*/
1458
 
1444
 
1459
UINT64 __TDFUu_min PROTO_N ((param_a, param_b))
1445
UINT64
1460
		   PROTO_T (UINT64 param_a X UINT64 param_b)
1446
__TDFUu_min(UINT64 param_a, UINT64 param_b)
1461
{
1447
{
1462
    if (__TDFUu_test(param_a, param_b) < 0) {
1448
    if (__TDFUu_test(param_a, param_b) < 0) {
1463
	return param_a;				/* a = min(a,b) */
1449
	return param_a;				/* a = min(a,b) */
1464
    }
1450
    }
1465
    return param_b;				/* b = min(a,b) */
1451
    return param_b;				/* b = min(a,b) */
Line 1475... Line 1461...
1475
**           0  if a = b;
1461
**           0  if a = b;
1476
**	     1  if a > b.
1462
**	     1  if a > b.
1477
**
1463
**
1478
*/
1464
*/
1479
 
1465
 
1480
int __TDFUs_test PROTO_N ((param_a, param_b))
-
 
-
 
1466
int
1481
		 PROTO_T (INT64 param_a X INT64 param_b)
1467
__TDFUs_test(INT64 param_a, INT64 param_b)
1482
{
1468
{
1483
    TDF_INT64	a, b;
1469
    TDF_INT64	a, b;
1484
 
1470
 
1485
    PARAM(a) = param_a;
1471
    PARAM(a) = param_a;
1486
    PARAM(b) = param_b;
1472
    PARAM(b) = param_b;
Line 1495... Line 1481...
1495
 
1481
 
1496
/*
1482
/*
1497
**	__TDFUu_test:  as for __TDFUs_test, but for unsigned types.
1483
**	__TDFUu_test:  as for __TDFUs_test, but for unsigned types.
1498
*/
1484
*/
1499
 
1485
 
1500
int __TDFUu_test PROTO_N ((param_a, param_b))
-
 
-
 
1486
int
1501
	         PROTO_T (UINT64 param_a X UINT64 param_b)
1487
__TDFUu_test(UINT64 param_a, UINT64 param_b)
1502
{
1488
{
1503
    TDF_INT64	a, b;
1489
    TDF_INT64	a, b;
1504
 
1490
 
1505
    UPARAM(a) = param_a;
1491
    UPARAM(a) = param_a;
1506
    UPARAM(b) = param_b;
1492
    UPARAM(b) = param_b;
Line 1520... Line 1506...
1520
**	__TDFUand
1506
**	__TDFUand
1521
**
1507
**
1522
**  ANDs the hi- and low-words together, and returns.
1508
**  ANDs the hi- and low-words together, and returns.
1523
*/
1509
*/
1524
 
1510
 
1525
UINT64 __TDFUand PROTO_N ((param_a, param_b))
1511
UINT64
1526
		 PROTO_T (UINT64 param_a X UINT64 param_b)
1512
__TDFUand(UINT64 param_a, UINT64 param_b)
1527
{
1513
{
1528
    TDF_INT64	a, b;
1514
    TDF_INT64	a, b;
1529
 
1515
 
1530
    UPARAM(a) = param_a;
1516
    UPARAM(a) = param_a;
1531
    UPARAM(b) = param_b;
1517
    UPARAM(b) = param_b;
1532
    CLEAR_ERRORS;
1518
    CLEAR_ERRORS;
1533
 
1519
 
1534
    hi_u32(a) = (hi_u32(a) & hi_u32(b));
1520
    hi_u32(a) = (hi_u32(a) & hi_u32(b));
1535
    lo_u32(a) = (lo_u32(a) & lo_u32(b));
1521
    lo_u32(a) = (lo_u32(a) & lo_u32(b));
1536
    return  UPARAM(a);
1522
    return UPARAM(a);
1537
}
1523
}
1538
 
1524
 
1539
 
1525
 
1540
/*
1526
/*
1541
**	__TDFUor
1527
**	__TDFUor
1542
**
1528
**
1543
**  ORs the hi- and low-words together, and returns.
1529
**  ORs the hi- and low-words together, and returns.
1544
*/
1530
*/
1545
 
1531
 
1546
UINT64 __TDFUor PROTO_N ((param_a, param_b))
1532
UINT64
1547
		PROTO_T (UINT64 param_a X UINT64 param_b)
1533
__TDFUor(UINT64 param_a, UINT64 param_b)
1548
{
1534
{
1549
    TDF_INT64	a, b;
1535
    TDF_INT64	a, b;
1550
 
1536
 
1551
    UPARAM(a) = param_a;
1537
    UPARAM(a) = param_a;
1552
    UPARAM(b) = param_b;
1538
    UPARAM(b) = param_b;
1553
    CLEAR_ERRORS;
1539
    CLEAR_ERRORS;
1554
 
1540
 
1555
    hi_u32(a) = (hi_u32(a) | hi_u32(b));
1541
    hi_u32(a) = (hi_u32(a) | hi_u32(b));
1556
    lo_u32(a) = (lo_u32(a) | lo_u32(b));
1542
    lo_u32(a) = (lo_u32(a) | lo_u32(b));
1557
    return  UPARAM(a);
1543
    return UPARAM(a);
1558
}
1544
}
1559
 
1545
 
1560
 
1546
 
1561
 
1547
 
1562
/*
1548
/*
1563
**	__TDFUxor
1549
**	__TDFUxor
1564
**
1550
**
1565
**  ORs the hi- and low-words together, and returns.
1551
**  ORs the hi- and low-words together, and returns.
1566
*/
1552
*/
1567
 
1553
 
1568
UINT64 __TDFUxor PROTO_N ((param_a, param_b))
1554
UINT64
1569
		 PROTO_T (UINT64 param_a X UINT64 param_b)
1555
__TDFUxor(UINT64 param_a, UINT64 param_b)
1570
{
1556
{
1571
    TDF_INT64	a, b;
1557
    TDF_INT64	a, b;
1572
 
1558
 
1573
    UPARAM(a) = param_a;
1559
    UPARAM(a) = param_a;
1574
    UPARAM(b) = param_b;
1560
    UPARAM(b) = param_b;
1575
    CLEAR_ERRORS;
1561
    CLEAR_ERRORS;
1576
 
1562
 
1577
    hi_u32(a) = (hi_u32(a) ^ hi_u32(b));
1563
    hi_u32(a) = (hi_u32(a)^ hi_u32(b));
1578
    lo_u32(a) = (lo_u32(a) ^ lo_u32(b));
1564
    lo_u32(a) = (lo_u32(a)^ lo_u32(b));
1579
    return  UPARAM(a);
1565
    return UPARAM(a);
1580
}
1566
}
1581
 
1567
 
1582
 
1568
 
1583
 
1569
 
1584
/*
1570
/*
1585
**	__TDFUnot
1571
**	__TDFUnot
1586
**
1572
**
1587
**  XORs the hi- and low-words each with 0xffffffff
1573
**  XORs the hi- and low-words each with 0xffffffff
1588
*/
1574
*/
1589
 
1575
 
1590
UINT64 __TDFUnot PROTO_N ((param_a))
1576
UINT64
1591
		 PROTO_T (UINT64 param_a)
1577
__TDFUnot(UINT64 param_a)
1592
{
1578
{
1593
    TDF_INT64	a;
1579
    TDF_INT64	a;
1594
 
1580
 
1595
    UPARAM(a) = param_a;
1581
    UPARAM(a) = param_a;
1596
    CLEAR_ERRORS;
1582
    CLEAR_ERRORS;
1597
    hi_u32(a) = hi_u32(a) ^ ((UINT32) 0xffffffff);
1583
    hi_u32(a) = hi_u32(a)^((UINT32)0xffffffff);
1598
    lo_u32(a) = lo_u32(a) ^ ((UINT32) 0xffffffff);
1584
    lo_u32(a) = lo_u32(a)^((UINT32)0xffffffff);
1599
    return  UPARAM(a);
1585
    return UPARAM(a);
1600
}
1586
}
1601
 
1587
 
1602
 
1588
 
1603
 
1589
 
1604
 
1590
 
1605
/* Functions only used for debug purposes - normally hidden */
1591
/* Functions only used for debug purposes - normally hidden */
1606
 
1592
 
1607
#if DEBUG
1593
#if DEBUG
1608
INT64 make_INT64 PROTO_N ((new_hi, new_lo))
1594
INT64
1609
		 PROTO_T (INT32 new_hi X UINT32 new_lo)
1595
make_INT64(INT32 new_hi, UINT32 new_lo)
1610
{
1596
{
1611
    TDF_INT64	new_int;
1597
    TDF_INT64	new_int;
1612
 
1598
 
1613
    hi_32 (new_int) = new_hi;
1599
    hi_32(new_int) = new_hi;
1614
    lo_32 (new_int) = new_lo;
1600
    lo_32(new_int) = new_lo;
1615
    return  PARAM(new_int);
1601
    return PARAM(new_int);
1616
}
1602
}
1617
 
1603
 
1618
 
1604
 
1619
UINT64 make_UINT64 PROTO_N ((new_hi, new_lo))
1605
UINT64
1620
		   PROTO_T (UINT32 new_hi X UINT32 new_lo)
1606
make_UINT64(UINT32 new_hi, UINT32 new_lo)
1621
{
1607
{
1622
    TDF_INT64	new_int;
1608
    TDF_INT64	new_int;
1623
 
1609
 
1624
    hi_u32 (new_int) = new_hi;
1610
    hi_u32(new_int) = new_hi;
1625
    lo_u32 (new_int) = new_lo;
1611
    lo_u32(new_int) = new_lo;
1626
    return  UPARAM(new_int);
1612
    return UPARAM(new_int);
1627
}
1613
}
1628
 
1614
 
1629
void INT64_print PROTO_N ((t1, a, t2))
1615
void
1630
		 PROTO_T (char * t1 X INT64 a X char *t2)
1616
INT64_print(char * t1, INT64 a, char *t2)
1631
{
1617
{
1632
    IGNORE printf ("%s(%d,%u)%s", t1, (int) a.hi32, (unsigned) a.lo32, t2);
1618
    IGNORE printf("%s(%d,%u)%s", t1, (int)a.hi32, (unsigned)a.lo32, t2);
1633
    return;
1619
    return;
1634
}
1620
}
1635
 
1621
 
1636
void UINT64_print PROTO_N ((t1, a, t2))
1622
void
1637
		  PROTO_T (char * t1 X UINT64 a X char * t2)
1623
UINT64_print(char * t1, UINT64 a, char * t2)
1638
{
1624
{
1639
    IGNORE printf ("%s(%u,%u)%s", t1, (unsigned) a.hi32, (unsigned) a.lo32, t2);
1625
    IGNORE printf("%s(%u,%u)%s", t1, (unsigned)a.hi32, (unsigned)a.lo32, t2);
1640
    return;
1626
    return;
1641
}
1627
}
1642
#endif  /* DEBUG */
1628
#endif  /* DEBUG */