» 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. Self made ASM Squareroot

Another snipper which I received from Alex Spurling. This code calculates the approximate squareroot of the given value (single) Simply call the function like:

intSQR = 3
Call fastSqr(intSQR)

Public Sub fastSqr(ByRef num As Single)
'//By Alex Spurling - Thanks!
'#ASM_START
' push ebp
' mov ebp, esp
' push edi
'
' mov edi, DWORD PTR [ebp+8]
' mov eax, [edi]
' add eax, 3F800000h
' shr eax, 1
' mov [edi], eax
'
' pop edi
' mov esp, ebp
' pop ebp
' ret 4
End Sub

VBSQR % faster than ASMApprox VBSQR (sec) ASMApprox (sec)
78.7% 0.000584 0.000327
77% 0.000582 0.000329
77% 0.00058 0.000328
274.7% 0.001219 0.000325
80.9% 0.000588 0.000325

VBSQR % faster than ASMApprox VBSQR (sec) ASMApprox (sec)
85.7% 0.001204 0.000649
82% 0.001181 0.000649
85% 0.0012 0.000649
85% 0.0012 0.000649
86.1% 0.001201 0.000645


User contributed notes:

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