1 // SPDX-License-Identifier: GPL-2.0
2 /*---------------------------------------------------------------------------+
3 | fpu_tags.c |
4 | |
5 | Set FPU register tags. |
6 | |
7 | Copyright (C) 1997 |
8 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
9 | E-mail billm@jacobi.maths.monash.edu.au |
10 | |
11 | |
12 +---------------------------------------------------------------------------*/
13
14 #include "fpu_emu.h"
15 #include "fpu_system.h"
16 #include "exception.h"
17
FPU_pop(void)18 void FPU_pop(void)
19 {
20 fpu_tag_word |= 3 << ((top & 7) * 2);
21 top++;
22 }
23
FPU_gettag0(void)24 int FPU_gettag0(void)
25 {
26 return (fpu_tag_word >> ((top & 7) * 2)) & 3;
27 }
28
FPU_gettagi(int stnr)29 int FPU_gettagi(int stnr)
30 {
31 return (fpu_tag_word >> (((top + stnr) & 7) * 2)) & 3;
32 }
33
FPU_gettag(int regnr)34 int FPU_gettag(int regnr)
35 {
36 return (fpu_tag_word >> ((regnr & 7) * 2)) & 3;
37 }
38
FPU_settag0(int tag)39 void FPU_settag0(int tag)
40 {
41 int regnr = top;
42 regnr &= 7;
43 fpu_tag_word &= ~(3 << (regnr * 2));
44 fpu_tag_word |= (tag & 3) << (regnr * 2);
45 }
46
FPU_settagi(int stnr,int tag)47 void FPU_settagi(int stnr, int tag)
48 {
49 int regnr = stnr + top;
50 regnr &= 7;
51 fpu_tag_word &= ~(3 << (regnr * 2));
52 fpu_tag_word |= (tag & 3) << (regnr * 2);
53 }
54
FPU_settag(int regnr,int tag)55 void FPU_settag(int regnr, int tag)
56 {
57 regnr &= 7;
58 fpu_tag_word &= ~(3 << (regnr * 2));
59 fpu_tag_word |= (tag & 3) << (regnr * 2);
60 }
61
FPU_Special(FPU_REG const * ptr)62 int FPU_Special(FPU_REG const *ptr)
63 {
64 int exp = exponent(ptr);
65
66 if (exp == EXP_BIAS + EXP_UNDER)
67 return TW_Denormal;
68 else if (exp != EXP_BIAS + EXP_OVER)
69 return TW_NaN;
70 else if ((ptr->sigh == 0x80000000) && (ptr->sigl == 0))
71 return TW_Infinity;
72 return TW_NaN;
73 }
74
isNaN(FPU_REG const * ptr)75 int isNaN(FPU_REG const *ptr)
76 {
77 return ((exponent(ptr) == EXP_BIAS + EXP_OVER)
78 && !((ptr->sigh == 0x80000000) && (ptr->sigl == 0)));
79 }
80
FPU_empty_i(int stnr)81 int FPU_empty_i(int stnr)
82 {
83 int regnr = (top + stnr) & 7;
84
85 return ((fpu_tag_word >> (regnr * 2)) & 3) == TAG_Empty;
86 }
87
FPU_stackoverflow(FPU_REG ** st_new_ptr)88 int FPU_stackoverflow(FPU_REG ** st_new_ptr)
89 {
90 *st_new_ptr = &st(-1);
91
92 return ((fpu_tag_word >> (((top - 1) & 7) * 2)) & 3) != TAG_Empty;
93 }
94
FPU_copy_to_regi(FPU_REG const * r,u_char tag,int stnr)95 void FPU_copy_to_regi(FPU_REG const *r, u_char tag, int stnr)
96 {
97 reg_copy(r, &st(stnr));
98 FPU_settagi(stnr, tag);
99 }
100
FPU_copy_to_reg1(FPU_REG const * r,u_char tag)101 void FPU_copy_to_reg1(FPU_REG const *r, u_char tag)
102 {
103 reg_copy(r, &st(1));
104 FPU_settagi(1, tag);
105 }
106
FPU_copy_to_reg0(FPU_REG const * r,u_char tag)107 void FPU_copy_to_reg0(FPU_REG const *r, u_char tag)
108 {
109 int regnr = top;
110 regnr &= 7;
111
112 reg_copy(r, &st(0));
113
114 fpu_tag_word &= ~(3 << (regnr * 2));
115 fpu_tag_word |= (tag & 3) << (regnr * 2);
116 }
117