;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.4.0 Tue Oct 12 01:18:40 2004

;--------------------------------------------------------
	.module sqrtf
	.optsdcc -mmcs51 --model-small
	
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
	.globl _sqrtf
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
;--------------------------------------------------------
; special function bits 
;--------------------------------------------------------
;--------------------------------------------------------
; overlayable register banks 
;--------------------------------------------------------
	.area REG_BANK_0	(REL,OVR,DATA)
	.ds 8
;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
	.area DSEG    (DATA)
;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
	.area OSEG    (OVR,DATA)
;--------------------------------------------------------
; indirectly addressable internal ram data
;--------------------------------------------------------
	.area ISEG    (DATA)
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
	.area BSEG    (BIT)
;--------------------------------------------------------
; external ram data
;--------------------------------------------------------
	.area XSEG    (XDATA)
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
	.area XISEG   (XDATA)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
	.area GSINIT  (CODE)
	.area GSFINAL (CODE)
	.area GSINIT  (CODE)
;--------------------------------------------------------
; Home
;--------------------------------------------------------
	.area HOME    (CODE)
	.area CSEG    (CODE)
;--------------------------------------------------------
; code
;--------------------------------------------------------
	.area CSEG    (CODE)
;------------------------------------------------------------
;Allocation info for local variables in function 'sqrtf'
;------------------------------------------------------------
;x                         Allocated to registers r2 r3 r4 r5 
;f                         Allocated to stack - offset 1
;y                         Allocated to stack - offset 5
;n                         Allocated to stack - offset 9
;sloc0                     Allocated to stack - offset 15
;------------------------------------------------------------
;sqrtf.c:27: float sqrtf(const float x) reentrant
;	-----------------------------------------
;	 function sqrtf
;	-----------------------------------------
_sqrtf:
	ar2 = 0x02
	ar3 = 0x03
	ar4 = 0x04
	ar5 = 0x05
	ar6 = 0x06
	ar7 = 0x07
	ar0 = 0x00
	ar1 = 0x01
	push	_bp
	mov	_bp,sp
	mov	r0,a
	mov	a,sp
	add	a,#0x0a
	mov	sp,a
	mov	a,r0
;     genReceive
;sqrtf.c:32: if (x==0.0) return x;
;     genAssign
;     genCall
	mov     r2,dpl
	mov     r3,dph
	mov     r4,b
	mov     r5,a
	mov     ___fseq_PARM_2,#0x00
	mov     (___fseq_PARM_2 + 1),#0x00
	mov     (___fseq_PARM_2 + 2),#0x00
	mov     (___fseq_PARM_2 + 3),#0x00
;       Peephole 238.a  removed 4 redundant moves
	push	ar2
	push	ar3
	push	ar4
	push	ar5
	lcall	___fseq
	mov	a,dpl
	pop	ar5
	pop	ar4
	pop	ar3
	pop	ar2
;     genIfx
;     genIfxJump
;       Peephole 110    removed ljmp by inverse jump logic
	jz      00107$
00117$:
;     genRet
	mov	dpl,r2
	mov	dph,r3
	mov	b,r4
	mov	a,r5
	ljmp	00111$
00107$:
;sqrtf.c:33: else if (x==1.0) return 1.0;
;     genAssign
	mov	___fseq_PARM_2,#0x00
	mov	(___fseq_PARM_2 + 1),#0x00
	mov	(___fseq_PARM_2 + 2),#0x80
	mov	(___fseq_PARM_2 + 3),#0x3F
;     genCall
	mov	dpl,r2
	mov	dph,r3
	mov	b,r4
	mov	a,r5
	push	ar2
	push	ar3
	push	ar4
	push	ar5
	lcall	___fseq
	mov	a,dpl
	pop	ar5
	pop	ar4
	pop	ar3
	pop	ar2
;     genIfx
;     genIfxJump
;       Peephole 110    removed ljmp by inverse jump logic
	jz      00104$
00118$:
;     genRet
;       Peephole 182.b  used 16 bit load of dptr
	mov     dptr,#0x0000
	mov	b,#0x80
	mov	a,#0x3F
	ljmp	00111$
