2021-01-29 00:47:31 +00:00
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
|
|
|
// Copyright © 2021 by Brett Kuntz. All rights reserved.
|
2021-01-28 18:19:26 +00:00
|
|
|
//--NOV-26-2018---------------------------------------------------------------------------------------------------------
|
2021-01-26 17:15:47 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
static_assert(CHAR_BIT == 8, "This code requires [char] to be exactly 8 bits.");
|
|
|
|
static_assert(sizeof(long) == 8, "This code requires [long] to be exactly 8 bytes."); // __builtin_popcountl
|
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef unsigned char u8 ; typedef char s8 ;
|
|
|
|
typedef uint16_t u16 ; typedef int16_t s16 ;
|
|
|
|
typedef uint32_t u32 ; typedef int32_t s32 ;
|
|
|
|
typedef uint64_t u64 ; typedef int64_t s64 ;
|
|
|
|
typedef __uint128_t u128 ; typedef __int128_t s128 ;
|
|
|
|
typedef unsigned int ui ; typedef int si ;
|
|
|
|
typedef unsigned long ul ; typedef long sl ;
|
|
|
|
typedef unsigned long long ull ; typedef long long sll ;
|
|
|
|
typedef float r32 ; typedef double r64 ;
|
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
|
|
|
#define halt do { fflush(0); while (1) sleep(-1); } while (0)
|
|
|
|
#define cwait do { fflush(0); sleep(1); do errno = 0, wait(0); while (errno != ECHILD); sleep(1); } while(0)
|
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
2021-01-30 03:13:53 +00:00
|
|
|
// 2nd cut is 37 (p0.14453125)
|
|
|
|
// 3rd cut is 23 (p0.08984375)
|
|
|
|
// 4th cut is 17 (p0.06640625)
|
|
|
|
// 5th cut is 14 (p0.05468750)
|
|
|
|
// 6th cut is 11 (p0.04296875)
|
|
|
|
// 7th cut is 9 (p0.03515625)
|
|
|
|
// 8th cut is 8 (p0.03125000)
|
|
|
|
// 9th cut is 7 (p0.02734375)
|
2021-01-31 18:41:30 +00:00
|
|
|
// 10th cut is 6 (p0.02343750)
|
2021-02-01 17:50:49 +00:00
|
|
|
// 11th cut is 6 (p0.02343750)
|
2021-02-02 17:51:10 +00:00
|
|
|
// 12th cut is 5
|
|
|
|
// 13th cut is 5
|
2021-02-03 17:48:54 +00:00
|
|
|
// 14th cut is 5 (or 4, we're going with 5 for now)
|
2021-02-03 01:13:07 +00:00
|
|
|
// 15th cut is 4
|
2021-02-03 17:48:54 +00:00
|
|
|
// 16th cut is 4
|
2021-02-04 04:36:30 +00:00
|
|
|
// 17th cut is 4
|
2021-02-07 02:17:59 +00:00
|
|
|
// 18th cut is 3
|
|
|
|
// 19th cut is 3
|
|
|
|
// 20th cut is 3
|
|
|
|
// 21st cut is 3
|
2021-02-11 22:01:38 +00:00
|
|
|
// 22nd cut is 3
|
|
|
|
// 23rd cut is 3
|
|
|
|
// 24th cut is 3
|
|
|
|
// 25th cut is 2
|
|
|
|
// 26th cut is ??
|
2021-01-26 17:15:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysinfo.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
2021-01-28 18:19:26 +00:00
|
|
|
static u64 * global_total, SAMPLES_PER_TEST;
|
|
|
|
static sem_t csoutput;
|
|
|
|
static const u64 BLAKE_IV = UINT64_C(0xA54FF53A5F1D36F1);
|
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
|
|
|
static void check(void);
|
|
|
|
static u64 find_hash(ui * const restrict, u8 * const restrict, u8 const * const restrict, u64 * const restrict, u64 * const restrict, u8 const * const restrict, const u64, const ui);
|
|
|
|
static u64 find_p_hash(ui * const restrict, u8 * const restrict, u8 const * const restrict, u64 * const restrict, u64 * const restrict, u8 const * const restrict, const u64, const u8, const ui);
|
2021-02-18 03:19:18 +00:00
|
|
|
static u64 find_p_hash2(ui * const restrict, u8 * const restrict, u8 const * const restrict, u64 * const restrict, u64 * const restrict, u8 const * const restrict, const u64, const ui, const ui);
|
|
|
|
static u64 find_p_hash3(ui * const restrict, u8 * const restrict, u8 const * const restrict, u64 * const restrict, u64 * const restrict, u8 const * const restrict, const u64, const ui, const ui);
|
2021-01-28 18:19:26 +00:00
|
|
|
static void hash(u8 * const restrict, u64 const * const restrict, u64 * const, u64 const * const restrict, u8 const * const restrict);
|
|
|
|
static void p_hash(u8 * const restrict, u64 const * const restrict, u64 * const, u64 const * const restrict, const u8, u8 const * const restrict);
|
2021-02-18 03:19:18 +00:00
|
|
|
static void p_hash2(u8 * const restrict, u64 const * const restrict, u64 * const, u64 const * const restrict, const ui, u8 const * const restrict);
|
|
|
|
static void p_hash3(u8 * const restrict, u64 const * const restrict, u64 * const, u64 const * const restrict, const ui, u8 const * const restrict);
|
2021-01-28 18:19:26 +00:00
|
|
|
static si get_hash_score(void const * const);
|
|
|
|
static void blake2b(u64 * const restrict, u64 const * const restrict);
|
|
|
|
static u64 tick(void);
|
|
|
|
static u16 rng(u64 * const restrict, u64 const * const restrict, const u16, ui * const restrict);
|
2021-02-18 03:19:18 +00:00
|
|
|
static u16 rng_word(u64 * const, u64 const * const restrict, ui * const restrict);
|
|
|
|
static ui get_bit(void const * const restrict, const ui);
|
|
|
|
static void set_bit(void * const restrict, const ui, const ui);
|
2021-01-28 18:19:26 +00:00
|
|
|
static void print_bytes(s8 const * const restrict, void const * const, const ui);
|
|
|
|
static void print_population(s8 const * const restrict, void const * const);
|
|
|
|
static void gen_test_file(s8 const * const restrict, const r64);
|
2021-02-18 03:19:18 +00:00
|
|
|
static void shuffle(u8 * const restrict, u64 const * const restrict, u64 * const restrict, u64 const * const restrict, u8 const * const restrict);
|
|
|
|
static u64 find_shuffle(u32 * const restrict, u8 * const restrict, u8 const * const restrict, u64 * const restrict, u64 * const restrict, u8 const * const restrict, const u64, const ui);
|
|
|
|
static s32 get_shuffle_score(void const * const restrict);
|
|
|
|
//----------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|