#include "rassert.h"
#include "swap.h"
-void core_hash_init(int process, int base, int blocks, int offset) {
- for (int i = 0; i < blocks; ++i) {
+void core_hash_init(int process, long base, long size, long offset) {
+ for (long i = 0; i < size; ++i) {
+ int addr = base + i;
#ifdef INDIRECT_CORE
- int core_block = core_table_mem[base + i];
-#else
- int core_block = base + i;
+ addr =
+ (core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
+ (addr & (BLOCK_SIZE - 1));
#endif
- 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(core_block_mem[core_block * BLOCK_SIZE + j] == 0xaa);
- core_block_mem[core_block * BLOCK_SIZE + j] = (uint8_t)hash;
- }
+ long long hash = process * 17 + (i + offset) * 29;
+ hash = (hash & 0xffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffLL) + (hash >> 16);
+ hash = (hash & 0xffLL) + (hash >> 8);
+ hash = (hash & 0xffLL) + (hash >> 8);
+ rassert(core_block_mem[addr] == 0xaa);
+ core_block_mem[addr] = (uint8_t)hash;
}
}
-void core_hash_verify(int process, int base, int blocks, int offset) {
- for (int i = 0; i < blocks; ++i) {
+void core_hash_verify(int process, long base, long size, long offset) {
+ for (long i = 0; i < size; ++i) {
+ int addr = base + i;
#ifdef INDIRECT_CORE
- int core_block = core_table_mem[base + i];
-#else
- int core_block = base + i;
+ addr =
+ (core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
+ (addr & (BLOCK_SIZE - 1));
#endif
- 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(core_block_mem[core_block * BLOCK_SIZE + j] == (uint8_t)hash);
- }
- memset(
- core_block_mem + core_block * BLOCK_SIZE,
- 0xaa,
- BLOCK_SIZE
- );
+ long long hash = process * 17 + (i + offset) * 29;
+ hash = (hash & 0xffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffLL) + (hash >> 16);
+ hash = (hash & 0xffLL) + (hash >> 8);
+ hash = (hash & 0xffLL) + (hash >> 8);
+ rassert(core_block_mem[addr] == (uint8_t)hash);
+ core_block_mem[addr] = 0xaa;
}
}
-void swap_hash_verify(int process, int base, int blocks, int offset) {
- for (int i = 0; i < blocks; ++i) {
+void swap_hash_verify(int process, long base, long size, long offset) {
+ for (long i = 0; i < size; ++i) {
+ int addr = base + i;
#ifdef INDIRECT_SWAP
- int swap_block = swap_table_mem[base + i];
-#else
- int swap_block = base + i;
+ addr =
+ (swap_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
+ (addr & (BLOCK_SIZE - 1));
#endif
- 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
- );
+ long long hash = process * 17 + (i + offset) * 29;
+ hash = (hash & 0xffffffffLL) + (hash >> 32);
+ hash = (hash & 0xffffLL) + (hash >> 16);
+ hash = (hash & 0xffLL) + (hash >> 8);
+ hash = (hash & 0xffLL) + (hash >> 8);
+ rassert(swap_block_mem[addr] == (uint8_t)hash);
+ swap_block_mem[addr] = 0xaa;
}
}
core_base + blocks
);
printf("new core [%d,%d)\n", core_base, core_base + blocks);
- core_hash_init(process, core_base, blocks, 0);
+ core_hash_init(
+ process,
+ (long)core_base << BLOCK_SHIFT,
+ (long)blocks << BLOCK_SHIFT,
+ 0L
+ );
#ifdef PREALLOCATE_SWAP
printf("new swap [%d,%d)\n", PER_PROCESS_SWAP_ITEM(processes + process).base, PER_PROCESS_SWAP_ITEM(processes + process).limit);
#endif
int blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
core_hash_verify(
process,
- core_base + blocks,
- actual_old_blocks - blocks,
- blocks
+ (long)(core_base + blocks) << BLOCK_SHIFT,
+ (long)(actual_old_blocks - blocks) << BLOCK_SHIFT,
+ (long)blocks << BLOCK_SHIFT
);
bool result = process_realloc(processes + process, size);
printf(
#endif
core_hash_init(
process,
- core_base + actual_old_blocks,
- blocks - actual_old_blocks,
- actual_old_blocks
+ (long)(core_base + actual_old_blocks) << BLOCK_SHIFT,
+ (long)(blocks - actual_old_blocks) << BLOCK_SHIFT,
+ (long)actual_old_blocks << BLOCK_SHIFT
);
}
}
rassert(core_blocks + swap_blocks == actual_old_blocks);
printf("old core [%d,%d) swap [%d,%d)\n", core_base, core_base + core_blocks, swap_base, swap_base + swap_blocks);
fflush(stdout);
- core_hash_verify(process, core_base, core_blocks, swap_blocks);
- swap_hash_verify(process, swap_base, swap_blocks, 0);
+ core_hash_verify(
+ process,
+ (long)core_base << BLOCK_SHIFT,
+ (long)core_blocks << BLOCK_SHIFT,
+ (long)swap_blocks << BLOCK_SHIFT
+ );
+ swap_hash_verify(
+ process,
+ (long)swap_base << BLOCK_SHIFT,
+ (long)swap_blocks << BLOCK_SHIFT,
+ 0L
+ );
process_free(processes + process);
processes[process].size = -1L;
printf("... ok\n");
swap_base,
swap_base + swap_blocks
);
- core_hash_verify(i, core_base, core_blocks, swap_blocks);
+ core_hash_verify(
+ i,
+ (long)core_base << BLOCK_SHIFT,
+ (long)core_blocks << BLOCK_SHIFT,
+ (long)swap_blocks << BLOCK_SHIFT
+ );
#ifdef INDIRECT_CORE
core_block_free(core_table_mem + core_base, core_blocks);
#endif
- swap_hash_verify(i, swap_base, swap_blocks, 0);
+ swap_hash_verify(
+ i,
+ (long)swap_base << BLOCK_SHIFT,
+ (long)swap_blocks << BLOCK_SHIFT,
+ 0L
+ );
#ifdef INDIRECT_SWAP
swap_block_free(swap_table_mem + swap_base, swap_blocks);
#endif