UpdateString: destructive insert

Bare metal programming in PureBasic, for experienced users
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: UpdateString: destructive insert

Post by netmaestro »

It says that if you use ebx the c++ compiler will have to preserve it for you, which implies it needs preserved. It can be assumed then that it will need preserved everywhere. The reference I quoted is simply giving the wrong impression.
BERESHEIT
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: UpdateString: destructive insert

Post by Thorium »

Demivec wrote:
netmaestro wrote:Thorium pointed me to an x64 registers page. Have a look here:

http://msdn.microsoft.com/en-us/library/k1a8ss06.aspx
That's a helpful reference but it deals with C++ inline assembly. How does that relate to PureBasic's inline assembly?
Yes it's for C++ but Windows uses that ABI, so any software on Windows needs to stick to that ABI. Otherwise there would be major incompatiblity with DLL's and stuff.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: UpdateString: destructive insert

Post by netmaestro »

@wilbert: Yes I failed to consider the case where the operands fall through each other, my mistake. Your solution seems elegant enough and is also very economical in clocks. With Procedure changed to ProcedureDLL it tailbites up with no problem (just ascii for now), passes fairly exhaustive testing and is now in my production library. Thanks for your help.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: UpdateString: destructive insert

Post by Trond »

I'm on 64-bit so I can't test the 32-bit assembly, but it would be interesting if someone could compare the speed of the assembly to this version:

Code: Select all

Macro UpdateString2(target, source, pos)
  CopyMemory(source, target+pos-1, MemoryStringLength(source))
EndMacro
Also I can confirm that EBX needs to be preserved.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: UpdateString: destructive insert

Post by netmaestro »

it would be interesting if someone could compare the speed of the assembly to this version:
Not quite apples to apples as there are two differences:

-assembly version returns the number of successfully replaced chars (impossible with a macro)
-assembly version contains a safety check for length and will never write past the end of the target string

Anyway, with those differences in mind, here is the result of this test (debugger off, of course):

Code: Select all

s=ElapsedMilliseconds()
For i=1 To 100000000
  updatestring2(@"hello world!", @"girls", 6)
Next
t=ElapsedMilliseconds()

MessageRequester("", Str(t-s))
Macro version: 1748 ms
Assembly version: 904 ms (wilbert's last version, not my original)
BERESHEIT
Post Reply