Hi.
I've written an integer square root in asm, and I'm a bit rusty when it comes to ARM assembler (it's been a while...)
From the algorithm it's the well known 2 bits per iteration method. I jut use clz to skip all unnessesary iterations for numbers smaller than 32 bits.
Any ideas how to improve it? I thought about unrolling the code and calculate a jump offset based on the leading zero count, but I doubt that this will be much faster due to the code caching (the code would grow up to about half a kilobyte).
Bye,
Nils
I've written an integer square root in asm, and I'm a bit rusty when it comes to ARM assembler (it's been a while...)
From the algorithm it's the well known 2 bits per iteration method. I jut use clz to skip all unnessesary iterations for numbers smaller than 32 bits.
Any ideas how to improve it? I thought about unrolling the code and calculate a jump offset based on the leading zero count, but I doubt that this will be much faster due to the code caching (the code would grow up to about half a kilobyte).
- Code:
isqrt PROC
CLZ R1, R0
MOV R3, #1
RSB R1, R1, #31
MOV R2, #0
MOV R1, R1 LSR #1
MOV R3, R3 LSL R1
|nextbits|
ADD R12, R3, R2 LSL #1
MOV R12, R12 LSL R1
CMP R0, R12
SUB R1, R1, #1
ADDCS R2, R2, R3
SUBCS R0, R0, R12
MOVS R3, R3 LSR #1
BNE |nextbits|
MOV R0, R2
MOV PC, LR
ENDP
Bye,
Nils