Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #536396

Re: memmove( z, x, sizeof x );

From F Russell <fr@random.info>
Newsgroups comp.os.linux.advocacy
Subject Re: memmove( z, x, sizeof x );
Date 2019-10-10 21:20 +0000
Organization NewsGuy.com
Message-ID <qno7aj0kh9@news2.newsguy.com> (permalink)
References <lF%mF.108280$LC2.8395@fx45.iad> <Jeff-Relf.Me@Oct.9--0.56am.Seattle.2019> <qEJnF.117555$LC2.85008@fx45.iad>

Show all headers | View raw


On Thu, 10 Oct 2019 13:13:06 -0400, DFS wrote:

> 
> One guy at this link
> 
> https://stackoverflow.com/questions/28623895/why-is-memmove-faster-than-memcpy
> 

Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha!

Hey.  You want sizzle?  I'll give you fucking sizzle.

The fastest byte move operation in the entire universe,
on modern, post-Haswell processors, is implemented with
the following assembly code:

mov rdi, destination
mov rsi, source
mov rcx, n(umber of bytes)
rep movb

The Intel "rep movb" instruction moves (copies) the n bytes from
source to destination so fucking fast that it'll blow your shit-stained,
piss-stained underwear a mile away.

I have implented this method as a GNU gcc inline function
using inline assembly.

The code is the same as my previous program but with the new
function substituted.

There is only one assembly instruction because the gcc calling
convention takes care of the first three instructions.

Wanna get your ass blown away?  Then run this program.
It sizzles.

#include <stdio.h>
#include <stdlib.h>

static inline void __movsb(char *dest, char *src, int n)
{
asm volatile("rep movsb"
	: "=D" (dest),
	"=S" (src),
	"=c" (n)
	: "0" (dest),
	"1" (src),
	"2" (n)
	: "memory");
}

int main()
{

int i;

char A[] = {'1','7','D','e','M','o','z'};
char B[] = {'A','c','p','S','x'};

int lenA = sizeof(A)/sizeof(char);
int lenB = sizeof(B)/sizeof(char);

// allocate array C on heap
char *C = (char *)malloc(sizeof(char)*(lenA+lenB));

// C = A append B
__movsb(C,A,lenA);
__movsb(C+lenA,B,lenB);

for(i=0; i<(lenA+lenB); i++) { fputc(C[i], stdout); } fputc('\n', stdout);

return 0;
}

