Implement simulated BLOCK_SIZE, hash create and check simulated block contents
authorNick Downing <nick@ndcode.org>
Sat, 23 Mar 2019 22:55:43 +0000 (09:55 +1100)
committerNick Downing <nick@ndcode.org>
Sat, 23 Mar 2019 22:55:43 +0000 (09:55 +1100)
core.c
core.h
pool_test_run.c
process_test_run.c
swap.c
swap.h

diff --git a/core.c b/core.c
index 388881b..2c78def 100644 (file)
--- a/core.c
+++ b/core.c
@@ -7,6 +7,8 @@
 struct pool_head core_table;
 
 #ifdef INDIRECT_CORE
+int *core_table_mem;
+
 static uint8_t masks[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
 static uint8_t bits[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
 
@@ -15,10 +17,8 @@ int n_core_block_bitmap;
 uint8_t *core_block_bitmap;
 int core_block_next;
 int core_block_avail;
-
-int *core_table_mem;
 #endif
-int *core_block_mem;
+uint8_t *core_block_mem;
 
 static void core_move(struct pool_item *item, int new_base) {
   int base = item->base;
@@ -36,8 +36,16 @@ static void core_move(struct pool_item *item, int new_base) {
     core_table_mem[new_base + i] = core_table_mem[base + i];
     core_table_mem[base + i] = 0x55555555;
 #else
-    core_block_mem[new_base + i] = core_block_mem[base + i];
-    core_block_mem[base + i] = 0xaaaaaaaa;
+    memcpy(
+      core_block_mem + (new_base + i) * BLOCK_SIZE,
+      core_block_mem + (base + i) * BLOCK_SIZE,
+      BLOCK_SIZE
+    );
+    memset(
+      core_block_mem + (base + i) * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
 #endif
   }
 }
@@ -59,8 +67,16 @@ static void core_move_up(struct pool_item *item, int new_limit) {
     core_table_mem[new_limit + i] = core_table_mem[limit + i];
     core_table_mem[limit + i] = 0x55555555;
 #else
-    core_block_mem[new_limit + i] = core_block_mem[limit + i];
-    core_block_mem[limit + i] = 0xaaaaaaaa;
+    memcpy(
+      core_block_mem + (new_limit + i) * BLOCK_SIZE,
+      core_block_mem + (limit + i) * BLOCK_SIZE,
+      BLOCK_SIZE
+    );
+    memset(
+      core_block_mem + (limit + i) * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
 #endif
   }
 }
@@ -104,9 +120,9 @@ void core_init(int n_blocks)
   core_block_avail = n_core_blocks;
 #endif
 
-  core_block_mem = malloc(n_blocks * sizeof(int));
+  core_block_mem = malloc(n_blocks * BLOCK_SIZE);
   rassert(core_block_mem);
-  memset(core_block_mem, 0xaa, n_blocks * sizeof(int));
+  memset(core_block_mem, 0xaa, n_blocks * BLOCK_SIZE);
 }
 
 #ifdef INDIRECT_CORE
@@ -179,30 +195,42 @@ void core_block_free(int *table, int size) {
 
 void core_hash_init(int process, int core_base, int base, int limit) {
   for (int i = base; i < limit; ++i) {
-    long long hash = process * 17 + i * 29;
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
 #ifdef INDIRECT_CORE
     int core_block = core_table_mem[core_base + i];
 #else
     int core_block = core_base + i;
 #endif
-    rassert(core_block_mem[core_block] == 0xaaaaaaaa);
-    core_block_mem[core_block] = (int)hash;
+    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) {
-    long long hash = process * 17 + i * 29;
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
 #ifdef INDIRECT_CORE
     int core_block = core_table_mem[core_base + i];
 #else
     int core_block = core_base + i;
 #endif
-    rassert(core_block_mem[core_block] == (int)hash);
-    core_block_mem[core_block] = 0xaaaaaaaa;
+    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 2b333bc..a3c98e2 100644 (file)
--- a/core.h
+++ b/core.h
@@ -6,6 +6,7 @@
 
 //#define INDIRECT_CORE 1
 #define MOVEABLE_CORE 1
+#define BLOCK_SIZE 0x1000
 
 #ifdef MOVEABLE_CORE
 #define core_table_alloc(item, size) \
 extern struct pool_head core_table;
 
 #ifdef INDIRECT_CORE
+extern int *core_table_mem;
+
 extern int n_core_blocks;
 int n_core_block_bitmap;
 extern uint8_t *core_block_bitmap;
 extern int core_block_next;
 extern int core_block_avail;
-
-extern int *core_table_mem;
 #endif
-extern int *core_block_mem;
+extern uint8_t *core_block_mem;
 
 #ifdef INDIRECT_CORE
 void core_init(int n_table, int n_blocks);
index 637769c..13e1139 100644 (file)
@@ -45,8 +45,8 @@ void move_up(struct pool_item *item, int new_limit) {
 void hash_init(int item, int item_base, int base, int limit) {
   for (int i = base; i < limit; ++i) {
     long long hash = item * 17 + i * 29;
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+    hash = (hash & 0xffffffffLL) + (hash >> 32);
+    hash = (hash & 0xffffffffLL) + (hash >> 32);
     rassert(mem[item_base + i] == 0xaaaaaaaa);
     mem[item_base + i] = (int)hash;
   }
@@ -55,8 +55,8 @@ void hash_init(int item, int item_base, int base, int limit) {
 void hash_verify(int item, int item_base, int base, int limit) {
   for (int i = base; i < limit; ++i) {
     long long hash = item * 17 + i * 29;
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
+    hash = (hash & 0xffffffffLL) + (hash >> 32);
+    hash = (hash & 0xffffffffLL) + (hash >> 32);
     rassert(mem[item_base + i] == (int)hash);
     mem[item_base + i] = 0xaaaaaaaa;
   }
index 2a0301e..cdff8a6 100644 (file)
@@ -342,7 +342,8 @@ done:
   }
 #endif
   for (int i = 0; i < n_core_blocks; ++i)
-    rassert(core_block_mem[i] == 0xaaaaaaaa);
+    for (int j = 0; j < BLOCK_SIZE; ++j)
+      rassert(core_block_mem[i * BLOCK_SIZE + j] == 0xaa);
 #ifdef INDIRECT_SWAP
   for (int i = 0; i < swap_table_size; ++i)
     rassert(swap_table_mem[i] == 0x55555555);
@@ -356,7 +357,8 @@ done:
   }
 #endif
   for (int i = 0; i < n_swap_blocks; ++i)
-    rassert(swap_block_mem[i] == 0xaaaaaaaa);
+    for (int j = 0; j < BLOCK_SIZE; ++j)
+      rassert(swap_block_mem[i * BLOCK_SIZE + j] == 0xaa);
 
   return 0;
 }
diff --git a/swap.c b/swap.c
index 5c96a47..32eae9e 100644 (file)
--- a/swap.c
+++ b/swap.c
@@ -8,6 +8,8 @@
 struct pool_head swap_table;
 
 #ifdef INDIRECT_SWAP
+int *swap_table_mem;
+
 static uint8_t masks[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
 static uint8_t bits[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
 
@@ -16,10 +18,8 @@ int n_swap_block_bitmap;
 uint8_t *swap_block_bitmap;
 int swap_block_next;
 int swap_block_avail;
-
-int *swap_table_mem;
 #endif
-int *swap_block_mem;
+uint8_t *swap_block_mem;
 
 // swap address native wrt. pool and complemented wrt. backing store,
 // means that swap_move() moves upward in backing store, do backward
@@ -42,8 +42,16 @@ static void swap_move(struct pool_item *item, int new_base) {
     swap_table_mem[new_limit + i] = swap_table_mem[limit + i];
     swap_table_mem[limit + i] = 0x55555555;
 #else
-    swap_block_mem[new_limit + i] = swap_block_mem[limit + i];
-    swap_block_mem[limit + i] = 0xaaaaaaaa;
+    memcpy(
+      swap_block_mem + (new_limit + i) * BLOCK_SIZE,
+      swap_block_mem + (limit + i) * BLOCK_SIZE,
+      BLOCK_SIZE
+    );
+    memset(
+      swap_block_mem + (limit + i) * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
 #endif
   }
 }
@@ -70,8 +78,16 @@ static void swap_move_up(struct pool_item *item, int new_limit) {
     swap_table_mem[new_base + i] = swap_table_mem[base + i];
     swap_table_mem[base + i] = 0x55555555;
 #else
-    swap_block_mem[new_base + i] = swap_block_mem[base + i];
-    swap_block_mem[base + i] = 0xaaaaaaaa;
+    memcpy(
+      swap_block_mem + (new_base + i) * BLOCK_SIZE,
+      swap_block_mem + (base + i) * BLOCK_SIZE,
+      BLOCK_SIZE
+    );
+    memset(
+      swap_block_mem + (base + i) * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
 #endif
   }
 }
@@ -115,9 +131,9 @@ void swap_init(int n_blocks)
   swap_block_avail = n_swap_blocks;
 #endif
 
-  swap_block_mem = malloc(n_blocks * sizeof(int));
+  swap_block_mem = malloc(n_blocks * BLOCK_SIZE);
   rassert(swap_block_mem);
-  memset(swap_block_mem, 0xaa, n_blocks * sizeof(int));
+  memset(swap_block_mem, 0xaa, n_blocks * BLOCK_SIZE);
 }
 
 #ifdef INDIRECT_SWAP
@@ -208,9 +224,18 @@ void swap_read(int swap_base, int core_base, int size) {
 #else
     int core_block = core_base + i;
 #endif
-    assert(core_block_mem[core_block] == 0xaaaaaaaa);
-    core_block_mem[core_block] = swap_block_mem[swap_block];
-    swap_block_mem[swap_block] = 0xaaaaaaaa;
+    for (int j = 0; j < BLOCK_SIZE; ++j)
+      assert(core_block_mem[core_block * BLOCK_SIZE + j] == 0xaa);
+    memcpy(
+      core_block_mem + core_block * BLOCK_SIZE,
+      swap_block_mem + swap_block * BLOCK_SIZE,
+      BLOCK_SIZE
+    );
+    memset(
+      swap_block_mem + swap_block * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
   }
 #ifdef INDIRECT_SWAP
  printf("\n");
@@ -236,9 +261,18 @@ void swap_write(int swap_base, int core_base, int size) {
 #else
     int swap_block = swap_base + i;
 #endif
-    assert(swap_block_mem[swap_block] == 0xaaaaaaaa);
-    swap_block_mem[swap_block] = core_block_mem[core_block];
-    core_block_mem[core_block] = 0xaaaaaaaa;
+    for (int j = 0; j < BLOCK_SIZE; ++j)
+      assert(swap_block_mem[swap_block * BLOCK_SIZE + j] == 0xaa);
+    memcpy(
+      swap_block_mem + swap_block * BLOCK_SIZE,
+      core_block_mem + core_block * BLOCK_SIZE,
+      BLOCK_SIZE
+    );
+    memset(
+      core_block_mem + core_block * BLOCK_SIZE,
+      0xaa,
+      BLOCK_SIZE
+    );
   }
 #ifdef INDIRECT_SWAP
  printf("\n");
@@ -253,15 +287,23 @@ void swap_hash_verify(
   int offset
 ) {
   for (int i = base; i < limit; ++i) {
-    long long hash = process * 17 + (i + offset) * 29;
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
-    hash = (hash & 0xffffffffffffffffLL) + (hash >> 32);
 #ifdef INDIRECT_SWAP
     int swap_block = swap_table_mem[swap_base + i];
 #else
     int swap_block = swap_base + i;
 #endif
-    rassert(swap_block_mem[swap_block] == (int)hash);
-    swap_block_mem[swap_block] = 0xaaaaaaaa;
+    for (int j = 0; j < BLOCK_SIZE; ++j) {
+      long long hash = process * 17 + (i + offset) * 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
+    );
   }
 }
diff --git a/swap.h b/swap.h
index f3c8627..9995041 100644 (file)
--- a/swap.h
+++ b/swap.h
 extern struct pool_head swap_table;
 
 #ifdef INDIRECT_SWAP
+extern int *swap_table_mem;
+
 extern int n_swap_blocks;
 int n_swap_block_bitmap;
 extern uint8_t *swap_block_bitmap;
 extern int swap_block_next;
 extern int swap_block_avail;
-
-extern int *swap_table_mem;
 #endif
-extern int *swap_block_mem;
+extern uint8_t *swap_block_mem;
 
 #ifdef INDIRECT_SWAP
 void swap_init(int n_table, int n_blocks);