Dhairya Malhotra 7 лет назад
Родитель
Сommit
c2d89449b7
2 измененных файлов с 14 добавлено и 19 удалено
  1. 4 3
      include/sctl/mem_mgr.txx
  2. 10 16
      include/sctl/morton.hpp

+ 4 - 3
include/sctl/mem_mgr.txx

@@ -95,7 +95,7 @@ template <class ValueType, Long DIM> inline StaticArray<ValueType, DIM>& StaticA
 inline MemoryManager::MemoryManager(Long N) {
   buff_size = N;
   {  // Allocate buff
-    assert(SCTL_MEM_ALIGN <= 0x8000);
+    SCTL_ASSERT(SCTL_MEM_ALIGN <= 0x8000);
     Long alignment = SCTL_MEM_ALIGN - 1;
     char* base_ptr = (char*)::malloc(N + 2 + alignment);
     SCTL_ASSERT_MSG(base_ptr, "memory allocation failed.");
@@ -120,7 +120,7 @@ inline MemoryManager::MemoryManager(Long N) {
   n_dummy.prev = 0;
   n_dummy.next = n_indx;
   n_dummy.mem_ptr = &buff[0];
-  assert(n_indx);
+  SCTL_ASSERT(n_indx);
 
   n.size = N;
   n.free = true;
@@ -142,7 +142,7 @@ inline MemoryManager::~MemoryManager() {
   omp_destroy_lock(&omp_lock);
 
   {  // free buff
-    assert(buff);
+    SCTL_ASSERT(buff);
     ::free(buff - ((uint16_t*)buff)[-1]);
   }
 }
@@ -478,6 +478,7 @@ template <class ValueType> inline Iterator<ValueType> aligned_new(Long n_elem, c
     for (Long i = 0; i < n_elem; i++) {
       ValueType* Ai = new (&A[i]) ValueType();
       assert(Ai == (&A[i]));
+      UNUSED(Ai);
     }
   } else {
 #ifdef SCTL_MEMDEBUG

+ 10 - 16
include/sctl/morton.hpp

@@ -17,16 +17,12 @@ template <Integer DIM = 3> class Morton {
  public:
   #if SCTL_MAX_DEPTH < 7
   typedef uint8_t UINT_T;
-  typedef int8_t INT_T;
   #elif SCTL_MAX_DEPTH < 15
   typedef uint16_t UINT_T;
-  typedef int16_t INT_T;
   #elif SCTL_MAX_DEPTH < 31
   typedef uint32_t UINT_T;
-  typedef int32_t INT_T;
   #elif SCTL_MAX_DEPTH < 63
   typedef uint64_t UINT_T;
-  typedef int64_t INT_T;
   #endif
 
   static const Integer MAX_DEPTH = SCTL_MAX_DEPTH;
@@ -101,16 +97,12 @@ template <Integer DIM = 3> class Morton {
       for (Integer i = 0; i < DIM; i++) {
         for (Integer j = 0; j < k; j++) {
           m = nlst[j];
-          INT_T xi = (INT_T)m.x[i] + (INT_T)mask;
-          if (xi >= maxCoord) xi -= maxCoord;
-          m.x[i] = xi;
+          m.x[i] = (m.x[i] + mask) & (maxCoord - 1);
           nlst.PushBack(m);
         }
         for (Integer j = 0; j < k; j++) {
           m = nlst[j];
-          INT_T xi = (INT_T)m.x[i] - (INT_T)mask;
-          if (xi < 0) xi += maxCoord;
-          m.x[i] = xi;
+          m.x[i] = (m.x[i] - mask) & (maxCoord - 1);
           nlst.PushBack(m);
         }
         k = nlst.Dim();
@@ -119,15 +111,17 @@ template <Integer DIM = 3> class Morton {
       for (Integer i = 0; i < DIM; i++) {
         for (Integer j = 0; j < k; j++) {
           m = nlst[j];
-          INT_T xi = (INT_T)m.x[i] + (INT_T)mask;
-          m.x[i] = xi;
-          if (xi < maxCoord) nlst.PushBack(m);
+          if (m.x[i] + mask < maxCoord) {
+            m.x[i] += mask;
+            nlst.PushBack(m);
+          }
         }
         for (Integer j = 0; j < k; j++) {
           m = nlst[j];
-          INT_T xi = (INT_T)m.x[i] - (INT_T)mask;
-          m.x[i] = xi;
-          if (xi >= 0) nlst.PushBack(m);
+          if (m.x[i] >= mask) {
+            m.x[i] -= mask;
+            nlst.PushBack(m);
+          }
         }
         k = nlst.Dim();
       }