Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:25:00+00:00 2026-06-13T16:25:00+00:00

Can I have a union like this union eight_floats_t { __m256 a; __m128 b[2];

  • 0

Can I have a union like this

  union eight_floats_t
  {
    __m256 a;
    __m128 b[2];
  };
  eight_floats_t eight_floats;

to have an instant access to the two 128 bit parts of a 256 bit register?

Edit: I was asking to understand the performance impact of this approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:25:02+00:00Added an answer on June 13, 2026 at 4:25 pm

    You certainly can do that. The C and C++ languages allow you do it. And it will most likely do what you want it to do.

    However, the fact that you’re using AVX means you care about performance. So it might be useful to know that this is one of the most common (performance) traps that SSE programmers fall into. (and many don’t notice)

    Problem 1:

    Current compilers implement such a union using a memory location. So that’s the first problem, every time you access the union from a different field, it forces the data to memory and reads it back. That’s one slow-down.

    Here’s what MSVC2010 generates for (with optimizations):

    eight_floats a;
    a.a = vecA[0];
    
    __m128 fvecA = a.b[0];
    __m128 fvecB = a.b[1];
    fvecA = _mm_add_ps(fvecA,fvecB);
    

    vmovaps YMMWORD PTR a$[rbp], ymm0
    movaps  xmm1, XMMWORD PTR a$[rbp+16]
    addps   xmm1, XMMWORD PTR a$[rbp]
    movaps  XMMWORD PTR fvecA$[rbp], xmm1
    movss   xmm1, DWORD PTR fvecA$[rbp]
    

    You can see that it’s being flushed to memory.

    Problem 2:

    The second slow-down is even worse. When you write something to memory, and immediately access it with a different word-size, you will likely trigger a store-to-load stall. (typically on the order of > 10 cycles)

    This is because the load-store queues on current processors aren’t usually designed to handle this (unusual) situation. So they deal with it by simply flushing the queues to memory.


    The “correct” way to access the lower and upper half of AVX datatypes is to use:

    • _mm256_extractf128_ps()
    • _mm256_insertf128_ps()
    • _mm256_castps256_ps128()

    and family. Likewise for the other datatypes as well.

    That said, it is possible that the compiler may be smart enough to recognize what you are doing and use those instructions anyway. (At least MSVC2010 doesn’t.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my SQL query can run like this. I have two tables: Key1,
I have a mysql query like this SELECT id, dpost FROM uid1088_qposts UNION SELECT
This is for Android SQLite. I have two queries like this: select * from
I have two tables which look like this: T1: T1ID | Date | Time
I have a union that looks like this: union { int intValue; double doubleValue;
I have used bit field with a structure like this, struct { unsigned int
I have a union that is defined like this: typedef union { enum {
I have a query like this: select data.* from ((select table1.col1 as a) union
What is the difference between JOIN and UNION ? Can I have an example?
I have a SQL query like this: SELECT * FROM ( (SELECT name FROM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.