This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/206] malloc does not align memory correctly for sse capable systems


------- Additional Comments From gotom at debian dot or dot jp  2004-06-07 14:04 -------
Subject: Re:  malloc does not align memory correctly for sse capable systems

Hi,

I agree that __m128 is NOT standard C type, so malloc() does NOT need
to align to 16byte for SSE instruction as Wolfram pointed out.

SSE is special vector-typed array, so __m128 is sometimes hard to handle
with like other types.  C++ new() does not have memory with alignment
designater, so "std::vector<__m128> x(13)" does not specify any alignment
too.

One idea to fix it is to use special handling aligned() for C++ new.  
__m128 typedef involves additional __attribute__ ((aligned (16))).  
AFAIK there is no way to tell the alignment to standard malloc() interface.
So, if g++ can allow to distinguish with aligned attribute and
switch new() code, then we can prepare another overloading new()
which has "aligned parameter" argument (I hope new operator for
vector also does the same thing).
Such overloaded new() with alignment parameter can use
posix_memalign() instead of malloc().  You may know that, there is
note description at build_new() at gcc/cp/init.c:

   Note that build_new does nothing to assure that any special
   alignment requirements of the type are met.  Rather, it leaves
   it up to malloc to do the right thing.  Otherwise, folding to
   the right alignment cal cause problems if the user tries to later
   free the memory returned by `new'.

But if one class or struct has __attribute__ ((aligned (16))), why do
we ignore it?  So I think handling aligned attribute is right way.
Is this appliable for g++?

BTW, I dunno that libmalloc16 is safe way or not.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |WAITING


http://sources.redhat.com/bugzilla/show_bug.cgi?id=206

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]