4 ; Fast square root routines
6 ; © 1995-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard header ------------------------------------------------------
34 ;----- Main code ------------------------------------------------------------
36 AREA |Sapphire$$Code|,CODE,READONLY
40 ; On entry: R0 == value to square-root
42 ; On exit: R0 == the result
44 ; Use: Evaluates the square root of the number given. This routine
45 ; is constructed from the information supplied by David Seal,
46 ; and is *extremely* fast.
51 STMFD R13!,{R1-R4,R14} ;Stack registers
52 MOV R1,#0 ;Result so far
53 MOV R2,#0 ;Current remainder
54 MOV R3,#1 ;A '01' pair
55 MOV R4,#3 ;A nice mask
58 count SETA 0 ;Start the count at 30
60 WHILE count<=28 ;Set up the loop condition
62 AND R14,R4,R0,LSR #30-count
80 c MOV R0,R1 ;Put the result in R0
81 LDMFD R13!,{R1-R4,PC}^ ;Return to caller
85 ;----- That's all, folks ----------------------------------------------------