Page 2 of 2
Re: UpdateString: destructive insert
Posted: Tue Oct 04, 2011 10:14 pm
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.
Re: UpdateString: destructive insert
Posted: Tue Oct 04, 2011 10:53 pm
by Thorium
Demivec wrote:
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.
Re: UpdateString: destructive insert
Posted: Tue Oct 04, 2011 11:29 pm
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.
Re: UpdateString: destructive insert
Posted: Sun Oct 23, 2011 3:38 pm
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.
Re: UpdateString: destructive insert
Posted: Sun Oct 23, 2011 8:21 pm
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)