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

  • SEARCH
  • Home
  • 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 8732613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:28:14+00:00 2026-06-13T09:28:14+00:00

I am loading elements from memory using SIMD load instructions, let say using Altivec,

  • 0

I am loading elements from memory using SIMD load instructions, let say using Altivec, assuming aligned addresses:

float X[SIZE];
vector float V0;
unsigned FLOAT_VEC_SIZE = sizeof(vector float);
for (int load_index =0; load_index < SIZE; load_index+=FLOAT_VEC_SIZE)
{
    V0 = vec_ld(load_index, X);
    /* some computation involving V0*/
}

Now if SIZE is not a multiple of FLOAT_VEC_SIZE, it is possible that V0 contains some invalid memory elements in the last loop iteration. One way to avoid that is to reduce the loop by one iteration, another one is to mask off the potential invalid elements, is there any other useful trick here? Considering the above is inner most in a set of nested loops. So any additional non-SIMD instruction will come with a performance penalty!

  • 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-13T09:28:14+00:00Added an answer on June 13, 2026 at 9:28 am

    Ideally you should pad your array to a multiple of vec_step(vector float) (i.e. multiple of 4 elements) and then mask out any additional unwanted values from SIMD processing or use scalar code to deal with the last few elements, e.g.

    const INT VF_ELEMS = vec_step(vector float);
    const int VEC_SIZE = (SIZE + VF_ELEMS - 1) / VF_ELEMS; // number of vectors in X, rounded up
    vector float VX[VEC_SIZE];   // padded array with 16 byte alignment
    float *X = = (float *)VX;    // float * pointer to base of array
    
    for (int i = 0; i <= SIZE - VF_ELEMS; i += VF_ELEMS)
    {                            // for each full SIMD vector
        V0 = vec_ld(0, &X[i]);
        /* some computation involving V0 */
    }
    if (i < SIZE)                // if we have a partial vector at the end
    {
    #if 1                        // either use SIMD and mask out the unwanted values
        V0 = vec_ld(0, &X[i]);
        /* some SIMD computation involving partial V0 */
    #else                        // or use a scalar loop for the remaining 1..3 elements
        /* small scalar loop to handle remaining points */
    #endif
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading properties attributes from a .properties file using Spring as follows: file: elements.properties
Let's say I have a javascript array with a bunch of elements (anywhere from
After loading a PHP template (using jQuery's load function), this simple script won't make
The .load() function of the jQuery library allows you to selectively load elements from
I am trying to load some elements from another page under my site, and
So I've been using a compact data type in c++, and saving from memory
I'm trying to be able to drag SVG elements (using Raphael) loaded from a
I am successfully loading via AJAX some svg from external file: $(#svg).load(svgUrl + svg,
Im loading an xml from stream XDocument xmlFile = XDocument.Load(stream); var query = from
I have some javascript applying changes to some elements and a function loading more

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.