realbasic-nug
[Top] [All Lists]

Re: High Performance Code (Was: Bitwise Shift operators)

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: High Performance Code (Was: Bitwise Shift operators)
From: Marco Bambini <marco at sqlabs dot net>
Date: Sat, 29 Sep 2007 19:46:55 +0200
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <BAY107-DAV8132ACB18FF1E0678E2E693B20 at phx dot gbl> <981FFB08-71D3-487B-8A80-4352EE252BB4 at chaoticbox dot com> <2E23AD6D-B086-4475-8213-4C68AB804CFC at great-white-software dot com> <8458FDB7-710C-4350-8FF2-435B36560A6B at declareSub dot com>
What is fast for you?
I mean, how many Microseconds it should take the FastSqrt function in  
order to be "fast enough"?

---
Marco Bambini
http://www.sqlabs.net
http://www.sqlabs.net/blog/
http://www.sqlabs.net/realsqlserver/



On Sep 29, 2007, at 7:02 PM, Charles Yeomans wrote:

>
> On Sep 29, 2007, at 12:26 PM, Norman Palardy wrote:
>
>>
>> On 29-Sep-07, at 12:51 AM, Frank Condello wrote:
>>
>>> So, for fun, I implemented the approximation in pure RB code. I knew
>>> the bit shift would be a problem but I was curious as to how Rb  
>>> would
>>> handle it - here's what I ended up with:
>>>
>>>    Function FastSqrt(x As Single) As Single
>>>      #pragma BackgroundTasks False
>>>      #pragma BoundsChecking False
>>>      #pragma NilObjectChecking False
>>>      #pragma StackOverflowChecking False
>>>      Static m As New MemoryBlock(4)
>>>      Static p As Ptr = m
>>>      Dim i As Integer
>>>      Dim y As Single
>>>      p.Single(0) = x
>>>      i = p.Integer(0)
>>>      i = &h5f375a86 - Bitwise.ShiftRight(i,1)
>>>      p.Integer(0) = i
>>>      y = p.Single(0)
>>>      y = y*(1.5-0.5*x*y*y)
>>>      return x * y
>>>    End Function
>>
>> What about getting rid of the bitshift ?
>>
>>       i = &h5f375a86 - (i/2)
>
>
> I tried this (actually i\2).  It saved a few ms, but that's it.
>
> Charles Yeomans
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>