Bug 10286

Summary: [3.2.1 regression] [x86] type-punning doesn't work with __m64 and -O
Product: gcc Reporter: mgw
Component: targetAssignee: Eric Botcazou <ebotcazou>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, jbuck
Priority: P3    
Version: 3.2.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: set64.i

Description mgw 2003-04-01 17:36:00 UTC
the following program (.i attached) prints:

44 33 22 11 00 00 00 00 44 33 22 11 00 00 00 00 44 33 22 11 00 00 00 00 

instead of the expected:

88 77 66 55 44 33 22 11 88 77 66 55 44 33 22 11 88 77 66 55 44 33 22 11 

the generated assembly uses a movd to fill in %mm0, leaving the upper 32-bits empty.

// gcc -O -mmmx -o set64 set64.c
#include <mmintrin.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

void
memset64(void *dst, uint32_t hi, uint32_t lo, size_t count)
{
        __m64 *p = (__m64 *)dst;
        __m64 fill = _mm_set_pi32(hi, lo);

        while (count--) {
                *p++ = fill;
        }
}

#define NUM 3 
int
main()
{
        uint8_t *buf = (uint8_t *)calloc(NUM * 2, sizeof(uint32_t));
        int i, count = NUM * 2 * sizeof(uint32_t);

        memset64(buf, 0x11223344, 0x55667788, NUM);
        for (i = 0; i < count; i++) {
                printf("%02x ", buf[i]);
        }
        printf("\n");
        return 0;
}

Release:
gcc-3.2.2

Environment:
Mandrake Linux 9.1.1

How-To-Repeat:
run attached program built with -O -mmmx
Comment 1 Eric Botcazou 2003-04-10 07:26:46 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed on 3.2 branch. 3.3 and mainline are not affected.
Comment 2 Eric Botcazou 2003-04-10 08:29:21 UTC
Responsible-Changed-From-To: unassigned->ebotcazou
Responsible-Changed-Why: Investigating.
Comment 3 Joe Buck 2003-04-25 21:51:55 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for 3.3.