00104$:
;sqrtf.c:34: else if (x<0.0)
;     genAssign
	mov	___fslt_PARM_2,#0x00
	mov	(___fslt_PARM_2 + 1),#0x00
	mov	(___fslt_PARM_2 + 2),#0x00
	mov	(___fslt_PARM_2 + 3),#0x00
;     genCall
	mov	dpl,r2
	mov	dph,r3
	mov	b,r4
	mov	a,r5
	push	ar2
	push	ar3
	push	ar4
	push	ar5
	lcall	___fslt
	mov	a,dpl
	pop	ar5
	pop	ar4
	pop	ar3
	pop	ar2
;     genIfx
;     genIfxJump
;       Peephole 110    removed ljmp by inverse jump logic
	jz      00108$
00119$:
;sqrtf.c:36: errno=EDOM;
;     genAssign
	clr	a
	mov	(_errno + 1),a
	mov	_errno,#0x21
;sqrtf.c:37: return 0.0;
;     genRet
	mov	dpl,#0x00
;       Peephole 3.a    changed mov to clr
;       Peephole 3.b    changed mov to clr
	clr     a
	mov     dph,a
	mov     b,a
	ljmp	00111$
00108$:
;sqrtf.c:39: f=frexpf(x, &n);
;     genAddrOf
	mov	a,_bp
	add	a,#0x09
	mov	r6,a
;     genCast
	mov	_frexpf_PARM_2,r6
	mov	(_frexpf_PARM_2 + 1),#0x00
	mov	(_frexpf_PARM_2 + 2),#0x0
;     genCall
	mov	dpl,r2
	mov	dph,r3
	mov	b,r4
	mov	a,r5
	lcall	_frexpf
	mov	r2,dpl
	mov	r3,dph
	mov	r4,b
	mov	r5,a
;     genAssign
;       Peephole 212    reduced add sequence to inc
	mov     r0,_bp
	inc     r0
	mov	@r0,ar2
	inc	r0
	mov	@r0,ar3
	inc	r0
	mov	@r0,ar4
	inc	r0
	mov	@r0,ar5
;sqrtf.c:40: y=0.41731+0.59016*f; /*Educated guess*/
;     genAssign
	mov	___fsmul_PARM_2,#0xBA
	mov	(___fsmul_PARM_2 + 1),#0x14
	mov	(___fsmul_PARM_2 + 2),#0x17
	mov	(___fsmul_PARM_2 + 3),#0x3F
;     genCall
;       Peephole 212    reduced add sequence to inc
	mov     r0,_bp
	inc     r0
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	lcall	___fsmul
;     genAssign
;     genCall
	mov     r6,dpl
	mov     r7,dph
	mov     r2,b
	mov     r3,a
	mov     ___fsadd_PARM_2,#0xA8
	mov     (___fsadd_PARM_2 + 1),#0xA9
	mov     (___fsadd_PARM_2 + 2),#0xD5
	mov     (___fsadd_PARM_2 + 3),#0x3E
;       Peephole 238.a  removed 4 redundant moves
	lcall	___fsadd
	mov	r2,dpl
	mov	r3,dph
	mov	r4,b
	mov	r5,a
;     genAssign
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	@r0,ar2
	inc	r0
	mov	@r0,ar3
	inc	r0
	mov	@r0,ar4
	inc	r0
	mov	@r0,ar5
;sqrtf.c:42: y+=f/y;
;     genAssign
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	___fsdiv_PARM_2,@r0
	inc	r0
	mov	(___fsdiv_PARM_2 + 1),@r0
	inc	r0
	mov	(___fsdiv_PARM_2 + 2),@r0
	inc	r0
	mov	(___fsdiv_PARM_2 + 3),@r0
;     genCall
;       Peephole 212    reduced add sequence to inc
	mov     r0,_bp
	inc     r0
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	lcall	___fsdiv
	mov	___fsadd_PARM_2,dpl
	mov	(___fsadd_PARM_2 + 1),dph
	mov	(___fsadd_PARM_2 + 2),b
	mov	(___fsadd_PARM_2 + 3),a
;     genCall
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	lcall	___fsadd
	mov	r2,dpl
	mov	r3,dph
	mov	r4,b
	mov	r5,a
