1 | 1 | 2 | sint.sa 3.1 12/10/90 2 | sint.sa 3.1 12/10/90 3 | 3 | 4 | The entry point sINT computes the roun 4 | The entry point sINT computes the rounded integer 5 | equivalent of the input argument, sINT 5 | equivalent of the input argument, sINTRZ computes 6 | the integer rounded to zero of the inp 6 | the integer rounded to zero of the input argument. 7 | 7 | 8 | Entry points sint and sintrz are calle 8 | Entry points sint and sintrz are called from do_func 9 | to emulate the fint and fintrz unimple 9 | to emulate the fint and fintrz unimplemented instructions, 10 | respectively. Entry point sintdo is u 10 | respectively. Entry point sintdo is used by bindec. 11 | 11 | 12 | Input: (Entry points sint and sintrz) 12 | Input: (Entry points sint and sintrz) Double-extended 13 | number X in the ETEMP space in 13 | number X in the ETEMP space in the floating-point 14 | save stack. 14 | save stack. 15 | (Entry point sintdo) Double-ext 15 | (Entry point sintdo) Double-extended number X in 16 | location pointed to by the add 16 | location pointed to by the address register a0. 17 | (Entry point sintd) Double-exte 17 | (Entry point sintd) Double-extended denormalized 18 | number X in the ETEMP space in 18 | number X in the ETEMP space in the floating-point 19 | save stack. 19 | save stack. 20 | 20 | 21 | Output: The function returns int(X) or 21 | Output: The function returns int(X) or intrz(X) in fp0. 22 | 22 | 23 | Modifies: fp0. 23 | Modifies: fp0. 24 | 24 | 25 | Algorithm: (sint and sintrz) 25 | Algorithm: (sint and sintrz) 26 | 26 | 27 | 1. If exp(X) >= 63, return X. 27 | 1. If exp(X) >= 63, return X. 28 | If exp(X) < 0, return +/- 0 or +/- 28 | If exp(X) < 0, return +/- 0 or +/- 1, according to 29 | the rounding mode. 29 | the rounding mode. 30 | 30 | 31 | 2. (X is in range) set rsc = 63 - exp( 31 | 2. (X is in range) set rsc = 63 - exp(X). Unnormalize the 32 | result to the exponent $403e. 32 | result to the exponent $403e. 33 | 33 | 34 | 3. Round the result in the mode given 34 | 3. Round the result in the mode given in USER_FPCR. For 35 | sintrz, force round-to-zero mode. 35 | sintrz, force round-to-zero mode. 36 | 36 | 37 | 4. Normalize the rounded result; store 37 | 4. Normalize the rounded result; store in fp0. 38 | 38 | 39 | For the denormalized cases, force the 39 | For the denormalized cases, force the correct result 40 | for the given sign and rounding mode. 40 | for the given sign and rounding mode. 41 | 41 | 42 | Sign(X) 42 | Sign(X) 43 | RMODE + - 43 | RMODE + - 44 | ----- -------- 44 | ----- -------- 45 | RN +0 -0 45 | RN +0 -0 46 | RZ +0 -0 46 | RZ +0 -0 47 | RM +0 -1 47 | RM +0 -1 48 | RP +1 -0 48 | RP +1 -0 49 | 49 | 50 | 50 | 51 | Copyright (C) Motorola, Inc. 1 51 | Copyright (C) Motorola, Inc. 1990 52 | All Rights Reserved 52 | All Rights Reserved 53 | 53 | 54 | For details on the license for this fi 54 | For details on the license for this file, please see the 55 | file, README, in this same directory. 55 | file, README, in this same directory. 56 56 57 |SINT idnt 2,1 | Motorola 040 Floating P 57 |SINT idnt 2,1 | Motorola 040 Floating Point Software Package 58 58 59 |section 8 59 |section 8 60 60 61 #include "fpsp.h" 61 #include "fpsp.h" 62 62 63 |xref dnrm_lp 63 |xref dnrm_lp 64 |xref nrm_set 64 |xref nrm_set 65 |xref round 65 |xref round 66 |xref t_inx2 66 |xref t_inx2 67 |xref ld_pone 67 |xref ld_pone 68 |xref ld_mone 68 |xref ld_mone 69 |xref ld_pzero 69 |xref ld_pzero 70 |xref ld_mzero 70 |xref ld_mzero 71 |xref snzrinx 71 |xref snzrinx 72 72 73 | 73 | 74 | FINT 74 | FINT 75 | 75 | 76 .global sint 76 .global sint 77 sint: 77 sint: 78 bfextu FPCR_MODE(%a6){#2:#2},%d1 78 bfextu FPCR_MODE(%a6){#2:#2},%d1 |use user's mode for rounding 79 | ;impli 79 | ;implicitly has extend precision 80 | ;in up 80 | ;in upper word. 81 movel %d1,L_SCR1(%a6) |save 81 movel %d1,L_SCR1(%a6) |save mode bits 82 bras sintexc 82 bras sintexc 83 83 84 | 84 | 85 | FINT with extended denorm inputs. 85 | FINT with extended denorm inputs. 86 | 86 | 87 .global sintd 87 .global sintd 88 sintd: 88 sintd: 89 btstb #5,FPCR_MODE(%a6) 89 btstb #5,FPCR_MODE(%a6) 90 beq snzrinx |if round near 90 beq snzrinx |if round nearest or round zero, +/- 0 91 btstb #4,FPCR_MODE(%a6) 91 btstb #4,FPCR_MODE(%a6) 92 beqs rnd_mns 92 beqs rnd_mns 93 rnd_pls: 93 rnd_pls: 94 btstb #sign_bit,LOCAL_EX(%a0) 94 btstb #sign_bit,LOCAL_EX(%a0) 95 bnes sintmz 95 bnes sintmz 96 bsr ld_pone |if round plus 96 bsr ld_pone |if round plus inf and pos, answer is +1 97 bra t_inx2 97 bra t_inx2 98 rnd_mns: 98 rnd_mns: 99 btstb #sign_bit,LOCAL_EX(%a0) 99 btstb #sign_bit,LOCAL_EX(%a0) 100 beqs sintpz 100 beqs sintpz 101 bsr ld_mone |if round mns 101 bsr ld_mone |if round mns inf and neg, answer is -1 102 bra t_inx2 102 bra t_inx2 103 sintpz: 103 sintpz: 104 bsr ld_pzero 104 bsr ld_pzero 105 bra t_inx2 105 bra t_inx2 106 sintmz: 106 sintmz: 107 bsr ld_mzero 107 bsr ld_mzero 108 bra t_inx2 108 bra t_inx2 109 109 110 | 110 | 111 | FINTRZ 111 | FINTRZ 112 | 112 | 113 .global sintrz 113 .global sintrz 114 sintrz: 114 sintrz: 115 movel #1,L_SCR1(%a6) |use r 115 movel #1,L_SCR1(%a6) |use rz mode for rounding 116 | ;impli 116 | ;implicitly has extend precision 117 | ;in up 117 | ;in upper word. 118 bras sintexc 118 bras sintexc 119 | 119 | 120 | SINTDO 120 | SINTDO 121 | 121 | 122 | Input: a0 points to an IEEE extended 122 | Input: a0 points to an IEEE extended format operand 123 | Output: fp0 has the result 123 | Output: fp0 has the result 124 | 124 | 125 | Exceptions: 125 | Exceptions: 126 | 126 | 127 | If the subroutine results in an inexact oper 127 | If the subroutine results in an inexact operation, the inx2 and 128 | ainx bits in the USER_FPSR are set. 128 | ainx bits in the USER_FPSR are set. 129 | 129 | 130 | 130 | 131 .global sintdo 131 .global sintdo 132 sintdo: 132 sintdo: 133 bfextu FPCR_MODE(%a6){#2:#2},%d1 133 bfextu FPCR_MODE(%a6){#2:#2},%d1 |use user's mode for rounding 134 | ;impli 134 | ;implicitly has ext precision 135 | ;in up 135 | ;in upper word. 136 movel %d1,L_SCR1(%a6) |save 136 movel %d1,L_SCR1(%a6) |save mode bits 137 | 137 | 138 | Real work of sint is in sintexc 138 | Real work of sint is in sintexc 139 | 139 | 140 sintexc: 140 sintexc: 141 bclrb #sign_bit,LOCAL_EX(%a0) |conve 141 bclrb #sign_bit,LOCAL_EX(%a0) |convert to internal extended 142 | ;forma 142 | ;format 143 sne LOCAL_SGN(%a0) 143 sne LOCAL_SGN(%a0) 144 cmpw #0x403e,LOCAL_EX(%a0) |check 144 cmpw #0x403e,LOCAL_EX(%a0) |check if (unbiased) exp > 63 145 bgts out_rnge 145 bgts out_rnge |branch if exp < 63 146 cmpw #0x3ffd,LOCAL_EX(%a0) |check 146 cmpw #0x3ffd,LOCAL_EX(%a0) |check if (unbiased) exp < 0 147 bgt in_rnge |if 63 147 bgt in_rnge |if 63 >= exp > 0, do calc 148 | 148 | 149 | Input is less than zero. Restore sign, and 149 | Input is less than zero. Restore sign, and check for directed 150 | rounding modes. L_SCR1 contains the rmode i 150 | rounding modes. L_SCR1 contains the rmode in the lower byte. 151 | 151 | 152 un_rnge: 152 un_rnge: 153 btstb #1,L_SCR1+3(%a6) 153 btstb #1,L_SCR1+3(%a6) |check for rn and rz 154 beqs un_rnrz 154 beqs un_rnrz 155 tstb LOCAL_SGN(%a0) |check 155 tstb LOCAL_SGN(%a0) |check for sign 156 bnes un_rmrp_neg 156 bnes un_rmrp_neg 157 | 157 | 158 | Sign is +. If rp, load +1.0, if rm, load +0 158 | Sign is +. If rp, load +1.0, if rm, load +0.0 159 | 159 | 160 cmpib #3,L_SCR1+3(%a6) 160 cmpib #3,L_SCR1+3(%a6) |check for rp 161 beqs un_ldpone |if rp 161 beqs un_ldpone |if rp, load +1.0 162 bsr ld_pzero |if rm 162 bsr ld_pzero |if rm, load +0.0 163 bra t_inx2 163 bra t_inx2 164 un_ldpone: 164 un_ldpone: 165 bsr ld_pone 165 bsr ld_pone 166 bra t_inx2 166 bra t_inx2 167 | 167 | 168 | Sign is -. If rm, load -1.0, if rp, load -0 168 | Sign is -. If rm, load -1.0, if rp, load -0.0 169 | 169 | 170 un_rmrp_neg: 170 un_rmrp_neg: 171 cmpib #2,L_SCR1+3(%a6) 171 cmpib #2,L_SCR1+3(%a6) |check for rm 172 beqs un_ldmone |if rm 172 beqs un_ldmone |if rm, load -1.0 173 bsr ld_mzero |if rp 173 bsr ld_mzero |if rp, load -0.0 174 bra t_inx2 174 bra t_inx2 175 un_ldmone: 175 un_ldmone: 176 bsr ld_mone 176 bsr ld_mone 177 bra t_inx2 177 bra t_inx2 178 | 178 | 179 | Rmode is rn or rz; return signed zero 179 | Rmode is rn or rz; return signed zero 180 | 180 | 181 un_rnrz: 181 un_rnrz: 182 tstb LOCAL_SGN(%a0) |check 182 tstb LOCAL_SGN(%a0) |check for sign 183 bnes un_rnrz_neg 183 bnes un_rnrz_neg 184 bsr ld_pzero 184 bsr ld_pzero 185 bra t_inx2 185 bra t_inx2 186 un_rnrz_neg: 186 un_rnrz_neg: 187 bsr ld_mzero 187 bsr ld_mzero 188 bra t_inx2 188 bra t_inx2 189 189 190 | 190 | 191 | Input is greater than 2^63. All bits are si 191 | Input is greater than 2^63. All bits are significant. Return 192 | the input. 192 | the input. 193 | 193 | 194 out_rnge: 194 out_rnge: 195 bfclr LOCAL_SGN(%a0){#0:#8} |chang 195 bfclr LOCAL_SGN(%a0){#0:#8} |change back to IEEE ext format 196 beqs intps 196 beqs intps 197 bsetb #sign_bit,LOCAL_EX(%a0) 197 bsetb #sign_bit,LOCAL_EX(%a0) 198 intps: 198 intps: 199 fmovel %fpcr,-(%sp) 199 fmovel %fpcr,-(%sp) 200 fmovel #0,%fpcr 200 fmovel #0,%fpcr 201 fmovex LOCAL_EX(%a0),%fp0 |if ex 201 fmovex LOCAL_EX(%a0),%fp0 |if exp > 63 202 | ;then 202 | ;then return X to the user 203 | ;there 203 | ;there are no fraction bits 204 fmovel (%sp)+,%fpcr 204 fmovel (%sp)+,%fpcr 205 rts 205 rts 206 206 207 in_rnge: 207 in_rnge: 208 | ;shift 208 | ;shift off fraction bits 209 clrl %d0 |clear 209 clrl %d0 |clear d0 - initial g,r,s for 210 | ;dnrm_ 210 | ;dnrm_lp 211 movel #0x403e,%d1 |set t 211 movel #0x403e,%d1 |set threshold for dnrm_lp 212 | ;assum 212 | ;assumes a0 points to operand 213 bsr dnrm_lp 213 bsr dnrm_lp 214 | ;retur 214 | ;returns unnormalized number 215 | ;point 215 | ;pointed by a0 216 | ;outpu 216 | ;output d0 supplies g,r,s 217 | ;used 217 | ;used by round 218 movel L_SCR1(%a6),%d1 |use s 218 movel L_SCR1(%a6),%d1 |use selected rounding mode 219 | 219 | 220 | 220 | 221 bsr round |round 221 bsr round |round the unnorm based on users 222 | ;input 222 | ;input a0 ptr to ext X 223 | ; 223 | ; d0 g,r,s bits 224 | ; 224 | ; d1 PREC/MODE info 225 | ;outpu 225 | ;output a0 ptr to rounded result 226 | ;inexa 226 | ;inexact flag set in USER_FPSR 227 | ;if in 227 | ;if initial grs set 228 | 228 | 229 | normalize the rounded result and store value 229 | normalize the rounded result and store value in fp0 230 | 230 | 231 bsr nrm_set |norma 231 bsr nrm_set |normalize the unnorm 232 | ;Input 232 | ;Input: a0 points to operand to 233 | ;be no 233 | ;be normalized 234 | ;Outpu 234 | ;Output: a0 points to normalized 235 | ;resul 235 | ;result 236 bfclr LOCAL_SGN(%a0){#0:#8} 236 bfclr LOCAL_SGN(%a0){#0:#8} 237 beqs nrmrndp 237 beqs nrmrndp 238 bsetb #sign_bit,LOCAL_EX(%a0) |retur 238 bsetb #sign_bit,LOCAL_EX(%a0) |return to IEEE extended format 239 nrmrndp: 239 nrmrndp: 240 fmovel %fpcr,-(%sp) 240 fmovel %fpcr,-(%sp) 241 fmovel #0,%fpcr 241 fmovel #0,%fpcr 242 fmovex LOCAL_EX(%a0),%fp0 |move 242 fmovex LOCAL_EX(%a0),%fp0 |move result to fp0 243 fmovel (%sp)+,%fpcr 243 fmovel (%sp)+,%fpcr 244 rts 244 rts 245 245 246 |end 246 |end
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.