Author Topic: repe repne are they faster than mov looped  (Read 3765 times)

mikeburr

  • Member
  • **
  • Posts: 184
repe repne are they faster than mov looped
« on: December 12, 2019, 05:12:12 AM »
 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

  • Guest
Re: repe repne are they faster than mov looped
« Reply #1 on: December 12, 2019, 08:30:07 PM »
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

  • Member
  • **
  • Posts: 249
    • LLC "AMS"
Re: repe repne are they faster than mov looped
« Reply #2 on: December 12, 2019, 10:42:02 PM »
 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.
« Last Edit: December 13, 2019, 07:29:22 PM by Adamanteus »

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: repe repne are they faster than mov looped
« Reply #3 on: December 13, 2019, 12:06:29 AM »
Here is a simple testbed for you :thup:

Code: [Select]
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
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9988
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: repe repne are they faster than mov looped
« Reply #4 on: December 13, 2019, 02:23:27 AM »
They are old junk that live in microcode, don't waste your time on them.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: repe repne are they faster than mov looped
« Reply #5 on: December 13, 2019, 03:20:02 AM »
It's actually surprisingly fast on my old Core i5 (source attached, no MasmBasic installation required):
Code: [Select]
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
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

mikeburr

  • Member
  • **
  • Posts: 184
Re: repe repne are they faster than mov looped
« Reply #6 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 ?? 

Siekmanski

  • Member
  • *****
  • Posts: 2589
Re: repe repne are they faster than mov looped
« Reply #7 on: December 13, 2019, 06:06:38 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

  • Member
  • ****
  • Posts: 864
Re: repe repne are they faster than mov looped
« Reply #8 on: December 13, 2019, 09:37:30 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

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: repe repne are they faster than mov looped
« Reply #9 on: December 13, 2019, 12:34:06 PM »
PS 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.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 9988
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: repe repne are they faster than mov looped
« Reply #10 on: December 13, 2019, 01:47:54 PM »
> 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:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

daydreamer

  • Member
  • *****
  • Posts: 2185
  • my kind of REAL10 Blonde
Re: repe repne are they faster than mov looped
« Reply #11 on: December 14, 2019, 12:00:52 PM »
PS 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
http://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."

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: repe repne are they faster than mov looped
« Reply #12 on: December 14, 2019, 01:46:21 PM »
Also 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:
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.