Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
|
I found some fairly optimal code, 51 cycles, no approximations and no tables.
;Wilco Dijkstra
;R0 = sqrt(R1)
;Use R0-R2
sqrt32f?A MOV r2, #3 << 30
MOV r0, #1 << 30
CMP r1, r0, ROR #2 * 0
SUBHS r1, r1, r0, ROR #2 * 0
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 1
SUBHS r1, r1, r0, ROR #2 * 1
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 2
SUBHS r1, r1, r0, ROR #2 * 2
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 3
SUBHS r1, r1, r0, ROR #2 * 3
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 4
SUBHS r1, r1, r0, ROR #2 * 4
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 5
SUBHS r1, r1, r0, ROR #2 * 5
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 6
SUBHS r1, r1, r0, ROR #2 * 6
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 7
SUBHS r1, r1, r0, ROR #2 * 7
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 8
SUBHS r1, r1, r0, ROR #2 * 8
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 9
SUBHS r1, r1, r0, ROR #2 * 9
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 10
SUBHS r1, r1, r0, ROR #2 * 10
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 11
SUBHS r1, r1, r0, ROR #2 * 11
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 12
SUBHS r1, r1, r0, ROR #2 * 12
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 13
SUBHS r1, r1, r0, ROR #2 * 13
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 14
SUBHS r1, r1, r0, ROR #2 * 14
ADC r0, r2, r0, LSL #1
CMP r1, r0, ROR #2 * 15
SUBHS r1, r1, r0, ROR #2 * 15
ADC r0, r2, r0, LSL #1
BIC r0, r0, #3 << 30 ; for rounding add: CMP r1, r0 ADC r0,r0, #1
mov pc,r14
|