Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 336 lines (306 sloc) 6.041 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
;; Compiler implementation of the D programming language
;; Copyright (c) 1999-2011 by Digital Mars
;; All Rights Reserved
;; written by Rainer Schuetze
;; http://www.digitalmars.com
;; License for redistribution is by either the Artistic License
;; in artistic.txt, or the GNU General Public License in gnu.txt.
;; See the included readme.txt for details.

;; 80 bit floating point value implementation for Microsoft compiler

;.386
;.model flat, c

; Custom Build Step, including a listing file placed in intermediate directory
; debug:
; ml -c -Zi "-Fl$(IntDir)\$(InputName).lst" "-Fo$(IntDir)\$(InputName).obj" "$(InputPath)"
; release:
; ml -c "-Fl$(IntDir)\$(InputName).lst" "-Fo$(IntDir)\$(InputName).obj" "$(InputPath)"
; outputs:
; $(IntDir)\$(InputName).obj

.data

twoPow63 dd 0, 80000000h, 03fffh + 63

.code

; double ld_read(longdouble* ld);
; rcx: ld
ld_read PROC
fld tbyte ptr [rcx]
push rax
fstp qword ptr [esp]
movq xmm0,qword ptr [rsp]
pop rax
ret
ld_read ENDP

; long long ld_readll(longdouble* ld);
; rcx: ld
ld_readll PROC
fld tbyte ptr [rcx]
push rax
fistp qword ptr [esp]
pop rax
ret
ld_readll ENDP

; unsigned long long ld_readull(longdouble* ld);
; rcx: ld
ld_readull PROC
fld tbyte ptr [rcx]
push rax
lea rax,twoPow63
fld tbyte ptr [rax]
fsubp ST(1),ST(0) ; move it into signed range
fistp qword ptr [esp]
pop rax
btc rax,63
ret
ld_readull ENDP

; void ld_set(longdouble* ld, double d);
; rcx: ld
; xmm1: d
ld_set PROC
push rax
movq qword ptr [rsp],xmm1
fld qword ptr [rsp]
fstp tbyte ptr [rcx]
pop rax
ret
ld_set ENDP

; void ld_setll(longdouble* ld, long long d);
; rcx: ld
; rdx: d
ld_setll PROC
push rdx
fild qword ptr [esp]
    fstp tbyte ptr [rcx]
    pop rax
ret
ld_setll ENDP

; void ld_setull(longdouble* ld, long long d);
; rcx: ld
; rax: d
ld_setull PROC
btc rdx,63
push rdx
fild qword ptr [esp]
lea rax,twoPow63
fld tbyte ptr [rax]
faddp ST(1),ST(0)
    fstp tbyte ptr [rcx]
    pop rax
ret
ld_setull ENDP

; void ld_expl(longdouble* ld, int exp);
; rcx: ld
; edx: exp
ld_expl PROC
push rdx
fild dword ptr [esp]
fld tbyte ptr [rcx]
fscale ; ST(0) = ST(0) * (2**ST(1))
fstp ST(1)
fstp tbyte ptr [rcx]
    pop rax
ret
ld_expl ENDP

; long_double ld_add(long_double ld1, long_double ld2);
; rcx: &res
; rdx: &ld1
; r8: &ld2
ld_add PROC
fld tbyte ptr [r8]
fld tbyte ptr [rdx]
fadd
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_add ENDP

; long_double ld_sub(long_double ld1, long_double ld2);
; rcx: &res
; rdx: &ld1
; r8: &ld2
ld_sub PROC
fld tbyte ptr [rdx]
fld tbyte ptr [r8]
fsub
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_sub ENDP

; long_double ld_mul(long_double ld1, long_double ld2);
; rcx: &res
; rdx: &ld1
; r8: &ld2
ld_mul PROC
fld tbyte ptr [r8]
fld tbyte ptr [rdx]
fmul
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_mul ENDP

; long_double ld_div(long_double ld1, long_double ld2);
; rcx: &res
; rdx: &ld1
; r8: &ld2
ld_div PROC
fld tbyte ptr [rdx]
fld tbyte ptr [r8]
fdiv
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_div ENDP

