From: Larry Serflaten on

"MM" <kylix_is(a)yahoo.co.uk> wrote

> No, it's not. It's even faster than SwapEndian08. Here's my latest
> attempt:
>
> Function Endian32_UsingShift(ByVal n As Long) As Long
>
> Endian32_UsingShift = ((ShiftLL(n And &HFF&, 24)) _
> Or (ShiftLL(n And &HFF00&, 8)) _
> Or (ShiftLR(n And &HFF0000, 8)) _
> Or (ShiftLR(n And &HFF000000, 24)))
>
> End Function
>

Something else to try....

Function EndianSwap(Value as long) As Long
Dim tmp as long

tmp = ShiftLL(Value And &HFF00FF&, 8) Or ShiftLR(Value And &HFF00FF00, 8)
EndianSwap = ShiftLL(tmp, 16) Or ShiftLR(tmp, 16)

End Function

LFS


From: Mike Williams on
"MM" <kylix_is(a)yahoo.co.uk> wrote in message
news:4m9np5tsba87an9ns7volhm0ke112gl46h(a)4ax.com...

> Here's my latest attempt:
> Function Endian32_UsingShift(ByVal n As Long) As Long
> Endian32_UsingShift = ((ShiftLL(n And &HFF&, 24)) _
> Or (ShiftLL(n And &HFF00&, 8)) _
> Or (ShiftLR(n And &HFF0000, 8)) _
> Or (ShiftLR(n And &HFF000000, 24)))
> End Function
> returns 18 secs for 1 million iterations on my Sempron
> 2.8 on Windows 98 SE.

?? 18 secs for 1 million ?? Presumably you mean 18 milliseconds?

> However, SwapEndian08 returns 19 secs.
> The shifts are from Crescent's QuickPak Professional.

I think to get the ultimate speed you're going to need to perform the whole
job (the shifts and the ORs / ANDs) in the same machine code routine so that
you call the function just once rather than calling a shift function four
times and performing the ANDs and ORs in VB. Maybe someone with up to date
ASM experience could write such a routine?

Mike



From: Jim Mack on
Mike Williams wrote:
>
> ?? 18 secs for 1 million ?? Presumably you mean 18 milliseconds?

Probably not. It's guaranteed to be slower, but not by that much.

There's simply no way that making 4 external ASM calls, especially to
a Declared function, is going to beat optimized, compiled VB6. I don't
believe it.

The reason I don't believe it is that I'm an ASM expert myself, and
sell a library that competed with QuickPak Pro (Ethan and I are old
friends).

In ASM (386+), you can perform this operation with two instructions
that literally take nanoseconds to execute:

Endian4 PROC PUBLIC
mov eax, [esp+4]
bswap eax
ret 4
Endian4 ENDP

From VB, then: Swapped& = Endian4(Unswapped&)

When we had this exact discussion here a couple of years ago, I placed
that function into a DLL, using a Typelib, and others here timed it
against the vbspeed code.

It lost. The reason is that VB jumps through a lot of hoops to make an
external call. For a Declared function, it must also call
SetLastDllError internally on each call.

So even though the code itself is perfectly optimal, it can't compete
with inline code optimized by the VB compiler.

If there's interest I'll do it again, making the DLL available for
anyone to DL and test.

And if anyone here has our Stamina library, try a call to
DxEndian(unswapped&, 4) and tell us how it fares.

--
Jim Mack
MicroDexterity Inc www.microdexterity.com

From: MM on
On Sat, 13 Mar 2010 12:41:10 -0500, "Jim Mack" <jmack(a)mdxi.nospam.com>
wrote:

>Mike Williams wrote:
>>
>> ?? 18 secs for 1 million ?? Presumably you mean 18 milliseconds?
>
>Probably not. It's guaranteed to be slower, but not by that much.
>
>There's simply no way that making 4 external ASM calls, especially to
>a Declared function, is going to beat optimized, compiled VB6. I don't
>believe it.

I did it. It does.

MM
From: Jim Mack on
MM wrote:
> On Sat, 13 Mar 2010 12:41:10 -0500, "Jim Mack"
> <jmack(a)mdxi.nospam.com> wrote:
>
>> Mike Williams wrote:
>>>
>>> ?? 18 secs for 1 million ?? Presumably you mean 18 milliseconds?
>>
>> Probably not. It's guaranteed to be slower, but not by that much.
>>
>> There's simply no way that making 4 external ASM calls, especially
>> to a Declared function, is going to beat optimized, compiled VB6.
>> I don't believe it.
>
> I did it. It does.

Are you doing this compiled to native code with all optimizations?

Just for comparison, try this:

http://www.microdexterity.com/other/bendian.dll

Read the text file first. I don't know what's different this time, but
I get a 40% speed advantage using the ASM code over the Swap08 code.
The last time we tried this people reported a 10% disadvantage IIRC.

--
Jim

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Prev: VB 6 & VS?
Next: C:\WINDOWS\system32\ieframe.dll\1