News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

repe repne are they faster than mov looped

Started by mikeburr, December 12, 2019, 05:12:12 AM

Previous topic - Next topic

mikeburr

 I daresay this has been raised many times before but i didnt see it in a search of the site
The repe is bound to be optimised but is it much faster than mov ???
Below is a sort of chunk of code from one of my programs. I produce a result
at the bottom end [rightmost] of a very large  buffer (here as Inputbuffer) which could be filled with info
at any length up to the maximum.. it will have numeric zeros at the front end where data
hasnt been written to the buffer and i want to extract the info from the far end so need a count of leading zeros [if any]
Below are two versions [approximately] of the same thing and im interested to know
whether and if so why they might not be comparable in speed ..  as i know that many of you have a lot of
experience with timing and have special routines for doing so

//////////////////////////////////////////////////////////////////////////////////////////////////////////
    mov     edi,offset Inputbuffer
    push edi
   
    mov     ecx,{some limit}   ; set neg so it runs to a char
    xor     eax,eax
    repe   scasb
    mov     eax,edi
   
    pop edi
    inc ecx
   
    cmp  ecx.... xxxx   ;  do some  check re Inputbuffer
   

//////////////////////////////////////////////////////////////////////////////////////////////////////////
  mov and loop equivalent

   
    xor ecx,ecx
Somelabel:
    inc ecx
    cmp ecx, {some limit}     
   jg an_error_routine       ; this is not quite as above but i validate out  blank records so this is " erm ...safety coding !! "
    cmp byte ptr Inputbuffer[ecx],0
   je Somelabel
    dec ecx
    cmp ecx .... xxx  ;  do some  check re Inputbuffer
   
   ///////////////////////////////////////////////////////////////////////////////////
   regards mikeb
           

aw27

mikeburr,

I don't recall any tests with both. We have made a few tests recently but mostly with vector instructions.
However, I don't think the repeat instructions will do any better. Only rep movsb has been optimized not the others.

Adamanteus

#2
 That's dependable from hardware, so good style of programming is to have set of macroses for common and  specal CPU instructions - what client will request.
Test is also will give variable results for etalon, special, server, hi-end, pc, notebook.

jj2007

Here is a simple testbed for you :thup:

include \masm32\include\masm32rt.inc

.code
start:
  mov esi, InputFile("\Masm32\include\Windows.inc")
  mov ebx, ecx ; #bytes 
  push 9
  .Repeat
lea edi, [esi+4000] ; skip the first S.INC
push rv(GetTickCount)
mov ecx, ebx
mov al, "S"
; int 3
.Repeat
repne scasb
.Until dword ptr [edi]=="CNI." ; .INC
invoke GetTickCount
pop ecx
sub eax, ecx
print str$(eax), " ticks", 9
print left$(edi, 40), 13, 10
dec dword ptr [esp]
  .Until Sign?
  inkey "ok?"
  exit

end start

hutch--

They are old junk that live in microcode, don't waste your time on them.

jj2007

It's actually surprisingly fast on my old Core i5 (source attached, no MasmBasic installation required):
1030    ticks repne scasb       .INC be modified but
1092    ticks find$()           .INC be modified but
1014    ticks CRT strstr        .INC be modified but


Timings are for 1000x find S.INC at the end of Windows.inc

mikeburr

Thanks JJ ... thanks for all your effort .. i wouldn't have been able to do anything nearly as comprehensive ..ill try it on my machine and report back but it wont be for a few days ... many thanks again ..guessing that they wouldn't be that dissimilar is OK but you generally Cant Beat real Evidence
regards Mike B 
PS why are you doing graphical plots of Life Expectancy in Different Countries ?? 

Siekmanski

Quote from: mikeburr on December 13, 2019, 04:25:12 AM
Thanks JJ ... thanks for all your effort .. i wouldn't have been able to do anything nearly as comprehensive ..ill try it on my machine and report back but it wont be for a few days ... many thanks again ..guessing that they wouldn't be that dissimilar is OK but you generally Cant Beat real Evidence
regards Mike B 
PS why are you doing graphical plots of Life Expectancy in Different Countries ??

I think JJ wants to show that the OIL industry has doubled our life expectancy over the last 150 years.  :biggrin:
Creative coders use backward thinking techniques as a strategy.

mineiro

Quote from: mikeburr on December 13, 2019, 04:25:12 AM
PS why are you doing graphical plots of Life Expectancy in Different Countries ??
Universe 25 ; A Mice Utopia (paradise).
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

jj2007

Quote from: mikeburr on December 13, 2019, 04:25:12 AMPS why are you doing graphical plots of Life Expectancy in Different Countries ??

Data plots and presentation are my hobby (see also GDI+), and life expectancy is perhaps the most interesting data set readily available on the web. I also like playing with Excel.

hutch--

> I think JJ wants to show that the OIL industry has doubled our life expectancy over the last 150 years.

Humerous part is that the oil industry probably has helped extend human life spans due to heating, electricity, transport and lubrication. I am sure they did so for purely altruistic reasons.  :tongue:

daydreamer

Quote from: jj2007 on December 13, 2019, 12:34:06 PM
Quote from: mikeburr on December 13, 2019, 04:25:12 AMPS why are you doing graphical plots of Life Expectancy in Different Countries ??

Data plots and presentation are my hobby (see also GDI+), and life expectancy is perhaps the most interesting data set readily available on the web. I also like playing with Excel.
Also seen map drawing,why don't add a. Fun quiz to geography and country  stats on different things?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Quote from: daydreamer on December 14, 2019, 12:00:52 PMAlso seen map drawing,why don't add a Fun quiz to geography and country stats on different things?

Good idea, but I don't want to hijack this thread, so I posted the answer here :thup: