1 | ; $Id: remainder.asm 96218 2022-08-15 12:33:57Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT remainder - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 |
|
---|
28 | %define RT_ASM_WITH_SEH64
|
---|
29 | %include "iprt/asmdefs.mac"
|
---|
30 | %include "iprt/x86.mac"
|
---|
31 |
|
---|
32 |
|
---|
33 | BEGINCODE
|
---|
34 |
|
---|
35 | ;;
|
---|
36 | ; See SUS.
|
---|
37 | ; @returns st(0) / xmm0
|
---|
38 | ; @param rd1 [ebp + 8h] xmm0 Dividend.
|
---|
39 | ; @param rd2 [ebp + 10h] xmm1 Divisor.
|
---|
40 | RT_NOCRT_BEGINPROC remainder
|
---|
41 | push xBP
|
---|
42 | SEH64_PUSH_xBP
|
---|
43 | mov xBP, xSP
|
---|
44 | SEH64_SET_FRAME_xBP 0
|
---|
45 | %ifdef RT_ARCH_AMD64
|
---|
46 | sub xSP, 20h
|
---|
47 | SEH64_ALLOCATE_STACK 20h
|
---|
48 | %endif
|
---|
49 | SEH64_END_PROLOGUE
|
---|
50 |
|
---|
51 | ;
|
---|
52 | ; Load the dividend into st0 and divisor into st1.
|
---|
53 | ;
|
---|
54 | %ifdef RT_ARCH_AMD64
|
---|
55 | movsd [xBP - 20h], xmm1
|
---|
56 | movsd [xBP - 10h], xmm0
|
---|
57 | fld qword [xBP - 20h]
|
---|
58 | fld qword [xBP - 10h]
|
---|
59 | %else
|
---|
60 | fld qword [ebp + 10h]
|
---|
61 | fld qword [ebp + 08h]
|
---|
62 | %endif
|
---|
63 |
|
---|
64 | ;
|
---|
65 | ; The fprem1 only does between 32 and 64 rounds, so we have to loop
|
---|
66 | ; here till we've got a final result. We count down in ECX to
|
---|
67 | ; avoid getting stuck here...
|
---|
68 | ;
|
---|
69 | mov ecx, 2048 / 32 + 4
|
---|
70 | .again:
|
---|
71 | fprem1
|
---|
72 | fstsw ax
|
---|
73 | test ah, (X86_FSW_C2 >> 8)
|
---|
74 | jz .done
|
---|
75 | dec cx
|
---|
76 | jnz .again
|
---|
77 | %ifdef RT_STRICT
|
---|
78 | int3
|
---|
79 | %endif
|
---|
80 |
|
---|
81 | ;
|
---|
82 | ; Return the result.
|
---|
83 | ;
|
---|
84 | .done:
|
---|
85 | fstp st1
|
---|
86 | %ifdef RT_ARCH_AMD64
|
---|
87 | fstp qword [rsp]
|
---|
88 | movsd xmm0, [rsp]
|
---|
89 | %endif
|
---|
90 |
|
---|
91 | leave
|
---|
92 | ret
|
---|
93 | ENDPROC RT_NOCRT(remainder)
|
---|
94 |
|
---|