Re: : impossible alignment requirements?
In article <1194958252.805504.290230@50g2000hsm.googlegroups.com>,
levicki.i@sezampro.yu says...
[ ... ]
Not having an operator new which returns _aligned_ memory seriously
hampers SIMD use in C++.
The C++ standard defines new as ($18.4.1.1): "The allocation function
(3.7.3.1) called by a new-expression (5.3.4) to allocate size bytes of
storage suitably aligned to represent any object of that size.
If your implementation returns memory that is not aligned, the problem
lies with the implementation, not the language.
What should one do with this code?
class foo
{
public:
__m128 vec;
...
foo(void)
{
vec = _mm_setzero_ps();
}
};
foo *p = new [](10);
As a description of a problem, this leaves everything to be desired. You
haven't described what an __m128 is, you haven't described what
_mm_setzero_ps() does, you haven't described what happens now, or what
you'd like to have happen. The only part that's clear is that the last
line, where you attempt to allocate memory isn't even syntactically
correct.
C++ regulatory body is obviously sitting with their collective thumbs
up their arses instead of listening to developers and their needs.
The people I've met on the committee have all been quite intelligent and
hard-working, but they can't read minds. If you want something done, you
need to at least specify the problem sufficiently that somebody can
actually figure out what the hell you're talking about. If you really
care about fixing that problem, making at least an attempt at telling
about how you'd suggest that the problem be fixed.
Right now, you've done nothing of the sort. The code you've posted lacks
almost any meaning as it stands; you seem to be assuming that some
requirements should be apparent, because whatever problem you seem to be
trying to cite isn't apparent (or necessarily correct) based strictly on
the code itself. Right now, the syntax of the allocation statement is
wrong, but it's hard to believe that this is really the point of your
post.
[ ... ]
There is a compiler option to force stack alignment on every
function entry to a given value. Problem is in the standard again,
if you force say 16-byte alignment:
void somefunc(void)
{
char buf[32]; // sure, this will be aligned to 16 bytes
...
for (int i = 0; i < 32; i++) {
char foo[32]; // but this won't!
__declspec(align(16)) char bar[32]; // unless you add explicit
alignment directive
}
}
Nothing in the standard requires that the data be misaligned. If your
compiler vendor says otherwise, they're just feeding you nonsense. I
suspect the problem you're having is fairly simple: it's very difficult
for the C++ committee to specify performance requirements, so if using a
misaligned buffer _works_, but much more slowly than an aligned buffer
would have, the standard provides no reasonable way to differentiate
between the two.
That doesn't mean your needs are being entirely ignored though. As far
as obtaining storage that's aligned to an arbitrary boundary, C++ 0x has
added a function named 'align' that does precisely that. See ptr.align
in N2461 for more details.
--
Later,
Jerry.
The universe is a figment of its own imagination.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]