Please note that if your instruction set has instructions for square root or power, you will be much better off using this. For example, x71 floating point instructions have the fsqrt command, and SSE2 add-ons include another sqrtsd command, which is likely to be much faster than most solutions written in C. In fact, at least gcc uses two when compiling is done on x86 machine.
For the authorities, however, everything is becoming somewhat muddy. There is an instruction in the x87 floating-point instruction set, which can be used to calculate n * log2 (n), namely fyl2x . Another fldl2e command stores fldl2e (e) on a floating point stack. You can look at them.
You can also see how separate C. dietlibc libraries do this, for example, just use fsqrt :
sqrt: fldl 4(%esp) fsqrt ret
glibc uses the Sun implementation for machines where a hardware square root instruction is not available (under sysdeps/ieee754/flt-32/e-sqrtf.c ) and uses fsqrt in the x86 command set (although gcc can be instructed to use the sqrtsd instruction instead).
source share