public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Paweł Sikora" <pluto@agmk.net>
To: gcc-help@gcc.gnu.org
Subject: how to correctly pass volatile pointer to _mm_loadu_ps?
Date: Sun, 23 Jan 2011 14:36:00 -0000	[thread overview]
Message-ID: <201101231535.32925.pluto@agmk.net> (raw)

[-- Attachment #1: Type: Text/Plain, Size: 1119 bytes --]

hi,

i'm trying to read 128-bits of unaligned data in one atomic move using 'movups' opcode.
the protoype with _mm_loadu_ps was optimized out by the compiler.

$ gcc46 hw_reg.c -Wall -c -O2 -m64 --save-temps
hw_reg.c: In function 'read_mapped_register_128':
hw_reg.c:19:2: warning: passing argument 1 of '_mm_loadu_ps' from incompatible pointer type [enabled by default]
/opt/gcc46/lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include/xmmintrin.h:904:1: note: expected 'const float *' but argument is of type 'const volatile __vector(4) float *'

i've tested another idea with intermediate volatile value:

static __m128 read_mapped_register_128( __m128 volatile const* address, ptrdiff_t index )
{
        __m128 volatile const* p = address + index;
        __m128 volatile const v = _mm_loadu_ps( p );
        return v;
}

but it generates 3 moves while one is enough:

unused_read_128_with_side_effects:
        salq    $4, %rsi
        movups  (%rdi,%rsi), %xmm0
        movaps  %xmm0, -24(%rsp)
        movaps  -24(%rsp), %xmm0
        ret

is there a nice solution in C language for such (one-move) access?

BR,
Pawel.

[-- Attachment #2: hw_reg.c --]
[-- Type: text/x-csrc, Size: 926 bytes --]

#include <stddef.h>
#include <xmmintrin.h>

static unsigned read_mapped_register_32( unsigned volatile const* address, ptrdiff_t index )
{
	unsigned volatile const* p = address + index;
	return *p;
}

static __m64 read_mapped_register_64( __m64 volatile const* address, ptrdiff_t index )
{
	__m64 volatile const* p = address + index;
	return *p;
}

static __m128 read_mapped_register_128( __m128 volatile const* address, ptrdiff_t index )
{
	__m128 volatile const* p = address + index;
	return _mm_loadu_ps( p );
}

void unused_read_32_with_side_effects( unsigned volatile const* address, ptrdiff_t index )
{ read_mapped_register_32( address, index ); }
void unused_read_64_with_side_effects( __m64 volatile const* address, ptrdiff_t index )
{ read_mapped_register_64( address, index );}
void unused_read_128_with_side_effects( __m128 volatile const* address, ptrdiff_t index )
{ read_mapped_register_128( address, index ); }

[-- Attachment #3: hw_reg.s --]
[-- Type: text/plain, Size: 1028 bytes --]

	.file	"hw_reg.c"
	.text
	.p2align 4,,15
	.globl	unused_read_32_with_side_effects
	.type	unused_read_32_with_side_effects, @function
unused_read_32_with_side_effects:
.LFB519:
	.cfi_startproc
	leaq	(%rdi,%rsi,4), %rax
	movl	(%rax), %eax
	ret
	.cfi_endproc
.LFE519:
	.size	unused_read_32_with_side_effects, .-unused_read_32_with_side_effects
	.p2align 4,,15
	.globl	unused_read_64_with_side_effects
	.type	unused_read_64_with_side_effects, @function
unused_read_64_with_side_effects:
.LFB520:
	.cfi_startproc
	leaq	(%rdi,%rsi,8), %rax
	movq	(%rax), %rax
	ret
	.cfi_endproc
.LFE520:
	.size	unused_read_64_with_side_effects, .-unused_read_64_with_side_effects
	.p2align 4,,15
	.globl	unused_read_128_with_side_effects
	.type	unused_read_128_with_side_effects, @function
unused_read_128_with_side_effects:
.LFB521:
	.cfi_startproc
	rep
	ret
	.cfi_endproc
.LFE521:
	.size	unused_read_128_with_side_effects, .-unused_read_128_with_side_effects
	.ident	"GCC: (GNU) 4.6.0 20110122 (experimental)"
	.section	.note.GNU-stack,"",@progbits

                 reply	other threads:[~2011-01-23 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=201101231535.32925.pluto@agmk.net \
    --to=pluto@agmk.net \
    --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).