smovecr.sa revision 1.1 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 * smovecr.sa 3.1 12/10/90
33 *
34 * The entry point sMOVECR returns the constant at the
35 * offset given in the instruction field.
36 *
37 * Input: An offset in the instruction word.
38 *
39 * Output: The constant rounded to the user's rounding
40 * mode unchecked for overflow.
41 *
42 * Modified: fp0.
43 *
44
45 SMOVECR IDNT 2,1 Motorola 040 Floating Point Software Package
46
47 section 8
48
49 include fpsp.h
50
51 xref nrm_set
52 xref round
53 xref PIRN
54 xref PIRZRM
55 xref PIRP
56 xref SMALRN
57 xref SMALRZRM
58 xref SMALRP
59 xref BIGRN
60 xref BIGRZRM
61 xref BIGRP
62
63 FZERO dc.l 00000000
64 *
65 * FMOVECR
66 *
67 xdef smovcr
68 smovcr:
69 bfextu CMDREG1B(a6){9:7},d0 ;get offset
70 bfextu USER_FPCR(a6){26:2},d1 ;get rmode
71 *
72 * check range of offset
73 *
74 tst.b d0 ;if zero, offset is to pi
75 beq.b PI_TBL ;it is pi
76 cmpi.b #$0a,d0 ;check range $01 - $0a
77 ble.b Z_VAL ;if in this range, return zero
78 cmpi.b #$0e,d0 ;check range $0b - $0e
79 ble.b SM_TBL ;valid constants in this range
80 cmpi.b #$2f,d0 ;check range $10 - $2f
81 ble.b Z_VAL ;if in this range, return zero
82 cmpi.b #$3f,d0 ;check range $30 - $3f
83 ble BG_TBL ;valid constants in this range
84 Z_VAL:
85 fmove.s FZERO,fp0
86 rts
87 PI_TBL:
88 tst.b d1 ;offset is zero, check for rmode
89 beq.b PI_RN ;if zero, rn mode
90 cmpi.b #$3,d1 ;check for rp
91 beq.b PI_RP ;if 3, rp mode
92 PI_RZRM:
93 lea.l PIRZRM,a0 ;rmode is rz or rm, load PIRZRM in a0
94 bra set_finx
95 PI_RN:
96 lea.l PIRN,a0 ;rmode is rn, load PIRN in a0
97 bra set_finx
98 PI_RP:
99 lea.l PIRP,a0 ;rmode is rp, load PIRP in a0
100 bra set_finx
101 SM_TBL:
102 subi.l #$b,d0 ;make offset in 0 - 4 range
103 tst.b d1 ;check for rmode
104 beq.b SM_RN ;if zero, rn mode
105 cmpi.b #$3,d1 ;check for rp
106 beq.b SM_RP ;if 3, rp mode
107 SM_RZRM:
108 lea.l SMALRZRM,a0 ;rmode is rz or rm, load SMRZRM in a0
109 cmpi.b #$2,d0 ;check if result is inex
110 ble set_finx ;if 0 - 2, it is inexact
111 bra no_finx ;if 3, it is exact
112 SM_RN:
113 lea.l SMALRN,a0 ;rmode is rn, load SMRN in a0
114 cmpi.b #$2,d0 ;check if result is inex
115 ble set_finx ;if 0 - 2, it is inexact
116 bra no_finx ;if 3, it is exact
117 SM_RP:
118 lea.l SMALRP,a0 ;rmode is rp, load SMRP in a0
119 cmpi.b #$2,d0 ;check if result is inex
120 ble set_finx ;if 0 - 2, it is inexact
121 bra no_finx ;if 3, it is exact
122 BG_TBL:
123 subi.l #$30,d0 ;make offset in 0 - f range
124 tst.b d1 ;check for rmode
125 beq.b BG_RN ;if zero, rn mode
126 cmpi.b #$3,d1 ;check for rp
127 beq.b BG_RP ;if 3, rp mode
128 BG_RZRM:
129 lea.l BIGRZRM,a0 ;rmode is rz or rm, load BGRZRM in a0
130 cmpi.b #$1,d0 ;check if result is inex
131 ble set_finx ;if 0 - 1, it is inexact
132 cmpi.b #$7,d0 ;second check
133 ble no_finx ;if 0 - 7, it is exact
134 bra set_finx ;if 8 - f, it is inexact
135 BG_RN:
136 lea.l BIGRN,a0 ;rmode is rn, load BGRN in a0
137 cmpi.b #$1,d0 ;check if result is inex
138 ble set_finx ;if 0 - 1, it is inexact
139 cmpi.b #$7,d0 ;second check
140 ble no_finx ;if 0 - 7, it is exact
141 bra set_finx ;if 8 - f, it is inexact
142 BG_RP:
143 lea.l BIGRP,a0 ;rmode is rp, load SMRP in a0
144 cmpi.b #$1,d0 ;check if result is inex
145 ble set_finx ;if 0 - 1, it is inexact
146 cmpi.b #$7,d0 ;second check
147 ble no_finx ;if 0 - 7, it is exact
148 * bra set_finx ;if 8 - f, it is inexact
149 set_finx:
150 or.l #inx2a_mask,USER_FPSR(a6) ;set inex2/ainex
151 no_finx:
152 mulu.l #12,d0 ;use offset to point into tables
153 move.l d1,L_SCR1(a6) ;load mode for round call
154 bfextu USER_FPCR(a6){24:2},d1 ;get precision
155 tst.l d1 ;check if extended precision
156 *
157 * Precision is extended
158 *
159 bne.b not_ext ;if extended, do not call round
160 fmovem.x (a0,d0),fp0 ;return result in fp0
161 rts
162 *
163 * Precision is single or double
164 *
165 not_ext:
166 swap d1 ;rnd prec in upper word of d1
167 add.l L_SCR1(a6),d1 ;merge rmode in low word of d1
168 move.l (a0,d0),FP_SCR1(a6) ;load first word to temp storage
169 move.l 4(a0,d0),FP_SCR1+4(a6) ;load second word
170 move.l 8(a0,d0),FP_SCR1+8(a6) ;load third word
171 clr.l d0 ;clear g,r,s
172 lea FP_SCR1(a6),a0
173 btst.b #sign_bit,LOCAL_EX(a0)
174 sne LOCAL_SGN(a0) ;convert to internal ext. format
175
176 bsr round ;go round the mantissa
177
178 bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format
179 beq.b fin_fcr
180 bset.b #sign_bit,LOCAL_EX(a0)
181 fin_fcr:
182 fmovem.x (a0),fp0
183 rts
184
185 end
186