; long_double ld_mod(long_double ld1, long_double ld2);
; rcx: &res
; rdx: &ld1
; r8: &ld2
ld_mod PROC
push rax
        fld tbyte ptr [r8]
        fld tbyte ptr [rdx] ; ST = x, ST1 = y
FM1: ; We don't use fprem1 because for some inexplicable
        ; reason we get -5 when we do _modulo(15, 10)
        fprem ; ST = ST % ST1
        fstsw word ptr [rsp]
        fwait
        mov AH,byte ptr [rsp+1] ; get msb of status word in AH
        sahf ; transfer to flags
        jp FM1 ; continue till ST < ST1
        fstp ST(1) ; leave remainder on stack
        fstp tbyte ptr [ecx]
pop rax
mov rax,rcx
ret
ld_mod ENDP

; bool ld_cmpb(long_double x, long_double y);
; rcx: &x
; rdx: &y
ld_cmpb PROC
fld tbyte ptr [rdx]
fld tbyte ptr [rcx]
fucomip ST(0),ST(1)
setb AL
setnp AH
and AL,AH
fstp ST(0)
ret
ld_cmpb ENDP

; bool ld_cmpbe(long_double x, long_double y);
; rcx: &x
; rdx: &y
ld_cmpbe PROC
fld tbyte ptr [rdx]
fld tbyte ptr [rcx]
fucomip ST(0),ST(1)
setbe AL
setnp AH
and AL,AH
fstp ST(0)
ret
ld_cmpbe ENDP

; bool ld_cmpa(long_double x, long_double y);
; rcx: &x
; rdx: &y
ld_cmpa PROC
fld tbyte ptr [rdx]
fld tbyte ptr [rcx]
fucomip ST(0),ST(1)
seta AL
setnp AH
and AL,AH
fstp ST(0)
ret
ld_cmpa ENDP

; bool ld_cmpae(long_double x, long_double y);
; rcx: &x
; rdx: &y
ld_cmpae PROC
fld tbyte ptr [rdx]
fld tbyte ptr [rcx]
fucomip ST(0),ST(1)
setae AL
setnp AH
and AL,AH
fstp ST(0)
ret
ld_cmpae ENDP

; bool ld_cmpe(long_double x, long_double y);
; rcx: &x
; rdx: &y
ld_cmpe PROC
fld tbyte ptr [rdx]
fld tbyte ptr [rcx]
fucomip ST(0),ST(1)
sete AL
setnp AH
and AL,AH
fstp ST(0)
ret
ld_cmpe ENDP

; bool ld_cmpne(long_double x, long_double y);
; rcx: &x
; rdx: &y
ld_cmpne PROC
fld tbyte ptr [rdx]
fld tbyte ptr [rcx]
fucomip ST(0),ST(1)
setne AL
setp AH
or AL,AH
fstp ST(0)
ret
ld_cmpne ENDP

; long_double ld_sqrt(long_double x);
; rcx: &res
; rdx: &x
ld_sqrt PROC
fld tbyte ptr [rdx]
fsqrt
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_sqrt ENDP

; long_double ld_sin(long_double x);
; rcx: &res
; rdx: &x
ld_sin PROC
fld tbyte ptr [rdx]
fsin
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_sin ENDP

; long_double ld_cos(long_double x);
; rcx: &res
; rdx: &x
ld_cos PROC
fld tbyte ptr [rdx]
fcos
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_cos ENDP

; long_double ld_tan(long_double x);
; rcx: &res
; rdx: &x
ld_tan PROC
fld tbyte ptr [rdx]
fptan
fstp st(0)
fstp tbyte ptr [rcx]
mov rax,rcx
ret
ld_tan ENDP

; int ld_initfpu(int bits, int mask)
; ecx: bits
; edx: mask
ld_initfpu PROC
push rcx
fstcw word ptr [rsp]
movzx EAX,word ptr [rsp] ; also return old CW in EAX
not EDX
and EDX,EAX
or ECX,EDX
mov dword ptr [rsp],ECX
fldcw word ptr [rsp]
pop rcx
ret
ld_initfpu ENDP

end
Something went wrong with that request. Please try again.