why does this crash?

hi there,

I'm working with sse2 code, and for some reason this code crashes and I have no clue why. (I tested it on gcc 4.6.3 32 bit linux)

any ideas why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <x86intrin.h>
#include <stdio.h>
 
class __attribute__((aligned (16))) vec
{
  public:
    __m128 d;
 
    vec() //calling new crashes here, wonder why?
    {
      d = _mm_set1_ps(0); //set each float to 0
    }
};
 
int main()
{
    printf("Alignment: %lu\n", __alignof__(vec)); //16
 
    vec* v = new vec; //crash here
 
    printf("Pointer: %p\n", (void*)v); //pointer value
 
    delete v; //free mem
 
    return 0;
}


Best regards,
Yours3lf
Last edited on
Works for me and Coliru

Are you sure that your PC support SSE2?
hi there,

yes, it does:


$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 14
model name : Genuine Intel(R) CPU T2130 @ 1.86GHz
stepping : 12
microcode : 0x59
cpu MHz : 798.000
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx constant_tsc arch_perfmon bts aperfmperf pni monitor est tm2 xtpr pdcm dtherm
bogomips : 3732.41
clflush size : 64
cache_alignment : 64
address sizes : 32 bits physical, 32 bits virtual
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 14
model name : Genuine Intel(R) CPU T2130 @ 1.86GHz
stepping : 12
microcode : 0x59
cpu MHz : 798.000
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx constant_tsc arch_perfmon bts aperfmperf pni monitor est tm2 xtpr pdcm dtherm
bogomips : 3754.05
clflush size : 64
cache_alignment : 64
address sizes : 32 bits physical, 32 bits virtual
power management:
Yeah it works for Coliru and other online platforms... it's really weird...
The crazy thing is that if I remove the assignment from the constructor then I can use the class with other sse instructions...
And I should get "illegal instruction" error if the cpu didn't support sse2...
Last edited on
Topic archived. No new replies allowed.