public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy()
@ 2005-09-07 19:54 tkoenig at gcc dot gnu dot org
  2005-09-08 21:25 ` [Bug libfortran/23770] " jblomqvi at cc dot hut dot fi
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2005-09-07 19:54 UTC (permalink / raw)
  To: gcc-bugs

Currently, the buffers for reading/writing integers
and reals in the i/o library are of type char[], which forces
the use of memcpy(), as in the fix for PR 23356.  It would
be better for performance if suitable alignment could be
forced on the buffers.

-- 
           Summary: unaligned buffers in i/o library force use of memcpy()
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
  2005-09-07 19:54 [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy() tkoenig at gcc dot gnu dot org
@ 2005-09-08 21:25 ` jblomqvi at cc dot hut dot fi
  2005-09-09  6:41 ` jblomqvi at cc dot hut dot fi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2005-09-08 21:25 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
  2005-09-07 19:54 [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy() tkoenig at gcc dot gnu dot org
  2005-09-08 21:25 ` [Bug libfortran/23770] " jblomqvi at cc dot hut dot fi
@ 2005-09-09  6:41 ` jblomqvi at cc dot hut dot fi
  2005-09-09  6:44 ` jblomqvi at cc dot hut dot fi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2005-09-09  6:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jblomqvi at cc dot hut dot fi  2005-09-09 06:41 -------
Did you by any chance mean PR 23556? That looks more like it.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
  2005-09-07 19:54 [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy() tkoenig at gcc dot gnu dot org
  2005-09-08 21:25 ` [Bug libfortran/23770] " jblomqvi at cc dot hut dot fi
  2005-09-09  6:41 ` 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
  4 siblings, 0 replies; 9+ messages in thread
From: jblomqvi at cc dot hut dot fi @ 2005-09-09  6:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jblomqvi at cc dot hut dot fi  2005-09-09 06:44 -------
And, there's a bug in my test program. Obviously the last for loop should be

for (i = 0; i < LEN; i += 4)

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
  2005-09-07 19:54 [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy() tkoenig at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2005-09-09 19:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From tkoenig at gcc dot gnu dot org  2005-09-09 19:38 -------
(In reply to comment #2)
> Did you by any chance mean PR 23556? That looks more like it.

Yes, I did.  Sorry for the confusion.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
  2005-09-07 19:54 [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy() tkoenig at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-09-09 19:38 ` tkoenig at gcc dot gnu dot org
@ 2005-09-15 19:48 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-15 19:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-15 19:48 -------
Really memcpy should only cause permissiveness at the tree level and nothing else as the memcpy 
should always be expanded to a load/store if alignedness does not matter.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
       [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
  2 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-02-16 16:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from fxcoudert at gcc dot gnu dot org  2007-02-16 16:15 -------
OK, given that we now have a fine memcpy code generation and nobody seems to
have an example, I'm closing this. Please reopen if you think I'm wrong.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
       [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
  2 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-01-05 14:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from fxcoudert at gcc dot gnu dot org  2007-01-05 14:15 -------
Is this still a bug, with the new patches for optimizing calls to memcpy?


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libfortran/23770] unaligned buffers in i/o library force use of memcpy()
       [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
  2 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-25 20:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2005-10-25 20:34 -------
Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-10-25 20:34:38
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-02-16 16:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-07 19:54 [Bug libfortran/23770] New: unaligned buffers in i/o library force use of memcpy() tkoenig at gcc dot gnu dot org
2005-09-08 21:25 ` [Bug libfortran/23770] " jblomqvi at cc dot hut dot fi
2005-09-09  6:41 ` 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

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).