public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: JP Fournier <jape41@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: is -O2 breaking sse2 alignment?
Date: Wed, 12 Mar 2008 23:31:00 -0000	[thread overview]
Message-ID: <47D8679C.4090606@gmail.com> (raw)


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 <stdio.h>
#include <emmintrin.h>

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






             reply	other threads:[~2008-03-12 23:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 23:31 JP Fournier [this message]
2008-03-13  0:28 ` Brian Dessent
2008-03-14  0:13   ` JP Fournier
2008-03-14 19:31     ` Brian Budge
2008-03-15  9:49       ` Andrew Haley
2008-03-15  0:10     ` Maximillian Murphy
2008-03-15 15:10       ` Maximillian Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47D8679C.4090606@gmail.com \
    --to=jape41@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).