Back to comp.os.linux.advocacy | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Feeb, can you improve this simple C code? DFS <nospam@dfs.com> - 2019-10-08 08:53 -0400
  Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 06:21 -0700
  Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 07:07 -0700
  Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 14:33 +0000
    Re: Feeb, can you improve this simple C code? DFS <nospam@dfs.com> - 2019-10-08 17:10 -0400
      Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 21:25 +0000
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:42 -0700
        Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-09 07:23 +0000
      Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:27 -0700
      Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 21:38 +0000
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:58 -0700
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 15:14 -0700
        Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-09 07:25 +0000
          Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-09 00:58 -0700
      Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 14:51 -0700
        Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 22:19 +0000
          Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 15:36 -0700
            Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 16:00 -0700
            Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-09 07:36 +0000
          Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 15:44 -0700
        Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-09 07:26 +0000
        Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-09 08:22 +0000
          Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-09 01:44 -0700
          Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-09 08:29 -0700
  Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 14:44 +0000
    Re: Feeb, can you improve this simple C code? Steve Carroll <"Steve Carroll"@noSPAM.none> - 2019-10-08 14:51 +0000
      Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 15:16 +0000
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 08:40 -0700
      Re: Feeb, can you improve this simple C code? Mel <mel@zzzzz.com> - 2019-10-08 18:11 +0200
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 09:40 -0700
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 09:55 -0700
        Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 18:38 +0000
          Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 11:56 -0700
          Re: Feeb, can you improve this simple C code? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-08 19:42 +0000
            Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 13:13 -0700
              Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 20:19 +0000
                Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 20:26 +0000
                Re: Feeb, can you improve this simple C code? Steve Carroll <fretwizzer@gmail.com> - 2019-10-08 13:38 -0700
                Re: Feeb, can you improve this simple C code? F Russell <fr@random.info> - 2019-10-08 20:55 +0000
                Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 14:12 -0700
                Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 13:57 -0700
                Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 13:42 -0700
              Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 13:27 -0700
    Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 07:53 -0700
    Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 08:09 -0700
    Re: Feeb, can you improve this simple C code? Mel <mel@zzzzz.com> - 2019-10-08 18:09 +0200
      Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 09:25 -0700
        Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 10:56 -0700
          Re: Feeb, can you improve this simple C code? Steve Carroll <frelwizzen@gmail.com> - 2019-10-08 12:11 -0700
  memmove( z, x, sizeof x ); Jeff-Relf.Me  @. - 2019-10-09 00:56 -0700
    Re: memmove( z, x, sizeof x ); DFS <nospam@dfs.com> - 2019-10-10 13:13 -0400
      "memcpy()" is a special case INSIDE "memmove()". Jeff-Relf.Me  @. - 2019-10-10 11:17 -0700
        Re: "memcpy()" is a special case INSIDE "memmove()". Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:27 +0000
      Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-10 21:20 +0000
        Re: memmove( z, x, sizeof x ); Siri Cruise <chine.bleu@yahoo.com> - 2019-10-10 15:07 -0700
          Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:36 +0000
          Re: memmove( z, x, sizeof x ); DFS <nospam@dfs.com> - 2019-10-11 09:29 -0400
            Re: memmove( z, x, sizeof x ); Siri Cruise <chine.bleu@yahoo.com> - 2019-10-11 08:28 -0700
              memmove( z, x, sizeof x ); Jeff-Relf.Me  @. - 2019-10-11 10:01 -0700
        Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:29 +0000
          Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 08:20 +0000
            Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 18:22 +0000
              Re: memmove( z, x, sizeof x ); chrisv <chrisv@nospam.invalid> - 2019-10-11 13:45 -0500
              Re: memmove( z, x, sizeof x ); DFS <nospam@dfs.com> - 2019-10-11 15:46 -0400
                Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 19:57 +0000
          Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 08:31 +0000
            Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 18:24 +0000
              Re: memmove( z, x, sizeof x ); "F. Russell" <frussell@random.info> - 2019-10-11 18:55 +0000
                Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 19:16 +0000
                Re: memmove( z, x, sizeof x ); "F. Russell" <frussell@random.info> - 2019-10-11 19:29 +0000
                Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-11 19:39 +0000
          Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 09:03 +0000
      Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-10 21:30 +0000
        Re: memmove( z, x, sizeof x ); Melzzzzz <Melzzzzz@zzzzz.com> - 2019-10-10 22:33 +0000
          Re: memmove( z, x, sizeof x ); F Russell <fr@random.info> - 2019-10-11 08:21 +0000
        Insane, Animalistic, Immoral, Detached. Jeff-Relf.Me  @. - 2019-10-10 15:43 -0700
          Asset bubbles make people horny, stupid. Jeff-Relf.Me  @. - 2019-10-10 16:04 -0700
          Re: Insane, Animalistic, Immoral, Detached. Checkmate <ricksabian1@gmail.com> - 2019-10-10 16:09 -0700
            Re: Insane, Animalistic, Immoral, Detached. Snit <usenet@gallopinginsanity.com> - 2019-10-10 16:28 -0700
              Re: Insane, Animalistic, Immoral, Detached. The Right And The Powerful <power2019@gmail.com> - 2019-10-10 18:35 -0500
                Re: Insane, Animalistic, Immoral, Detached. Snit <usenet@gallopinginsanity.com> - 2019-10-10 16:47 -0700
                Re: Insane, Animalistic, Immoral, Detached. The Right And The Powerful <power2019@gmail.com> - 2019-10-10 20:39 -0500
                Re: Insane, Animalistic, Immoral, Detached. Checkmate <ricksabian1@gmail.com> - 2019-10-10 20:39 -0700
                Re: Insane, Animalistic, Immoral, Detached. Snit <usenet@gallopinginsanity.com> - 2019-10-11 08:31 +0000
                Re: Insane, Animalistic, Immoral, Detached. chrisv <chrisv@nospam.invalid> - 2019-10-11 08:36 -0500
                Re: Insane, Animalistic, Immoral, Detached. Checkmate <ricksabian1@gmail.com> - 2019-10-10 20:36 -0700
                Re: Insane, Animalistic, Immoral, Detached. % <persent@gmail.com> - 2019-10-10 20:41 -0700
                Re: Insane, Animalistic, Immoral, Detached. chrisv <chrisv@nospam.invalid> - 2019-10-11 08:53 -0500
                Re: Insane, Animalistic, Immoral, Detached. Sergio <invalid@invalid.com> - 2019-10-11 10:14 -0500

csiph-web