public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jblomqvi at cc dot hut dot fi" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy() Date: Thu, 08 Sep 2005 21:25:00 -0000 [thread overview] Message-ID: <20050908212508.18854.qmail@sourceware.org> (raw) In-Reply-To: <20050907195346.23770.tkoenig@gcc.gnu.org> ------- Additional Comments From jblomqvi at cc dot hut dot fi 2005-09-08 21:25 ------- Huh, I don't see how this relates to PR 23356. Surely you wrote the wrong number? Anyway, I don't think memcpy is that bad. Consider the following program: #include <stdio.h> #include <time.h> #include <string.h> #define LEN 100000000 char foo[LEN], bar[LEN]; int main (void) { int i; clock_t beg, as, mc, mc2; beg = clock (); for (i = 0; i < LEN; i++) { foo[i] = bar[i]; } as = clock () - beg; beg = clock (); memcpy (&foo, &bar, LEN); mc = clock () - beg; beg = clock (); for (i = 0; i < LEN/4; i++) { memcpy (&foo[i], &bar[i], 4); } mc2 = clock () - beg; printf ("Copying char arrays with assignment took %d cycles.\n", as); printf ("Using memcpy () it took %d cycles.\n", mc); printf ("Copying 4 byte blocks (real, int) with memcpy () took %d cycles.\n", mc2); } On my computer, compiled without optimization I get: Copying char arrays with assignment took 790000 cycles. Using memcpy () it took 90000 cycles. Copying 4 byte blocks (real, int) with memcpy () took 500000 cycles. And with -O2 I get Copying char arrays with assignment took 290000 cycles. Using memcpy () it took 90000 cycles. Copying 4 byte blocks (real, int) with memcpy () took 60000 cycles. So, memcpy is very fast. Of course, alignment always helps, and that is perhaps an orthogonal issue wrt memcpy vs. looping. But I'm not sure which variables you want to be better aligned. The buffers in struct unix_stream, or? Anyway, gcc has __attribute__ ((aligned (num_bytes))) which I think could be used. See http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Variable-Attributes.html -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770
next prev parent reply other threads:[~2005-09-08 21:25 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-09-07 19:54 [Bug libfortran/23770] New: " tkoenig at gcc dot gnu dot org 2005-09-08 21:25 ` jblomqvi at cc dot hut dot fi [this message] 2005-09-09 6:41 ` [Bug libfortran/23770] " jblomqvi at cc dot hut dot fi 2005-09-09 6:44 ` jblomqvi at cc dot hut dot fi 2005-09-09 19:38 ` tkoenig at gcc dot gnu dot org 2005-09-15 19:48 ` pinskia at gcc dot gnu dot org [not found] <bug-23770-10391@http.gcc.gnu.org/bugzilla/> 2005-10-25 20:34 ` pinskia at gcc dot gnu dot org 2007-01-05 14:16 ` fxcoudert at gcc dot gnu dot org 2007-02-16 16:15 ` fxcoudert at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050908212508.18854.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).