Bug 27412 - Incorrect result with sse intrinsic while extracting int
Summary: Incorrect result with sse intrinsic while extracting int
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-03 23:25 UTC by Micha Riser
Modified: 2006-06-20 06:17 UTC (History)
61 users (show)

See Also:
Host: i686 linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Micha Riser 2006-05-03 23:25:03 UTC
Following code sets a 4 32-bit int sse vector to 1 for all elements and extracts one int out of the vector. g++ returns an incorrect result when compiling with -O2 or -O3 but not with -O1 or -O0

// -----------------------
#include <stdio.h>
#include <emmintrin.h>

int main() {

  __m128i ix = _mm_set1_epi32(1);		
  int res = ((int*)&ix)[1];
  printf("results: %i\n", res);
	
}
// -----------------------

compiled with:
$ g++-4.1.0 -O2 -msse2 

expected result: 1
actual result: -1209151480

similar misbehavior by gcc-3.4.5
acutal result: 134513897

$ g++-4.1.0 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.1.0/work/gcc-4.1.0/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.0 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.0 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.0/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.0/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --disable-libunwind-exceptions --disable-multilib --disable-libmudflap --disable-libssp --enable-java-awt=gtk --enable-languages=c,c++,java,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.0 (Gentoo 4.1.0)
Comment 1 Andrew Pinski 2006-05-03 23:27:38 UTC
You are violating C aliasing rules, use an union (which is non standard) or memcpy.
  int res = ((int*)&ix)[1];

*** This bug has been marked as a duplicate of 21920 ***