Re: Aliasing in C99

Discussion in 'C Programming' started by Xavier Roche, May 31, 2012.

  1. Xavier Roche

    Xavier Roche Guest

    On 05/31/2012 04:01 PM, David Brown wrote:
    > It is also possible to use pointers to unions in casts:


    This would break strict aliasing, too. You probably need an intermediate
    union for that. Another way would be to only use union everywhere (on
    x86-64 ABI, it will be stored in a integer register when passed as
    argument to functions, so this won't make too much harm)

    The unfortunate thing is that gcc, for example, will correctly handle
    the integer part, but tend to copy temporarily to the stack the
    register, and copy it back to the floating register. (gcc 4.3, Linux
    ABI, x86-64)

    Note: you may want to check out this excellent introduction to strict
    aliasing here:
    http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
    Xavier Roche, May 31, 2012
    #1
    1. Advertising

  2. Xavier Roche

    Xavier Roche Guest

    Le 31/05/2012 20:47, David Brown a écrit :
    > But I think gcc does it this way because the
    > floating point data is in an SSE register of some sort, and can't easily
    > be moved into a normal register


    Hmm, no, you can do that quite easily (movq %rax,%xmm0 for example).

    I'm wondering if this is because gcc has troubles extracting pieces of
    data inside a structure put in a register (structures of size <= 8 are
    packed entirely in a register if I am correct on this architecture)

    So I'll double check the produced code on other archs to be sure if I
    were you :)
    Xavier Roche, May 31, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Glen Low

    C99 complex numbers and aliasing

    Glen Low, Aug 3, 2004, in forum: C Programming
    Replies:
    5
    Views:
    405
    David R Tribble
    Aug 20, 2004
  2. Mike

    C99, strict aliasing

    Mike, Jul 20, 2010, in forum: C Programming
    Replies:
    5
    Views:
    615
    Tim Rentsch
    Jul 21, 2010
  3. James Kuyper

    Re: Aliasing in C99

    James Kuyper, May 31, 2012, in forum: C Programming
    Replies:
    0
    Views:
    237
    James Kuyper
    May 31, 2012
  4. Eric Sosman

    Re: Aliasing in C99

    Eric Sosman, May 31, 2012, in forum: C Programming
    Replies:
    3
    Views:
    308
    Tim Rentsch
    May 31, 2012
  5. Tim Rentsch

    Re: Aliasing in C99

    Tim Rentsch, May 31, 2012, in forum: C Programming
    Replies:
    2
    Views:
    328
    Tim Rentsch
    Jun 1, 2012
Loading...

Share This Page