Move the hash generation and verification stuff into process_test_run.c
authorNick Downing <nick@ndcode.org>
Thu, 4 Apr 2019 09:12:30 +0000 (20:12 +1100)
committerNick Downing <nick@ndcode.org>
Thu, 4 Apr 2019 09:15:50 +0000 (20:15 +1100)
core.c
core.h
process_test_run.c
swap.c
swap.h

diff --git a/core.c b/core.c
index 2c78def..3c5fb24 100644 (file)
--- a/core.c
+++ b/core.c
@@ -193,44 +193,3 @@ void core_block_free(int *table, int size) {
 }
 #endif
 
-void core_hash_init(int process, int core_base, int base, int limit) {
-  for (int i = base; i < limit; ++i) {
-#ifdef INDIRECT_CORE
-    int core_block = core_table_mem[core_base + i];
-#else
-    int core_block = core_base + i;
-#endif
-    for (int j = 0; j < BLOCK_SIZE; ++j) {
-      long long hash = process * 17 + i * 29 + j * 37;
-      hash = (hash & 0xffffffffLL) + (hash >> 32);
-      hash = (hash & 0xffffLL) + (hash >> 16);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      rassert(core_block_mem[core_block * BLOCK_SIZE + j] == 0xaa);
-      core_block_mem[core_block * BLOCK_SIZE + j] = (uint8_t)hash;
-    }
-  }
-}
-
-void core_hash_verify(int process, int core_base, int base, int limit) {
-  for (int i = base; i < limit; ++i) {
-#ifdef INDIRECT_CORE
-    int core_block = core_table_mem[core_base + i];
-#else
-    int core_block = core_base + i;
-#endif
-    for (int j = 0; j < BLOCK_SIZE; ++j) {
-      long long hash = process * 17 + i * 29 + j * 37;
-      hash = (hash & 0xffffffffLL) + (hash >> 32);
-      hash = (hash & 0xffffLL) + (hash >> 16);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      rassert(core_block_mem[core_block * BLOCK_SIZE + j] == (uint8_t)hash);
-    }
-    memset(
-      core_block_mem + core_block * BLOCK_SIZE,
-      0xaa,
-      BLOCK_SIZE
-    );
-  }
-}
diff --git a/core.h b/core.h
index 3fddba1..6fc8630 100644 (file)
--- a/core.h
+++ b/core.h
@@ -52,7 +52,5 @@ void core_block_free(int *blocks, int size);
 #else
 void core_init(int n_table);
 #endif
-void core_hash_init(int process, int core_base, int base, int limit);
-void core_hash_verify(int process, int core_base, int base, int limit);
 
 #endif
index d13ec8a..e052745 100644 (file)
@@ -7,6 +7,71 @@
 #include "rassert.h"
 #include "swap.h"
 
