Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/* 	$Id: cross.c,v 1.1.1.1 1998/01/17 15:55:59 release Exp $	 */
32
 
33
#ifndef lint
34
static char vcid[] = "$Id: cross.c,v 1.1.1.1 1998/01/17 15:55:59 release Exp $";
35
#endif /* lint */
36
 
37
/*
38
$Log: cross.c,v $
39
 * Revision 1.1.1.1  1998/01/17  15:55:59  release
40
 * First version to be checked into rolling release.
41
 *
42
 * Revision 1.2  1995/05/23  10:54:34  john
43
 * Cosmetic changes
44
 *
45
 * Revision 1.1.1.1  1995/03/23  10:39:05  john
46
 * Entered into CVS
47
 *
48
 * Revision 1.8  1995/01/12  15:03:36  john
49
 * Minor Fix
50
 *
51
*/
52
 
53
/*
54
  cross.c
55
 
56
  This file contains code to allow 64 bit arithmetic to be handled 
57
  portably.
58
*/
59
 
60
#include "output.h"
61
#include "config.h"
62
#include "flpttypes.h"
63
#include "cross.h"
64
#include "main.h"
65
#include "config.h"
66
#include "fail.h"
67
#include "flpt.h"
68
#include "f64.h"
69
#include "expmacs.h"
70
 
71
#if FS_64_BIT
72
 
73
INT64 flt64_to_INT64
74
    PROTO_N ( ( arg ) )
75
    PROTO_T ( flt64 arg )
76
{
77
  INT64 res;
78
  res = arg.small+((long)arg.big<<32);
79
  return res;
80
}
81
 
82
 
83
INT64 exp_to_INT64
84
    PROTO_N ( ( e ) )
85
    PROTO_T ( exp e )
86
{
87
  if(isbigval(e)){
88
    return flt64_to_INT64(exp_to_f64(e));
89
  }
90
  else{
91
    return no(e);
92
  }
93
}
94
 
95
 
96
 
97
 
98
#else /* FS_64_BIT */
99
 
100
/*
101
  This function outputs a literal 64 bit int value to the 
102
  assembler file.  If the value of the argument exceeds the integer
103
  range of the machine it is output in hexadecimal representation;
104
  otherwise it is output as a decimal.
105
*/
106
void out_INT64
107
    PROTO_N ( ( val ) )
108
    PROTO_T ( INT64 val )
109
{
110
  if(isquad(val)){
111
    outhex(high_INT64(val));
112
    outhigh(low_INT64(val));
113
  }
114
  else{
115
    outint(low_INT64(val));
116
  }
117
}
118
 
119
 
120
 
121
/*
122
  The following functions implement the basic arithmetic 
123
  operations for the INT64 type.  In each case the procedure 
124
  is to convert the arguments into the internal floating point 
125
  representation and then use the floating point arithmetic and 
126
  conversion functions provided by the common installer code to 
127
  calculate the result.  In the event of an error in evaluation 
128
  the functions will each print an error message and execution 
129
  will halt; otherwise the result will be returned as an INT64.
130
  note: as the f64_to_flt function can change the base address 
131
  of flptnos, all references to the flptnos array should be made 
132
  _after_ this function has been called.
133
*/
134
 
135
/*******************************************************************/
136
 
137
INT64 INT64_mult
138
    PROTO_N ( ( arg1,arg2,sgned ) )
139
    PROTO_T ( INT64 arg1 X INT64 arg2 X bool sgned )
140
{
141
  int ov;
142
  flpt farg1;
143
  flpt	farg2;
144
  flt64 res;
145
  flpt fresno=new_flpt();
146
  flt *fres;
147
  farg1 = f64_to_flt(arg1,sgned);
148
  farg2 = f64_to_flt(arg2,sgned);
149
  fres= &flptnos[fresno];
150
  if(flt_mul(flptnos[farg1],flptnos[farg2],fres)==EXP2BIG){
151
    alphafail(BIG_MULTIPLICATION);
152
    abort();
153
  }
154
  res = flt_to_f64(fresno,sgned,&ov);
155
  flpt_ret(fresno);
156
  flpt_ret(farg1);
157
  flpt_ret(farg2);
158
  return flt64_to_INT64(res);
159
}
160
 
161
 
162
INT64 INT64_divide
163
    PROTO_N ( ( arg1,arg2,sgned ) )
164
    PROTO_T ( INT64 arg1 X INT64 arg2 X bool sgned )
165
{
166
  flpt farg1;
167
  flpt farg2;
168
  flt64 res;
169
  flpt fresno = new_flpt();
170
  flt  *fres;
171
  int ov;
172
  int divexit;
173
  farg1 = f64_to_flt(arg1,sgned);
174
  farg2 = f64_to_flt(arg2,sgned);
175
  fres = &flptnos[fresno];
176
  divexit = flt_div(flptnos[farg1],flptnos[farg2],fres);
177
  if((divexit == EXP2BIG)||(divexit == DIVBY0)){
178
    alphafail(BIG_DIVISION);
179
    abort();
180
  }
181
  res = flt_to_f64(fresno,sgned,&ov);
182
  flpt_ret(fresno);
183
  flpt_ret(farg1);
184
  flpt_ret(farg2);
185
  return flt64_to_INT64(res);
186
}
187
 
188
 
189
INT64 INT64_add
190
    PROTO_N ( ( arg1,arg2,sgned ) )
191
    PROTO_T ( INT64 arg1 X INT64 arg2 X bool sgned )
192
{
193
  flpt farg1;
194
  flpt farg2;
195
  flpt fresno = new_flpt();	
196
  flt  *fres;
197
  flt64 res;
198
  int ov;
199
  farg1 = f64_to_flt(arg1,sgned);
200
  farg2 = f64_to_flt(arg2,sgned);
201
  fres  = &flptnos[fresno];
202
  if(flt_add(flptnos[farg1],flptnos[farg2],fres) == EXP2BIG){
203
    alphafail(BIG_ADDITION);
204
    abort();
205
  }
206
  res = flt_to_f64(fresno,sgned,&ov);
207
  flpt_ret(fresno);
208
  flpt_ret(farg1);
209
  flpt_ret(farg2);
210
  return flt64_to_INT64(res);
211
}
212
 
213
 
214
INT64 INT64_subtract
215
    PROTO_N ( ( arg1,arg2,sgned ) )
216
    PROTO_T ( INT64 arg1 X INT64 arg2 X bool sgned )
217
{
218
  flpt farg1;
219
  flpt farg2;
220
  flpt fresno = new_flpt();
221
  flt *fres;
222
  flt64 res;
223
  int ov;
224
  farg1 = f64_to_flt(arg1,sgned);
225
  farg2 = f64_to_flt(arg2,sgned); 
226
  fres = &flptnos[fresno];
227
  if(flt_sub(flptnos[farg1],flptnos[farg2],fres) == EXP2BIG){
228
    alphafail(BIG_SUBTRACTION);
229
    abort();
230
  }
231
  res = flt_to_f64(fresno,sgned,&ov);
232
  flpt_ret(fresno);
233
  flpt_ret(farg1);
234
  flpt_ret(farg2);
235
  return flt64_to_INT64(res);
236
}  
237
 
238
 
239
INT64 INT64_increment
240
    PROTO_N ( ( arg ) )
241
    PROTO_T ( INT64 arg )
242
{
243
  INT64 inc_64=make_INT64(0U,1);
244
  return INT64_add(arg,inc_64,1);
245
}
246
 
247
INT64 INT64_decrement
248
    PROTO_N ( ( arg ) )
249
    PROTO_T ( INT64 arg )
250
{
251
  INT64 dec_64=make_INT64(0U,1);
252
  return INT64_subtract(arg,dec_64,1);
253
}
254
 
255
 
256
 
257
/*******************************************************************/
258
 
259
 
260
 
261
/*
262
   The following functions implement bitwise logical operations 
263
   for the INT64 type.  
264
*/
265
 
266
/*******************************************************************/
267
 
268
INT64 INT64_or
269
    PROTO_N ( ( arg1,arg2 ) )
270
    PROTO_T ( INT64 arg1 X INT64 arg2 )
