Guest User

Untitled

a guest
Sep 9th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <xmmintrin.h>
  2.  
  3. #define MAX_DOTS 7
  4. #define N 3
  5. #define NS 8
  6.  
  7. typedef union
  8. {
  9.     float c[4];
  10.     __v4sf vect;
  11. } dot __attribute__ ((aligned (16)));
  12.  
  13. typedef struct
  14. {
  15.     dot dots[MAX_DOTS];
  16.     unsigned int dots_num;
  17. } set;
  18.  
  19. union node_data
  20. {
  21.     struct node *children[8];
  22.     set dots;
  23. };
  24.  
  25. struct node
  26. {
  27.     unsigned int flags;
  28.    
  29.     dot bb_min;
  30.     dot bb_max;
  31.  
  32.     union node_data data;
  33. };
  34.  
  35. dot voxel = {{1.0, 1.0, 1.0, 0.0}};
  36.  
  37. dot calc_avg (const dot *set, unsigned int n)
  38. {
  39.     dot res;
  40.     int i;
  41.     __builtin_ia32_xorps (res.vect, res.vect);
  42.    
  43.     for (i=0; i<n; i++) res.vect += set[i].vect;
  44.     res.vect /= (float)n;
  45.     return res;
  46. }
  47.  
  48. /*void calc_bounding_box (const dot *set, unsigned int n, dot *min, dot *max)
  49. {
  50.     int i;
  51.  
  52.     min->vect = set[0].vect;
  53.     max->vect = set[0].vect;
  54.    
  55.     for (i=1; i<n; i++)
  56.     {
  57.         min->vect = __buildin_ia32_minps (min->vect, set[i].vect);
  58.         max->vect = __buildin_ia32_maxps (max->vect, set[i].vect);
  59.     }
  60.     }*/
  61.  
  62. int main ()
  63. {
  64.     dot res, min, max;
  65.     dot set[2] = {{1.0,1.0, 2.0, 4.0}, {3.0, 2.0, 1.0, 10.0}};
  66.     res = calc_avg (set, 2);
  67.  
  68. //    calc_bounding_box (set, 2, &min, &max);
  69.    
  70.     printf ("%f %f %f %f\n", res.c[0], res.c[1], res.c[2], res.c[3]);
  71.     printf ("%f %f %f %f\n", min.c[0], min.c[1], min.c[2], min.c[3]);
  72.     printf ("%f %f %f %f\n", max.c[0], max.c[1], max.c[2], max.c[3]);
  73.     printf ("%i %i\n", sizeof(__m128),sizeof(__v4sf));
  74.     printf ("%i\n", sizeof (struct node));
  75. }
Advertisement
Add Comment
Please, Sign In to add comment