1 | ; $Id: exp2.asm 96182 2022-08-13 00:53:43Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT exp2 - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 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 | BEGINCODE
|
---|
33 |
|
---|
34 | ;;
|
---|
35 | ; Calculate two to the power of @a rd.
|
---|
36 | ;
|
---|
37 | ; @returns st(0) / xmm0
|
---|
38 | ; @param rd [rbp + 8] / xmm0
|
---|
39 | RT_NOCRT_BEGINPROC exp2
|
---|
40 | push xBP
|
---|
41 | SEH64_PUSH_xBP
|
---|
42 | mov xBP, xSP
|
---|
43 | SEH64_SET_FRAME_xBP 0
|
---|
44 | %ifdef RT_ARCH_AMD64
|
---|
45 | sub xSP, 10h
|
---|
46 | SEH64_ALLOCATE_STACK 10h
|
---|
47 | %endif
|
---|
48 | SEH64_END_PROLOGUE
|
---|
49 |
|
---|
50 | ;
|
---|
51 | ; Load the value into st(0).
|
---|
52 | ;
|
---|
53 | %ifdef RT_ARCH_AMD64
|
---|
54 | movsd [xSP], xmm0
|
---|
55 | fld qword [xSP]
|
---|
56 | %else
|
---|
57 | fld qword [xBP + xCB*2]
|
---|
58 | %endif
|
---|
59 |
|
---|
60 | ;
|
---|
61 | ; Return immediately if NaN or infinity.
|
---|
62 | ;
|
---|
63 | fxam
|
---|
64 | fstsw ax
|
---|
65 | test ax, X86_FSW_C0 ; C0 is set for NaN, Infinity and Empty register. The latter is not the case.
|
---|
66 | jz .input_ok
|
---|
67 | %ifdef RT_ARCH_AMD64
|
---|
68 | ffreep st0 ; return the xmm0 register value unchanged, as FLD changes SNaN to QNaN.
|
---|
69 | %endif
|
---|
70 | test ax, X86_FSW_C2 ; C2 is clear for NaN (and Empty) but set for Infinity.
|
---|
71 | jz .return_val2
|
---|
72 | test ax, X86_FSW_C1 ; C1 = sign bit
|
---|
73 | jz .return_val2 ; Not sign, return +Inf.
|
---|
74 | %ifndef RT_ARCH_AMD64
|
---|
75 | ffreep st0
|
---|
76 | %endif
|
---|
77 | fldz ; Signed, so return zero as that's a good approximation for 2**-Inf.
|
---|
78 | jmp .return_val
|
---|
79 | .input_ok:
|
---|
80 |
|
---|
81 | ;
|
---|
82 | ; Split the job in two on the fraction and integer input parts.
|
---|
83 | ;
|
---|
84 | fld st0 ; Push a copy of the input on the stack.
|
---|
85 | frndint ; st0 = (int)input
|
---|
86 | fsub st1, st0 ; st1 = input - (int)input; i.e. st1 = fraction, st0 = integer.
|
---|
87 | fxch ; st0 = fraction, st1 = integer.
|
---|
88 |
|
---|
89 | ; 1. Calculate on the fraction.
|
---|
90 | f2xm1 ; st0 = 2**fraction - 1.0
|
---|
91 | fld1
|
---|
92 | faddp ; st0 = 2**fraction
|
---|
93 |
|
---|
94 | ; 2. Apply the integer power of two.
|
---|
95 | fscale ; st0 = result; st1 = integer part of input.
|
---|
96 | fstp st1 ; st0 = result; no st1.
|
---|
97 |
|
---|
98 | .return_val:
|
---|
99 | %ifdef RT_ARCH_AMD64
|
---|
100 | fstp qword [xSP]
|
---|
101 | movsd xmm0, [xSP]
|
---|
102 | %endif
|
---|
103 | .return_val2:
|
---|
104 | leave
|
---|
105 | ret
|
---|
106 | ENDPROC RT_NOCRT(exp2)
|
---|
107 |
|
---|