From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8812 invoked by alias); 12 Mar 2008 23:31:05 -0000 Received: (qmail 8801 invoked by uid 22791); 12 Mar 2008 23:31:03 -0000 X-Spam-Check-By: sourceware.org Received: from smtp102.rog.mail.re2.yahoo.com (HELO smtp102.rog.mail.re2.yahoo.com) (206.190.36.80) by sourceware.org (qpsmtpd/0.31) with SMTP; Wed, 12 Mar 2008 23:30:41 +0000 Received: (qmail 95718 invoked from network); 12 Mar 2008 23:30:37 -0000 Received: from unknown (HELO ?192.168.2.102?) (jfournier121@rogers.com@206.248.132.9 with plain) by smtp102.rog.mail.re2.yahoo.com with SMTP; 12 Mar 2008 23:30:37 -0000 X-YMail-OSG: fHxbuXwVM1m46a5yupEE4ZfTJWZQoRR6pEMEbN1qN3Yh0blPvJTQ2FiA84A7sBuGiQ-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <47D8679C.4090606@gmail.com> Date: Wed, 12 Mar 2008 23:31:00 -0000 From: JP Fournier User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: is -O2 breaking sse2 alignment? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg00110.txt.bz2 Hi All. In the example below, compiling with -O2 results in incorrect output from the program. -O seems OK. Am I missing something alignment wise (or otherwise) or is -O2 breaking my alignment? If I use _mm_storeu_si128 then both -O2 and -O work as expected. Any thoughts appreciated. jp ------ bash-3.1$ gcc -O -msse2 -o sse2 sse2.c bash-3.1$ ./sse2 c0=2 c1=2 bash-3.1$ gcc -O2 -msse2 -o sse2 sse2.c bash-3.1$ ./sse2 c0=0 c1=0 bash-3.1$ gcc --version gcc (GCC) 4.1.2 bash-3.1$ uname -a Linux puma 2.6.22.8 #1 SMP Tue Sep 25 20:41:25 BST 2007 x86_64 x86_64 x86_64 GNU/Linux sse2.c: #include #include void test_int() { // array of 2 8 byte ints long int *a = _mm_malloc(16, 16); long int *b = _mm_malloc(16, 16); long int *c = _mm_malloc(16, 16); __m128i ai __attribute__ ((aligned (16))); __m128i bi __attribute__ ((aligned (16))); __m128i ci __attribute__ ((aligned (16))); a[0] = a[1] = 1; b[0] = b[1] = 1; c[0] = c[1] = 0; ai = _mm_load_si128( (__m128i *) (void*)a ); bi = _mm_load_si128( (__m128i *) (void*)b ); ci = _mm_add_epi8( ai, bi ); _mm_store_si128( (__m128i *) (void*)c, ci ); printf("c0=%ld c1=%ld\n", c[0], c[1] ); } int main( int count, char ** args ) { test_int(); return 0; }