smovecr.sa revision 1.1 1 1.1 mycroft * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
2 1.1 mycroft * M68000 Hi-Performance Microprocessor Division
3 1.1 mycroft * M68040 Software Package
4 1.1 mycroft *
5 1.1 mycroft * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
6 1.1 mycroft * All rights reserved.
7 1.1 mycroft *
8 1.1 mycroft * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
9 1.1 mycroft * To the maximum extent permitted by applicable law,
10 1.1 mycroft * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
11 1.1 mycroft * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
12 1.1 mycroft * PARTICULAR PURPOSE and any warranty against infringement with
13 1.1 mycroft * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
14 1.1 mycroft * and any accompanying written materials.
15 1.1 mycroft *
16 1.1 mycroft * To the maximum extent permitted by applicable law,
17 1.1 mycroft * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
18 1.1 mycroft * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
19 1.1 mycroft * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
20 1.1 mycroft * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
21 1.1 mycroft * SOFTWARE. Motorola assumes no responsibility for the maintenance
22 1.1 mycroft * and support of the SOFTWARE.
23 1.1 mycroft *
24 1.1 mycroft * You are hereby granted a copyright license to use, modify, and
25 1.1 mycroft * distribute the SOFTWARE so long as this entire notice is retained
26 1.1 mycroft * without alteration in any modified and/or redistributed versions,
27 1.1 mycroft * and that such modified versions are clearly identified as such.
28 1.1 mycroft * No licenses are granted by implication, estoppel or otherwise
29 1.1 mycroft * under any patents or trademarks of Motorola, Inc.
30 1.1 mycroft
31 1.1 mycroft *
32 1.1 mycroft * smovecr.sa 3.1 12/10/90
33 1.1 mycroft *
34 1.1 mycroft * The entry point sMOVECR returns the constant at the
35 1.1 mycroft * offset given in the instruction field.
36 1.1 mycroft *
37 1.1 mycroft * Input: An offset in the instruction word.
38 1.1 mycroft *
39 1.1 mycroft * Output: The constant rounded to the user's rounding
40 1.1 mycroft * mode unchecked for overflow.
41 1.1 mycroft *
42 1.1 mycroft * Modified: fp0.
43 1.1 mycroft *
44 1.1 mycroft
45 1.1 mycroft SMOVECR IDNT 2,1 Motorola 040 Floating Point Software Package
46 1.1 mycroft
47 1.1 mycroft section 8
48 1.1 mycroft
49 1.1 mycroft include fpsp.h
50 1.1 mycroft
51 1.1 mycroft xref nrm_set
52 1.1 mycroft xref round
53 1.1 mycroft xref PIRN
54 1.1 mycroft xref PIRZRM
55 1.1 mycroft xref PIRP
56 1.1 mycroft xref SMALRN
57 1.1 mycroft xref SMALRZRM
58 1.1 mycroft xref SMALRP
59 1.1 mycroft xref BIGRN
60 1.1 mycroft xref BIGRZRM
61 1.1 mycroft xref BIGRP
62 1.1 mycroft
63 1.1 mycroft FZERO dc.l 00000000
64 1.1 mycroft *
65 1.1 mycroft * FMOVECR
66 1.1 mycroft *
67 1.1 mycroft xdef smovcr
68 1.1 mycroft smovcr:
69 1.1 mycroft bfextu CMDREG1B(a6){9:7},d0 ;get offset
70 1.1 mycroft bfextu USER_FPCR(a6){26:2},d1 ;get rmode
71 1.1 mycroft *
72 1.1 mycroft * check range of offset
73 1.1 mycroft *
74 1.1 mycroft tst.b d0 ;if zero, offset is to pi
75 1.1 mycroft beq.b PI_TBL ;it is pi
76 1.1 mycroft cmpi.b #$0a,d0 ;check range $01 - $0a
77 1.1 mycroft ble.b Z_VAL ;if in this range, return zero
78 1.1 mycroft cmpi.b #$0e,d0 ;check range $0b - $0e
79 1.1 mycroft ble.b SM_TBL ;valid constants in this range
80 1.1 mycroft cmpi.b #$2f,d0 ;check range $10 - $2f
81 1.1 mycroft ble.b Z_VAL ;if in this range, return zero
82 1.1 mycroft cmpi.b #$3f,d0 ;check range $30 - $3f
83 1.1 mycroft ble BG_TBL ;valid constants in this range
84 1.1 mycroft Z_VAL:
85 1.1 mycroft fmove.s FZERO,fp0
86 1.1 mycroft rts
87 1.1 mycroft PI_TBL:
88 1.1 mycroft tst.b d1 ;offset is zero, check for rmode
89 1.1 mycroft beq.b PI_RN ;if zero, rn mode
90 1.1 mycroft cmpi.b #$3,d1 ;check for rp
91 1.1 mycroft beq.b PI_RP ;if 3, rp mode
92 1.1 mycroft PI_RZRM:
93 1.1 mycroft lea.l PIRZRM,a0 ;rmode is rz or rm, load PIRZRM in a0
94 1.1 mycroft bra set_finx
95 1.1 mycroft PI_RN:
96 1.1 mycroft lea.l PIRN,a0 ;rmode is rn, load PIRN in a0
97 1.1 mycroft bra set_finx
98 1.1 mycroft PI_RP:
99 1.1 mycroft lea.l PIRP,a0 ;rmode is rp, load PIRP in a0
100 1.1 mycroft bra set_finx
101 1.1 mycroft SM_TBL:
102 1.1 mycroft subi.l #$b,d0 ;make offset in 0 - 4 range
103 1.1 mycroft tst.b d1 ;check for rmode
104 1.1 mycroft beq.b SM_RN ;if zero, rn mode
105 1.1 mycroft cmpi.b #$3,d1 ;check for rp
106 1.1 mycroft beq.b SM_RP ;if 3, rp mode
107 1.1 mycroft SM_RZRM:
108 1.1 mycroft lea.l SMALRZRM,a0 ;rmode is rz or rm, load SMRZRM in a0
109 1.1 mycroft cmpi.b #$2,d0 ;check if result is inex
110 1.1 mycroft ble set_finx ;if 0 - 2, it is inexact
111 1.1 mycroft bra no_finx ;if 3, it is exact
112 1.1 mycroft SM_RN:
113 1.1 mycroft lea.l SMALRN,a0 ;rmode is rn, load SMRN in a0
114 1.1 mycroft cmpi.b #$2,d0 ;check if result is inex
115 1.1 mycroft ble set_finx ;if 0 - 2, it is inexact
116 1.1 mycroft bra no_finx ;if 3, it is exact
117 1.1 mycroft SM_RP:
118 1.1 mycroft lea.l SMALRP,a0 ;rmode is rp, load SMRP in a0
119 1.1 mycroft cmpi.b #$2,d0 ;check if result is inex
120 1.1 mycroft ble set_finx ;if 0 - 2, it is inexact
121 1.1 mycroft bra no_finx ;if 3, it is exact
122 1.1 mycroft BG_TBL:
123 1.1 mycroft subi.l #$30,d0 ;make offset in 0 - f range
124 1.1 mycroft tst.b d1 ;check for rmode
125 1.1 mycroft beq.b BG_RN ;if zero, rn mode
126 1.1 mycroft cmpi.b #$3,d1 ;check for rp
127 1.1 mycroft beq.b BG_RP ;if 3, rp mode
128 1.1 mycroft BG_RZRM:
129 1.1 mycroft lea.l BIGRZRM,a0 ;rmode is rz or rm, load BGRZRM in a0
130 1.1 mycroft cmpi.b #$1,d0 ;check if result is inex
131 1.1 mycroft ble set_finx ;if 0 - 1, it is inexact
132 1.1 mycroft cmpi.b #$7,d0 ;second check
133 1.1 mycroft ble no_finx ;if 0 - 7, it is exact
134 1.1 mycroft bra set_finx ;if 8 - f, it is inexact
135 1.1 mycroft BG_RN:
136 1.1 mycroft lea.l BIGRN,a0 ;rmode is rn, load BGRN in a0
137 1.1 mycroft cmpi.b #$1,d0 ;check if result is inex
138 1.1 mycroft ble set_finx ;if 0 - 1, it is inexact
139 1.1 mycroft cmpi.b #$7,d0 ;second check
140 1.1 mycroft ble no_finx ;if 0 - 7, it is exact
141 1.1 mycroft bra set_finx ;if 8 - f, it is inexact
142 1.1 mycroft BG_RP:
143 1.1 mycroft lea.l BIGRP,a0 ;rmode is rp, load SMRP in a0
144 1.1 mycroft cmpi.b #$1,d0 ;check if result is inex
145 1.1 mycroft ble set_finx ;if 0 - 1, it is inexact
146 1.1 mycroft cmpi.b #$7,d0 ;second check
147 1.1 mycroft ble no_finx ;if 0 - 7, it is exact
148 1.1 mycroft * bra set_finx ;if 8 - f, it is inexact
149 1.1 mycroft set_finx:
150 1.1 mycroft or.l #inx2a_mask,USER_FPSR(a6) ;set inex2/ainex
151 1.1 mycroft no_finx:
152 1.1 mycroft mulu.l #12,d0 ;use offset to point into tables
153 1.1 mycroft move.l d1,L_SCR1(a6) ;load mode for round call
154 1.1 mycroft bfextu USER_FPCR(a6){24:2},d1 ;get precision
155 1.1 mycroft tst.l d1 ;check if extended precision
156 1.1 mycroft *
157 1.1 mycroft * Precision is extended
158 1.1 mycroft *
159 1.1 mycroft bne.b not_ext ;if extended, do not call round
160 1.1 mycroft fmovem.x (a0,d0),fp0 ;return result in fp0
161 1.1 mycroft rts
162 1.1 mycroft *
163 1.1 mycroft * Precision is single or double
164 1.1 mycroft *
165 1.1 mycroft not_ext:
166 1.1 mycroft swap d1 ;rnd prec in upper word of d1
167 1.1 mycroft add.l L_SCR1(a6),d1 ;merge rmode in low word of d1
168 1.1 mycroft move.l (a0,d0),FP_SCR1(a6) ;load first word to temp storage
169 1.1 mycroft move.l 4(a0,d0),FP_SCR1+4(a6) ;load second word
170 1.1 mycroft move.l 8(a0,d0),FP_SCR1+8(a6) ;load third word
171 1.1 mycroft clr.l d0 ;clear g,r,s
172 1.1 mycroft lea FP_SCR1(a6),a0
173 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0)
174 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext. format
175 1.1 mycroft
176 1.1 mycroft bsr round ;go round the mantissa
177 1.1 mycroft
178 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format
179 1.1 mycroft beq.b fin_fcr
180 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0)
181 1.1 mycroft fin_fcr:
182 1.1 mycroft fmovem.x (a0),fp0
183 1.1 mycroft rts
184 1.1 mycroft
185 1.1 mycroft end
186