Here's another version if anyone feels like testing it. I'm pretty sure it'll always be slower than the first version I tested but...well, just thought I'd experiment.
Instead of returning the result, you pass the result in as a float pointer
This requires a modification to the benchmarking function as well, and so I only tested this solution "alone" (too lazy to change all the other functions :).
As it is, it's about 200 ms slower for me than my first version.
Here's the code to test it
Instead of returning the result, you pass the result in as a float pointer
This requires a modification to the benchmarking function as well, and so I only tested this solution "alone" (too lazy to change all the other functions :).
As it is, it's about 200 ms slower for me than my first version.
Here's the code to test it
Function InvSqrtSOS2(x:Float, ret:Float Ptr) Local xhalf:Float = 0.5*x Local i:Int = $5f3759df - Int Ptr(Varptr(x))[0] Shr 1 Local ox:Float = Float Ptr(Varptr(i))[0] ret[0] = ox *(1.5 - (xhalf*ox*ox)) End Function Function BenchmarkInvSqrt(label:String, func(x:Float, ret:Float Ptr)) Local ii:Int Local res:Float Ptr = New Float[1] Local startTime:Long Local endTime:Long startTime = MilliSecs() For ii=1 To 100000000 func(Float(ii), res) 'Print res Next endTime = MilliSecs() - startTime Print label + ":"+ endTime End Function BenchmarkInvSqrt("SoS2", InvSqrtSOS2)