Re: Miscellaneous XCode Questions
Re: Miscellaneous XCode Questions
- Subject: Re: Miscellaneous XCode Questions
- From: Sanjay Patel <email@hidden>
- Date: Fri, 12 May 2006 04:57:58 -0700 (PDT)
> >> 3. When a pointer (to say, a char) is cast to a vUInt16* pointer,
> >> gcc implicitly assumes that it is 16-byte aligned, and loads data
> >> with movdqa. Is it legal for gcc to assume this? Do misaligned
> >> loads always have to be coded explicitly?
Minimal test case:
#include <xmmintrin.h>
__m128 foo( char* a ) {
return *( __m128* )( a );
}
Codegen:
...
movl 8(ëp), êx
movaps (êx), %xmm0
...
Strictly speaking, casting your pointer to a different type is not legal 'C'.
So I think the answer is going to be "your code is wrong, and the compiler
can generate whatever it wants."
Always use the _mm_load* intrinsics with SSE code. You should *never* cast
MMX/SSE data - not even from __m128 to __m128i, etc. Some compilers (ICC)
will not accept the syntax.
There are intrinsics for every conversion...although IIRC, the GCC4 headers
are missing a couple...someone at Apple can check Radar or email archives to
confirm.
I found these:
emmintrin.h:_mm_castpd_ps(__m128d __A)
emmintrin.h:_mm_castpd_si128(__m128d __A)
emmintrin.h:_mm_castps_pd(__m128 __A)
emmintrin.h:_mm_castps_si128(__m128 __A)
emmintrin.h:_mm_castsi128_ps(__m128i __A)
emmintrin.h:_mm_castsi128_pd(__m128i __A)
--Sanjay
> >> 3. When a pointer (to say, a char) is cast to a vUInt16* pointer,
> >> gcc implicitly assumes that it is 16-byte aligned, and loads data
> >> with movdqa. Is it legal for gcc to assume this? Do misaligned
> >> loads always have to be coded explicitly?
> >
> > That depends processor model to processor model. Use the #pragma
> > align directives to control alignment explicitly, but the compiler
> > will never (knock wood) generate illegal instruction alignment for
> > a particular processor.
>
> This is for x86, where misaligned vector loads are legal, but use a
> different load instruction. My code is trying to read 16 contiguous
> bytes from an array, from an arbitrary (possibly misaligned) starting
> index. Something like this:
>
> vuint8 load(uint8* p) { return *(vuint8*)p; }
>
> The compiler assumes that p is aligned and generates an aligned load
> instruction, which causes an alignment exception and crash. I would
> think that the compiler, not knowing whether the pointer is aligned,
> should not be making this assumption... Most stack-based data is
> known at compile-time to be aligned, but not arbitrary pointers. I
> haven't found this behavior documented anywhere one way or the other.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden