How do you load/store from/to an array of doubles with GNU C Vector Extensions?

前端 未结 3 2027
北荒
北荒 2020-12-21 01:36

I\'m using GNU C Vector Extensions, not Intel\'s _mm_* intrinsics.

I want to do the same thing as Intel\'s _m256_loadu_pd intrinsic. Assign

3条回答
  •  余生分开走
    2020-12-21 02:00

    If you don't need to get a copy of a, use a pointer instead (see v_ptr in example). If you need a copy, use memmove (see v_copy)

    #include 
    #include 
    
    typedef double vector __attribute__((vector_size(4 * sizeof(double))));
    
    int main(int argc, char **argv) {
      double a[4] = {1.0, 2.0, 3.0, 4.0};
      vector *v_ptr;
      vector v_copy;
    
      v_ptr = (vector*)&a;
      memmove(&v_copy, a, sizeof(a));
    
      printf("a[0] = %f // v[0] = %f // v_copy[0] = %f\n", a[0], (*v_ptr)[0], v_copy[0]);
      printf("a[2] = %f // v[2] = %f // v_copy[0] = %f\n", a[2], (*v_ptr)[2], v_copy[2]);
      return 0;
    }
    

    output:

    a[0] = 1.000000 // v[0] = 1.000000 // v_copy[0] = 1.000000
    a[2] = 3.000000 // v[2] = 3.000000 // v_copy[0] = 3.000000
    

提交回复
热议问题