+void core_hash_init(int process, int core_base, int base, int limit) {
+  for (int i = base; i < limit; ++i) {
+#ifdef INDIRECT_CORE
+    int core_block = core_table_mem[core_base + i];
+#else
+    int core_block = core_base + i;
+#endif
+    for (int j = 0; j < BLOCK_SIZE; ++j) {
+      long long hash = process * 17 + i * 29 + j * 37;
+      hash = (hash & 0xffffffffLL) + (hash >> 32);
+      hash = (hash & 0xffffLL) + (hash >> 16);
+      hash = (hash & 0xffLL) + (hash >> 8);
+      hash = (hash & 0xffLL) + (hash >> 8);
+      rassert(core_block_mem[core_block * BLOCK_SIZE + j] == 0xaa);
+      core_block_mem[core_block * BLOCK_SIZE + j] = (uint8_t)hash;
+    }
+  }
+}
+
+void core_hash_verify(int process, int core_base, int base, int limit) {
+  for (int i = base; i < limit; ++i) {
+#ifdef INDIRECT_CORE
+    int core_block = core_table_mem[core_base + i];
+#else
+    int core_block = core_base + i;
+#endif
+    for (int j = 0; j < BLOCK_SIZE; ++j) {
+      long long hash = process * 17 + i * 29 + j * 37;
+      hash = (hash & 0xffffffffLL) + (hash >> 32);
+      hash = (hash & 0xffffLL) + (hash >> 16);
+      hash = (hash & 0xffLL) + (hash >> 8);
+      hash = (hash & 0xffLL) + (hash >> 8);
+      rassert(core_block_mem[core_block * BLOCK_SIZE + j] == (uint8_t)hash);
+    }
+    memset(
+      core_block_mem + core_block * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
+  }
+}
+
+void swap_hash_verify(int process, int swap_base, int base, int limit) {
+  for (int i = base; i < limit; ++i) {
+#ifdef INDIRECT_SWAP
+    int swap_block = swap_table_mem[swap_base + i];
+#else
+    int swap_block = swap_base + i;
+#endif
+    for (int j = 0; j < BLOCK_SIZE; ++j) {
+      long long hash = process * 17 + i * 29 + j * 37;
+      hash = (hash & 0xffffffffLL) + (hash >> 32);
+      hash = (hash & 0xffffLL) + (hash >> 16);
+      hash = (hash & 0xffLL) + (hash >> 8);
+      hash = (hash & 0xffLL) + (hash >> 8);
+      rassert(swap_block_mem[swap_block * BLOCK_SIZE + j] == (uint8_t)hash);
+    }
+    memset(
+      swap_block_mem + swap_block * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
+  }
+}
+
 int main(int argc, char **argv) {
   if (argc < 5) {
 #if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
diff --git a/swap.c b/swap.c
index 0a04074..175b103 100644 (file)
--- a/swap.c
+++ b/swap.c
@@ -194,50 +194,6 @@ void swap_block_free(int *table, int size) {
 }
 #endif
 
-#if 0 // not needed as always done in core before copying to swap
-void swap_hash_init(int process, int swap_base, int base, int limit) {
-  for (int i = base; i < limit; ++i) {
-#ifdef INDIRECT_SWAP
-    int swap_block = swap_table_mem[swap_base + i];
-#else
-    int swap_block = swap_base + i;
-#endif
-    for (int j = 0; j < BLOCK_SIZE; ++j) {
-      long long hash = process * 17 + i * 29 + j * 37;
-      hash = (hash & 0xffffffffLL) + (hash >> 32);
-      hash = (hash & 0xffffLL) + (hash >> 16);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      rassert(swap_block_mem[swap_block * BLOCK_SIZE + j] == 0xaa);
-      swap_block_mem[swap_block * BLOCK_SIZE + j] = (uint8_t)hash;
-    }
-  }
-}
-#endif
-
-void swap_hash_verify(int process, int swap_base, int base, int limit) {
-  for (int i = base; i < limit; ++i) {
-#ifdef INDIRECT_SWAP
-    int swap_block = swap_table_mem[swap_base + i];
-#else
-    int swap_block = swap_base + i;
-#endif
-    for (int j = 0; j < BLOCK_SIZE; ++j) {
-      long long hash = process * 17 + i * 29 + j * 37;
-      hash = (hash & 0xffffffffLL) + (hash >> 32);
-      hash = (hash & 0xffffLL) + (hash >> 16);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      rassert(swap_block_mem[swap_block * BLOCK_SIZE + j] == (uint8_t)hash);
-    }
-    memset(
-      swap_block_mem + swap_block * BLOCK_SIZE,
-      0xaa,
-      BLOCK_SIZE
-    );
-  }
-}
-
 void swap_read(int swap_base, int core_base, int size) {
  printf("swap_read swap [%d,%d) to core [%d,%d)\n", swap_base, swap_base + size, core_base, core_base + size);
 #if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
diff --git a/swap.h b/swap.h
index 384ad49..c720a0b 100644 (file)
--- a/swap.h
+++ b/swap.h
@@ -50,8 +50,6 @@ void swap_block_free(int *blocks, int size);
 #else
 void swap_init(int n_table);
 #endif
-//void swap_hash_init(int process, int swap_base, int base, int limit);
-void swap_hash_verify(int process, int swap_base, int base, int limit);
 void swap_read(int swap_base, int core_base, int size);
 void swap_write(int swap_base, int core_base, int size);