» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Sqr() vs. ASM fsqrt

This is a small snippet which I received from Alex Spurling. It calculates the square root from the given number. The result is similar to VB's sqr() function.

'//Call this like:
'//intSQR = 3
'//Call asmSqr(intSQR)

Public Sub asmSqr(ByRef num As Single)
'//By Alex Spurling - Thanks!
'#ASM_START
' push ebp
' mov ebp, esp
'
' mov eax, DWORD PTR [ebp+8]
'
' fld dword ptr [eax]
' fsqrt
' fstp dword ptr [eax]
'
' mov esp, ebp
' pop ebp
' ret 4
'#ASM_END
End Sub

VBSQR % faster than ASMSQR VBSQR (sec) ASMSQR (sec)
133.7% 0.000762 0.000326
80.4% 0.000585 0.000324
82.2% 0.000593 0.000325
81.4% 0.00059 0.000325
92.8% 0.000627 0.000325

VBSQR % faster than ASMSQR VBSQR (sec) ASMSQR (sec)
47.3% 0.001373 0.000932
86.8% 0.001207 0.000646
100.9% 0.001298 0.000646
87.3% 0.001215 0.000649
50.3% 0.0012 0.000799


User contributed notes:

Author: Tom (hurendo_kun at hotmail dot com) Date: 05:09 23/09/2005
Not sure why this is different. VB delegates to the FPU anyway.

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: