Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #ifdef SAFE_VERSION
  2. #define SIMD_OVERLAP_TEST (_mm_movemask_ps(_mm_cmpngt_ps(b, _mm_load_ps(box)))==15)
  3. #else
  4. #define SIMD_OVERLAP_TEST (_mm_movemask_ps(_mm_cmpnle_ps(_mm_load_ps(box), b))==12)
  5. #endif
  6.  
  7.  
  8. bool Meshmerizer::CompleteBoxPruning(udword nb, const AABB* list, Container& pairs)
  9. {
  10. // Checkings
  11. if(!nb || !list)
  12. return false;
  13.  
  14. SIMD_AABB_X* BoxListX = new SIMD_AABB_X[nb+1+5];
  15. SIMD_AABB_YZ* BoxListYZ = (SIMD_AABB_YZ*)_aligned_malloc(sizeof(SIMD_AABB_YZ)*(nb+1), 16);
  16.  
  17. udword* Remap;
  18. // {
  19. // Allocate some temporary data
  20. float* PosList = new float[nb+1];
  21.  
  22. // 1) Build main list using the primary axis
  23. for(udword i=0;i<nb;i++)
  24. PosList[i] = list[i].mMin.x;
  25. PosList[nb] = FLT_MAX;
  26.  
  27. // 2) Sort the list
  28. static PRUNING_SORTER RS; // Static for coherence
  29. Remap = RS.Sort(PosList, nb+1).GetRanks();
  30.  
  31. for(udword i=0;i<nb;i++)
  32. {
  33. const udword SortedIndex = Remap[i];
  34. BoxListX[i].InitFrom(list[SortedIndex]);
  35. BoxListYZ[i].InitFrom(list[SortedIndex]);
  36. }
  37. BoxListX[nb].mMinX = FLT_MAX;
  38. BoxListX[nb+1].mMinX = FLT_MAX;
  39. BoxListX[nb+2].mMinX = FLT_MAX;
  40. BoxListX[nb+3].mMinX = FLT_MAX;
  41. BoxListX[nb+4].mMinX = FLT_MAX;
  42. DELETEARRAY(PosList);
  43. // }
  44.  
  45. // 3) Prune the list
  46. udword RunningAddress = 0;
  47. udword Index0 = 0;
  48. while(RunningAddress<nb && Index0<nb)
  49. {
  50. const SIMD_AABB_X& Box0X = BoxListX[Index0];
  51.  
  52. const float MinLimit = Box0X.mMinX;
  53. while(BoxListX[RunningAddress++].mMinX<MinLimit);
  54.  
  55. const SIMD_AABB_YZ& Box0YZ = BoxListYZ[Index0];
  56. SIMD_OVERLAP_INIT(Box0YZ)
  57.  
  58. const float MaxLimit = Box0X.mMaxX;
  59. const udword RIndex0 = Remap[Index0];
  60.  
  61. udword Offset = 0;
  62. const char* const CurrentBoxListYZ = (const char*)&BoxListYZ[RunningAddress];
  63. const char* const CurrentBoxListX = (const char*)&BoxListX[RunningAddress];
  64.  
  65. goto FastLoop;
  66. _asm align 16
  67. FoundSlot2:
  68. Offset += 8;
  69. _asm align 16
  70. FoundSlot1:
  71. Offset += 8;
  72. _asm align 16
  73. FoundSlot0:
  74. Offset += 8;
  75. _asm align 16
  76. FastFoundOne:
  77. {
  78. const udword Index = (CurrentBoxListX + Offset - 8 - (const char*)BoxListX)>>3;
  79. outputPair(RIndex0, Index, pairs, Remap);
  80. }
  81. _asm align 16
  82. FastLoop:
  83. while(*(const float*)(CurrentBoxListX + Offset + 8*4)<=MaxLimit)
  84. {
  85. const float* box = (const float*)(CurrentBoxListYZ + Offset*2);
  86. if(SIMD_OVERLAP_TEST)
  87. goto FoundSlot0;
  88.  
  89. box = (const float*)(CurrentBoxListYZ + Offset*2 + 16);
  90. if(SIMD_OVERLAP_TEST)
  91. goto FoundSlot1;
  92.  
  93. box = (const float*)(CurrentBoxListYZ + Offset*2 + 16*2);
  94. if(SIMD_OVERLAP_TEST)
  95. goto FoundSlot2;
  96.  
  97. box = (const float*)(CurrentBoxListYZ + Offset*2 + 16*3);
  98. Offset += 32;
  99. if(SIMD_OVERLAP_TEST)
  100. goto FastFoundOne;
  101. }
  102.  
  103. #define BLOCK if(*(const float*)(CurrentBoxListX + Offset)<=MaxLimit) \
  104. {const float* box = (const float*)(CurrentBoxListYZ + Offset*2);\
  105. if(SIMD_OVERLAP_TEST) \
  106. goto BeforeLoop; \
  107. Offset += 8;
  108.  
  109. goto StartLoop;
  110. _asm align 16
  111. BeforeLoop:
  112. {const udword Index = (CurrentBoxListX + Offset - (const char*)BoxListX)>>3;
  113. outputPair(RIndex0, Index, pairs, Remap);
  114. Offset += 8;
  115. }
  116. _asm align 16
  117. StartLoop:
  118. BLOCK
  119. BLOCK
  120. BLOCK
  121. BLOCK
  122. BLOCK
  123. }
  124. }
  125. }
  126. }
  127. goto StartLoop;
  128. }
  129.  
  130.  
  131. Index0++;
  132. }
  133.  
  134. _aligned_free(BoxListYZ);
  135. DELETEARRAY(BoxListX);
  136. return true;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement