Linux Audio

Check our new training course

Loading...
v4.17
 
  1/*
  2 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3 *
  4 * Floating-point emulation code
  5 *  Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
  6 *
  7 *    This program is free software; you can redistribute it and/or modify
  8 *    it under the terms of the GNU General Public License as published by
  9 *    the Free Software Foundation; either version 2, or (at your option)
 10 *    any later version.
 11 *
 12 *    This program is distributed in the hope that it will be useful,
 13 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 *    GNU General Public License for more details.
 16 *
 17 *    You should have received a copy of the GNU General Public License
 18 *    along with this program; if not, write to the Free Software
 19 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 20 */
 21/*
 22 * BEGIN_DESC
 23 * 
 24 *  File: 
 25 *      @(#)	pa/spmath/float.h		$Revision: 1.1 $
 26 * 
 27 *  Purpose:
 28 *      <<please update with a synopis of the functionality provided by this file>>
 29 * 
 30 *  BE header:  no
 31 *
 32 *  Shipped:  yes
 33 *	/usr/conf/pa/spmath/float.h
 34 *
 35 * END_DESC  
 36*/
 37
 38#ifdef __NO_PA_HDRS
 39    PA header file -- do not include this header file for non-PA builds.
 40#endif
 41
 42#include "fpbits.h"
 43#include "hppa.h"
 44/*
 45 * Want to pick up the FPU capability flags, not the PDC structures.
 46 * 'LOCORE' isn't really true in this case, but we don't want the C structures
 47 * so it suits our purposes
 48 */
 49#define LOCORE
 50#include "fpu.h"
 51
 52/*
 53 * Declare the basic structures for the 3 different
 54 * floating-point precisions.
 55 *        
 56 * Single number  
 57 * +-------+-------+-------+-------+-------+-------+-------+-------+
 58 * |s|       exp     |               mantissa                      |
 59 * +-------+-------+-------+-------+-------+-------+-------+-------+
 60 */
 61#define	Sall(object) (object)
 62#define	Ssign(object) Bitfield_extract( 0,  1,object)
 63#define	Ssignedsign(object) Bitfield_signed_extract( 0,  1,object)
 64#define	Sexponent(object) Bitfield_extract( 1,  8,object)
 65#define	Smantissa(object) Bitfield_mask( 9, 23,object)
 66#define	Ssignaling(object) Bitfield_extract( 9,  1,object)
 67#define	Ssignalingnan(object) Bitfield_extract( 1,  9,object)
 68#define	Shigh2mantissa(object) Bitfield_extract( 9,  2,object)
 69#define	Sexponentmantissa(object) Bitfield_mask( 1, 31,object)
 70#define	Ssignexponent(object) Bitfield_extract( 0,  9,object)
 71#define	Shidden(object) Bitfield_extract( 8,  1,object)
 72#define	Shiddenoverflow(object) Bitfield_extract( 7,  1,object)
 73#define	Shiddenhigh7mantissa(object) Bitfield_extract( 8,  8,object)
 74#define	Shiddenhigh3mantissa(object) Bitfield_extract( 8,  4,object)
 75#define	Slow(object) Bitfield_mask( 31,  1,object)
 76#define	Slow4(object) Bitfield_mask( 28,  4,object)
 77#define	Slow31(object) Bitfield_mask( 1, 31,object)
 78#define	Shigh31(object) Bitfield_extract( 0, 31,object)
 79#define	Ssignedhigh31(object) Bitfield_signed_extract( 0, 31,object)
 80#define	Shigh4(object) Bitfield_extract( 0,  4,object)
 81#define	Sbit24(object) Bitfield_extract( 24,  1,object)
 82#define	Sbit28(object) Bitfield_extract( 28,  1,object)
 83#define	Sbit29(object) Bitfield_extract( 29,  1,object)
 84#define	Sbit30(object) Bitfield_extract( 30,  1,object)
 85#define	Sbit31(object) Bitfield_mask( 31,  1,object)
 86
 87#define Deposit_ssign(object,value) Bitfield_deposit(value,0,1,object)
 88#define Deposit_sexponent(object,value) Bitfield_deposit(value,1,8,object)
 89#define Deposit_smantissa(object,value) Bitfield_deposit(value,9,23,object)
 90#define Deposit_shigh2mantissa(object,value) Bitfield_deposit(value,9,2,object)
 91#define Deposit_sexponentmantissa(object,value) \
 92    Bitfield_deposit(value,1,31,object)
 93#define Deposit_ssignexponent(object,value) Bitfield_deposit(value,0,9,object)
 94#define Deposit_slow(object,value) Bitfield_deposit(value,31,1,object)
 95#define Deposit_shigh4(object,value) Bitfield_deposit(value,0,4,object)
 96
 97#define	Is_ssign(object) Bitfield_mask( 0,  1,object)
 98#define	Is_ssignaling(object) Bitfield_mask( 9,  1,object)
 99#define	Is_shidden(object) Bitfield_mask( 8,  1,object)
100#define	Is_shiddenoverflow(object) Bitfield_mask( 7,  1,object)
101#define	Is_slow(object) Bitfield_mask( 31,  1,object)
102#define	Is_sbit24(object) Bitfield_mask( 24,  1,object)
103#define	Is_sbit28(object) Bitfield_mask( 28,  1,object)
104#define	Is_sbit29(object) Bitfield_mask( 29,  1,object)
105#define	Is_sbit30(object) Bitfield_mask( 30,  1,object)
106#define	Is_sbit31(object) Bitfield_mask( 31,  1,object)
107
108/* 
109 * Double number.
110 * +-------+-------+-------+-------+-------+-------+-------+-------+
111 * |s|       exponent      |          mantissa part 1              |
112 * +-------+-------+-------+-------+-------+-------+-------+-------+
113 *
114 * +-------+-------+-------+-------+-------+-------+-------+-------+
115 * |                    mantissa part 2                            |
116 * +-------+-------+-------+-------+-------+-------+-------+-------+
117 */
118#define Dallp1(object) (object)
119#define Dsign(object) Bitfield_extract( 0,  1,object)
120#define Dsignedsign(object) Bitfield_signed_extract( 0,  1,object)
121#define Dexponent(object) Bitfield_extract( 1,  11,object)
122#define Dmantissap1(object) Bitfield_mask( 12, 20,object)
123#define Dsignaling(object) Bitfield_extract( 12,  1,object)
124#define Dsignalingnan(object) Bitfield_extract( 1,  12,object)
125#define Dhigh2mantissa(object) Bitfield_extract( 12,  2,object)
126#define Dexponentmantissap1(object) Bitfield_mask( 1, 31,object)
127#define Dsignexponent(object) Bitfield_extract( 0, 12,object)
128#define Dhidden(object) Bitfield_extract( 11,  1,object)
129#define Dhiddenoverflow(object) Bitfield_extract( 10,  1,object)
130#define Dhiddenhigh7mantissa(object) Bitfield_extract( 11,  8,object)
131#define Dhiddenhigh3mantissa(object) Bitfield_extract( 11,  4,object)
132#define Dlowp1(object) Bitfield_mask( 31,  1,object)
133#define Dlow31p1(object) Bitfield_mask( 1, 31,object)
134#define Dhighp1(object) Bitfield_extract( 0,  1,object)
135#define Dhigh4p1(object) Bitfield_extract( 0,  4,object)
136#define Dhigh31p1(object) Bitfield_extract( 0, 31,object)
137#define Dsignedhigh31p1(object) Bitfield_signed_extract( 0, 31,object)
138#define Dbit3p1(object) Bitfield_extract( 3,  1,object)
139
140#define Deposit_dsign(object,value) Bitfield_deposit(value,0,1,object)
141#define Deposit_dexponent(object,value) Bitfield_deposit(value,1,11,object)
142#define Deposit_dmantissap1(object,value) Bitfield_deposit(value,12,20,object)
143#define Deposit_dhigh2mantissa(object,value) Bitfield_deposit(value,12,2,object)
144#define Deposit_dexponentmantissap1(object,value) \
145    Bitfield_deposit(value,1,31,object)
146#define Deposit_dsignexponent(object,value) Bitfield_deposit(value,0,12,object)
147#define Deposit_dlowp1(object,value) Bitfield_deposit(value,31,1,object)
148#define Deposit_dhigh4p1(object,value) Bitfield_deposit(value,0,4,object)
149
150#define Is_dsign(object) Bitfield_mask( 0,  1,object)
151#define Is_dsignaling(object) Bitfield_mask( 12,  1,object)
152#define Is_dhidden(object) Bitfield_mask( 11,  1,object)
153#define Is_dhiddenoverflow(object) Bitfield_mask( 10,  1,object)
154#define Is_dlowp1(object) Bitfield_mask( 31,  1,object)
155#define Is_dhighp1(object) Bitfield_mask( 0,  1,object)
156#define Is_dbit3p1(object) Bitfield_mask( 3,  1,object)
157
158#define Dallp2(object) (object)
159#define Dmantissap2(object) (object)
160#define Dlowp2(object) Bitfield_mask( 31,  1,object)
161#define Dlow4p2(object) Bitfield_mask( 28,  4,object)
162#define Dlow31p2(object) Bitfield_mask( 1, 31,object)
163#define Dhighp2(object) Bitfield_extract( 0,  1,object)
164#define Dhigh31p2(object) Bitfield_extract( 0, 31,object)
165#define Dbit2p2(object) Bitfield_extract( 2,  1,object)
166#define Dbit3p2(object) Bitfield_extract( 3,  1,object)
167#define Dbit21p2(object) Bitfield_extract( 21,  1,object)
168#define Dbit28p2(object) Bitfield_extract( 28,  1,object)
169#define Dbit29p2(object) Bitfield_extract( 29,  1,object)
170#define Dbit30p2(object) Bitfield_extract( 30,  1,object)
171#define Dbit31p2(object) Bitfield_mask( 31,  1,object)
172
173#define Deposit_dlowp2(object,value) Bitfield_deposit(value,31,1,object)
174
175#define Is_dlowp2(object) Bitfield_mask( 31,  1,object)
176#define Is_dhighp2(object) Bitfield_mask( 0,  1,object)
177#define Is_dbit2p2(object) Bitfield_mask( 2,  1,object)
178#define Is_dbit3p2(object) Bitfield_mask( 3,  1,object)
179#define Is_dbit21p2(object) Bitfield_mask( 21,  1,object)
180#define Is_dbit28p2(object) Bitfield_mask( 28,  1,object)
181#define Is_dbit29p2(object) Bitfield_mask( 29,  1,object)
182#define Is_dbit30p2(object) Bitfield_mask( 30,  1,object)
183#define Is_dbit31p2(object) Bitfield_mask( 31,  1,object)
184
185/* 
186 * Quad number.
187 * +-------+-------+-------+-------+-------+-------+-------+-------+
188 * |s|          exponent           |      mantissa part 1          |
189 * +-------+-------+-------+-------+-------+-------+-------+-------+
190 *
191 * +-------+-------+-------+-------+-------+-------+-------+-------+
192 * |                    mantissa part 2                            |
193 * +-------+-------+-------+-------+-------+-------+-------+-------+
194 *
195 * +-------+-------+-------+-------+-------+-------+-------+-------+
196 * |                    mantissa part 3                            |
197 * +-------+-------+-------+-------+-------+-------+-------+-------+
198 *
199 * +-------+-------+-------+-------+-------+-------+-------+-------+
200 * |                    mantissa part 4                            |
201 * +-------+-------+-------+-------+-------+-------+-------+-------+
202 */
203typedef struct
204    {
205    union
206	{
207	struct { unsigned qallp1; } u_qallp1;
208/* Not needed for now...
209	Bitfield_extract( 0,  1,u_qsign,qsign)
210	Bitfield_signed_extract( 0,  1,u_qsignedsign,qsignedsign)
211	Bitfield_extract( 1, 15,u_qexponent,qexponent)
212	Bitfield_extract(16, 16,u_qmantissap1,qmantissap1)
213	Bitfield_extract(16,  1,u_qsignaling,qsignaling)
214	Bitfield_extract(1,  16,u_qsignalingnan,qsignalingnan)
215	Bitfield_extract(16,  2,u_qhigh2mantissa,qhigh2mantissa)
216	Bitfield_extract( 1, 31,u_qexponentmantissap1,qexponentmantissap1)
217	Bitfield_extract( 0, 16,u_qsignexponent,qsignexponent)
218	Bitfield_extract(15,  1,u_qhidden,qhidden)
219	Bitfield_extract(14,  1,u_qhiddenoverflow,qhiddenoverflow)
220	Bitfield_extract(15,  8,u_qhiddenhigh7mantissa,qhiddenhigh7mantissa)
221	Bitfield_extract(15,  4,u_qhiddenhigh3mantissa,qhiddenhigh3mantissa)
222	Bitfield_extract(31,  1,u_qlowp1,qlowp1)
223	Bitfield_extract( 1, 31,u_qlow31p1,qlow31p1)
224	Bitfield_extract( 0,  1,u_qhighp1,qhighp1)
225	Bitfield_extract( 0,  4,u_qhigh4p1,qhigh4p1)
226	Bitfield_extract( 0, 31,u_qhigh31p1,qhigh31p1)
227  */
228	} quad_u1;
229    union
230	{
231	struct { unsigned qallp2; } u_qallp2;
232  /* Not needed for now...
233	Bitfield_extract(31,  1,u_qlowp2,qlowp2)
234	Bitfield_extract( 1, 31,u_qlow31p2,qlow31p2)
235	Bitfield_extract( 0,  1,u_qhighp2,qhighp2)
236	Bitfield_extract( 0, 31,u_qhigh31p2,qhigh31p2)
237   */
238	} quad_u2;
239    union
240	{
241	struct { unsigned qallp3; } u_qallp3;
242  /* Not needed for now...
243	Bitfield_extract(31,  1,u_qlowp3,qlowp3)
244	Bitfield_extract( 1, 31,u_qlow31p3,qlow31p3)
245	Bitfield_extract( 0,  1,u_qhighp3,qhighp3)
246	Bitfield_extract( 0, 31,u_qhigh31p3,qhigh31p3)
247   */ 
248	} quad_u3;
249    union
250	{
251	struct { unsigned qallp4; } u_qallp4;
252    /* Not need for now...
253	Bitfield_extract(31,  1,u_qlowp4,qlowp4)
254	Bitfield_extract( 1, 31,u_qlow31p4,qlow31p4)
255	Bitfield_extract( 0,  1,u_qhighp4,qhighp4)
256	Bitfield_extract( 0, 31,u_qhigh31p4,qhigh31p4)
257     */
258	} quad_u4;
259    } quad_floating_point;
260
261/* Extension - An additional structure to hold the guard, round and
262 *             sticky bits during computations.
263 */
264#define Extall(object) (object)
265#define Extsign(object) Bitfield_extract( 0,  1,object)
266#define Exthigh31(object) Bitfield_extract( 0, 31,object)
267#define Extlow31(object) Bitfield_extract( 1, 31,object)
268#define Extlow(object) Bitfield_extract( 31,  1,object)
269
270/*
271 * Single extended - The upper word is just like single precision,
272 *                 but one additional word of mantissa is needed.
273 */
274#define Sextallp1(object) (object)
275#define Sextallp2(object) (object)
276#define Sextlowp1(object) Bitfield_extract( 31,  1,object)
277#define Sexthighp2(object) Bitfield_extract( 0,  1,object)
278#define Sextlow31p2(object) Bitfield_extract( 1, 31,object)
279#define Sexthiddenoverflow(object) Bitfield_extract( 4,  1,object)
280#define Is_sexthiddenoverflow(object) Bitfield_mask( 4,  1,object)
281
282/*
283 * Double extended - The upper two words are just like double precision,
284 *		     but two additional words of mantissa are needed.
285 */
286#define Dextallp1(object) (object)
287#define Dextallp2(object) (object)
288#define Dextallp3(object) (object)
289#define Dextallp4(object) (object)
290#define Dextlowp2(object) Bitfield_extract( 31,  1,object)
291#define Dexthighp3(object) Bitfield_extract( 0,  1,object)
292#define Dextlow31p3(object) Bitfield_extract( 1, 31,object)
293#define Dexthiddenoverflow(object) Bitfield_extract( 10,  1,object)
294#define Is_dexthiddenoverflow(object) Bitfield_mask( 10,  1,object)
295#define Deposit_dextlowp4(object,value) Bitfield_deposit(value,31,1,object)
296
297/*
298 * Declare the basic structures for the 3 different
299 * fixed-point precisions.
300 *        
301 * Single number  
302 * +-------+-------+-------+-------+-------+-------+-------+-------+
303 * |s|                    integer                                  |
304 * +-------+-------+-------+-------+-------+-------+-------+-------+
305 */
306typedef int sgl_integer;
307
308/* 
309 * Double number.
310 * +-------+-------+-------+-------+-------+-------+-------+-------+
311 * |s|                     high integer                            |
312 * +-------+-------+-------+-------+-------+-------+-------+-------+
313 *
314 * +-------+-------+-------+-------+-------+-------+-------+-------+
315 * |                       low integer                             |
316 * +-------+-------+-------+-------+-------+-------+-------+-------+
317 */
318struct dint {
319        int  wd0;
320        unsigned int wd1;
321};
322
323struct dblwd {
324        unsigned int wd0;
325        unsigned int wd1;
326};
327
328/* 
329 * Quad number.
330 * +-------+-------+-------+-------+-------+-------+-------+-------+
331 * |s|                  integer part1                              |
332 * +-------+-------+-------+-------+-------+-------+-------+-------+
333 *
334 * +-------+-------+-------+-------+-------+-------+-------+-------+
335 * |                    integer part 2                             |
336 * +-------+-------+-------+-------+-------+-------+-------+-------+
337 *
338 * +-------+-------+-------+-------+-------+-------+-------+-------+
339 * |                    integer part 3                             |
340 * +-------+-------+-------+-------+-------+-------+-------+-------+
341 *
342 * +-------+-------+-------+-------+-------+-------+-------+-------+
343 * |                    integer part 4                             |
344 * +-------+-------+-------+-------+-------+-------+-------+-------+
345 */
346
347struct quadwd {
348        int  wd0;
349        unsigned int wd1;
350        unsigned int wd2;
351        unsigned int wd3;
352};
353
354typedef struct quadwd quad_integer;
355
356
357/* useful typedefs */
358typedef unsigned int sgl_floating_point;
359typedef struct dblwd dbl_floating_point;
360typedef struct dint dbl_integer;
361typedef struct dblwd dbl_unsigned;
362
363/* 
364 * Define the different precisions' parameters.
365 */
366#define SGL_BITLENGTH 32
367#define SGL_EMAX 127
368#define SGL_EMIN (-126)
369#define SGL_BIAS 127
370#define SGL_WRAP 192
371#define SGL_INFINITY_EXPONENT (SGL_EMAX+SGL_BIAS+1)
372#define SGL_THRESHOLD 32
373#define SGL_EXP_LENGTH 8
374#define SGL_P 24
375
376#define DBL_BITLENGTH 64
377#define DBL_EMAX 1023
378#define DBL_EMIN (-1022)
379#define DBL_BIAS 1023
380#define DBL_WRAP 1536
381#define DBL_INFINITY_EXPONENT (DBL_EMAX+DBL_BIAS+1)
382#define DBL_THRESHOLD 64
383#define DBL_EXP_LENGTH 11
384#define DBL_P 53
385
386#define QUAD_BITLENGTH 128
387#define QUAD_EMAX 16383
388#define QUAD_EMIN (-16382)
389#define QUAD_BIAS 16383
390#define QUAD_WRAP 24576
391#define QUAD_INFINITY_EXPONENT (QUAD_EMAX+QUAD_BIAS+1)
392#define QUAD_P 113
393
394/* Boolean Values etc. */
395#define FALSE 0
396#define TRUE (!FALSE)
397#define NOT !
398#define XOR ^
399
400/* other constants */
401#undef NULL
402#define NULL 0
403#define NIL 0
404#define SGL 0
405#define DBL 1
406#define BADFMT 2
407#define QUAD 3
408
409
410/* Types */
411typedef int boolean;
412typedef int FORMAT;
413typedef int VOID;
414
415
416/* Declare status register equivalent to FPUs architecture.
417 *
418 *  0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
419 * +-------+-------+-------+-------+-------+-------+-------+-------+
420 * |V|Z|O|U|I|C|  rsv  |  model    | version |RM |rsv|T|r|V|Z|O|U|I|
421 * +-------+-------+-------+-------+-------+-------+-------+-------+
422 */
423#define Cbit(object) Bitfield_extract( 5, 1,object)
424#define Tbit(object) Bitfield_extract( 25, 1,object)
425#define Roundingmode(object) Bitfield_extract( 21, 2,object)
426#define Invalidtrap(object) Bitfield_extract( 27, 1,object)
427#define Divisionbyzerotrap(object) Bitfield_extract( 28, 1,object)
428#define Overflowtrap(object) Bitfield_extract( 29, 1,object)
429#define Underflowtrap(object) Bitfield_extract( 30, 1,object)
430#define Inexacttrap(object) Bitfield_extract( 31, 1,object)
431#define Invalidflag(object) Bitfield_extract( 0, 1,object)
432#define Divisionbyzeroflag(object) Bitfield_extract( 1, 1,object)
433#define Overflowflag(object) Bitfield_extract( 2, 1,object)
434#define Underflowflag(object) Bitfield_extract( 3, 1,object)
435#define Inexactflag(object) Bitfield_extract( 4, 1,object)
436#define Allflags(object) Bitfield_extract( 0, 5,object)
437
438/* Definitions relevant to the status register */
439
440/* Rounding Modes */
441#define ROUNDNEAREST 0
442#define ROUNDZERO    1
443#define ROUNDPLUS    2
444#define ROUNDMINUS   3
445
446/* Exceptions */
447#define NOEXCEPTION		0x0
448#define INVALIDEXCEPTION	0x20
449#define DIVISIONBYZEROEXCEPTION	0x10
450#define OVERFLOWEXCEPTION	0x08
451#define UNDERFLOWEXCEPTION	0x04
452#define INEXACTEXCEPTION	0x02
453#define UNIMPLEMENTEDEXCEPTION	0x01
454
455/* New exceptions for the 2E Opcode */
456#define OPC_2E_INVALIDEXCEPTION     0x30
457#define OPC_2E_OVERFLOWEXCEPTION    0x18
458#define OPC_2E_UNDERFLOWEXCEPTION   0x0c
459#define OPC_2E_INEXACTEXCEPTION     0x12
460
461/* Declare exception registers equivalent to FPUs architecture 
462 *
463 *  0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
464 * +-------+-------+-------+-------+-------+-------+-------+-------+
465 * |excepttype |  r1     | r2/ext  |  operation  |parm |n| t/cond  |
466 * +-------+-------+-------+-------+-------+-------+-------+-------+
467 */
468#define Allexception(object) (object)
469#define Exceptiontype(object) Bitfield_extract( 0, 6,object)
470#define Instructionfield(object) Bitfield_mask( 6,26,object)
471#define Parmfield(object) Bitfield_extract( 23, 3,object)
472#define Rabit(object) Bitfield_extract( 24, 1,object)
473#define Ibit(object) Bitfield_extract( 25, 1,object)
474
475#define Set_exceptiontype(object,value) Bitfield_deposit(value, 0, 6,object)
476#define Set_parmfield(object,value) Bitfield_deposit(value, 23, 3,object)
477#define Set_exceptiontype_and_instr_field(exception,instruction,object) \
478    object = exception << 26 | instruction
479
480/* Declare the condition field
481 *
482 *  0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
483 * +-------+-------+-------+-------+-------+-------+-------+-------+
484 * |                                                     |G|L|E|U|X|
485 * +-------+-------+-------+-------+-------+-------+-------+-------+
486 */
487#define Greaterthanbit(object) Bitfield_extract( 27, 1,object)
488#define Lessthanbit(object) Bitfield_extract( 28, 1,object)
489#define Equalbit(object) Bitfield_extract( 29, 1,object)
490#define Unorderedbit(object) Bitfield_extract( 30, 1,object)
491#define Exceptionbit(object) Bitfield_extract( 31, 1,object)
492
493/* An alias name for the status register */
494#define Fpustatus_register (*status)
495
496/**************************************************
497 * Status register referencing and manipulation.  *
498 **************************************************/
499
500/* Rounding mode */
501#define Rounding_mode()  Roundingmode(Fpustatus_register)
502#define Is_rounding_mode(rmode) \
503    (Roundingmode(Fpustatus_register) == rmode)
504#define Set_rounding_mode(value) \
505    Bitfield_deposit(value,21,2,Fpustatus_register)
506
507/* Boolean testing of the trap enable bits */
508#define Is_invalidtrap_enabled() Invalidtrap(Fpustatus_register)
509#define Is_divisionbyzerotrap_enabled() Divisionbyzerotrap(Fpustatus_register)
510#define Is_overflowtrap_enabled() Overflowtrap(Fpustatus_register)
511#define Is_underflowtrap_enabled() Underflowtrap(Fpustatus_register)
512#define Is_inexacttrap_enabled() Inexacttrap(Fpustatus_register)
513
514/* Set the indicated flags in the status register */
515#define Set_invalidflag() Bitfield_deposit(1,0,1,Fpustatus_register)
516#define Set_divisionbyzeroflag() Bitfield_deposit(1,1,1,Fpustatus_register)
517#define Set_overflowflag() Bitfield_deposit(1,2,1,Fpustatus_register)
518#define Set_underflowflag() Bitfield_deposit(1,3,1,Fpustatus_register)
519#define Set_inexactflag() Bitfield_deposit(1,4,1,Fpustatus_register)
520
521#define Clear_all_flags() Bitfield_deposit(0,0,5,Fpustatus_register)
522
523/* Manipulate the trap and condition code bits (tbit and cbit) */
524#define Set_tbit() Bitfield_deposit(1,25,1,Fpustatus_register)
525#define Clear_tbit() Bitfield_deposit(0,25,1,Fpustatus_register)
526#define Is_tbit_set() Tbit(Fpustatus_register)
527#define Is_cbit_set() Cbit(Fpustatus_register)
528
529#define Set_status_cbit(value)  \
530        Bitfield_deposit(value,5,1,Fpustatus_register)
531
532/*******************************
533 * Condition field referencing *
534 *******************************/
535#define Unordered(cond) Unorderedbit(cond)
536#define Equal(cond) Equalbit(cond)
537#define Lessthan(cond) Lessthanbit(cond)
538#define Greaterthan(cond) Greaterthanbit(cond)
539#define Exception(cond) Exceptionbit(cond)
540
541
542/* Defines for the extension */
543#define Ext_isone_sign(extent) (Extsign(extent))
544#define Ext_isnotzero(extent) \
545    (Extall(extent))
546#define Ext_isnotzero_lower(extent) \
547    (Extlow31(extent))
548#define Ext_leftshiftby1(extent) \
549    Extall(extent) <<= 1
550#define Ext_negate(extent) \
551    (int )Extall(extent) = 0 - (int )Extall(extent)
552#define Ext_setone_low(extent) Bitfield_deposit(1,31,1,extent)
553#define Ext_setzero(extent) Extall(extent) = 0
554
555typedef int operation;
556
557/* error messages */
558
559#define		NONE		0
560#define		UNDEFFPINST	1
561
562/* Function definitions: opcode, opclass */
563#define FTEST	(1<<2) | 0
564#define FCPY	(2<<2) | 0
565#define FABS	(3<<2) | 0
566#define FSQRT   (4<<2) | 0
567#define FRND    (5<<2) | 0
568
569#define FCNVFF	(0<<2) | 1
570#define FCNVXF	(1<<2) | 1
571#define FCNVFX	(2<<2) | 1
572#define FCNVFXT	(3<<2) | 1
573
574#define FCMP    (0<<2) | 2
575
576#define FADD	(0<<2) | 3
577#define FSUB	(1<<2) | 3
578#define FMPY	(2<<2) | 3
579#define FDIV	(3<<2) | 3
580#define FREM	(4<<2) | 3
581
v6.2
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  4 *
  5 * Floating-point emulation code
  6 *  Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  7 */
  8/*
  9 * BEGIN_DESC
 10 * 
 11 *  File: 
 12 *      @(#)	pa/spmath/float.h		$Revision: 1.1 $
 13 * 
 14 *  Purpose:
 15 *      <<please update with a synopis of the functionality provided by this file>>
 16 * 
 17 *  BE header:  no
 18 *
 19 *  Shipped:  yes
 20 *	/usr/conf/pa/spmath/float.h
 21 *
 22 * END_DESC  
 23*/
 24
 25#ifdef __NO_PA_HDRS
 26    PA header file -- do not include this header file for non-PA builds.
 27#endif
 28
 29#include "fpbits.h"
 30#include "hppa.h"
 31/*
 32 * Want to pick up the FPU capability flags, not the PDC structures.
 33 * 'LOCORE' isn't really true in this case, but we don't want the C structures
 34 * so it suits our purposes
 35 */
 36#define LOCORE
 37#include "fpu.h"
 38
 39/*
 40 * Declare the basic structures for the 3 different
 41 * floating-point precisions.
 42 *        
 43 * Single number  
 44 * +-------+-------+-------+-------+-------+-------+-------+-------+
 45 * |s|       exp     |               mantissa                      |
 46 * +-------+-------+-------+-------+-------+-------+-------+-------+
 47 */
 48#define	Sall(object) (object)
 49#define	Ssign(object) Bitfield_extract( 0,  1,object)
 50#define	Ssignedsign(object) Bitfield_signed_extract( 0,  1,object)
 51#define	Sexponent(object) Bitfield_extract( 1,  8,object)
 52#define	Smantissa(object) Bitfield_mask( 9, 23,object)
 53#define	Ssignaling(object) Bitfield_extract( 9,  1,object)
 54#define	Ssignalingnan(object) Bitfield_extract( 1,  9,object)
 55#define	Shigh2mantissa(object) Bitfield_extract( 9,  2,object)
 56#define	Sexponentmantissa(object) Bitfield_mask( 1, 31,object)
 57#define	Ssignexponent(object) Bitfield_extract( 0,  9,object)
 58#define	Shidden(object) Bitfield_extract( 8,  1,object)
 59#define	Shiddenoverflow(object) Bitfield_extract( 7,  1,object)
 60#define	Shiddenhigh7mantissa(object) Bitfield_extract( 8,  8,object)
 61#define	Shiddenhigh3mantissa(object) Bitfield_extract( 8,  4,object)
 62#define	Slow(object) Bitfield_mask( 31,  1,object)
 63#define	Slow4(object) Bitfield_mask( 28,  4,object)
 64#define	Slow31(object) Bitfield_mask( 1, 31,object)
 65#define	Shigh31(object) Bitfield_extract( 0, 31,object)
 66#define	Ssignedhigh31(object) Bitfield_signed_extract( 0, 31,object)
 67#define	Shigh4(object) Bitfield_extract( 0,  4,object)
 68#define	Sbit24(object) Bitfield_extract( 24,  1,object)
 69#define	Sbit28(object) Bitfield_extract( 28,  1,object)
 70#define	Sbit29(object) Bitfield_extract( 29,  1,object)
 71#define	Sbit30(object) Bitfield_extract( 30,  1,object)
 72#define	Sbit31(object) Bitfield_mask( 31,  1,object)
 73
 74#define Deposit_ssign(object,value) Bitfield_deposit(value,0,1,object)
 75#define Deposit_sexponent(object,value) Bitfield_deposit(value,1,8,object)
 76#define Deposit_smantissa(object,value) Bitfield_deposit(value,9,23,object)
 77#define Deposit_shigh2mantissa(object,value) Bitfield_deposit(value,9,2,object)
 78#define Deposit_sexponentmantissa(object,value) \
 79    Bitfield_deposit(value,1,31,object)
 80#define Deposit_ssignexponent(object,value) Bitfield_deposit(value,0,9,object)
 81#define Deposit_slow(object,value) Bitfield_deposit(value,31,1,object)
 82#define Deposit_shigh4(object,value) Bitfield_deposit(value,0,4,object)
 83
 84#define	Is_ssign(object) Bitfield_mask( 0,  1,object)
 85#define	Is_ssignaling(object) Bitfield_mask( 9,  1,object)
 86#define	Is_shidden(object) Bitfield_mask( 8,  1,object)
 87#define	Is_shiddenoverflow(object) Bitfield_mask( 7,  1,object)
 88#define	Is_slow(object) Bitfield_mask( 31,  1,object)
 89#define	Is_sbit24(object) Bitfield_mask( 24,  1,object)
 90#define	Is_sbit28(object) Bitfield_mask( 28,  1,object)
 91#define	Is_sbit29(object) Bitfield_mask( 29,  1,object)
 92#define	Is_sbit30(object) Bitfield_mask( 30,  1,object)
 93#define	Is_sbit31(object) Bitfield_mask( 31,  1,object)
 94
 95/* 
 96 * Double number.
 97 * +-------+-------+-------+-------+-------+-------+-------+-------+
 98 * |s|       exponent      |          mantissa part 1              |
 99 * +-------+-------+-------+-------+-------+-------+-------+-------+
100 *
101 * +-------+-------+-------+-------+-------+-------+-------+-------+
102 * |                    mantissa part 2                            |
103 * +-------+-------+-------+-------+-------+-------+-------+-------+
104 */
105#define Dallp1(object) (object)
106#define Dsign(object) Bitfield_extract( 0,  1,object)
107#define Dsignedsign(object) Bitfield_signed_extract( 0,  1,object)
108#define Dexponent(object) Bitfield_extract( 1,  11,object)
109#define Dmantissap1(object) Bitfield_mask( 12, 20,object)
110#define Dsignaling(object) Bitfield_extract( 12,  1,object)
111#define Dsignalingnan(object) Bitfield_extract( 1,  12,object)
112#define Dhigh2mantissa(object) Bitfield_extract( 12,  2,object)
113#define Dexponentmantissap1(object) Bitfield_mask( 1, 31,object)
114#define Dsignexponent(object) Bitfield_extract( 0, 12,object)
115#define Dhidden(object) Bitfield_extract( 11,  1,object)
116#define Dhiddenoverflow(object) Bitfield_extract( 10,  1,object)
117#define Dhiddenhigh7mantissa(object) Bitfield_extract( 11,  8,object)
118#define Dhiddenhigh3mantissa(object) Bitfield_extract( 11,  4,object)
119#define Dlowp1(object) Bitfield_mask( 31,  1,object)
120#define Dlow31p1(object) Bitfield_mask( 1, 31,object)
121#define Dhighp1(object) Bitfield_extract( 0,  1,object)
122#define Dhigh4p1(object) Bitfield_extract( 0,  4,object)
123#define Dhigh31p1(object) Bitfield_extract( 0, 31,object)
124#define Dsignedhigh31p1(object) Bitfield_signed_extract( 0, 31,object)
125#define Dbit3p1(object) Bitfield_extract( 3,  1,object)
126
127#define Deposit_dsign(object,value) Bitfield_deposit(value,0,1,object)
128#define Deposit_dexponent(object,value) Bitfield_deposit(value,1,11,object)
129#define Deposit_dmantissap1(object,value) Bitfield_deposit(value,12,20,object)
130#define Deposit_dhigh2mantissa(object,value) Bitfield_deposit(value,12,2,object)
131#define Deposit_dexponentmantissap1(object,value) \
132    Bitfield_deposit(value,1,31,object)
133#define Deposit_dsignexponent(object,value) Bitfield_deposit(value,0,12,object)
134#define Deposit_dlowp1(object,value) Bitfield_deposit(value,31,1,object)
135#define Deposit_dhigh4p1(object,value) Bitfield_deposit(value,0,4,object)
136
137#define Is_dsign(object) Bitfield_mask( 0,  1,object)
138#define Is_dsignaling(object) Bitfield_mask( 12,  1,object)
139#define Is_dhidden(object) Bitfield_mask( 11,  1,object)
140#define Is_dhiddenoverflow(object) Bitfield_mask( 10,  1,object)
141#define Is_dlowp1(object) Bitfield_mask( 31,  1,object)
142#define Is_dhighp1(object) Bitfield_mask( 0,  1,object)
143#define Is_dbit3p1(object) Bitfield_mask( 3,  1,object)
144
145#define Dallp2(object) (object)
146#define Dmantissap2(object) (object)
147#define Dlowp2(object) Bitfield_mask( 31,  1,object)
148#define Dlow4p2(object) Bitfield_mask( 28,  4,object)
149#define Dlow31p2(object) Bitfield_mask( 1, 31,object)
150#define Dhighp2(object) Bitfield_extract( 0,  1,object)
151#define Dhigh31p2(object) Bitfield_extract( 0, 31,object)
152#define Dbit2p2(object) Bitfield_extract( 2,  1,object)
153#define Dbit3p2(object) Bitfield_extract( 3,  1,object)
154#define Dbit21p2(object) Bitfield_extract( 21,  1,object)
155#define Dbit28p2(object) Bitfield_extract( 28,  1,object)
156#define Dbit29p2(object) Bitfield_extract( 29,  1,object)
157#define Dbit30p2(object) Bitfield_extract( 30,  1,object)
158#define Dbit31p2(object) Bitfield_mask( 31,  1,object)
159
160#define Deposit_dlowp2(object,value) Bitfield_deposit(value,31,1,object)
161
162#define Is_dlowp2(object) Bitfield_mask( 31,  1,object)
163#define Is_dhighp2(object) Bitfield_mask( 0,  1,object)
164#define Is_dbit2p2(object) Bitfield_mask( 2,  1,object)
165#define Is_dbit3p2(object) Bitfield_mask( 3,  1,object)
166#define Is_dbit21p2(object) Bitfield_mask( 21,  1,object)
167#define Is_dbit28p2(object) Bitfield_mask( 28,  1,object)
168#define Is_dbit29p2(object) Bitfield_mask( 29,  1,object)
169#define Is_dbit30p2(object) Bitfield_mask( 30,  1,object)
170#define Is_dbit31p2(object) Bitfield_mask( 31,  1,object)
171
172/* 
173 * Quad number.
174 * +-------+-------+-------+-------+-------+-------+-------+-------+
175 * |s|          exponent           |      mantissa part 1          |
176 * +-------+-------+-------+-------+-------+-------+-------+-------+
177 *
178 * +-------+-------+-------+-------+-------+-------+-------+-------+
179 * |                    mantissa part 2                            |
180 * +-------+-------+-------+-------+-------+-------+-------+-------+
181 *
182 * +-------+-------+-------+-------+-------+-------+-------+-------+
183 * |                    mantissa part 3                            |
184 * +-------+-------+-------+-------+-------+-------+-------+-------+
185 *
186 * +-------+-------+-------+-------+-------+-------+-------+-------+
187 * |                    mantissa part 4                            |
188 * +-------+-------+-------+-------+-------+-------+-------+-------+
189 */
190typedef struct
191    {
192    union
193	{
194	struct { unsigned qallp1; } u_qallp1;
195/* Not needed for now...
196	Bitfield_extract( 0,  1,u_qsign,qsign)
197	Bitfield_signed_extract( 0,  1,u_qsignedsign,qsignedsign)
198	Bitfield_extract( 1, 15,u_qexponent,qexponent)
199	Bitfield_extract(16, 16,u_qmantissap1,qmantissap1)
200	Bitfield_extract(16,  1,u_qsignaling,qsignaling)
201	Bitfield_extract(1,  16,u_qsignalingnan,qsignalingnan)
202	Bitfield_extract(16,  2,u_qhigh2mantissa,qhigh2mantissa)
203	Bitfield_extract( 1, 31,u_qexponentmantissap1,qexponentmantissap1)
204	Bitfield_extract( 0, 16,u_qsignexponent,qsignexponent)
205	Bitfield_extract(15,  1,u_qhidden,qhidden)
206	Bitfield_extract(14,  1,u_qhiddenoverflow,qhiddenoverflow)
207	Bitfield_extract(15,  8,u_qhiddenhigh7mantissa,qhiddenhigh7mantissa)
208	Bitfield_extract(15,  4,u_qhiddenhigh3mantissa,qhiddenhigh3mantissa)
209	Bitfield_extract(31,  1,u_qlowp1,qlowp1)
210	Bitfield_extract( 1, 31,u_qlow31p1,qlow31p1)
211	Bitfield_extract( 0,  1,u_qhighp1,qhighp1)
212	Bitfield_extract( 0,  4,u_qhigh4p1,qhigh4p1)
213	Bitfield_extract( 0, 31,u_qhigh31p1,qhigh31p1)
214  */
215	} quad_u1;
216    union
217	{
218	struct { unsigned qallp2; } u_qallp2;
219  /* Not needed for now...
220	Bitfield_extract(31,  1,u_qlowp2,qlowp2)
221	Bitfield_extract( 1, 31,u_qlow31p2,qlow31p2)
222	Bitfield_extract( 0,  1,u_qhighp2,qhighp2)
223	Bitfield_extract( 0, 31,u_qhigh31p2,qhigh31p2)
224   */
225	} quad_u2;
226    union
227	{
228	struct { unsigned qallp3; } u_qallp3;
229  /* Not needed for now...
230	Bitfield_extract(31,  1,u_qlowp3,qlowp3)
231	Bitfield_extract( 1, 31,u_qlow31p3,qlow31p3)
232	Bitfield_extract( 0,  1,u_qhighp3,qhighp3)
233	Bitfield_extract( 0, 31,u_qhigh31p3,qhigh31p3)
234   */ 
235	} quad_u3;
236    union
237	{
238	struct { unsigned qallp4; } u_qallp4;
239    /* Not need for now...
240	Bitfield_extract(31,  1,u_qlowp4,qlowp4)
241	Bitfield_extract( 1, 31,u_qlow31p4,qlow31p4)
242	Bitfield_extract( 0,  1,u_qhighp4,qhighp4)
243	Bitfield_extract( 0, 31,u_qhigh31p4,qhigh31p4)
244     */
245	} quad_u4;
246    } quad_floating_point;
247
248/* Extension - An additional structure to hold the guard, round and
249 *             sticky bits during computations.
250 */
251#define Extall(object) (object)
252#define Extsign(object) Bitfield_extract( 0,  1,object)
253#define Exthigh31(object) Bitfield_extract( 0, 31,object)
254#define Extlow31(object) Bitfield_extract( 1, 31,object)
255#define Extlow(object) Bitfield_extract( 31,  1,object)
256
257/*
258 * Single extended - The upper word is just like single precision,
259 *                 but one additional word of mantissa is needed.
260 */
261#define Sextallp1(object) (object)
262#define Sextallp2(object) (object)
263#define Sextlowp1(object) Bitfield_extract( 31,  1,object)
264#define Sexthighp2(object) Bitfield_extract( 0,  1,object)
265#define Sextlow31p2(object) Bitfield_extract( 1, 31,object)
266#define Sexthiddenoverflow(object) Bitfield_extract( 4,  1,object)
267#define Is_sexthiddenoverflow(object) Bitfield_mask( 4,  1,object)
268
269/*
270 * Double extended - The upper two words are just like double precision,
271 *		     but two additional words of mantissa are needed.
272 */
273#define Dextallp1(object) (object)
274#define Dextallp2(object) (object)
275#define Dextallp3(object) (object)
276#define Dextallp4(object) (object)
277#define Dextlowp2(object) Bitfield_extract( 31,  1,object)
278#define Dexthighp3(object) Bitfield_extract( 0,  1,object)
279#define Dextlow31p3(object) Bitfield_extract( 1, 31,object)
280#define Dexthiddenoverflow(object) Bitfield_extract( 10,  1,object)
281#define Is_dexthiddenoverflow(object) Bitfield_mask( 10,  1,object)
282#define Deposit_dextlowp4(object,value) Bitfield_deposit(value,31,1,object)
283
284/*
285 * Declare the basic structures for the 3 different
286 * fixed-point precisions.
287 *        
288 * Single number  
289 * +-------+-------+-------+-------+-------+-------+-------+-------+
290 * |s|                    integer                                  |
291 * +-------+-------+-------+-------+-------+-------+-------+-------+
292 */
293typedef int sgl_integer;
294
295/* 
296 * Double number.
297 * +-------+-------+-------+-------+-------+-------+-------+-------+
298 * |s|                     high integer                            |
299 * +-------+-------+-------+-------+-------+-------+-------+-------+
300 *
301 * +-------+-------+-------+-------+-------+-------+-------+-------+
302 * |                       low integer                             |
303 * +-------+-------+-------+-------+-------+-------+-------+-------+
304 */
305struct dint {
306        int  wd0;
307        unsigned int wd1;
308};
309
310struct dblwd {
311        unsigned int wd0;
312        unsigned int wd1;
313};
314
315/* 
316 * Quad number.
317 * +-------+-------+-------+-------+-------+-------+-------+-------+
318 * |s|                  integer part1                              |
319 * +-------+-------+-------+-------+-------+-------+-------+-------+
320 *
321 * +-------+-------+-------+-------+-------+-------+-------+-------+
322 * |                    integer part 2                             |
323 * +-------+-------+-------+-------+-------+-------+-------+-------+
324 *
325 * +-------+-------+-------+-------+-------+-------+-------+-------+
326 * |                    integer part 3                             |
327 * +-------+-------+-------+-------+-------+-------+-------+-------+
328 *
329 * +-------+-------+-------+-------+-------+-------+-------+-------+
330 * |                    integer part 4                             |
331 * +-------+-------+-------+-------+-------+-------+-------+-------+
332 */
333
334struct quadwd {
335        int  wd0;
336        unsigned int wd1;
337        unsigned int wd2;
338        unsigned int wd3;
339};
340
341typedef struct quadwd quad_integer;
342
343
344/* useful typedefs */
345typedef unsigned int sgl_floating_point;
346typedef struct dblwd dbl_floating_point;
347typedef struct dint dbl_integer;
348typedef struct dblwd dbl_unsigned;
349
350/* 
351 * Define the different precisions' parameters.
352 */
353#define SGL_BITLENGTH 32
354#define SGL_EMAX 127
355#define SGL_EMIN (-126)
356#define SGL_BIAS 127
357#define SGL_WRAP 192
358#define SGL_INFINITY_EXPONENT (SGL_EMAX+SGL_BIAS+1)
359#define SGL_THRESHOLD 32
360#define SGL_EXP_LENGTH 8
361#define SGL_P 24
362
363#define DBL_BITLENGTH 64
364#define DBL_EMAX 1023
365#define DBL_EMIN (-1022)
366#define DBL_BIAS 1023
367#define DBL_WRAP 1536
368#define DBL_INFINITY_EXPONENT (DBL_EMAX+DBL_BIAS+1)
369#define DBL_THRESHOLD 64
370#define DBL_EXP_LENGTH 11
371#define DBL_P 53
372
373#define QUAD_BITLENGTH 128
374#define QUAD_EMAX 16383
375#define QUAD_EMIN (-16382)
376#define QUAD_BIAS 16383
377#define QUAD_WRAP 24576
378#define QUAD_INFINITY_EXPONENT (QUAD_EMAX+QUAD_BIAS+1)
379#define QUAD_P 113
380
381/* Boolean Values etc. */
382#define FALSE 0
383#define TRUE (!FALSE)
384#define NOT !
385#define XOR ^
386
387/* other constants */
388#undef NULL
389#define NULL 0
390#define NIL 0
391#define SGL 0
392#define DBL 1
393#define BADFMT 2
394#define QUAD 3
395
396
397/* Types */
398typedef int boolean;
399typedef int FORMAT;
400typedef int VOID;
401
402
403/* Declare status register equivalent to FPUs architecture.
404 *
405 *  0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
406 * +-------+-------+-------+-------+-------+-------+-------+-------+
407 * |V|Z|O|U|I|C|  rsv  |  model    | version |RM |rsv|T|r|V|Z|O|U|I|
408 * +-------+-------+-------+-------+-------+-------+-------+-------+
409 */
410#define Cbit(object) Bitfield_extract( 5, 1,object)
411#define Tbit(object) Bitfield_extract( 25, 1,object)
412#define Roundingmode(object) Bitfield_extract( 21, 2,object)
413#define Invalidtrap(object) Bitfield_extract( 27, 1,object)
414#define Divisionbyzerotrap(object) Bitfield_extract( 28, 1,object)
415#define Overflowtrap(object) Bitfield_extract( 29, 1,object)
416#define Underflowtrap(object) Bitfield_extract( 30, 1,object)
417#define Inexacttrap(object) Bitfield_extract( 31, 1,object)
418#define Invalidflag(object) Bitfield_extract( 0, 1,object)
419#define Divisionbyzeroflag(object) Bitfield_extract( 1, 1,object)
420#define Overflowflag(object) Bitfield_extract( 2, 1,object)
421#define Underflowflag(object) Bitfield_extract( 3, 1,object)
422#define Inexactflag(object) Bitfield_extract( 4, 1,object)
423#define Allflags(object) Bitfield_extract( 0, 5,object)
424
425/* Definitions relevant to the status register */
426
427/* Rounding Modes */
428#define ROUNDNEAREST 0
429#define ROUNDZERO    1
430#define ROUNDPLUS    2
431#define ROUNDMINUS   3
432
433/* Exceptions */
434#define NOEXCEPTION		0x0
435#define INVALIDEXCEPTION	0x20
436#define DIVISIONBYZEROEXCEPTION	0x10
437#define OVERFLOWEXCEPTION	0x08
438#define UNDERFLOWEXCEPTION	0x04
439#define INEXACTEXCEPTION	0x02
440#define UNIMPLEMENTEDEXCEPTION	0x01
441
442/* New exceptions for the 2E Opcode */
443#define OPC_2E_INVALIDEXCEPTION     0x30
444#define OPC_2E_OVERFLOWEXCEPTION    0x18
445#define OPC_2E_UNDERFLOWEXCEPTION   0x0c
446#define OPC_2E_INEXACTEXCEPTION     0x12
447
448/* Declare exception registers equivalent to FPUs architecture 
449 *
450 *  0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
451 * +-------+-------+-------+-------+-------+-------+-------+-------+
452 * |excepttype |  r1     | r2/ext  |  operation  |parm |n| t/cond  |
453 * +-------+-------+-------+-------+-------+-------+-------+-------+
454 */
455#define Allexception(object) (object)
456#define Exceptiontype(object) Bitfield_extract( 0, 6,object)
457#define Instructionfield(object) Bitfield_mask( 6,26,object)
458#define Parmfield(object) Bitfield_extract( 23, 3,object)
459#define Rabit(object) Bitfield_extract( 24, 1,object)
460#define Ibit(object) Bitfield_extract( 25, 1,object)
461
462#define Set_exceptiontype(object,value) Bitfield_deposit(value, 0, 6,object)
463#define Set_parmfield(object,value) Bitfield_deposit(value, 23, 3,object)
464#define Set_exceptiontype_and_instr_field(exception,instruction,object) \
465    object = exception << 26 | instruction
466
467/* Declare the condition field
468 *
469 *  0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
470 * +-------+-------+-------+-------+-------+-------+-------+-------+
471 * |                                                     |G|L|E|U|X|
472 * +-------+-------+-------+-------+-------+-------+-------+-------+
473 */
474#define Greaterthanbit(object) Bitfield_extract( 27, 1,object)
475#define Lessthanbit(object) Bitfield_extract( 28, 1,object)
476#define Equalbit(object) Bitfield_extract( 29, 1,object)
477#define Unorderedbit(object) Bitfield_extract( 30, 1,object)
478#define Exceptionbit(object) Bitfield_extract( 31, 1,object)
479
480/* An alias name for the status register */
481#define Fpustatus_register (*status)
482
483/**************************************************
484 * Status register referencing and manipulation.  *
485 **************************************************/
486
487/* Rounding mode */
488#define Rounding_mode()  Roundingmode(Fpustatus_register)
489#define Is_rounding_mode(rmode) \
490    (Roundingmode(Fpustatus_register) == rmode)
491#define Set_rounding_mode(value) \
492    Bitfield_deposit(value,21,2,Fpustatus_register)
493
494/* Boolean testing of the trap enable bits */
495#define Is_invalidtrap_enabled() Invalidtrap(Fpustatus_register)
496#define Is_divisionbyzerotrap_enabled() Divisionbyzerotrap(Fpustatus_register)
497#define Is_overflowtrap_enabled() Overflowtrap(Fpustatus_register)
498#define Is_underflowtrap_enabled() Underflowtrap(Fpustatus_register)
499#define Is_inexacttrap_enabled() Inexacttrap(Fpustatus_register)
500
501/* Set the indicated flags in the status register */
502#define Set_invalidflag() Bitfield_deposit(1,0,1,Fpustatus_register)
503#define Set_divisionbyzeroflag() Bitfield_deposit(1,1,1,Fpustatus_register)
504#define Set_overflowflag() Bitfield_deposit(1,2,1,Fpustatus_register)
505#define Set_underflowflag() Bitfield_deposit(1,3,1,Fpustatus_register)
506#define Set_inexactflag() Bitfield_deposit(1,4,1,Fpustatus_register)
507
508#define Clear_all_flags() Bitfield_deposit(0,0,5,Fpustatus_register)
509
510/* Manipulate the trap and condition code bits (tbit and cbit) */
511#define Set_tbit() Bitfield_deposit(1,25,1,Fpustatus_register)
512#define Clear_tbit() Bitfield_deposit(0,25,1,Fpustatus_register)
513#define Is_tbit_set() Tbit(Fpustatus_register)
514#define Is_cbit_set() Cbit(Fpustatus_register)
515
516#define Set_status_cbit(value)  \
517        Bitfield_deposit(value,5,1,Fpustatus_register)
518
519/*******************************
520 * Condition field referencing *
521 *******************************/
522#define Unordered(cond) Unorderedbit(cond)
523#define Equal(cond) Equalbit(cond)
524#define Lessthan(cond) Lessthanbit(cond)
525#define Greaterthan(cond) Greaterthanbit(cond)
526#define Exception(cond) Exceptionbit(cond)
527
528
529/* Defines for the extension */
530#define Ext_isone_sign(extent) (Extsign(extent))
531#define Ext_isnotzero(extent) \
532    (Extall(extent))
533#define Ext_isnotzero_lower(extent) \
534    (Extlow31(extent))
535#define Ext_leftshiftby1(extent) \
536    Extall(extent) <<= 1
537#define Ext_negate(extent) \
538    (int )Extall(extent) = 0 - (int )Extall(extent)
539#define Ext_setone_low(extent) Bitfield_deposit(1,31,1,extent)
540#define Ext_setzero(extent) Extall(extent) = 0
541
542typedef int operation;
543
544/* error messages */
545
546#define		NONE		0
547#define		UNDEFFPINST	1
548
549/* Function definitions: opcode, opclass */
550#define FTEST	(1<<2) | 0
551#define FCPY	(2<<2) | 0
552#define FABS	(3<<2) | 0
553#define FSQRT   (4<<2) | 0
554#define FRND    (5<<2) | 0
555
556#define FCNVFF	(0<<2) | 1
557#define FCNVXF	(1<<2) | 1
558#define FCNVFX	(2<<2) | 1
559#define FCNVFXT	(3<<2) | 1
560
561#define FCMP    (0<<2) | 2
562
563#define FADD	(0<<2) | 3
564#define FSUB	(1<<2) | 3
565#define FMPY	(2<<2) | 3
566#define FDIV	(3<<2) | 3
567#define FREM	(4<<2) | 3
568