News for hackers. Stuff that matters.
Re:Echo – Assembly program that prints the first positional ... by Stratoscope on Monday January 02, 2017 @05:17AM (#13300298)
The latter. The various REPxx prefixes cause a string instruction like SCASB to be repeated until some condition is satisfied.

These date back all the way to the 8086/8088. They were the fastest way to do string operations on those early CPUs, but I don't think this the case on modern CPUs.

https://www.google.com/search?q=intel+rep+prefix

http://wiki.osdev.org/X86-64_Instruction_Encoding#REPNE.2FRE...

https://courses.engr.illinois.edu/ece390/archive/spr2002/boo...

Re:Echo – Assembly program that prints the first positional ... by tptacek on Monday January 02, 2017 @06:07AM (#13300459)
They're still the x86-64 implementation for things like strlen on a bunch of platforms. They're not always the fastest, but have code size advantages.

http://agner.org/optimize/optimizing_assembly.pdf

Re:Echo – Assembly program that prints the first positional ... by Stratoscope on Monday January 02, 2017 @06:25AM (#13300531)
That's a really interesting document - I am going to spend some time studying it, thanks!

Good point about the code size. I imagine there are likely to be cases where that would let some algorithm run faster overall because it fits in the instruction cache, even if the string operation considered on its own is slower.

Re:Echo – Assembly program that prints the first positional ... by exDM69 on Monday January 02, 2017 @07:07AM (#13300682)
> They were the fastest way to do string operations on those early CPUs, but I don't think this the case on modern CPUs.

Modern CPUs still have a fast path for string operations, and I recall hearing that they even had some improvements not too long ago (in Sandy Bridge or other recent arch).

CPUs may be smart enough to detect a memcpy done with a loop, but REPxx is the preferred way - even on modern CPUs.

Re:Echo – Assembly program that prints the first positional ... by pvitz on Monday January 02, 2017 @06:32AM (#13300554)
I also remember them being called "software machine gun" by Duntemann in his assembly book. Using REP STOSW could save you 5 instructions.