MONADIC.GEN revision 1.2 1 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
2 * M68000 Hi-Performance Microprocessor Division
3 * M68040 Software Package
4 *
5 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
6 * All rights reserved.
7 *
8 * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
9 * To the maximum extent permitted by applicable law,
10 * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
11 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
12 * PARTICULAR PURPOSE and any warranty against infringement with
13 * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
14 * and any accompanying written materials.
15 *
16 * To the maximum extent permitted by applicable law,
17 * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
18 * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
19 * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
20 * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
21 * SOFTWARE. Motorola assumes no responsibility for the maintenance
22 * and support of the SOFTWARE.
23 *
24 * You are hereby granted a copyright license to use, modify, and
25 * distribute the SOFTWARE so long as this entire notice is retained
26 * without alteration in any modified and/or redistributed versions,
27 * and that such modified versions are clearly identified as such.
28 * No licenses are granted by implication, estoppel or otherwise
29 * under any patents or trademarks of Motorola, Inc.
30
31 *
32 * MONADIC.GEN 1.5 5/18/92
33 *
34 * MONADIC.GEN 1.4 1/16/92
35 *
36 * MONADIC.GEN 1.3 4/30/91
37 *
38 * MONADIC.GEN --- generic MONADIC template
39 *
40 * This version saves all registers that will be used by the emulation
41 * routines and restores all but FP0 on exit. The FPSR is
42 * updated to reflect the result of the operation. Return value
43 * is placed in FP0 for single, double and extended results.
44 *
45 * The package subroutines expect the incoming FPCR to be zeroed
46 * since they need extended precision to work properly. The
47 * 'final' FPCR is expected in d1 so that the calculated result
48 * can be properly sized and rounded. Also, if the incoming FPCR
49 * has enabled any exceptions, the exception will be taken on the
50 * final fmovem in this template.
51 *
52 * Customizations:
53 * 1. Remove the movem.l at the entry and exit of
54 * each routine if your compiler treats those
55 * registers as scratch.
56 * 2. Likewise, don't save FP0/FP1 if they are scratch
57 * registers.
58 * 3. Delete handling of the fpsr if you only care about
59 * the result.
60 * 4. Some (most?) C compilers convert all float arguments
61 * to double, and provide no support at all for extended
62 * precision so remove the _OPs_ and _OPx_ entry points.
63 * 5. Move the result to d0/d1 if the compiler is that old.
64 *
65
66 xref tag
67 xref _OPr_
68 xref _OPz_
69 xref _OPi_
70 xref _OPn_
71 xref _OPm_
72
73 xdef _OPs_
74 _OPs_:
75 link a6,#-LOCAL_SIZE
76 movem.l d0-d1/a0-a1,USER_DA(a6)
77 fmovem.x fp0-fp3,USER_FP0(a6)
78 fmove.l fpsr,USER_FPSR(a6)
79 fmove.l fpcr,USER_FPCR(a6)
80 fmove.l fpcr,d1 ; user's rounding mode/precision
81 fmove.l #0,fpcr ; force rounding mode/prec to extended,rn
82 *
83 * copy, convert and tag input argument
84 *
85 fmove.s 8(a6),fp0
86 fmove.x fp0,ETEMP(a6)
87 lea ETEMP(a6),a0
88 bsr tag
89 move.b d0,STAG(a6)
90 tst.b d0
91 bne.b _TMP_2
92 bsr _OPr_ ; normalized (regular) number
93 bra.b _TMP_6
94 _TMP_2:
95 cmp.b #$20,d0 ; zero?
96 bne.b _TMP_3
97 bsr _OPz_
98 bra.b _TMP_6
99 _TMP_3:
100 cmp.b #$40,d0 ; infinity?
101 bne.b _TMP_4
102 bsr _OPi_
103 bra.b _TMP_6
104 _TMP_4:
105 cmp.b #$60,d0 ; NaN?
106 bne.b _TMP_5
107 bsr _OPn_
108 bra.b _TMP_6
109 _TMP_5:
110 bsr _OPm_ ; assuming a denorm...
111
112 _TMP_6:
113 fmove.l fpsr,d0 ; update status register
114 or.b FPSR_AEXCEPT(a6),d0 ;add previously accrued exceptions
115 fmove.l d0,fpsr
116 *
117 * Result is now in FP0
118 *
119 movem.l USER_DA(a6),d0-d1/a0-a1
120 fmovem.x USER_FP1(a6),fp1-fp3 ; note: FP0 not restored
121 fmove.l USER_FPCR(a6),fpcr ; fpcr restored
122 unlk a6
123 rts
124
125 xdef _OPd_
126 _OPd_:
127 link a6,#-LOCAL_SIZE
128 movem.l d0-d1/a0-a1,USER_DA(a6)
129 fmovem.x fp0-fp3,USER_FP0(a6)
130 fmove.l fpsr,USER_FPSR(a6)
131 fmove.l fpcr,USER_FPCR(a6)
132 fmove.l fpcr,d1 ; user's rounding mode/precision
133 fmove.l #0,fpcr ; force rounding mode/prec to extended,rn
134 *
135 * copy, convert and tag input argument
136 *
137 fmove.d 8(a6),fp0
138 fmove.x fp0,ETEMP(a6)
139 lea ETEMP(a6),a0
140 bsr tag
141 move.b d0,STAG(a6)
142 tst.b d0
143 bne.b _TMP_7
144 bsr _OPr_ ; normalized (regular) number
145 bra.b _TMP_B
146 _TMP_7:
147 cmp.b #$20,d0 ; zero?
148 bne.b _TMP_8
149 bsr _OPz_
150 bra.b _TMP_B
151 _TMP_8:
152 cmp.b #$40,d0 ; infinity?
153 bne.b _TMP_9
154 bsr _OPi_
155 bra.b _TMP_B
156 _TMP_9:
157 cmp.b #$60,d0 ; NaN?
158 bne.b _TMP_A
159 bsr _OPn_
160 bra.b _TMP_B
161 _TMP_A:
162 bsr _OPm_ ; assuming a denorm...
163
164 _TMP_B:
165 fmove.l fpsr,d0 ; update status register
166 or.b FPSR_AEXCEPT(a6),d0 ;add previously accrued exceptions
167 fmove.l d0,fpsr
168 *
169 * Result is now in FP0
170 *
171 movem.l USER_DA(a6),d0-d1/a0-a1
172 fmovem.x USER_FP1(a6),fp1-fp3 ; note: FP0 not restored
173 fmove.l USER_FPCR(a6),fpcr ; fpcr restored
174 unlk a6
175 rts
176
177 xdef _OPx_
178 _OPx_:
179 link a6,#-LOCAL_SIZE
180 movem.l d0-d1/a0-a1,USER_DA(a6)
181 fmovem.x fp0-fp3,USER_FP0(a6)
182 fmove.l fpsr,USER_FPSR(a6)
183 fmove.l fpcr,USER_FPCR(a6)
184 fmove.l fpcr,d1 ; user's rounding mode/precision
185 fmove.l #0,fpcr ; force rounding mode/prec to extended,rn
186 *
187 * copy, convert and tag input argument
188 *
189 fmove.x 8(a6),fp0
190 fmove.x fp0,ETEMP(a6)
191 lea ETEMP(a6),a0
192 bsr tag
193 move.b d0,STAG(a6)
194 tst.b d0
195 bne.b _TMP_C
196 bsr _OPr_ ; normalized (regular) number
197 bra.b _TMP_G
198 _TMP_C:
199 cmp.b #$20,d0 ; zero?
200 bne.b _TMP_D
201 bsr _OPz_
202 bra.b _TMP_G
203 _TMP_D:
204 cmp.b #$40,d0 ; infinity?
205 bne.b _TMP_E
206 bsr _OPi_
207 bra.b _TMP_G
208 _TMP_E:
209 cmp.b #$60,d0 ; NaN?
210 bne.b _TMP_F
211 bsr _OPn_
212 bra.b _TMP_G
213 _TMP_F:
214 bsr _OPm_ ; assuming a denorm...
215
216 _TMP_G:
217 fmove.l fpsr,d0 ; update status register
218 or.b FPSR_AEXCEPT(a6),d0 ;add previously accrued exceptions
219 fmove.l d0,fpsr
220 *
221 * Result is now in FP0
222 *
223 movem.l USER_DA(a6),d0-d1/a0-a1
224 fmovem.x USER_FP1(a6),fp1-fp3 ; note: FP0 not restored
225 fmove.l USER_FPCR(a6),fpcr ; fpcr restored
226 unlk a6
227 rts
228
229