STM32F4 have FPU unit.
So, almost floating point operations can be compute in one instruction cycle.
I made a fast SQRT function, that use VSQRT FPU instruction.
Enjoy.
Code: Select all
program Test_SQRT;
var res : real;
function SQRT_F4(f_in : real) : real;
begin
R0 := @f_in;
asm
VLDR.32 S0, [R0, #0]
VSQRT.F32 S0, S0
end;
R0 := @result;
asm
VSTR.32 S0, [R0, #0]
end;
end;
begin
res := SQRT_F4(1000000.0); // 39 cycle, using FPU internal VSQRT instruction
res := sqrt(1000000.0); // 276 cycle, using internal trigon library
end.