;     genAssign
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	@r0,ar2
	inc	r0
	mov	@r0,ar3
	inc	r0
	mov	@r0,ar4
	inc	r0
	mov	@r0,ar5
;sqrtf.c:43: y=ldexpf(y, -2) + f/y; /*Faster version of 0.25 * y + f/y*/
;     genAssign
	mov	_ldexpf_PARM_2,#0xFE
	mov	(_ldexpf_PARM_2 + 1),#0xFF
;     genCall
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	lcall	_ldexpf
	mov	r6,dpl
	mov	r7,dph
	mov	r2,b
	mov	r3,a
;     genAssign
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	___fsdiv_PARM_2,@r0
	inc	r0
	mov	(___fsdiv_PARM_2 + 1),@r0
	inc	r0
	mov	(___fsdiv_PARM_2 + 2),@r0
	inc	r0
	mov	(___fsdiv_PARM_2 + 3),@r0
;     genCall
;       Peephole 212    reduced add sequence to inc
	mov     r0,_bp
	inc     r0
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	push	ar2
	push	ar3
	push	ar6
	push	ar7
	lcall	___fsdiv
	mov	___fsadd_PARM_2,dpl
	mov	(___fsadd_PARM_2 + 1),dph
	mov	(___fsadd_PARM_2 + 2),b
	mov	(___fsadd_PARM_2 + 3),a
	pop	ar7
	pop	ar6
	pop	ar3
	pop	ar2
;     genCall
	mov	dpl,r6
	mov	dph,r7
	mov	b,r2
	mov	a,r3
	lcall	___fsadd
	mov	r2,dpl
	mov	r3,dph
	mov	r4,b
	mov	r5,a
;     genAssign
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	@r0,ar2
	inc	r0
	mov	@r0,ar3
	inc	r0
	mov	@r0,ar4
	inc	r0
	mov	@r0,ar5
;sqrtf.c:45: if (n&1)
;     genAnd
	mov	a,_bp
	add	a,#0x09
	mov	r0,a
	mov	a,@r0
;     genIfxJump
;       Peephole 111    removed ljmp by inverse jump logic
	jnb     acc.0,00110$
00120$:
;sqrtf.c:47: y*=0.7071067812;
;     genAssign
	mov	___fsmul_PARM_2,#0xF3
	mov	(___fsmul_PARM_2 + 1),#0x04
	mov	(___fsmul_PARM_2 + 2),#0x35
	mov	(___fsmul_PARM_2 + 3),#0x3F
;     genCall
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	lcall	___fsmul
	mov	r2,dpl
	mov	r3,dph
	mov	r4,b
	mov	r5,a
;     genAssign
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	@r0,ar2
	inc	r0
	mov	@r0,ar3
	inc	r0
	mov	@r0,ar4
	inc	r0
	mov	@r0,ar5
;sqrtf.c:48: ++n;
;     genPlus
	mov	a,_bp
	add	a,#0x09
	mov	r0,a
;     genPlusIncr
	mov	a,#0x01
	add	a,@r0
	mov	@r0,a
;       Peephole 181    changed mov to clr
	clr     a
	inc	r0
	addc	a,@r0
	mov	@r0,a
00110$:
;sqrtf.c:50: return ldexpf(y, n/2);
;     genAssign
	clr	a
	mov	(__divsint_PARM_2 + 1),a
	mov	__divsint_PARM_2,#0x02
;     genCall
	mov	a,_bp
	add	a,#0x09
	mov	r0,a
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	lcall	__divsint
	mov	_ldexpf_PARM_2,dpl
	mov	(_ldexpf_PARM_2 + 1),dph
;     genCall
	mov	a,_bp
	add	a,#0x05
	mov	r0,a
	mov	dpl,@r0
	inc	r0
	mov	dph,@r0
	inc	r0
	mov	b,@r0
	inc	r0
	mov	a,@r0
	lcall	_ldexpf
;     genRet
;       Peephole 191    removed redundant mov
	mov     r2,dpl
	mov     r3,dph
	mov     r4,b
	mov     r5,a
;       Peephole 238.b  removed 3 redundant moves
00111$:
	mov	sp,_bp
	pop	_bp
	ret
	.area CSEG    (CODE)
	.area XINIT   (CODE)