271
{
272
  INT64 res;
273
  low_INT64(res)=low_INT64(arg1)|low_INT64(arg2);
274
  high_INT64(res)=high_INT64(arg1)|high_INT64(arg2);
275
  return res;
276
}
277
 
278
INT64 INT64_and
279
    PROTO_N ( ( arg1,arg2 ) )
280
    PROTO_T ( INT64 arg1 X INT64 arg2 )
281
{
282
  INT64 res;
283
  low_INT64(res)=low_INT64(arg1)&low_INT64(arg2);
284
  high_INT64(res)=high_INT64(arg1)&high_INT64(arg2);
285
  return res;
286
}
287
 
288
INT64 INT64_not
289
    PROTO_N ( ( arg ) )
290
    PROTO_T ( INT64 arg )
291
{
292
  INT64 res;
293
  low_INT64(res) = ~low_INT64(arg);
294
  high_INT64(res) = ~high_INT64(arg);
295
  return res;
296
}
297
 
298
 
299
/*******************************************************************/
300
 
301
 
302
 
303
/*
304
   The following functions implement left and right shift operations 
305
   for the INT64 type.
306
*/
307
 
308
/*******************************************************************/
309
 
310
INT64 INT64_shift_left
311
    PROTO_N ( ( arg,shift,sgned ) )
312
    PROTO_T ( INT64 arg X int shift X int sgned )
313
{
314
  INT64 multiplier;
315
  if(shift<=31){
316
    low_INT64(multiplier)=(1<<shift);
317
    high_INT64(multiplier)=0;
318
  }
319
  else{
320
    high_INT64(multiplier)=(1<<(shift-32));
321
    low_INT64(multiplier)=0;
322
  }
323
  return INT64_mult(arg,multiplier,sgned);
324
}
325
 
326
 
327
 
328
INT64 INT64_shift_right
329
    PROTO_N ( ( arg,shift,sgned ) )
330
    PROTO_T ( INT64 arg X int shift X int sgned )
331
{
332
  INT64 divisor;
333
  if(shift<=31){
334
    low_INT64(divisor)=(1<<shift);
335
    high_INT64(divisor)=0;
336
  }
337
  else{
338
    low_INT64(divisor)=0;
339
    high_INT64(divisor)=(1<<(shift-32));
340
  }
341
  return INT64_divide(arg,divisor,sgned);
342
}
343
 
344
/*******************************************************************/
345
 
346
 
347
 
348
 
349
/*
350
   The following functions implement the comparison operations 
351
   >,>= and = for the INT64 type.
352
*/
353
 
354
/*******************************************************************/
355
bool INT64_eq
356
    PROTO_N ( ( arg1,arg2 ) )
357
    PROTO_T ( INT64 arg1 X INT64 arg2 )
358
{
359
  return (low_INT64(arg1)==low_INT64(arg2))&&
360
    (high_INT64(arg1)==high_INT64(arg2));
361
}
362
 
363
bool INT64_leq
364
    PROTO_N ( ( arg1,arg2 ) )
365
    PROTO_T ( INT64 arg1 X INT64 arg2 )
366
{
367
  /*
368
     test arg1<arg2
369
     */
370
  return ((high_INT64(arg1)<high_INT64(arg2))||
371
	  ((high_INT64(arg1)==high_INT64(arg2))&&
372
	   (low_INT64(arg1)<=low_INT64(arg2))));
373
}
374
 
375
bool INT64_lt
376
    PROTO_N ( ( arg1,arg2 ) )
377
    PROTO_T ( INT64 arg1 X INT64 arg2 )
378
{
379
  return ((high_INT64(arg1)<high_INT64(arg2))||
380
	  ((high_INT64(arg1)==high_INT64(arg2))&&
381
	   (low_INT64(arg1)<low_INT64(arg2))));
382
}
383
 
384
 
385
 
386
 
387
 
388
 
389
/*
390
   This function constructs an INT64 variable from two INT32
391
*/
392
INT64 make_INT64
393
    PROTO_N ( ( big,small ) )
394
    PROTO_T ( INT32 big X UINT32 small )
395
{
396
  INT64 res;
397
  high_INT64(res)=big;
398
  low_INT64(res)=small;
399
  return res;
400
}
401
 
402
#endif /* FS_64_BIT */