1
/* Copyright (c) 2009 Dmitry Xmelkov
4
Redistribution and use in source and binary forms, with or without
5
modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright
8
notice, this list of conditions and the following disclaimer.
9
* Redistributions in binary form must reproduce the above copyright
10
notice, this list of conditions and the following disclaimer in
11
the documentation and/or other materials provided with the
13
* Neither the name of the copyright holders nor the names of
14
contributors may be used to endorse or promote products derived
15
from this software without specific prior written permission.
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
POSSIBILITY OF SUCH DAMAGE. */
29
/* $Id: cbrt.S,v 1.1.2.2 2009/05/24 06:34:23 dmix Exp $ */
34
/* double cbrt (double)
81
RY0 - zero (was counter)
85
#if defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
86
.Ldiv3: mov REM, rA3 ; save
90
mov rA3, r1 ; quotient (((rA3 + 1) * 85) / 256)
92
mul RY0, rA3 ; r1 := 0, as the result is less than 256
93
sub REM, r0 ; remainder
97
.Ldiv3: sub REM, REM ; clear remainder and carry
98
ldi RY0, 8 ; loop counter
107
com rA3 ; because C flag was complemented in loop
111
0: rjmp _U(__fp_mpack)
114
; split and check arg.
115
rcall _U(__fp_splitA)
116
brcs 0b ; !isfinite(A)
118
breq 0b ; return 0 with original sign
121
.irp .L_reg, r29,r28,r17,r16,r15,r14,r13,r12,r11,r10,r9,r8
125
/* Calculate exponent.
131
; normalize, if A is subnormal
134
1: inc rA3 ; increment absolute value of negative exponent
143
brmi 4f ; remainder was 0
144
brne 3f ; REM: 2 --> 1
145
subi REM, -2 ; REM: 1 --> 2
146
3: inc rA3 ; correct quotient
147
; restore sign of exponent
152
; save result exponent
153
6: subi rA3, lo8(-127)
157
clr RY1 ; RY0 == 0 after .Ldiv3 function
165
; shift mantissa by 1..3 positions
173
/* --------------------------------------------------------------------
181
Free registers for temporary values:
232
; RM = (RM << 3) <-- (RA << 3)
246
/* --------------------------------------------------------------------
354
; restore registers and return
355
.irp .L_reg, r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r28,r29