diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..016487ef
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+* text=auto
+
+*.sh text eol=lf
\ No newline at end of file
diff --git a/.github/actions/build-asset-linux.sh b/.github/actions/build-asset-unix.sh
similarity index 56%
rename from .github/actions/build-asset-linux.sh
rename to .github/actions/build-asset-unix.sh
index 6706499d..b7fc8920 100755
--- a/.github/actions/build-asset-linux.sh
+++ b/.github/actions/build-asset-unix.sh
@@ -5,9 +5,15 @@
# - BB_ARTIFACT_NAME
# - BB_VERSION
#
-set -e
-set -o pipefail
+set -eo pipefail
+thread_count=2
+
+if [[ $OSTYPE == 'darwin'* ]]; then
+ thread_count=$(sysctl -n hw.logicalcpu)
+else
+ thread_count=$(nproc --all)
+fi
# TODO: Use specific GCC version
echo "System: $(uname -s)"
@@ -15,18 +21,25 @@ gcc --version
mkdir build && cd build
cmake ..
-bash -e -o pipefail ../extract-version.sh
-cmake --build . --target bladebit --config Release -j $(nproc --all)
+bash -eo pipefail ../embed-version.sh
+cmake --build . --target bladebit --config Release -j $thread_count
chmod +x ./bladebit
+if [[ $OSTYPE == 'msys'* ]] || [[ $OSTYPE == 'cygwin'* ]]; then
+ ls -la Release
+else
+ ls -la
+fi
+
# Ensure bladebit version matches expected version
bb_version="$(./bladebit --version | xargs)"
if [[ "$bb_version" != "$BB_VERSION" ]]; then
- >&2 echo "Incorrect bladebit version. Got but '$bb_version' expected '$BB_VERSION'."
+ >&2 echo "Incorrect bladebit version. Got '$bb_version' but expected '$BB_VERSION'."
exit 1
fi
+tar --version
tar -czvf $BB_ARTIFACT_NAME bladebit
mkdir ../bin
mv $BB_ARTIFACT_NAME ../bin/
diff --git a/.github/actions/get-version.sh b/.github/actions/get-version.sh
index 70190ec0..81dea115 100755
--- a/.github/actions/get-version.sh
+++ b/.github/actions/get-version.sh
@@ -1,23 +1,34 @@
#! /usr/bin/env bash
# NOTE: This is meant to be run from the repo root dir
#
-set -e
-set -o pipefail
+set -eo pipefail
os=$1
arch=$2
-version=$(cat VERSION)
-suffix=
-ext="tar.gz"
+shift $#
-if [[ "$GITHUB_REF_NAME" != "master" ]]; then
- suffix="-$GITHUB_REF_NAME"
-fi
+# version_cmp=($(./extract-version.sh))
+. ./extract-version.sh
+
+ver_maj=$bb_ver_maj
+ver_min=$bb_ver_min
+ver_rev=$bb_ver_rev
+ver_suffix=$bb_version_suffix
+
+version="${ver_maj}.${ver_min}.${ver_rev}${ver_suffix}"
+
+# echo "Ref name: '$GITHUB_REF_NAME'"
+# if [[ "$GITHUB_REF_NAME" != "master" ]]; then
+# suffix="-${GITHUB_REF_NAME}"
+# fi
+
+ext="tar.gz"
if [[ "$os" == "windows" ]]; then
ext="zip"
fi
echo "::set-output name=BB_VERSION::$version"
-echo "::set-output name=BB_ARTIFACT_NAME::bladebit-v${version}${suffix}-${os}-${arch}.${ext}"
+echo "::set-output name=BB_ARTIFACT_NAME::bladebit-v${version}-${os}-${arch}.${ext}"
+
diff --git a/.github/workflows/attach-release-assets.yml b/.github/workflows/attach-release-assets.yml
index 53e9ddd9..50818edd 100644
--- a/.github/workflows/attach-release-assets.yml
+++ b/.github/workflows/attach-release-assets.yml
@@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
with:
ref: master
# Setup Node
- - uses: actions/setup-node@v2
- with: { node-version: '14' }
+ - uses: actions/setup-node@v3
+ with: { node-version: '16' }
- run: cd .github/actions && npm install @octokit/action
# Upload Artifacts as Release Assets
@@ -35,6 +35,8 @@ jobs:
bladebit-v${BB_VERSION}-ubuntu-arm64.tar.gz
bladebit-v${BB_VERSION}-centos-arm64.tar.gz
bladebit-v${BB_VERSION}-windows-x86-64.zip
+ bladebit-v${BB_VERSION}-macos-arm64.tar.gz
+ bladebit-v${BB_VERSION}-macos-x86-64.tar.gz
)
mkdir -p bin
diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml
index 2651162b..bef7e232 100644
--- a/.github/workflows/build-release.yml
+++ b/.github/workflows/build-release.yml
@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Get Version Number
id: version_number
@@ -22,7 +22,7 @@ jobs:
env:
BB_ARTIFACT_NAME: ${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
BB_VERSION: ${{steps.version_number.outputs.BB_VERSION}}
- run: .github/actions/build-asset-linux.sh
+ run: .github/actions/build-asset-unix.sh
- name: Upload Artifact Ubuntu x86-64
uses: actions/upload-artifact@v2
@@ -34,10 +34,10 @@ jobs:
build-centos-x86-64:
runs-on: ubuntu-20.04
container:
- image: centos:8
+ image: quay.io/centos/centos:stream8
steps:
- name: Checkout Repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Get Version Number
id: version_number
@@ -54,7 +54,7 @@ jobs:
BB_VERSION: ${{steps.version_number.outputs.BB_VERSION}}
run: |
source /opt/rh/gcc-toolset-9/enable
- .github/actions/build-asset-linux.sh
+ .github/actions/build-asset-unix.sh
- name: Upload Artifact CentOS x86-64
uses: actions/upload-artifact@v2
@@ -64,15 +64,15 @@ jobs:
if-no-files-found: error
build-ubuntu-arm64:
- runs-on: [ARM64]
+ runs-on: [ARM64, Linux]
container:
- image: ubuntu:20.04
+ image: chianetwork/ubuntu-20.04-builder:latest
defaults:
run:
shell: bash
steps:
- name: Checkout Repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Get Version Number
id: version_number
@@ -82,13 +82,13 @@ jobs:
run: |
export DEBIAN_FRONTEND=noninteractive
apt update
- apt install -y build-essential git cmake libgmp-dev libnuma-dev
+ apt install -y build-essential git libgmp-dev libnuma-dev
- name: Build
env:
BB_ARTIFACT_NAME: ${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
BB_VERSION: ${{steps.version_number.outputs.BB_VERSION}}
- run: .github/actions/build-asset-linux.sh
+ run: .github/actions/build-asset-unix.sh
- name: Upload Artifact Ubuntu ARM64
uses: actions/upload-artifact@v2
@@ -98,12 +98,12 @@ jobs:
if-no-files-found: error
build-centos-arm64:
- runs-on: [ARM64]
+ runs-on: [ARM64, Linux]
container:
- image: centos:8
+ image: quay.io/centos/centos:stream8
steps:
- name: Checkout Repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Get Version Number
id: version_number
@@ -120,7 +120,7 @@ jobs:
BB_VERSION: ${{steps.version_number.outputs.BB_VERSION}}
run: |
source /opt/rh/gcc-toolset-9/enable
- .github/actions/build-asset-linux.sh
+ .github/actions/build-asset-unix.sh
- name: Upload Artifact CentOS ARM64
uses: actions/upload-artifact@v2
@@ -133,7 +133,7 @@ jobs:
runs-on: windows-2019
steps:
- name: Checkout Repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Get Version Number
shell: bash
@@ -149,7 +149,7 @@ jobs:
mkdir build && cd build
cmake ..
- bash -e -o pipefail ../extract-version.sh
+ bash -e -o pipefail ../embed-version.sh
cat ../src/Version.h
cmake --build . --target bladebit --config Release
@@ -163,6 +163,7 @@ jobs:
mkdir ../bin
cd Release
+ ls -la
7z.exe a -tzip ../../bin/${BB_ARTIFACT_NAME} bladebit.exe
ls -la ../../bin
@@ -173,3 +174,60 @@ jobs:
path: ${{ github.workspace }}/bin/${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
if-no-files-found: error
+ build-macos-arm64:
+ runs-on: [macOS, ARM64]
+ steps:
+ - name: Cleanup Environment
+ uses: Chia-Network/actions/clean-workspace@main
+
+ - name: Checkout Repo
+ uses: actions/checkout@v3
+
+ - name: Get Version Number
+ id: version_number
+ run: bash -e .github/actions/get-version.sh macos arm64
+
+ - name: Install Prerequisites
+ run: brew install cmake
+
+ - name: Build
+ env:
+ BB_ARTIFACT_NAME: ${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
+ BB_VERSION: ${{steps.version_number.outputs.BB_VERSION}}
+ run: .github/actions/build-asset-unix.sh
+
+ - name: Upload Artifact macOS arm64
+ uses: actions/upload-artifact@v2
+ with:
+ name: ${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
+ path: ${{ github.workspace }}/bin/${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
+ if-no-files-found: error
+
+ build-macos-x86-64:
+ runs-on: macOS-11
+ steps:
+ - name: Cleanup Environment
+ uses: Chia-Network/actions/clean-workspace@main
+
+ - name: Checkout Repo
+ uses: actions/checkout@v3
+
+ - name: Get Version Number
+ id: version_number
+ run: .github/actions/get-version.sh macos x86-64
+
+ - name: Install Prerequisites
+ run: brew install cmake
+
+ - name: Build
+ env:
+ BB_ARTIFACT_NAME: ${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
+ BB_VERSION: ${{steps.version_number.outputs.BB_VERSION}}
+ run: .github/actions/build-asset-unix.sh
+
+ - name: Upload Artifact macOS x86-64
+ uses: actions/upload-artifact@v2
+ with:
+ name: ${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
+ path: ${{ github.workspace }}/bin/${{ steps.version_number.outputs.BB_ARTIFACT_NAME }}
+ if-no-files-found: error
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 00000000..19d93171
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,65 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL"
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [ "master" ]
+ schedule:
+ - cron: '32 4 * * 2'
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+ permissions:
+ actions: read
+ contents: read
+ security-events: write
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [ 'cpp', 'javascript' ]
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v2
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
+ # queries: security-extended,security-and-quality
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Build
+ # uses: github/codeql-action/autobuild@v2
+ run: |
+ sudo apt update
+ sudo apt install -y build-essential cmake libgmp-dev libnuma-dev
+ cmake . -Bbuild
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v2
diff --git a/.gitignore b/.gitignore
index 2b57b132..76391d19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,19 +1,21 @@
-.[bB]in/
-.[oP]bj/
-[bB]in/
-[oP]bj/
-[tT]mp/
-_[tT]mp/
-
-.vs/
-.sandbox/
-.dist/
-.keys/
-dist/
-
-.DS_Store
-*.log
-park*_hash.txt
-
-lib/*
-build/
+.[bB]in/
+.[oP]bj/
+[bB]in/
+[oP]bj/
+[tT]mp/
+_[tT]mp/
+
+.vs/
+.sandbox/
+.dist/
+.keys/
+dist/
+out/
+
+.DS_Store
+*.log
+park*_hash.txt
+
+lib/*
+build*/
+cmake-build*/
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..13566b81
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/bladebit.iml b/.idea/bladebit.iml
new file mode 100644
index 00000000..f08604bb
--- /dev/null
+++ b/.idea/bladebit.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 00000000..f23d5249
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/deployment.xml b/.idea/deployment.xml
new file mode 100644
index 00000000..00345774
--- /dev/null
+++ b/.idea/deployment.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..b8e73a4a
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..92fd63aa
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..e88cc20c
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index a6220f2e..8ae95aee 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -1,25 +1,43 @@
-{
- "configurations": [
- {
- "name": "Win32",
- "includePath": [
- "${workspaceFolder}/**"
- ],
- "defines": [
- "_DEBUG",
- "UNICODE",
- "_UNICODE"
- ],
- "windowsSdkVersion": "10.0.19041.0",
- "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\cl.exe",
- "cStandard": "c17",
- "cppStandard": "c++17",
- "intelliSenseMode": "windows-msvc-x64",
- "configurationProvider": "ms-vscode.cmake-tools"
- ,"forcedInclude": [
- "src/pch.h"
- ]
- }
- ],
- "version": 4
+{
+ "configurations": [
+ {
+ "name": "Win32",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "defines": [
+ "_DEBUG",
+ "UNICODE",
+ "_UNICODE"
+ ],
+ "windowsSdkVersion": "10.0.19041.0",
+ "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\cl.exe",
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "windows-msvc-x64",
+ "configurationProvider": "ms-vscode.cmake-tools",
+ "forcedInclude": [
+ "src/pch.h"
+ ]
+ },
+ {
+ "name": "macOS",
+ "includePath": [
+ "${workspaceFolder}/**"
+ ],
+ "defines": [],
+ "macFrameworkPath": [
+ "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
+ ],
+ "compilerPath": "/usr/bin/clang",
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "macos-clang-arm64",
+ "configurationProvider": "ms-vscode.cmake-tools",
+ "forcedInclude": [
+ "src/pch.h"
+ ]
+ }
+ ],
+ "version": 4
}
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 7ce970ce..246a5532 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
- "name" : "Bladebit",
+ "name" : "Bladebit RAM",
"type" : "cppdbg",
"request" : "launch",
"stopAtEntry" : false,
@@ -33,40 +33,223 @@
"args": [
"-f", "ade0cc43610ce7540ab96a524d0ab17f5df7866ef13d1221a7203e5d10ad2a4ae37f7b73f6cdfd6ddf4122e8a1c2f8ef",
"-p", "80a836a74b077cabaca7a76d1c3c9f269f7f3a8f2fa196a65ee8953eb81274eb8b7328d474982617af5a0fe71b47e9b8",
- "-n", "2",
+ "-i", "c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835",
+ // "-n", "1",
"-w",
"-v",
- "${workspaceFolder}/.sandbox"
+ "ramplot",
+ "~/plot/tmp"
]
- }
+ },
- ,{
- "name" : "Bladebit Dev",
+ {
+ "name" : "Bladebit Disk",
"type" : "cppdbg",
"request" : "launch",
"stopAtEntry" : false,
"cwd" : "${workspaceFolder}",
- "preLaunchTask" : "build_dev_debug",
+ "preLaunchTask" : "build_debug",
"console" : "internalConsole",
+ "program": "${workspaceFolder}/build/bladebit",
+
+ "osx": {
+ "MIMode": "lldb",
+ "args": [
+ "-f", "ade0cc43610ce7540ab96a524d0ab17f5df7866ef13d1221a7203e5d10ad2a4ae37f7b73f6cdfd6ddf4122e8a1c2f8ef",
+ "-p", "80a836a74b077cabaca7a76d1c3c9f269f7f3a8f2fa196a65ee8953eb81274eb8b7328d474982617af5a0fe71b47e9b8",
+ "-i", "c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835",
+ "diskplot",
+ "-t1", "/Volumes/Plotting", "/Volumes/Plotting"
+ ]
+ },
+
"windows": {
"type" : "cppvsdbg",
- "program": "${workspaceFolder}/build/debug/bladebit_dev.exe"
+ "program": "${workspaceFolder}/build/debug/bladebit.exe"
},
+
+ "args": [
+ "-f", "ade0cc43610ce7540ab96a524d0ab17f5df7866ef13d1221a7203e5d10ad2a4ae37f7b73f6cdfd6ddf4122e8a1c2f8ef",
+ "-p", "80a836a74b077cabaca7a76d1c3c9f269f7f3a8f2fa196a65ee8953eb81274eb8b7328d474982617af5a0fe71b47e9b8",
+// "-c", "xch1uf48n3f50xrs7zds0uek9wp9wmyza6crnex6rw8kwm3jnm39y82q5mvps6",
+ "-t", "62",
+ // "-w",
+ // "-v",
+ // "-n", "3",
+ "-i", "c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835", // No overflow
+ "--memo", "80a836a74b077cabaca7a76d1c3c9f269f7f3a8f2fa196a65ee8953eb81274eb8b7328d474982617af5a0fe71b47e9b8ade0cc43610ce7540ab96a524d0ab17f5df7866ef13d1221a7203e5d10ad2a4ae37f7b73f6cdfd6ddf4122e8a1c2f8ef01b7bf8a22a9ac82a003e07b551c851ea683839f3e1beb8ac9ede57d2c020669",
+
+ // "-i", "7a709594087cca18cffa37be61bdecf9b6b465de91acb06ecb6dbe0f4a536f73", // Yes overflow
+ // "--memo", "80a836a74b077cabaca7a76d1c3c9f269f7f3a8f2fa196a65ee8953eb81274eb8b7328d474982617af5a0fe71b47e9b8ade0cc43610ce7540ab96a524d0ab17f5df7866ef13d1221a7203e5d10ad2a4ae37f7b73f6cdfd6ddf4122e8a1c2f8ef207d52406afa2b6d7d92ea778f407205bd9dca40816c1b1cacfca2a6612b93eb",
+
+ "--show-memo",
+
+ "diskplot",
+
+ "-t1", "~/plot/tmp",
+ "--f1-threads", "24",
+ // "--fp-threads", "62",
+ "--c-threads", "28",
+ "--p2-threads", "24",
+
+ // "-a",
+ // "--cache", "110G",
+ // "--cache", "99G",
+ "--cache", "200G",
+ // "--cache", "64G",
+ // "-s",
+ // "--k32-bounded",
+ "-b", "64",
+ // "--sizes",
+ // "-b", "128",
+ // "-b", "256",
+
+ "--c-threads", "26",
+ "--p2-threads", "24",
+ "--p3-threads", "48",
+ "~/plot/tmp"
+ ],
+
+ // ,"stopAtEntry": true
- "linux": {
- "program": "${workspaceFolder}/build/bladebit_dev"
- },
+ "environment": []
+ },
+ {
+ "name" : "IOTest",
+
+ "type" : "cppdbg",
+ "request" : "launch",
+ "stopAtEntry" : false,
+ "cwd" : "${workspaceFolder}",
+ "preLaunchTask" : "build_debug",
+ "console" : "internalConsole",
+ "program" : "${workspaceFolder}/build/bladebit",
+
+ "windows": {
+ "type" : "cppvsdbg",
+ "program": "${workspaceFolder}/build/debug/bladebit.exe"
+ },
+
"osx": {
- "program": "${workspaceFolder}/build/bladebit_dev"
+ "program" : "${workspaceFolder}/build/bladebit",
+ "MIMode": "lldb"
+ },
+
+ "environment": [],
+
+ "args": [
+
+ // "-t", "32",
+ // "iotest",
+ // "memtest",
+ // "-s", "64MB"
+ // "-s", "32G",
+ // "-m", "32G",
+ // "/mnt/p5510a/disk_tmp"
+
+ /// macOS
+ "-t", "8",
+ "memtest",
+ "-s", "6G",
+ ".sandbox"
+ ]
+ },
+
+ {
+ "name" : "Tests",
+
+ "type" : "cppdbg",
+ "request" : "launch",
+ "stopAtEntry" : false,
+ "cwd" : "${workspaceFolder}",
+ "preLaunchTask" : "build_tests_debug",
+ "console" : "internalConsole",
+
+ "program": "${workspaceRoot}/build/tests",
+
+ "environment": [
+ // { "name": "bbtest_thread_count", "value": "2" }
+ ],
+
+ "args": [
+ "-b",
+ // "F1GenBucketized"
+ // "FxSort"
+ // "FxDisk"
+ // "F1Disk"
+ // "PairsAndMap"
+ // "bucket-slice-write"
+ // "line-point-deltas"
+ ]
+ }
+
+
+ ,{
+ "name" : "Plot Tool",
+
+ "type" : "cppdbg",
+ "request" : "launch",
+ "stopAtEntry" : false,
+ "cwd" : "${workspaceFolder}",
+ "preLaunchTask" : "build_debug",
+ "console" : "internalConsole",
+
+ "program": "${workspaceFolder}/build/bladebit",
+
+ "windows": {
+ "type" : "cppvsdbg",
+ "program": "${workspaceFolder}/build/debug/bladebit.exe"
},
"environment": [],
+ "args": [
+ /// Validate
+ // "-t", "32",
+ // "-t", "1",
+ "validate",
+
+ "--f7", "2534554965",
+ "~/plot/tmp/plot-k32-2022-10-18-22-25-c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835.plot"
+
+ // "-m",
+ // "-u",
+ // "~/plot/tmp/plot-k32-2022-10-17-15-05-c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835.plot",
+
+ // "/mnt/p5510a/disk_tmp/plot.dat"
+
+ /// Compare
+ // "plotcmp",
+ // "/mnt/p5510a/disk_tmp/plot-k32-2022-04-12-13-53-c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835.plot",
+ // "/mnt/p5510a/disk_tmp/plot-k32-2022-04-12-13-03-c6b84729c23dc6d60c92f22c17083f47845c1179227c5509f07a5d2804a7b835.plot"
+ ]
+ },
+
+ {
+ "name" : "FSEGen",
+
+ "type" : "cppdbg",
+ "request" : "launch",
+ "stopAtEntry" : false,
+ "cwd" : "${workspaceFolder}",
+ "preLaunchTask" : "build_fsegen_debug",
+ "console" : "internalConsole",
+
+ "program": "${workspaceRoot}/build/fsegen",
+
+ // "windows": {
+ // "type" : "cppvsdbg",
+ // "program": "${workspaceFolder}/build/debug/fsegen.exe"
+ // },
+
+ "environment": [],
+
"args": [
]
}
+
]
}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
index d79f45ad..be694e05 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,112 +1,111 @@
-{
- "cSpell.ignoreWords": [
- "ndebug",
- "nominmax"
- ],
- "files.associations": {
- "Fastfile": "ruby",
- "*.plist": "xml",
- "*.sd": "yaml",
- "*.json": "jsonc",
- "*.ir": "llvm",
- "*.qs": "javascript",
- "*.ac": "shellscript",
- "player": "json",
- "*.userprefs": "xml",
- "memory": "cpp",
- "cstddef": "cpp",
- "string": "cpp",
- "chrono": "cpp",
- "atomic": "cpp",
- "cerrno": "cpp",
- "*.tcc": "cpp",
- "fstream": "cpp",
- "type_traits": "cpp",
- "algorithm": "cpp",
- "cmath": "cpp",
- "array": "cpp",
- "deque": "cpp",
- "vector": "cpp",
- "string_view": "cpp",
- "cctype": "cpp",
- "clocale": "cpp",
- "cstdarg": "cpp",
- "cstdint": "cpp",
- "cstdio": "cpp",
- "cstdlib": "cpp",
- "ctime": "cpp",
- "cwchar": "cpp",
- "cwctype": "cpp",
- "unordered_map": "cpp",
- "exception": "cpp",
- "memory_resource": "cpp",
- "optional": "cpp",
- "ratio": "cpp",
- "system_error": "cpp",
- "tuple": "cpp",
- "utility": "cpp",
- "initializer_list": "cpp",
- "iosfwd": "cpp",
- "istream": "cpp",
- "limits": "cpp",
- "new": "cpp",
- "ostream": "cpp",
- "sstream": "cpp",
- "stdexcept": "cpp",
- "streambuf": "cpp",
- "thread": "cpp",
- "typeinfo": "cpp",
- "bitset": "cpp",
- "functional": "cpp",
- "iomanip": "cpp",
- "regex": "cpp",
- "future": "cpp",
- "bit": "cpp",
- "cinttypes": "cpp",
- "codecvt": "cpp",
- "condition_variable": "cpp",
- "cstring": "cpp",
- "list": "cpp",
- "map": "cpp",
- "set": "cpp",
- "unordered_set": "cpp",
- "iterator": "cpp",
- "numeric": "cpp",
- "random": "cpp",
- "iostream": "cpp",
- "mutex": "cpp",
- "shared_mutex": "cpp",
- "variant": "cpp",
- "segwit_addr.h": "c",
- "complex": "cpp",
- "forward_list": "cpp",
- "typeindex": "cpp",
- "valarray": "cpp",
- "__bit_reference": "cpp",
- "__config": "cpp",
- "__debug": "cpp",
- "__errc": "cpp",
- "__functional_base": "cpp",
- "__hash_table": "cpp",
- "__locale": "cpp",
- "__mutex_base": "cpp",
- "__node_handle": "cpp",
- "__nullptr": "cpp",
- "__split_buffer": "cpp",
- "__string": "cpp",
- "__threading_support": "cpp",
- "__tree": "cpp",
- "__tuple": "cpp",
- "ios": "cpp",
- "locale": "cpp",
- "stack": "cpp"
- },
- "cSpell.words": [
- "Ryzen"
- ],
- "C_Cpp.errorSquiggles": "Enabled",
- "cmake.configureOnOpen": true,
- "cmake.sourceDirectory": "${workspaceFolder}/."
-
- ,"cmake.generator": "Unix Makefiles"
+{
+ "cSpell.ignoreWords": [
+ "ndebug",
+ "nominmax"
+ ],
+ "files.associations": {
+ "Fastfile": "ruby",
+ "*.plist": "xml",
+ "*.sd": "yaml",
+ "*.json": "jsonc",
+ "*.ir": "llvm",
+ "*.qs": "javascript",
+ "*.ac": "shellscript",
+ "player": "json",
+ "*.userprefs": "xml",
+ "memory": "cpp",
+ "cstddef": "cpp",
+ "string": "cpp",
+ "chrono": "cpp",
+ "atomic": "cpp",
+ "cerrno": "cpp",
+ "*.tcc": "cpp",
+ "fstream": "cpp",
+ "type_traits": "cpp",
+ "algorithm": "cpp",
+ "cmath": "cpp",
+ "array": "cpp",
+ "deque": "cpp",
+ "vector": "cpp",
+ "string_view": "cpp",
+ "cctype": "cpp",
+ "clocale": "cpp",
+ "cstdarg": "cpp",
+ "cstdint": "cpp",
+ "cstdio": "cpp",
+ "cstdlib": "cpp",
+ "ctime": "cpp",
+ "cwchar": "cpp",
+ "cwctype": "cpp",
+ "unordered_map": "cpp",
+ "exception": "cpp",
+ "memory_resource": "cpp",
+ "optional": "cpp",
+ "ratio": "cpp",
+ "system_error": "cpp",
+ "tuple": "cpp",
+ "utility": "cpp",
+ "initializer_list": "cpp",
+ "iosfwd": "cpp",
+ "istream": "cpp",
+ "limits": "cpp",
+ "new": "cpp",
+ "ostream": "cpp",
+ "sstream": "cpp",
+ "stdexcept": "cpp",
+ "streambuf": "cpp",
+ "thread": "cpp",
+ "typeinfo": "cpp",
+ "bitset": "cpp",
+ "functional": "cpp",
+ "iomanip": "cpp",
+ "regex": "cpp",
+ "future": "cpp",
+ "bit": "cpp",
+ "cinttypes": "cpp",
+ "codecvt": "cpp",
+ "condition_variable": "cpp",
+ "cstring": "cpp",
+ "list": "cpp",
+ "map": "cpp",
+ "set": "cpp",
+ "unordered_set": "cpp",
+ "iterator": "cpp",
+ "numeric": "cpp",
+ "random": "cpp",
+ "iostream": "cpp",
+ "mutex": "cpp",
+ "shared_mutex": "cpp",
+ "variant": "cpp",
+ "segwit_addr.h": "c",
+ "complex": "cpp",
+ "forward_list": "cpp",
+ "typeindex": "cpp",
+ "valarray": "cpp",
+ "__bit_reference": "cpp",
+ "__config": "cpp",
+ "__debug": "cpp",
+ "__errc": "cpp",
+ "__functional_base": "cpp",
+ "__hash_table": "cpp",
+ "__locale": "cpp",
+ "__mutex_base": "cpp",
+ "__node_handle": "cpp",
+ "__nullptr": "cpp",
+ "__split_buffer": "cpp",
+ "__string": "cpp",
+ "__threading_support": "cpp",
+ "__tree": "cpp",
+ "__tuple": "cpp",
+ "ios": "cpp",
+ "locale": "cpp",
+ "stack": "cpp",
+ "*.include": "cpp",
+ "relic_core.h": "c"
+ },
+ "cSpell.words": [
+ "Ryzen"
+ ],
+ "C_Cpp.errorSquiggles": "Enabled",
+ "cmake.configureOnOpen": true
}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 535f178b..be6ce096 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -1,73 +1,230 @@
-{
- "version": "2.0.0",
- "tasks": [
- {
- "type" : "shell",
- "label" : "build_debug",
- "detail" : "Build Debug Bladebit",
- "command": "cmake",
-
- "args": [
- "--build", ".",
- "--target", "bladebit",
- "--config", "Debug",
- "-j", "24"
- ],
-
- "windows":{
- },
-
- "linux":{
- "problemMatcher": [ "$gcc" ]
- },
-
- "osx":{
- "problemMatcher": [ "$gcc" ]
- },
-
- "options": {
- "cwd": "${workspaceFolder}/build"
- },
-
- "group": {
- "kind": "build",
- "isDefault": true
- }
- }
-
- // Build Debug Develop
- ,{
- "type" : "shell",
- "label" : "build_dev_debug",
- "detail" : "Build Develop Debug",
- "command": "cmake",
-
- "args": [
- "--build", ".",
- "--target", "bladebit_dev",
- "--config", "Debug",
- "-j", "24"
- ],
-
- "windows":{
- },
-
- "linux":{
- "problemMatcher": [ "$gcc" ]
- },
-
- "osx":{
- "problemMatcher": [ "$gcc" ]
- },
-
- "options": {
- "cwd": "${workspaceFolder}/build"
- },
-
- "group": {
- "kind": "build",
- "isDefault": true
- }
- }
- ]
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "type" : "shell",
+ "label" : "build_debug",
+ "detail" : "Build Debug Bladebit",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--target", "bladebit",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "windows":{
+ },
+
+ "linux":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "osx":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ },
+
+ {
+ "type" : "shell",
+ "label" : "rebuild_debug",
+ "detail" : "Rebuild Debug Bladebit",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--clean-first",
+ "--target", "bladebit",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "windows":{
+ },
+
+ "linux":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "osx":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+
+ // Build Debug Develop
+ ,{
+ "type" : "shell",
+ "label" : "build_dev_debug",
+ "detail" : "Build Develop Debug",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--target", "bladebit_dev",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "windows":{
+ },
+
+ "linux":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "osx":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+
+ // Build Tests Debug
+ ,{
+ "type" : "shell",
+ "label" : "build_tests_debug",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--target", "tests",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "problemMatcher": [ "$gcc" ],
+
+ "windows":{
+ "problemMatcher":[ "$msCompile" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+
+ // Build Disk Debug
+ ,{
+ "type" : "shell",
+ "label" : "build_disk_debug",
+ "detail" : "Build Disk Debug",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--target", "bladebit_disk",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "windows":{
+ },
+
+ "linux":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "osx":{
+ "problemMatcher": [ "$gcc" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+
+ // Build plot_tool tool
+ ,{
+ "type" : "shell",
+ "label" : "build_plot_tool_debug",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--target", "plot_tool",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "problemMatcher": [ "$gcc" ],
+
+ "windows":{
+ "problemMatcher":[ "$msCompile" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+
+ // Build fsegen
+ ,{
+ "type" : "shell",
+ "label" : "build_fsegen_debug",
+ "command": "cmake",
+
+ "args": [
+ "--build", ".",
+ "--target", "fsegen",
+ "--config", "Debug",
+ "-j", "24"
+ ],
+
+ "problemMatcher": [ "$gcc" ],
+
+ "windows":{
+ "problemMatcher":[ "$msCompile" ]
+ },
+
+ "options": {
+ "cwd": "${workspaceFolder}/build"
+ },
+
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+ ]
}
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 517c4405..a8022376 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,322 +1,428 @@
-cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
-
-set(CMAKE_CXX_STANDARD 17)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-
-set(CMAKE_CONFIGURATION_TYPES Release Debug)
-
-if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE "Release"
- CACHE STRING "Possible values are: Release, Debug"
- FORCE
- )
-endif()
-message("Config: ${CMAKE_BUILD_TYPE}")
-
-project(bladebit)
-
-# On CI, update Version.h from our VERSION file
-# if(DEFINED ENV{CI})
-# message("Updating Version.h")
-# if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
-# execute_process(COMMAND bash.exe extract-version.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-# else()
-# execute_process(COMMAND bash extract-version.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
-# endif()
-# endif()
-
-
-
-set(CMAKE_MODULE_PATH
- ${CMAKE_MODULE_PATH}
- ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
-)
-
-# Grab BLS
-include(FetchContent)
-
-FetchContent_Declare(
- bls
- GIT_REPOSITORY https://github.com/Chia-Network/bls-signatures.git
- GIT_TAG 1.0.6
-)
-
-set(BUILD_BLS_PYTHON_BINDINGS "0" CACHE STRING "0")
-set(BUILD_BLS_TESTS "0" CACHE STRING "")
-set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "")
-FetchContent_MakeAvailable(bls)
-
-# Config
-set(CMAKE_C_FLAGS_RELEASE_INIT)
-set(CMAKE_C_FLAGS_DEBUG_INIT)
-set(CMAKE_CXX_FLAGS_RELEASE_INIT)
-set(CMAKE_CXX_FLAGS_DEBUG_INIT)
-
-
-set(c_opts)
-set(link_opts)
-
-set(release_c_opts)
-set(debug_c_opts)
-set(dev_c_opts)
-
-set(release_link_opts)
-set(debug_link_opts)
-
-if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
-
- # MSVC
- set(c_opts
- /std:c++17
- /Zc:__cplusplus
- /MP
- /Zi
- # /EHsc-
- # /Wall
- /W3
- /WX
- /FIpch.h
- /wd4068
- /wd4464
- /wd4668
- /wd4820
- /wd4514
- /wd4626
- /wd5027
- /DUNICODE=1
- /DWIN32_LEAN_AND_MEAN=1
- /DNOMINMAX=1
- /D_CRT_SECURE_NO_WARNINGS=1
- /D_HAS_EXCEPTIONS=0
- ${c_opts})
-
- set(link_opts
- /SUBSYSTEM:CONSOLE
- /STACK:33554432,1048576
- ${link_opts})
-
- set(release_c_opts
- /MT
- /Oi
- /O2
- /Gy
- /GL
- /DNDEBUG=1
- /D_NDEBUG=1
- ${release_c_opts})
-
- set(debug_c_opts
- /MTd
- /Od
- /DDEBUG=1
- /D_DEBUG=1
- ${debug_c_opts})
-
- set(dev_c_opts
- ${dev_c_opts})
-
-
- set(release_link_opts
- /DEBUG:FULL
- /LTCG
- /OPT:REF,ICF,LBR
- ${release_link_opts})
-
- set(debug_link_opts
- /DEBUG:FASTLINK
- /OPT:NOREF,NOICF,NOLBR
- /INCREMENTAL
- ${debug_link_opts})
-
- # Dependency config
- target_compile_options(bls PRIVATE /MP)
- target_compile_options(relic_s PRIVATE /MP)
- target_compile_options(sodium PRIVATE /MP)
-
- target_compile_options(bls PRIVATE $<$:/MT>)
- target_compile_options(relic_s PRIVATE $<$:/MT>)
- target_compile_options(sodium PRIVATE $<$:/MT>)
-
- target_compile_options(bls PRIVATE $<$:/MTd>)
- target_compile_options(relic_s PRIVATE $<$:/MTd>)
- target_compile_options(sodium PRIVATE $<$:/MTd>)
-
-else()
-
- # *Nix
- set(c_opts --include=pch.h -Wall -Wno-comment -Wno-unknown-pragmas -g ${c_opts})
-
- set(release_c_opts
- -O3 -flto
- -D_NDEBUG=1
- -DNDEBUG=1
- ${release_c_opts})
-
- set(debug_c_opts
- -O0
- -DDEBUG=1
- -D_DEBUG=1
- ${debug_c_opts})
-
- set(dev_c_opts
- ${dev_c_opts})
-
- # GCC
- if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
-
- set(c_opts -fmax-errors=5 ${c_opts})
-
- # Clang
- elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
-
- set(c_opts_FLAGS -ferror-limit=5 -fdeclspec -Wunknown-pragmas ${c_opts})
-
- endif()
-
-endif()
-
-
-# Main Sources
-file(GLOB_RECURSE bb_sources
- RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS
- LIST_DIRECTORIES false
- src/*.cpp
- src/*.c
-)
-
-# Headers
-file(GLOB_RECURSE bb_headers
- RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS
- LIST_DIRECTORIES false
- src/*.h
- src/*.hpp
- src/*.inl
-)
-
-# Configure dependent on config/platform/architecture
-list(FILTER bb_sources EXCLUDE REGEX "src/main\.cpp")
-list(FILTER bb_sources EXCLUDE REGEX "src/(test|platform)/.+")
-list(FILTER bb_sources EXCLUDE REGEX "src/b3/blake3_(avx|sse).+")
-
-# Architecture
-if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64")
-
- if(NOT MSVC)
-
- list(APPEND bb_sources
- src/b3/blake3_avx2_x86-64_unix.S
- src/b3/blake3_avx512_x86-64_unix.S
- src/b3/blake3_sse41_x86-64_unix.S
- )
-
- set_source_files_properties(
- src/b3/blake3_avx2_x86-64_unix.S
- src/b3/blake3_avx512_x86-64_unix.S
- src/b3/blake3_sse41_x86-64_unix.S
- PROPERTIES LANGUAGE C)
- else()
- list(APPEND bb_sources
- src/b3/blake3_avx2.c
- src/b3/blake3_avx512.c
- src/b3/blake3_sse41.c
- )
- # Disable blake3 convertion loss of data warnings
- set_source_files_properties(
- src/b3/blake3_avx2.c
- src/b3/blake3_avx512.c
- src/b3/blake3_sse41.c
- PROPERTIES COMPILE_FLAGS
- /wd4244
- )
- endif()
-
-elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
-else()
- message( FATAL_ERROR "Unsupported architecture '${CMAKE_HOST_SYSTEM_PROCESSOR}'" )
-endif()
-
-# OS
-if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
-
- file(GLOB_RECURSE src_linux RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS LIST_DIRECTORIES false
- src/platform/unix/*.cpp
- src/platform/linux/*.cpp
- )
- list(APPEND bb_sources ${src_linux})
-
-elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
-
- file(GLOB_RECURSE src_win RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS LIST_DIRECTORIES false
- src/platform/win32/*.cpp
- )
- list(APPEND bb_sources ${src_win})
-
-elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
-
- file(GLOB_RECURSE src_mac RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS LIST_DIRECTORIES false
- src/platform/unix/*.cpp
- src/platform/macos/*.cpp
- )
- list(APPEND bb_sources ${src_mac})
-
-else()
- message( FATAL_ERROR "Unsupported operating system '${CMAKE_SYSTEM_NAME}'" )
-endif()
-
-# Dev config?
-file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS LIST_DIRECTORIES false
- src/test/*.cpp
-)
-
-file(GLOB_RECURSE headers_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- CONFIGURE_DEPENDS LIST_DIRECTORIES false
- src/test/*.h
-)
-
-
-# Exe
-find_package(Threads REQUIRED)
-
-set(platform_libs)
-
-if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
- find_package(NUMA REQUIRED)
- set(platform_libs ${NUMA_LIBRARY} gmp)
-endif()
-
-set(bb_include_dirs
- ${INCLUDE_DIRECTORIES}
- ${CMAKE_CURRENT_SOURCE_DIR}/src
-)
-
-
-# BladeBit
-add_executable(bladebit src/main.cpp ${bb_sources} ${bb_headers})
-add_executable(bladebit_dev EXCLUDE_FROM_ALL src/test/test_main.cpp ${bb_sources} ${src_dev} ${bb_headers} ${headers_dev})
-
-macro(config_proj tgt)
-
- target_compile_options(${tgt} PRIVATE $<$:${c_opts} ${release_c_opts}>)
- target_compile_options(${tgt} PRIVATE $<$:${c_opts} ${debug_c_opts}>)
- target_link_options(${tgt} PRIVATE $<$:${link_opts} ${release_link_opts}>)
- target_link_options(${tgt} PRIVATE $<$:${link_opts} ${debug_link_opts}>)
-
- target_include_directories(${tgt} PRIVATE ${bb_include_dirs})
- target_link_libraries(${tgt} Threads::Threads bls ${platform_libs})
-endmacro()
-
-config_proj(bladebit)
-config_proj(bladebit_dev)
-
-
-# Pretty source view for IDE projects
-source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src
- FILES ${bb_sources} ${bb_headers} ${src_dev} ${headers_dev}
-)
-
+cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+set(CMAKE_CONFIGURATION_TYPES Release Debug)
+
+if(NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Release"
+ CACHE STRING "Possible values are: Release, Debug"
+ FORCE
+ )
+endif()
+
+set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "macOS minimum supported version.")
+set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "MSVC Runtime Library")
+
+project(bladebit C CXX ASM)
+
+message("Config : ${CMAKE_BUILD_TYPE}")
+message("Compiler : ${CMAKE_CXX_COMPILER_ID}")
+if(DEFINED ENV{CI})
+ message("CI build : true")
+else()
+ message("CI build : false")
+endif()
+
+set(CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules
+)
+
+
+#
+# Grab Dependencies
+#
+set(platform_libs)
+
+# BLS
+include(FetchContent)
+
+FetchContent_Declare(
+ bls
+ GIT_REPOSITORY https://github.com/Chia-Network/bls-signatures.git
+ GIT_TAG 1.0.10
+)
+
+set(BUILD_BLS_PYTHON_BINDINGS "0" CACHE STRING "0")
+set(BUILD_BLS_TESTS "0" CACHE STRING "")
+set(BUILD_BLS_BENCHMARKS "0" CACHE STRING "")
+FetchContent_MakeAvailable(bls)
+
+# Threads
+find_package(Threads REQUIRED)
+
+# NUMA
+if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+ find_package(NUMA REQUIRED)
+ set(platform_libs ${NUMA_LIBRARY})
+endif()
+
+# Catch
+# TODO: Add configuration var to disable this
+include(cmake_modules/FindCatch2.cmake)
+set_target_properties(Catch2 PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>")
+set_target_properties(Catch2WithMain PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>")
+
+
+# Config
+set(c_opts)
+set(link_opts)
+
+set(release_c_opts)
+set(debug_c_opts)
+set(dev_c_opts)
+
+set(release_link_opts)
+set(debug_link_opts)
+
+option(BENCHMARK_MODE "Enable benchmark mode for memplot. No final plot is written." OFF)
+if(BENCHMARK_MODE)
+ add_compile_definitions("BB_BENCHMARK_MODE=1")
+endif()
+
+option(ENABLE_DISK_METRICS "Enable I/O metrics for diskplot." OFF)
+if(ENABLE_DISK_METRICS)
+ add_compile_definitions("BB_IO_METRICS_ON=1")
+endif()
+
+# Embed version inline when in dev mode
+if((NOT DEFINED ENV{CI}) AND (NOT DEFINED CACHE{bb_version_embedded}))
+ message("Embedding local build version")
+
+ set(bb_version_embedded on CACHE BOOL "Version embedding has already happened.")
+
+ set(cmd_ver bash)
+ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+ set(cmd_ver bash.exe)
+ endif()
+
+ execute_process(COMMAND ${cmd_ver} extract-version.sh major OUTPUT_VARIABLE bb_ver_maj WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY)
+ execute_process(COMMAND ${cmd_ver} extract-version.sh minor OUTPUT_VARIABLE bb_ver_min WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY)
+ execute_process(COMMAND ${cmd_ver} extract-version.sh revision OUTPUT_VARIABLE bb_ver_rev WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY)
+ execute_process(COMMAND ${cmd_ver} extract-version.sh suffix OUTPUT_VARIABLE bb_ver_suffix WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY)
+ execute_process(COMMAND ${cmd_ver} extract-version.sh commit OUTPUT_VARIABLE bb_ver_commit WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_ERROR_IS_FATAL ANY)
+
+ # Remove trailing whitespace incurred in windows gitbash
+ string(STRIP "${bb_ver_maj}" bb_ver_maj)
+ string(STRIP "${bb_ver_min}" bb_ver_min)
+ string(STRIP "${bb_ver_rev}" bb_ver_rev)
+ string(STRIP "${bb_ver_suffix}" bb_ver_suffix)
+ string(STRIP "${bb_ver_commit}" bb_ver_commit)
+
+ set(bb_ver_suffix ${bb_ver_suffix}-dev)
+
+ # This is slow on windows, so let's cache them
+ set(bb_ver_maj ${bb_ver_maj} CACHE STRING "")
+ set(bb_ver_min ${bb_ver_min} CACHE STRING "")
+ set(bb_ver_rev ${bb_ver_rev} CACHE STRING "")
+ set(bb_ver_suffix ${bb_ver_suffix} CACHE STRING "")
+ set(bb_ver_commit ${bb_ver_commit} CACHE STRING "")
+endif()
+
+if(NOT DEFINED ENV{CI})
+ add_compile_definitions(BLADEBIT_VERSION_MAJ=${bb_ver_maj})
+ add_compile_definitions(BLADEBIT_VERSION_MIN=${bb_ver_min})
+ add_compile_definitions(BLADEBIT_VERSION_REV=${bb_ver_rev})
+ add_compile_definitions(BLADEBIT_VERSION_SUFFIX="${bb_ver_suffix}")
+ add_compile_definitions(BLADEBIT_GIT_COMMIT="${bb_ver_commit}")
+endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+
+ # MSVC
+ set(c_opts
+ /std:c++17
+ /Zc:__cplusplus
+ /MP
+ /Zi
+ # /EHsc-
+ # /Wall
+ /W3
+ /WX
+ /FIpch.h
+ /wd4068
+ /wd4464
+ /wd4668
+ /wd4820
+ /wd4514
+ /wd4626
+ /wd5027
+ /DUNICODE=1
+ /DWIN32_LEAN_AND_MEAN=1
+ /DNOMINMAX=1
+ /D_CRT_SECURE_NO_WARNINGS=1
+ /D_HAS_EXCEPTIONS=0
+ ${c_opts})
+
+ set(tests_c_opts /DBB_TEST_MODE=1 ${tests_c_opts})
+
+ set(link_opts
+ /SUBSYSTEM:CONSOLE
+ /STACK:33554432,1048576
+ ${link_opts})
+
+ set(release_c_opts
+ /Oi
+ /O2
+ /Gy
+ /GL
+ /DNDEBUG=1
+ /D_NDEBUG=1
+ ${release_c_opts})
+
+ set(debug_c_opts
+ /Od
+ /DDEBUG=1
+ /D_DEBUG=1
+ ${debug_c_opts})
+
+ set(dev_c_opts
+ ${dev_c_opts})
+
+
+ set(release_link_opts
+ /DEBUG:FULL
+ /LTCG
+ /OPT:REF,ICF,LBR
+ ${release_link_opts})
+
+ set(debug_link_opts
+# /DEBUG:FASTLINK
+ /OPT:NOREF,NOICF,NOLBR
+# /INCREMENTAL
+ ${debug_link_opts})
+
+ # Dependency config
+ target_compile_options(bls PRIVATE /MP)
+ target_compile_options(relic_s PRIVATE /MP)
+ target_compile_options(sodium PRIVATE /MP)
+
+ target_compile_options(bls PRIVATE $<$:/MT>)
+ target_compile_options(relic_s PRIVATE $<$:/MT>)
+ target_compile_options(sodium PRIVATE $<$:/MT>)
+
+ target_compile_options(bls PRIVATE $<$:/MTd>)
+ target_compile_options(relic_s PRIVATE $<$:/MTd>)
+ target_compile_options(sodium PRIVATE $<$:/MTd>)
+
+else()
+
+ # *Nix
+ set(c_opts --include=pch.h -Wall -Wno-comment -Wno-unknown-pragmas -g ${c_opts})
+
+ set(tests_c_opts -DBB_TEST_MODE=1 ${tests_c_opts})
+
+ set(release_c_opts
+ -O3 #-flto
+ -D_NDEBUG=1
+ -DNDEBUG=1
+ ${release_c_opts})
+
+ set(debug_c_opts
+ -O0
+ -DDEBUG=1
+ -D_DEBUG=1
+ ${debug_c_opts})
+
+ set(dev_c_opts
+ ${dev_c_opts})
+
+ set(link_opts -g -rdynamic #-flto
+ ${link_opts})
+
+ # GCC
+ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+
+ set(c_opts -fmax-errors=5 ${c_opts})
+
+ # Avoid ranlib error: plugin needed to handle lto objectR "gcc-ar")
+ # set(c_opts -ffat-lto-objects ${c_opts})
+
+ # Build with native architecture when not building release packages
+ if(NOT DEFINED ENV{CI})
+ set(c_opts -march=native ${c_opts})
+ endif()
+
+ # Clang
+ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+
+ set(c_opts -ferror-limit=5 -fdeclspec -Wno-empty-body ${c_opts})
+
+ endif()
+
+endif()
+
+#
+# Sources
+#
+file(GLOB_RECURSE bb_sources
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS
+ LIST_DIRECTORIES false
+ src/*.cpp
+ src/*.c
+)
+set(src_full ${bb_sources})
+
+# Headers
+file(GLOB_RECURSE bb_headers
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS
+ LIST_DIRECTORIES false
+ src/*.h
+ src/*.hpp
+ src/*.inl
+)
+
+# Ignore some sources
+list(FILTER bb_sources EXCLUDE REGEX "src/main\\.cpp")
+list(FILTER bb_sources EXCLUDE REGEX "src/tools/FSETableGenerator.cpp")
+list(FILTER bb_sources EXCLUDE REGEX "src/sandbox/.+")
+list(FILTER bb_sources EXCLUDE REGEX "src/platform/.+")
+list(FILTER bb_sources EXCLUDE REGEX "src/b3/blake3_(avx|sse).+")
+list(FILTER bb_sources EXCLUDE REGEX "src/uint128_t/.+")
+
+
+# Project-specific sources
+file(GLOB_RECURSE src_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS LIST_DIRECTORIES false
+ tests/*.cpp
+)
+
+file(GLOB_RECURSE src_dev RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS LIST_DIRECTORIES false
+ src/sandbox/*.cpp
+ src/sandbox/*.h
+)
+
+
+# Configure dependent on config/platform/architecture
+# Architecture
+if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64")
+
+ if(NOT MSVC)
+ list(APPEND bb_sources
+ src/b3/blake3_avx2_x86-64_unix.S
+ src/b3/blake3_avx512_x86-64_unix.S
+ src/b3/blake3_sse41_x86-64_unix.S
+ )
+ else()
+ list(APPEND bb_sources
+ src/b3/blake3_avx2.c
+ src/b3/blake3_avx512.c
+ src/b3/blake3_sse41.c
+ src/uint128_t/uint128_t.cpp
+ )
+ # Disable blake3 conversion loss of data warnings
+ set_source_files_properties(
+ src/b3/blake3_avx2.c
+ src/b3/blake3_avx512.c
+ src/b3/blake3_sse41.c
+ PROPERTIES COMPILE_FLAGS
+ /wd4244
+ )
+ endif()
+
+elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64" OR ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
+else()
+ message( FATAL_ERROR "Unsupported architecture '${CMAKE_HOST_SYSTEM_PROCESSOR}'" )
+endif()
+
+# OS
+if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+
+ file(GLOB_RECURSE src_linux RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS LIST_DIRECTORIES false
+ src/platform/unix/*.cpp
+ src/platform/linux/*.cpp
+ )
+ list(APPEND bb_sources ${src_linux})
+
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+
+ file(GLOB_RECURSE src_win RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS LIST_DIRECTORIES false
+ src/platform/win32/*.cpp
+ )
+ list(APPEND bb_sources ${src_win})
+
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+
+ file(GLOB_RECURSE src_mac RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ CONFIGURE_DEPENDS LIST_DIRECTORIES false
+ src/platform/unix/*.cpp
+ src/platform/macos/*.cpp
+ )
+ list(APPEND bb_sources ${src_mac})
+
+else()
+ message( FATAL_ERROR "Unsupported operating system '${CMAKE_SYSTEM_NAME}'" )
+endif()
+
+
+#
+# Targets
+#
+set(bb_include_dirs
+ ${INCLUDE_DIRECTORIES}
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+)
+
+# macro(config_proj tgt)
+# message("Configuring target ${tgt}:${CMAKE_BUILD_TYPE}.")
+# target_compile_options(${tgt} PRIVATE $<$:${c_opts} ${release_c_opts}>)
+# target_compile_options(${tgt} PRIVATE $<$:${c_opts} ${debug_c_opts}>)
+# target_link_options(${tgt} PRIVATE $<$:${link_opts} ${release_link_opts}>)
+# target_link_options(${tgt} PRIVATE $<$:${link_opts} ${debug_link_opts}>)
+
+# target_include_directories(${tgt} PRIVATE ${bb_include_dirs})
+# endmacro()
+
+# BladeBit
+add_library(lib_bladebit ${bb_sources} ${bb_headers} src/plotdisk/k32/FpMatchBounded.inl src/plotdisk/k32/F1Bounded.inl)
+
+set_target_properties(lib_bladebit PROPERTIES
+ OUTPUT_NAME bladebit
+ MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>"
+)
+target_link_libraries(lib_bladebit PUBLIC Threads::Threads bls ${platform_libs})
+target_include_directories(lib_bladebit PUBLIC ${bb_include_dirs})
+
+target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${release_c_opts}>)
+target_compile_options(lib_bladebit PUBLIC $<$:${c_opts} ${debug_c_opts}>)
+target_link_options(lib_bladebit PUBLIC $<$:${link_opts} ${release_link_opts}>)
+target_link_options(lib_bladebit PUBLIC $<$:${link_opts} ${debug_link_opts}>)
+
+add_executable(bladebit ${bb_headers} src/main.cpp src/plotdisk/k32/FxBounded.inl)
+target_link_libraries(bladebit PRIVATE lib_bladebit)
+
+add_executable(bladebit_dev EXCLUDE_FROM_ALL src/sandbox/sandbox_main.cpp ${src_dev} ${bb_headers})
+target_link_libraries(bladebit_dev PRIVATE lib_bladebit)
+
+# Tools
+add_executable(fsegen src/tools/FSETableGenerator.cpp ${bb_sources} ${bb_headers})
+target_link_libraries(fsegen PRIVATE lib_bladebit)
+
+# add_executable(plot_tool
+# src/tools/PlotTools_Main.cpp
+# src/tools/PlotReader.cpp
+# src/tools/PlotValidator.cpp
+# src/tools/PlotComparer.cpp
+# ${bb_headers}
+# )
+# target_link_libraries(plot_tool PRIVATE lib_bladebit)
+
+# Tests
+add_executable(tests ${src_tests} ${bb_headers})
+target_compile_options(tests PUBLIC $<$:${c_opts} ${release_c_opts} ${tests_c_opts}>)
+target_compile_options(tests PUBLIC $<$:${c_opts} ${debug_c_opts} ${tests_c_opts}>)
+set_target_properties(tests PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>")
+target_link_libraries(tests PRIVATE lib_bladebit Catch2::Catch2WithMain)
+
+# Pretty source view for IDE projects
+source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src
+ FILES ${src_full} ${bb_headers}
+)
+
diff --git a/CMakeSettings.json b/CMakeSettings.json
new file mode 100644
index 00000000..fb51b4bc
--- /dev/null
+++ b/CMakeSettings.json
@@ -0,0 +1,24 @@
+{
+ "configurations": [
+ {
+ "name": "x64-Debug",
+ "generator": "Ninja",
+ "configurationType": "Debug",
+ "inheritEnvironments": [ "msvc_x64_x64" ],
+ "buildRoot": "${projectDir}\\out\\build\\${name}",
+ "installRoot": "${projectDir}\\out\\install\\${name}",
+ "ctestCommandArgs": ""
+ },
+ {
+ "name": "MemTest",
+ "generator": "Ninja",
+ "configurationType": "Debug",
+ "buildRoot": "${projectDir}\\out\\build\\${name}",
+ "installRoot": "${projectDir}\\out\\install\\${name}",
+ "cmakeCommandArgs": "",
+ "buildCommandArgs": "",
+ "ctestCommandArgs": "",
+ "inheritEnvironments": [ "msvc_x64_x64" ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 1f11ebce..6bbf859d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,201 +1,201 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright 2021 Harold Brenes, Chia Network Inc
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2021 Harold Brenes, Chia Network Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
diff --git a/NOTICE b/NOTICE
index 6d3c00df..2e0e2ee5 100644
--- a/NOTICE
+++ b/NOTICE
@@ -1,738 +1,738 @@
-Chiapos
-https://github.com/Chia-Network/chiapos
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
-BLS Signatures Library
-https://github.com/Chia-Network/bls-signatures
-
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
-Libsodium license
- The libsodium static library is licensed under the ISC license which requires the following copyright notice.
-
-ISC License
-
- Copyright (c) 2013-2020 Frank Denis
-
- Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-GMP license
- GMP is distributed under the GNU LGPL v3 license
-
-Relic license
- Relic is used with the Apache 2.0 license
-
-
-BLAKE3
-https://github.com/BLAKE3-team/BLAKE3
-
- This work is released into the public domain with CC0 1.0. Alternatively, it is
- licensed under the Apache License 2.0.
-
- -------------------------------------------------------------------------------
-
- Creative Commons Legal Code
-
- CC0 1.0 Universal
-
- CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
- LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
- ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
- INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
- REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
- PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
- THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
- HEREUNDER.
-
- Statement of Purpose
-
- The laws of most jurisdictions throughout the world automatically confer
- exclusive Copyright and Related Rights (defined below) upon the creator
- and subsequent owner(s) (each and all, an "owner") of an original work of
- authorship and/or a database (each, a "Work").
-
- Certain owners wish to permanently relinquish those rights to a Work for
- the purpose of contributing to a commons of creative, cultural and
- scientific works ("Commons") that the public can reliably and without fear
- of later claims of infringement build upon, modify, incorporate in other
- works, reuse and redistribute as freely as possible in any form whatsoever
- and for any purposes, including without limitation commercial purposes.
- These owners may contribute to the Commons to promote the ideal of a free
- culture and the further production of creative, cultural and scientific
- works, or to gain reputation or greater distribution for their Work in
- part through the use and efforts of others.
-
- For these and/or other purposes and motivations, and without any
- expectation of additional consideration or compensation, the person
- associating CC0 with a Work (the "Affirmer"), to the extent that he or she
- is an owner of Copyright and Related Rights in the Work, voluntarily
- elects to apply CC0 to the Work and publicly distribute the Work under its
- terms, with knowledge of his or her Copyright and Related Rights in the
- Work and the meaning and intended legal effect of CC0 on those rights.
-
- 1. Copyright and Related Rights. A Work made available under CC0 may be
- protected by copyright and related or neighboring rights ("Copyright and
- Related Rights"). Copyright and Related Rights include, but are not
- limited to, the following:
-
- i. the right to reproduce, adapt, distribute, perform, display,
- communicate, and translate a Work;
- ii. moral rights retained by the original author(s) and/or performer(s);
- iii. publicity and privacy rights pertaining to a person's image or
- likeness depicted in a Work;
- iv. rights protecting against unfair competition in regards to a Work,
- subject to the limitations in paragraph 4(a), below;
- v. rights protecting the extraction, dissemination, use and reuse of data
- in a Work;
- vi. database rights (such as those arising under Directive 96/9/EC of the
- European Parliament and of the Council of 11 March 1996 on the legal
- protection of databases, and under any national implementation
- thereof, including any amended or successor version of such
- directive); and
- vii. other similar, equivalent or corresponding rights throughout the
- world based on applicable law or treaty, and any national
- implementations thereof.
-
- 2. Waiver. To the greatest extent permitted by, but not in contravention
- of, applicable law, Affirmer hereby overtly, fully, permanently,
- irrevocably and unconditionally waives, abandons, and surrenders all of
- Affirmer's Copyright and Related Rights and associated claims and causes
- of action, whether now known or unknown (including existing as well as
- future claims and causes of action), in the Work (i) in all territories
- worldwide, (ii) for the maximum duration provided by applicable law or
- treaty (including future time extensions), (iii) in any current or future
- medium and for any number of copies, and (iv) for any purpose whatsoever,
- including without limitation commercial, advertising or promotional
- purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
- member of the public at large and to the detriment of Affirmer's heirs and
- successors, fully intending that such Waiver shall not be subject to
- revocation, rescission, cancellation, termination, or any other legal or
- equitable action to disrupt the quiet enjoyment of the Work by the public
- as contemplated by Affirmer's express Statement of Purpose.
-
- 3. Public License Fallback. Should any part of the Waiver for any reason
- be judged legally invalid or ineffective under applicable law, then the
- Waiver shall be preserved to the maximum extent permitted taking into
- account Affirmer's express Statement of Purpose. In addition, to the
- extent the Waiver is so judged Affirmer hereby grants to each affected
- person a royalty-free, non transferable, non sublicensable, non exclusive,
- irrevocable and unconditional license to exercise Affirmer's Copyright and
- Related Rights in the Work (i) in all territories worldwide, (ii) for the
- maximum duration provided by applicable law or treaty (including future
- time extensions), (iii) in any current or future medium and for any number
- of copies, and (iv) for any purpose whatsoever, including without
- limitation commercial, advertising or promotional purposes (the
- "License"). The License shall be deemed effective as of the date CC0 was
- applied by Affirmer to the Work. Should any part of the License for any
- reason be judged legally invalid or ineffective under applicable law, such
- partial invalidity or ineffectiveness shall not invalidate the remainder
- of the License, and in such case Affirmer hereby affirms that he or she
- will not (i) exercise any of his or her remaining Copyright and Related
- Rights in the Work or (ii) assert any associated claims and causes of
- action with respect to the Work, in either case contrary to Affirmer's
- express Statement of Purpose.
-
- 4. Limitations and Disclaimers.
-
- a. No trademark or patent rights held by Affirmer are waived, abandoned,
- surrendered, licensed or otherwise affected by this document.
- b. Affirmer offers the Work as-is and makes no representations or
- warranties of any kind concerning the Work, express, implied,
- statutory or otherwise, including without limitation warranties of
- title, merchantability, fitness for a particular purpose, non
- infringement, or the absence of latent or other defects, accuracy, or
- the present or absence of errors, whether or not discoverable, all to
- the greatest extent permissible under applicable law.
- c. Affirmer disclaims responsibility for clearing rights of other persons
- that may apply to the Work or any use thereof, including without
- limitation any person's Copyright and Related Rights in the Work.
- Further, Affirmer disclaims responsibility for obtaining any necessary
- consents, permissions or other rights required for any use of the
- Work.
- d. Affirmer understands and acknowledges that Creative Commons is not a
- party to this document and has no duty or obligation with respect to
- this CC0 or use of the Work.
-
- -------------------------------------------------------------------------------
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright 2019 Jack O'Connor and Samuel Neves
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
+Chiapos
+https://github.com/Chia-Network/chiapos
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+BLS Signatures Library
+https://github.com/Chia-Network/bls-signatures
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+Libsodium license
+ The libsodium static library is licensed under the ISC license which requires the following copyright notice.
+
+ISC License
+
+ Copyright (c) 2013-2020 Frank Denis
+
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+GMP license
+ GMP is distributed under the GNU LGPL v3 license
+
+Relic license
+ Relic is used with the Apache 2.0 license
+
+
+BLAKE3
+https://github.com/BLAKE3-team/BLAKE3
+
+ This work is released into the public domain with CC0 1.0. Alternatively, it is
+ licensed under the Apache License 2.0.
+
+ -------------------------------------------------------------------------------
+
+ Creative Commons Legal Code
+
+ CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+ Statement of Purpose
+
+ The laws of most jurisdictions throughout the world automatically confer
+ exclusive Copyright and Related Rights (defined below) upon the creator
+ and subsequent owner(s) (each and all, an "owner") of an original work of
+ authorship and/or a database (each, a "Work").
+
+ Certain owners wish to permanently relinquish those rights to a Work for
+ the purpose of contributing to a commons of creative, cultural and
+ scientific works ("Commons") that the public can reliably and without fear
+ of later claims of infringement build upon, modify, incorporate in other
+ works, reuse and redistribute as freely as possible in any form whatsoever
+ and for any purposes, including without limitation commercial purposes.
+ These owners may contribute to the Commons to promote the ideal of a free
+ culture and the further production of creative, cultural and scientific
+ works, or to gain reputation or greater distribution for their Work in
+ part through the use and efforts of others.
+
+ For these and/or other purposes and motivations, and without any
+ expectation of additional consideration or compensation, the person
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+ is an owner of Copyright and Related Rights in the Work, voluntarily
+ elects to apply CC0 to the Work and publicly distribute the Work under its
+ terms, with knowledge of his or her Copyright and Related Rights in the
+ Work and the meaning and intended legal effect of CC0 on those rights.
+
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
+ protected by copyright and related or neighboring rights ("Copyright and
+ Related Rights"). Copyright and Related Rights include, but are not
+ limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+ iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+ vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
+ irrevocably and unconditionally waives, abandons, and surrenders all of
+ Affirmer's Copyright and Related Rights and associated claims and causes
+ of action, whether now known or unknown (including existing as well as
+ future claims and causes of action), in the Work (i) in all territories
+ worldwide, (ii) for the maximum duration provided by applicable law or
+ treaty (including future time extensions), (iii) in any current or future
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
+ including without limitation commercial, advertising or promotional
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+ member of the public at large and to the detriment of Affirmer's heirs and
+ successors, fully intending that such Waiver shall not be subject to
+ revocation, rescission, cancellation, termination, or any other legal or
+ equitable action to disrupt the quiet enjoyment of the Work by the public
+ as contemplated by Affirmer's express Statement of Purpose.
+
+ 3. Public License Fallback. Should any part of the Waiver for any reason
+ be judged legally invalid or ineffective under applicable law, then the
+ Waiver shall be preserved to the maximum extent permitted taking into
+ account Affirmer's express Statement of Purpose. In addition, to the
+ extent the Waiver is so judged Affirmer hereby grants to each affected
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
+ maximum duration provided by applicable law or treaty (including future
+ time extensions), (iii) in any current or future medium and for any number
+ of copies, and (iv) for any purpose whatsoever, including without
+ limitation commercial, advertising or promotional purposes (the
+ "License"). The License shall be deemed effective as of the date CC0 was
+ applied by Affirmer to the Work. Should any part of the License for any
+ reason be judged legally invalid or ineffective under applicable law, such
+ partial invalidity or ineffectiveness shall not invalidate the remainder
+ of the License, and in such case Affirmer hereby affirms that he or she
+ will not (i) exercise any of his or her remaining Copyright and Related
+ Rights in the Work or (ii) assert any associated claims and causes of
+ action with respect to the Work, in either case contrary to Affirmer's
+ express Statement of Purpose.
+
+ 4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
+
+ -------------------------------------------------------------------------------
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2019 Jack O'Connor and Samuel Neves
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
index 0912251a..6d9c8337 100644
--- a/README.md
+++ b/README.md
@@ -2,21 +2,35 @@
[![Release Builds](https://github.com/Chia-Network/bladebit/actions/workflows/build-release.yml/badge.svg?branch=master&event=push)](https://github.com/Chia-Network/bladebit/actions/workflows/build-release.yml)
-A fast **RAM-only**, **k32-only**, Chia plotter.
+A high-performance **k32-only**, Chia (XCH) plotter supporting in-RAM and disk-based plotting.
## Requirements
-**416 GiB of RAM are required** to run it, plus a few more megabytes for stack space and small allocations.
+
+### In-RAM
+**416 GiB of RAM are required** to run it, and a few more megabytes for stack space and small allocations.
64-bit is supported only, for obvious reasons.
+
+### Disk-based
+A minimum of **4 GiB of RAM** is required, with lower bucket counts requiring up to 12 GiB of RAM.
+
+Around **480 GiB** of total temporary space is required when plotting to disk in the default mode, or around 390 GiB with `--alternate` mode enabled.
+
+The exact amounts of RAM and disk space required may vary slightly depending on the system's page size and the target disk file system block size (block-alignment is required for direct I/O).
+
+SSDs are highly recommended for disk-based plotting.
+
+
## Prerequisites
-Only **Linux** & **Windows** are supported.
+Linux, Windows and MacOS (both intel and ARM (Apple Silicon)) are supported.
+
### Linux
Install the following packages:
```bash
-# CentOS or Amazon Linux
+# CentOS or RHEL-based
sudo yum group install -y "Development Tools"
sudo yum install -y cmake gmp-devel numactl-devel
@@ -25,19 +39,25 @@ sudo apt install -y build-essential cmake libgmp-dev libnuma-dev
```
### Windows
-Must have [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) or its build tools installed.
+Must have at least [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) or its build tools installed.
-## Building
+### macOS
+Must have Xcode or Xcode build tools installed.
+`brew install cmake`
+
+Optionally install `gmp`:
+`brew install gmp`
+## Building
+
```bash
# Clone the repo & its submodules
git clone https://github.com/Chia-Network/bladebit.git && cd bladebit
# Create a build directory for cmake and cd into it
-mkdir build
-cd build
+mkdir -p build && cd build
# Generate config files & build
cmake ..
@@ -51,7 +71,7 @@ On Windows it will be under `build/Release/`.
Run **bladebit** with the `-h` for complete usage and command line options:
```bash
-# Linux
+# Linux & macOS
build/bladebit -h
# Windows
@@ -59,29 +79,50 @@ build/Release/bladebit.exe -h
```
-## License
-Licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0). See [LICENSE](LICENSE).
+The bladebit CLI uses the format `bladebit `.
+
+Use the aforementioned `-h` parameter to get the full list of sub-commands and `GLOBAL_OPTIONS`.
+The `sub_command`-specific `COMMAND_OPTIONS` can be obtained by using the `help` sub command with the desired command as the parameter:
+
+```bash
+bladebit help ramplot
+bladebit help diskplot
+```
+
+### In-RAM
+Basic `ramplot` usage:
+```bash
+# OG plots
+./bladebit -f -p ramplot
+# Portable plots
+./bladebit -f -c ramplot
+```
-# Other Details
+### Disk-Based
+Basic `diskplot` usage:
+```bash
-## Disk I/O
-Writes to disk only occur to the final plot file, and it is done sequentially, un-buffered, with direct I/O. This means that writes will be block-aligned. If you've gotten faster writes elsewhere in your drive than you will get with this, it is likely that it is using buffered writes, therefore it "finishes" before it actually finishes writing to disk. The kernel will handle the I/O in the background from cache (you can confirm this with tools such as iotop). The final writes here ought to pretty much saturate your sequential writes. Writes begin happening in the background at Phase 3 and will continue to do so, depending on the disk I/O throughput, through the next plot, if it did not finish beforehand. At some point in Phase 1 of the next plot, it might stall if it still has not finished writing to disk and a buffer it requires is still being written to disk. On the system I tested, there was no interruption when using an NVMe drive.
+# OG plots
+./bladebit -f -p diskplot -t1
+# Portable plots
+./bladebit -f -c diskplot -t1
-## Pool Plots
-Pool plots are fully supported and tested against the chia-blockchain implementation. The community has also verified that pool plots are working properly and winning proofs with them.
+# Differing temp directories:
+./bladebit -f ... -c ... diskplot -t1 /path/to/temp_1 -t2 /path/to/temp2 /my/output/dir
-## NUMA systems
-Memory is bound on interleaved mode for NUMA systems which currently gives the best performance on systems with several nodes. This is the default behavior on NUMA systems, it can be disabled with with the `-m or --no-numa` switch.
+# With a 100 GiB temp2 cache and alternating mode
+./bladebit -f ... -c ... diskplot -a --cache 100G -t1 /path/to/temp_1 -t2 /path/to/temp2 /my/output/dir
+# With fine-grained thread control depending on the workload
+./bladebit -f ... -c ... diskplot --f1-threads 12 --fp-threads 32 -t1 /path/to/temp_1 /my/output/dir
+```
-## Huge TLBs
-This is not supported yet. Some folks have reported some gains when using huge page sizes. Although this was something I wanted to test, I focused first instead on things that did not necessarily depended on system config. But I'd like to add support for it in the future (trivial from the development point of view, I have just not configured the test system with huge page sizes).
-## Other Observations
-This implementation is highly memory-bound so optimizing your system towards fast memory access is essential. CPUs with large caches will benefit as well.
+## License
+Licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0). See [LICENSE](LICENSE).
-Copyright 2021 Harold Brenes, Chia Network Inc
+Copyright 2022 Harold Brenes, Chia Network Inc
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 00000000..6c40593a
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,18 @@
+# Current Bladebit Disk Beta TODOS
+
+- [x] Fix compiler issues that popped up on macOS/clang after eliminating wrnings on Linux & Windows.
+- [] Fix 128 buckets bug (linepoints are not serialized incorrectly)
+- [x] Fix 1024 buckets bug (crashes on P1 T4, probably related to below large block crash)
+- [] Fix 1024 buckets bug on P3
+- [] Fix crash on P1 T4 w/ RAID, which actually seems to be w/ big block sizes. (I believe this is due to not rounding up some buffers to block sizes. There's anote about this in fp code.)
+- [x] Add no-direct-io flag for both tmp dirs
+- [x] Add no-direct-io flag for final plot
+- [] Perhaps add a different queue for t2 if it's a different physical disk
+- [-] Add k32 bounded/non-overflowing version
+- [] Add synchronos tmp IO (good with cache)
+- [x] Add interleaved-only writing method for bigger write chunks/more sequential I/O.
+ - [] Integrate this into other phases
+- [x] Add method to reduce cache requirements to 96G instead of 192G
+ - [] Integrate cache reduction into the plotting process
+- [] Bring in avx256 linepoint conversion (already implemented in an old BB branch)
+- [] Allow sub temp directories or plot-speific file temp file names (allows for concurrent plotting).
diff --git a/VERSION b/VERSION
index b966e81a..227cea21 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.4
\ No newline at end of file
+2.0.0
diff --git a/bladebit.natvis b/bladebit.natvis
index a0cb31fd..1a670f01 100644
--- a/bladebit.natvis
+++ b/bladebit.natvis
@@ -1,13 +1,45 @@
-
-
-
-
- [{length}]
-
-
- length
- values[$i]
-
-
-
+
+
+
+
+ [{length}]
+
+
+ length
+ values[$i]
+
+
+
+
+
+ {{empty}}
+ [{_length} / {_capacity}] {{ {_elements[0]} }}
+ [{_length} / {_capacity}] {{ {_elements[0]}, {_elements[1]} }}
+ [{_length} / {_capacity}] {{ {_elements[0]}, {_elements[1]}, {_elements[2]} }}
+ [{_length} / {_capacity}] {{ {_elements[0]}, {_elements[1]}, {_elements[2]}, {_elements[3]} }}
+ [{_length} / {_capacity}] {{ {_elements[0]}, {_elements[1]}, {_elements[2]}, {_elements[3]}, {_elements[4]} }}
+ [{_length} / {_capacity}] {{ {_elements[0]}, {_elements[1]}, {_elements[2]}, {_elements[3]}, {_elements[4]}, ... }}
+
+
+
+ _length
+ _elements[$i]
+
+
+
+
+
+ [Address: {(void*)address} Size: {size}]
+
+
+ {(void*)address} ( {(uintptr_t)address} )
+
+
+ {(void*)(address + size)} ( {(uintptr_t)(address + size)} )
+
+ size
+
+
+
+
\ No newline at end of file
diff --git a/build.sh b/build.sh
new file mode 100755
index 00000000..e0a8744f
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+set -e
+_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
+cd $_dir
+
+build_dir=build-release
+mkdir -p ${build_dir}
+cd ${build_dir}
+
+cmake .. -DCMAKE_BUILD_TYPE=Release
+cmake --build . --target clean --config Release
+cmake --build . --target bladebit --config Release -j32
diff --git a/cmake_modules/FindCatch2.cmake b/cmake_modules/FindCatch2.cmake
new file mode 100644
index 00000000..ddced5a8
--- /dev/null
+++ b/cmake_modules/FindCatch2.cmake
@@ -0,0 +1,9 @@
+Include(FetchContent)
+
+FetchContent_Declare(
+ Catch2
+ GIT_REPOSITORY https://github.com/catchorg/Catch2.git
+ GIT_TAG v3.0.0-preview4
+)
+
+FetchContent_MakeAvailable(Catch2)
diff --git a/cmake_modules/FindNUMA.cmake b/cmake_modules/FindNUMA.cmake
index c5d288ba..741fa8db 100644
--- a/cmake_modules/FindNUMA.cmake
+++ b/cmake_modules/FindNUMA.cmake
@@ -1,24 +1,24 @@
-# Find libnuma
-#
-# NUMA_FOUND : True if libnuma was found
-# NUMA_INCLUDE_DIR : Where to find numa.h & numaif.h
-# NUMA_LIBRARY : Library to link
-
-include(FindPackageHandleStandardArgs)
-
-find_path(NUMA_INCLUDE_DIR
- NAMES numa.h numaif.h
- HINTS ${INCLUDE_INSTALL_DIR})
-
-find_library(NUMA_LIBRARY
- NAMES numa
- HINTS ${LIB_INSTALL_DIR})
-
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(NUMA
- REQUIRED_VARS NUMA_INCLUDE_DIR NUMA_LIBRARY)
-
-mark_as_advanced(
- NUMA_INCLUDE_DIR
+# Find libnuma
+#
+# NUMA_FOUND : True if libnuma was found
+# NUMA_INCLUDE_DIR : Where to find numa.h & numaif.h
+# NUMA_LIBRARY : Library to link
+
+include(FindPackageHandleStandardArgs)
+
+find_path(NUMA_INCLUDE_DIR
+ NAMES numa.h numaif.h
+ HINTS ${INCLUDE_INSTALL_DIR})
+
+find_library(NUMA_LIBRARY
+ NAMES numa
+ HINTS ${LIB_INSTALL_DIR})
+
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(NUMA
+ REQUIRED_VARS NUMA_INCLUDE_DIR NUMA_LIBRARY)
+
+mark_as_advanced(
+ NUMA_INCLUDE_DIR
NUMA_LIBRARY)
\ No newline at end of file
diff --git a/embed-version.sh b/embed-version.sh
new file mode 100755
index 00000000..f9c8d834
--- /dev/null
+++ b/embed-version.sh
@@ -0,0 +1,28 @@
+#! /usr/bin/env bash
+set -eo pipefail
+cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
+
+# version=($(./extract-version.sh))
+. ./extract-version.sh
+
+ver_maj=$bb_ver_maj
+ver_min=$bb_ver_min
+ver_rev=$bb_ver_rev
+ver_suffix=$bb_version_suffix
+git_commit=$bb_git_commit
+
+echo "Version: $ver_maj.$ver_min.$ver_rev$ver_suffix"
+echo "Commit : $git_commit"
+
+sed_inline=
+if [[ $OSTYPE == 'darwin'* ]]; then
+ sed_inline="\'\'"
+fi
+
+version_header='src/Version.h'
+sed -i ${sed_inline} -E -r "s/([[:space:]]*#define[[:space:]]+BLADEBIT_VERSION_MAJ[[:space:]]+)([0-9]+)/\1$ver_maj/g" $version_header
+sed -i ${sed_inline} -E -r "s/([[:space:]]*#define[[:space:]]+BLADEBIT_VERSION_MIN[[:space:]]+)([0-9]+)/\1$ver_min/g" $version_header
+sed -i ${sed_inline} -E -r "s/([[:space:]]*#define[[:space:]]+BLADEBIT_VERSION_REV[[:space:]]+)([0-9]+)/\1$ver_rev/g" $version_header
+sed -i ${sed_inline} -E -r "s/([[:space:]]*#define[[:space:]]+BLADEBIT_VERSION_SUFFIX[[:space:]]+)(\".*\")/\1\"$ver_suffix\"/g" $version_header
+sed -i ${sed_inline} -E -r "s/([[:space:]]*#define[[:space:]]+BLADEBIT_GIT_COMMIT[[:space:]]+)(\".*\")/\1\"$git_commit\"/g" $version_header
+
diff --git a/extract-version.sh b/extract-version.sh
old mode 100644
new mode 100755
index 11c8ca3c..5797c556
--- a/extract-version.sh
+++ b/extract-version.sh
@@ -1,33 +1,76 @@
#! /usr/bin/env bash
-set -e
-set -o pipefail
+set -eo pipefail
_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
cd $_dir
-set IFS=
+# Arguments
+ver_component=$1 # The user specified a specified component from the full verison.
+ # See the case switch below.
-version_str=$(cat VERSION | xargs)
+# Grab version specified in the file
+_IFS=IFS
+IFS=
+version_str=$(cat VERSION | head -n 1 | xargs)
+bb_version_suffix=$(cat VERSION | tail -n 1 | xargs)
version_header='src/Version.h'
+IFS=$_IFS
-ver_maj=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/' | xargs)
-ver_min=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\2/' | xargs)
-ver_rev=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\3/' | xargs)
+if [[ "$version_str" == "$bb_version_suffix" ]]; then
+ bb_version_suffix=
+fi
+
+bb_ver_maj=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/' | xargs)
+bb_ver_min=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\2/' | xargs)
+bb_ver_rev=$(printf $version_str | sed -E -r 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\3/' | xargs)
-set +e
-git_commit=$(git rev-parse HEAD)
-set -e
-if [[ -z $git_commit ]]; then
- git_commit=$GITHUB_SHA
+bb_git_commit=$GITHUB_SHA
+if [[ -z $bb_git_commit ]]; then
+ set +e
+ bb_git_commit=$(git rev-parse HEAD)
+ set -e
fi
-if [[ -z $git_commit ]]; then
- git_commit="unknown"
+if [[ -z $bb_git_commit ]]; then
+ bb_git_commit="unknown"
fi
-echo "Version: $ver_maj.$ver_min.$ver_rev-$git_commit"
+# Check if the user wants a specific component
+if [[ -n $ver_component ]]; then
+
+ case "$ver_component" in
+
+ "major")
+ echo -n $bb_ver_maj
+ ;;
+
+ "minor")
+ echo -n $bb_ver_min
+ ;;
+
+ "revision")
+ echo -n $bb_ver_rev
+ ;;
+
+ "suffix")
+ echo -n $bb_version_suffix
+ ;;
+
+ "commit")
+ echo -n $bb_git_commit
+ ;;
+
+ *)
+ >&2 echo "Invalid version component '${ver_component}'"
+ exit 1
+ ;;
+ esac
+ exit 0
+fi
-sed -i -E -r "s/(#define BLADEBIT_VERSION_MAJ )([0-9]+)/\1$ver_maj/g" $version_header
-sed -i -E -r "s/(#define BLADEBIT_VERSION_MIN )([0-9]+)/\1$ver_min/g" $version_header
-sed -i -E -r "s/(#define BLADEBIT_VERSION_REV )([0-9]+)/\1$ver_rev/g" $version_header
-sed -i -E -r "s/(#define BLADEBIT_GIT_COMMIT )(.+)/\1\"$git_commit\"/g" $version_header
+# Emit all version components
+# echo "$bb_ver_maj"
+# echo "$bb_ver_min"
+# echo "$bb_ver_rev"
+# echo "$bb_version_suffix"
+# echo "$bb_git_commit"
diff --git a/src/ChiaConsts.h b/src/ChiaConsts.h
index ee8006e9..e5ef6ece 100644
--- a/src/ChiaConsts.h
+++ b/src/ChiaConsts.h
@@ -1,143 +1,165 @@
-#pragma once
-#include "Util.h"
-
-// Hard-coded k to 32
-#define _K 32
-#define ENTRIES_PER_TABLE ( 1ull << _K )
-
-enum class TableId
-{
- Table1 = 0,
- Table2 = 1,
- Table3 = 2,
- Table4 = 3,
- Table5 = 4,
- Table6 = 5,
- Table7 = 6
-
- ,_Count
-};
-
-///
-/// These are extracted from chiapos.
-/// Comments are taken directly from chiapos unless otherwise specified.
-///
-
-// F1 evaluations are done in batches of 2^kBatchSizes
-#define kBatchSizes 8
-
-// ChaCha8 block size
-#define kF1BlockSizeBits 512
-
-// Extra bits of output from the f functions. Instead of being a function from k -> k bits,
-// it's a function from k -> k + kExtraBits bits. This allows less collisions in matches.
-// Refer to the paper for mathematical motivations.
-#define kExtraBits 6
-
-// Convenience variable
-#define kExtraBitsPow (1 << kExtraBits)
-
-// B and C groups which constitute a bucket, or BC group. These groups determine how
-// elements match with each other. Two elements must be in adjacent buckets to match.
-#define kB 119ull
-#define kC 127ull
-#define kBC (kB * kC)
-
-// This (times k) is the length of the metadata that must be kept for each entry. For example,
-// for a table 4 entry, we must keep 4k additional bits for each entry, which is used to compute f5.
-// @Harold: Not that we changed this from 1-indexing in the chiapos implementation
-// to use 0-indexing. So index 0 == table 1.
-const byte kVectorLens[] = { 0, 1, 2, 4, 4, 3, 2 };
-
-// Defined in PlotContext.cpp
-extern uint16_t L_targets[2][kBC][kExtraBitsPow];
-
-
-// How many f7s per C1 entry, and how many C1 entries per C2 entry
-#define kCheckpoint1Interval 10000
-#define kCheckpoint2Interval 10000
-
-// EPP for the final file, the higher this is, the less variability, and lower delta
-// Note: if this is increased, ParkVector size must increase
-#define kEntriesPerPark 2048
-
-// To store deltas for EPP entries, the average delta must be less than this number of bits
-#define kMaxAverageDeltaTable1 5.6
-#define kMaxAverageDelta 3.5
-
-// C3 entries contain deltas for f7 values, the max average size is the following
-#define kC3BitsPerEntry 2.4
-
-// The number of bits in the stub is k minus this value
-#define kStubMinusBits 3
-
-// The ANS encoding R values for the 7 final plot tables
-// Tweaking the R values might allow lowering of the max average deltas,
-// and reducing final plot size
-const double kRValues[7] = { 4.7, 2.75, 2.75, 2.7, 2.6, 2.45 };
-
-// The ANS encoding R value for the C3 checkpoint table
-#define kC3R 1.0
-
-#define kPOSMagic "Proof of Space Plot"
-#define kFormatDescription "v1.0"
-
-// Initializes L_targets table
-//-----------------------------------------------------------
-inline void LoadLTargets()
-{
- static bool _initialized = false;
-
- if( _initialized )
- return;
-
- _initialized = true;
-
- for( byte parity = 0; parity < 2; parity++ )
- {
- for( uint16 i = 0; i < kBC; i++ )
- {
- uint16_t indJ = i / kC;
-
- for( uint16 m = 0; m < kExtraBitsPow; m++ )
- {
- const uint16 yr = ((indJ + m) % kB) * kC + (((2 * m + parity) * (2 * m + parity) + i) % kC);
-
- L_targets[parity][i][m] = yr;
- }
- }
- }
-}
-
-
-// This is the full size of the deltas section in a park. However, it will not be fully filled
-//-----------------------------------------------------------
-inline size_t CalculateMaxDeltasSize( TableId tableId )
-{
- if( tableId == TableId::Table1 )
- return CDiv( (size_t)((kEntriesPerPark - 1) * kMaxAverageDeltaTable1), 8 );
-
- return CDiv( (size_t)( (kEntriesPerPark - 1) * kMaxAverageDelta ), 8 );
-}
-
-/// Fixed size for parks
-//-----------------------------------------------------------
-inline size_t CalculateParkSize( TableId tableId )
-{
- return
- CDiv( _K * 2, 8 ) + // LinePoint size
- CDiv( (kEntriesPerPark - 1) * (_K - kStubMinusBits), 8 ) + // Stub Size
- CalculateMaxDeltasSize( tableId ); // Max delta
-
- // return CalculateLinePointSize(k) + CalculateStubsSize(k) +
- // CalculateMaxDeltasSize(k, table_index);
-}
-
-// Calculates the size of one C3 park. This will store bits for each f7 between
-// two C1 checkpoints, depending on how many times that f7 is present. For low
-// values of k, we need extra space to account for the additional variability.
-constexpr inline static size_t CalculateC3Size()
-{
- return (size_t)CDiv( kC3BitsPerEntry * kCheckpoint1Interval, 8 );
-}
-
+#pragma once
+#include "util/Util.h"
+#include "plotting/Tables.h"
+
+// Hard-coded k to 32
+#define _K 32
+#define ENTRIES_PER_TABLE ( 1ull << _K )
+
+///
+/// These are extracted from chiapos.
+/// Comments are taken directly from chiapos unless otherwise specified.
+///
+
+// F1 evaluations are done in batches of 2^kBatchSizes
+#define kBatchSizes 8
+
+// ChaCha8 block size
+#define kF1BlockSizeBits 512
+
+#define kF1BlockSize (kF1BlockSizeBits / 8u)
+
+// Extra bits of output from the f functions. Instead of being a function from k -> k bits,
+// it's a function from k -> k + kExtraBits bits. This allows less collisions in matches.
+// Refer to the paper for mathematical motivations.
+#define kExtraBits 6
+
+// Convenience variable
+#define kExtraBitsPow (1 << kExtraBits)
+
+// B and C groups which constitute a bucket, or BC group. These groups determine how
+// elements match with each other. Two elements must be in adjacent buckets to match.
+#define kB 119ull
+#define kC 127ull
+#define kBC (kB * kC)
+
+// This (times k) is the length of the metadata that must be kept for each entry. For example,
+// for a table 4 entry, we must keep 4k additional bits for each entry, which is used to compute f5.
+// @Harold: Not that we changed this from 1-indexing in the chiapos implementation
+// to use 0-indexing. So index 0 == table 1.
+const byte kVectorLens[] = { 0, 1, 2, 4, 4, 3, 2 };
+
+// Defined in PlotContext.cpp
+extern uint16_t L_targets[2][kBC][kExtraBitsPow];
+
+
+// How many f7s per C1 entry, and how many C1 entries per C2 entry
+#define kCheckpoint1Interval 10000
+#define kCheckpoint2Interval 10000
+
+// EPP for the final file, the higher this is, the less variability, and lower delta
+// Note: if this is increased, ParkVector size must increase
+#define kEntriesPerPark 2048
+
+// To store deltas for EPP entries, the average delta must be less than this number of bits
+#define kMaxAverageDeltaTable1 5.6
+#define kMaxAverageDelta 3.5
+
+// C3 entries contain deltas for f7 values, the max average size is the following
+#define kC3BitsPerEntry 2.4
+
+// The number of bits in the stub is k minus this value
+#define kStubMinusBits 3
+
+// The ANS encoding R values for the 7 final plot tables
+// Tweaking the R values might allow lowering of the max average deltas,
+// and reducing final plot size
+const double kRValues[7] = { 4.7, 2.75, 2.75, 2.7, 2.6, 2.45 };
+
+// The ANS encoding R value for the C3 checkpoint table
+#define kC3R 1.0
+
+#define kPOSMagic "Proof of Space Plot"
+#define kFormatDescription "v1.0"
+
+// Initializes L_targets table
+//-----------------------------------------------------------
+inline void LoadLTargets()
+{
+ static bool _initialized = false;
+
+ if( _initialized )
+ return;
+
+ _initialized = true;
+
+ for( byte parity = 0; parity < 2; parity++ )
+ {
+ for( uint16 i = 0; i < kBC; i++ )
+ {
+ uint16_t indJ = i / kC;
+
+ for( uint16 m = 0; m < kExtraBitsPow; m++ )
+ {
+ const uint16 yr = ((indJ + m) % kB) * kC + (((2 * m + parity) * (2 * m + parity) + i) % kC);
+
+ L_targets[parity][i][m] = yr;
+ }
+ }
+ }
+}
+
+
+// This is the full size of the deltas section in a park. However, it will not be fully filled
+//-----------------------------------------------------------
+inline constexpr size_t CalculateMaxDeltasSize( const TableId tableId )
+{
+ ASSERT( tableId < TableId::Table7 );
+
+ if( tableId == TableId::Table1 )
+ return CDiv( (size_t)((kEntriesPerPark - 1) * kMaxAverageDeltaTable1), 8 );
+
+ return CDiv( (size_t)( (kEntriesPerPark - 1) * kMaxAverageDelta ), 8 );
+}
+
+/// Fixed size for parks
+//-----------------------------------------------------------
+inline size_t CalculateParkSize( TableId tableId )
+{
+ return
+ CDiv( _K * 2, 8 ) + // LinePoint size
+ CDiv( (kEntriesPerPark - 1) * (_K - kStubMinusBits), 8 ) + // Stub Size
+ CalculateMaxDeltasSize( tableId ); // Max delta
+
+ // return CalculateLinePointSize(k) + CalculateStubsSize(k) +
+ // CalculateMaxDeltasSize(k, table_index);
+}
+
+//-----------------------------------------------------------
+inline constexpr size_t CalculateParkSize( const TableId tableId, const uint32 k )
+{
+ ASSERT( k >= 20 );
+
+ return
+ CDiv( k * 2, 8 ) + // LinePoint size
+ CDiv( (kEntriesPerPark - 1) * (k - kStubMinusBits), 8 ) + // Stub Size
+ CalculateMaxDeltasSize( tableId ); // Max delta
+
+ // return CalculateLinePointSize(k) + CalculateStubsSize(k) +
+ // CalculateMaxDeltasSize(k, table_index);
+}
+
+// Calculates the size of one C3 park. This will store bits for each f7 between
+// two C1 checkpoints, depending on how many times that f7 is present.
+constexpr inline static size_t CalculateC3Size()
+{
+ return (size_t)CDiv( kC3BitsPerEntry * kCheckpoint1Interval, 8 );
+}
+
+//-----------------------------------------------------------
+inline constexpr static size_t CalculatePark7Size( const uint k )
+{
+ return CDiv( (k + 1) * (uint64)kEntriesPerPark, 8 );
+}
+
+//-----------------------------------------------------------
+constexpr inline static size_t LinePointSizeBits( uint32 k )
+{
+ return (size_t)k * 2;
+}
+
+//-----------------------------------------------------------
+constexpr inline static size_t LinePointSizeBytes( uint32 k )
+{
+ return CDiv( LinePointSizeBits( k ), 8 );
+}
diff --git a/src/Config.h b/src/Config.h
index 28d6a36d..35b12788 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -1,43 +1,49 @@
-
-// Maximum number of supported threads.
-// Jobs will be stack allocated to this size.
-// #TODO: This should perhaps be named max jobs.
-#define MAX_THREADS 256
-
-// Perform Y sorts at the block level.
-// Unrolling loops by chacha block size.
-#define Y_SORT_BLOCK_MODE 1
-
-///
-/// Debug Stuff
-///
-
-// #define DBG_VERIFY_SORT_F1 1
-// #define DBG_VERIFY_SORT_FX 1
-
-// #define DBG_VALIDATE_KB_GROUPS 1
-// #define DBG_TEST_PAIRS 1
-
-// #define DBG_WRITE_Y_VALUES 1
-
-// #define BOUNDS_PROTECTION 1
-
-#define DBG_TEST_PROOF_RANGE { 167000899, 3 }
-// #define DBG_DUMP_PROOFS 1
-
-// #define DBG_WRITE_PHASE_1_TABLES 1
-#if !DBG_WRITE_PHASE_1_TABLES
- // #define DBG_READ_PHASE_1_TABLES 1
-#endif
-
-// #define DBG_WRITE_MARKED_TABLES 1
-#if !DBG_WRITE_MARKED_TABLES
- // #define DBG_READ_MARKED_TABLES 1
-#endif
-
-// #define DBG_WRITE_LINE_POINTS 1
-// #define DBG_WRITE_SORTED_F7_TABLE 1
-
-// Enable to test plotting times without writing to disk
-// #define BB_BENCHMARK_MODE 1
-
+
+// Maximum number of supported threads.
+// Jobs will be stack allocated to this size.
+// #TODO: This should perhaps be named max jobs.
+#define MAX_THREADS 256
+#define BB_MAX_JOBS MAX_THREADS
+
+// Perform Y sorts at the block level.
+// Unrolling loops by chacha block size.
+#define Y_SORT_BLOCK_MODE 1
+
+///
+/// Debug Stuff
+///
+
+// #define DBG_VERIFY_SORT_F1 1
+// #define DBG_VERIFY_SORT_FX 1
+
+// #define DBG_VALIDATE_KB_GROUPS 1
+// #define DBG_TEST_PAIRS 1
+
+// #define DBG_WRITE_Y_VALUES 1
+
+// #define BOUNDS_PROTECTION 1
+
+#define DBG_TEST_PROOF_RANGE { 167000899, 3 }
+// #define DBG_DUMP_PROOFS 1
+
+// #define DBG_WRITE_PHASE_1_TABLES 1
+#if !DBG_WRITE_PHASE_1_TABLES
+ // #define DBG_READ_PHASE_1_TABLES 1
+#endif
+
+// #define DBG_WRITE_MARKED_TABLES 1
+#if !DBG_WRITE_MARKED_TABLES
+ // #define DBG_READ_MARKED_TABLES 1
+#endif
+
+// #define DBG_WRITE_LINE_POINTS 1
+// #define DBG_WRITE_SORTED_F7_TABLE 1
+
+// Enable to test plotting times without writing to disk
+// #define BB_BENCHMARK_MODE 1
+
+// Enable for verbose debug logging.
+// Good for tracking internal state changes and finding bugs.
+// #define DBG_LOG_ENABLE 1
+
+
diff --git a/src/Globals.h b/src/Globals.h
index ac2a4100..b0e5916a 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -1,155 +1,200 @@
-#pragma once
-
-#define DEFER( m, ...) m( __VA_ARGS__ )
-#define XSTR( x ) #x
-#define STR( x ) XSTR( x )
-
-
-
-#ifdef _MSC_VER
- #define FORCE_INLINE __forceinline
- #define WARNING_PUSH Unimplemented
-
- #ifdef _M_ARM
- #define PLATFORM_IS_ARM 1
- #endif
-#else
-
- #if __aarch64__
- #define PLATFORM_IS_ARM 1
- #endif
-
- #if defined( __clang__ )
- #define FORCE_INLINE __attribute__((always_inline))
- // #define WARNING_PUSH _Pragma( STR() )
- #elif defined( __GNUC__ )
- #define FORCE_INLINE __attribute__((always_inline))
- #endif
-#endif
-
-#if __linux__ || __APPLE__
- #define PLATFORM_IS_UNIX 1
-#endif
-
-#if __linux__
- #define PLATFORM_IS_LINUX 1
-#elif __APPLE__
- #define PLATFORM_IS_APPLE 1
-
- #include
- #if TARGET_OS_MAC
- #define PLATFORM_IS_MACOS 1
- #else
- error Unsupported Apple platform.
- #endif
-
-#elif defined( _WIN32 )
- #define PLATFORM_IS_WINDOWS 1
-#endif
-
-
-#define TimerBegin() std::chrono::steady_clock::now()
-#define TimerEnd( startTime ) \
- (std::chrono::duration_cast( std::chrono::steady_clock::now() - (startTime) ).count() / 1000.0)
-
-
-
-#define ImplementFlagOps( FlagType ) \
-inline FlagType operator | ( FlagType lhs, FlagType rhs ) \
-{ \
- using FlagT = typename std::underlying_type::type; \
- return static_cast( static_cast( lhs ) | static_cast( rhs ) ); \
-} \
- \
-inline FlagType& operator |= ( FlagType& lhs, FlagType rhs ) \
-{ \
- using FlagT = typename std::underlying_type::type; \
- lhs = static_cast( static_cast( lhs ) | static_cast( rhs ) ); \
- return lhs; \
-} \
- \
-inline FlagType operator & ( FlagType lhs, FlagType rhs ) \
-{ \
- using FlagT = typename std::underlying_type::type; \
- return static_cast( static_cast( lhs ) & static_cast( rhs ) ); \
-} \
- \
-inline FlagType& operator &= ( FlagType& lhs, FlagType rhs ) \
-{ \
- using FlagT = typename std::underlying_type::type; \
- lhs = static_cast( static_cast( lhs ) & static_cast( rhs ) ); \
- return lhs; \
-} \
- \
-inline FlagType operator ~ ( FlagType lhs ) \
-{ \
- using FlagT = typename std::underlying_type::type; \
- lhs = static_cast( ~static_cast( lhs ) ); \
- return lhs; \
-}
-
-
-
-template< typename T>
-inline bool IsFlagSet( T flags, T flag )
-{
- using UT = typename std::underlying_type::type;
- return ( static_cast( flags ) & static_cast( flag ) ) != static_cast( 0 );
-}
-
-template< typename T>
-inline bool AreAllFlagSet( T flagsToCheck, T flagsRequired )
-{
- using UT = typename std::underlying_type::type;
- return ( static_cast( flagsToCheck ) & static_cast( flagsRequired ) ) == static_cast( flagsRequired );
-}
-
-template< typename T>
-inline T SetFlag( T& flags, T flag )
-{
- using UT = typename std::underlying_type::type;
- flags = static_cast( static_cast( flags ) | static_cast( flag ) );
-
- return flags;
-}
-
-template< typename T>
-inline T UnSetFlag( T& flags, T flag )
-{
- using UT = typename std::underlying_type::type;
- flags = static_cast( static_cast( flags ) & ~( static_cast( flag ) ) );
-
- return flags;
-}
-
-template< typename T>
-inline T ToggleFlag( T& flags, T flag, bool value )
-{
- if( value )
- SetFlag( flags, flag );
- else
- UnSetFlag( flags, flag );
-
- return flags;
-}
-
-
-template
-struct Span
-{
- T* values;
- size_t length;
-
- inline Span(){}
-
- inline Span( T* values, size_t length )
- : values( values )
- , length( length )
- {}
-
- inline T& operator[]( unsigned int index ) const { return this->values[index]; }
- inline T& operator[]( int index ) const { return this->values[index]; }
-
-};
-
-typedef Span ByteSpan;
+#pragma once
+
+#define DEFER( m, ...) m( __VA_ARGS__ )
+#define XSTR( x ) #x
+#define STR( x ) XSTR( x )
+
+
+
+#ifdef _MSC_VER
+ #define FORCE_INLINE __forceinline
+ #define WARNING_PUSH Unimplemented
+
+ #ifdef _M_ARM
+ #define PLATFORM_IS_ARM 1
+ #endif
+#else
+
+ #if __aarch64__
+ #define PLATFORM_IS_ARM 1
+ #endif
+
+ #if defined( __clang__ )
+ #define FORCE_INLINE __attribute__((always_inline))
+ // #define WARNING_PUSH _Pragma( STR() )
+ #elif defined( __GNUC__ )
+ #define FORCE_INLINE __attribute__((always_inline))
+ #endif
+#endif
+
+#if __linux__ || __APPLE__
+ #define PLATFORM_IS_UNIX 1
+#endif
+
+#if __linux__
+ #define PLATFORM_IS_LINUX 1
+#elif __APPLE__
+ #define PLATFORM_IS_APPLE 1
+
+ #include
+ #if TARGET_OS_MAC
+ #define PLATFORM_IS_MACOS 1
+ #else
+ error Unsupported Apple platform.
+ #endif
+
+#elif defined( _WIN32 )
+ #define PLATFORM_IS_WINDOWS 1
+#endif
+
+
+#define TimerBegin() std::chrono::steady_clock::now()
+#define TimerEnd( startTime ) \
+ (std::chrono::duration_cast( std::chrono::steady_clock::now() - (startTime) ).count() / 1000.0)
+
+#define TimerEndTicks( startTime ) \
+ (std::chrono::steady_clock::now() - (startTime))
+
+#define TicksToSeconds( duration ) \
+ ( std::chrono::duration_cast( (duration) ).count() * 1e-9 )
+
+
+#define ImplementFlagOps( FlagType ) \
+inline FlagType operator | ( FlagType lhs, FlagType rhs ) \
+{ \
+ using FlagT = typename std::underlying_type::type; \
+ return static_cast( static_cast( lhs ) | static_cast( rhs ) ); \
+} \
+ \
+inline FlagType& operator |= ( FlagType& lhs, FlagType rhs ) \
+{ \
+ using FlagT = typename std::underlying_type::type; \
+ lhs = static_cast( static_cast( lhs ) | static_cast( rhs ) ); \
+ return lhs; \
+} \
+ \
+inline FlagType operator & ( FlagType lhs, FlagType rhs ) \
+{ \
+ using FlagT = typename std::underlying_type::type; \
+ return static_cast( static_cast( lhs ) & static_cast( rhs ) ); \
+} \
+ \
+inline FlagType& operator &= ( FlagType& lhs, FlagType rhs ) \
+{ \
+ using FlagT = typename std::underlying_type::type; \
+ lhs = static_cast( static_cast( lhs ) & static_cast( rhs ) ); \
+ return lhs; \
+} \
+ \
+inline FlagType operator ~ ( FlagType lhs ) \
+{ \
+ using FlagT = typename std::underlying_type::type; \
+ lhs = static_cast( ~static_cast( lhs ) ); \
+ return lhs; \
+}
+
+#define ImplementArithmeticOps( EnumType ) \
+constexpr inline EnumType operator+( EnumType lhs, EnumType rhs ) \
+{ \
+ using BaseT = typename std::underlying_type::type; \
+ return static_cast( static_cast( lhs ) + \
+ static_cast( rhs ) ); \
+} \
+constexpr inline EnumType operator+( EnumType lhs, int rhs ) \
+{ \
+ using BaseT = typename std::underlying_type::type; \
+ return static_cast( static_cast( lhs ) + rhs); \
+} \
+ \
+constexpr inline EnumType operator-( EnumType lhs, EnumType rhs ) \
+{ \
+ using BaseT = typename std::underlying_type::type; \
+ return static_cast( static_cast( lhs ) - \
+ static_cast( rhs ) ); \
+} \
+constexpr inline EnumType operator-( EnumType lhs, int rhs ) \
+{ \
+ using BaseT = typename std::underlying_type::type; \
+ return static_cast( static_cast( lhs ) - rhs );\
+} \
+/* Prefix ++*/ \
+constexpr inline EnumType& operator++( EnumType& self ) \
+{ \
+ self = self + static_cast( 1 ); \
+ return self; \
+} \
+/* Postfix ++*/ \
+constexpr inline EnumType operator++( EnumType& self, int ) \
+{ \
+ return ++self; \
+} \
+/* Prefix --*/ \
+constexpr inline EnumType& operator--( EnumType& self ) \
+{ \
+ self = self - static_cast( 1 ); \
+ return self; \
+} \
+/* Postfix --*/ \
+constexpr inline EnumType operator--( EnumType& self, int ) \
+{ \
+ return --self; \
+} \
+ \
+
+
+template< typename T>
+inline bool IsFlagSet( T flags, T flag )
+{
+ using UT = typename std::underlying_type::type;
+ return ( static_cast( flags ) & static_cast( flag ) ) != static_cast( 0 );
+}
+
+template< typename T>
+inline bool AreAllFlagSet( T flagsToCheck, T flagsRequired )
+{
+ using UT = typename std::underlying_type::type;
+ return ( static_cast( flagsToCheck ) & static_cast( flagsRequired ) ) == static_cast( flagsRequired );
+}
+
+template< typename T>
+inline T SetFlag( T& flags, T flag )
+{
+ using UT = typename std::underlying_type::type;
+ flags = static_cast( static_cast( flags ) | static_cast( flag ) );
+
+ return flags;
+}
+
+template< typename T>
+inline T UnSetFlag( T& flags, T flag )
+{
+ using UT = typename std::underlying_type::type;
+ flags = static_cast( static_cast( flags ) & ~( static_cast( flag ) ) );
+
+ return flags;
+}
+
+template< typename T>
+inline T ToggleFlag( T& flags, T flag, bool value )
+{
+ if( value )
+ SetFlag( flags, flag );
+ else
+ UnSetFlag( flags, flag );
+
+ return flags;
+}
+
+
+template
+struct NBytes
+{
+ uint8_t data[_size];
+
+ inline uint8_t& operator[]( size_t index ) const { return this->values[index]; }
+ inline uint8_t& operator[]( uint32_t index ) const { return this->values[index]; }
+ inline uint8_t& operator[]( int32_t index ) const { return this->values[index]; }
+ inline uint8_t& operator[]( int64_t index ) const { return this->values[index]; }
+};
+
+
diff --git a/src/Platform.h b/src/Platform.h
index c11f94f3..5e731d76 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -1,43 +1,63 @@
-#pragma once
-
-#ifdef _WIN32
-
- #define NOMINMAX 1
- #define WIN32_LEAN_AND_MEAN 1
- #include
-
- typedef HANDLE ThreadId;
- typedef HANDLE SemaphoreId;
-
-// *nix
-#elif __linux__ || __APPLE__
-
- #ifndef _GNU_SOURCE
- #define _GNU_SOURCE
- #endif
-
- #ifndef _LARGEFILE64_SOURCE
- #define _LARGEFILE64_SOURCE
- #endif
-
- #include
- #include
- #include
- #include
- #include
- #include
-
- #if __linux__
- #include
- #elif __APPLE__
- #include
- #include
- #endif
-
-
- typedef pthread_t ThreadId;
- typedef sem_t SemaphoreId;
-
-#else
- #error Unsupported platform
-#endif
+#pragma once
+
+#ifdef _WIN32
+
+ #define NOMINMAX 1
+ #define WIN32_LEAN_AND_MEAN 1
+ // #NOTE: Not including globally anymore as we're getting some naming conflicts
+ //#include
+
+ #include
+
+ // Must match Windows.h definitions.
+ typedef void* HANDLE;
+ #define INVALID_WIN32_HANDLE ((HANDLE)(intptr_t)-1) // Same as INVALID_HANDLE_VALUE
+ typedef HANDLE ThreadId;
+ typedef HANDLE SemaphoreId;
+
+ #define BBDebugBreak() __debugbreak()
+
+// *nix
+#elif __linux__ || __APPLE__
+
+ #ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+ #endif
+
+ #ifndef _LARGEFILE64_SOURCE
+ #define _LARGEFILE64_SOURCE
+ #endif
+
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+
+ #if __linux__
+ #include
+
+ typedef pthread_t ThreadId;
+ typedef sem_t SemaphoreId;
+ #elif __APPLE__
+ #include
+
+ typedef pthread_t ThreadId;
+ typedef dispatch_semaphore_t SemaphoreId;
+ #endif
+
+ #define BBDebugBreak() raise( SIGTRAP )
+
+
+#else
+ #error Unsupported platform
+#endif
+
+
+#if !_DEBUG
+ #undef BBDebugBreak
+ #define BBDebugBreak()
+#endif
+
diff --git a/src/PlotContext.cpp b/src/PlotContext.cpp
index 05240861..41bb4894 100644
--- a/src/PlotContext.cpp
+++ b/src/PlotContext.cpp
@@ -1,5 +1,5 @@
-#include "PlotContext.h"
-#include "SysHost.h"
-
-uint16_t L_targets[2][kBC][kExtraBitsPow];
-
+#include "PlotContext.h"
+#include "SysHost.h"
+
+uint16_t L_targets[2][kBC][kExtraBitsPow];
+
diff --git a/src/PlotContext.h b/src/PlotContext.h
index 035372aa..c216a6b3 100644
--- a/src/PlotContext.h
+++ b/src/PlotContext.h
@@ -1,86 +1,81 @@
-#pragma once
-#include "Config.h"
-#include "ChiaConsts.h"
-#include "threading/ThreadPool.h"
-#include "PlotWriter.h"
-
-struct PlotRequest
-{
- const byte* plotId; // Id of the plot we want to create
- const char* outPath; // Output plot path
- const byte* memo; // Plot memo
- uint16 memoSize;
- bool IsFinalPlot;
-};
-
-struct Pair
-{
- uint32 left;
- uint32 right;
-};
-static_assert( sizeof( Pair ) == 8, "Invalid Pair struct." );
-
-
-///
-/// Context for a in-memory plotting
-///
-struct MemPlotContext
-{
- // They id of the plot being plotted
- const byte* plotId;
-
- const byte* plotMemo;
- uint16 plotMemoSize;
-
- // How many threads to use for the thread pool?
- // #TODO: Remove this, just use the thread pool's count.
- uint32 threadCount;
-
- // Thread pool to use when running jobs
- ThreadPool* threadPool;
-
- ///
- /// Buffers
- ///
- // Permanent table data buffers
- uint32* t1XBuffer ; // 16 GiB
- Pair* t2LRBuffer; // 32 GiB
- Pair* t3LRBuffer; // 32 GiB
- Pair* t4LRBuffer; // 32 GiB
- Pair* t5LRBuffer; // 32 GiB
- Pair* t6LRBuffer; // 32 GiB
- Pair* t7LRBuffer; // 32 GiB
- uint32* t7YBuffer ; // 16 GiB
-
- // Temporary read/write y buffers
- uint64* yBuffer0; // 32GiB each
- uint64* yBuffer1;
-
- // Temporary read/write metadata buffers
- uint64* metaBuffer0; // 64GiB each
- uint64* metaBuffer1;
-
- uint64 maxKBCGroups;
- uint64 maxPairs; // Max total pairs our buffer can hold
-
- // Number of entries per-table
- uint64 entryCount[7];
-
- // Added by Phase 2:
- byte* usedEntries[6]; // Used entries per each table.
- // These are only used for tables 2-6 (inclusive).
- // These buffers map to regions in yBuffer0.
-
- DiskPlotWriter* plotWriter;
-
- // The buffer used to write to disk the Phase 4 data.
- // This may be metaBuffer0 or a an L/R buffer from
- // table 3 and up, the highest one available to use.
- // If null, then no buffer is in use.
- byte* p4WriteBuffer;
- byte* p4WriteBufferWriter;
-
- // How many plots we've made so far
- uint64 plotCount;
-};
-
+#pragma once
+#include "Config.h"
+#include "ChiaConsts.h"
+#include "threading/ThreadPool.h"
+#include "PlotWriter.h"
+#include "plotting/PlotTypes.h"
+
+struct PlotRequest
+{
+ const byte* plotId; // Id of the plot we want to create
+ const char* outPath; // Output plot path
+ const byte* memo; // Plot memo
+ uint16 memoSize;
+ bool IsFinalPlot;
+};
+
+
+
+///
+/// Context for a in-memory plotting
+///
+struct MemPlotContext
+{
+ // They id of the plot being plotted
+ const byte* plotId;
+
+ const byte* plotMemo;
+ uint16 plotMemoSize;
+
+ // How many threads to use for the thread pool?
+ // #TODO: Remove this, just use the thread pool's count.
+ uint32 threadCount;
+
+ // Thread pool to use when running jobs
+ ThreadPool* threadPool;
+
+ ///
+ /// Buffers
+ ///
+ // Permanent table data buffers
+ uint32* t1XBuffer ; // 16 GiB
+ Pair* t2LRBuffer; // 32 GiB
+ Pair* t3LRBuffer; // 32 GiB
+ Pair* t4LRBuffer; // 32 GiB
+ Pair* t5LRBuffer; // 32 GiB
+ Pair* t6LRBuffer; // 32 GiB
+ Pair* t7LRBuffer; // 32 GiB
+ uint32* t7YBuffer ; // 16 GiB
+
+ // Temporary read/write y buffers
+ uint64* yBuffer0; // 32GiB each
+ uint64* yBuffer1;
+
+ // Temporary read/write metadata buffers
+ uint64* metaBuffer0; // 64GiB each
+ uint64* metaBuffer1;
+
+ uint64 maxKBCGroups;
+ uint64 maxPairs; // Max total pairs our buffer can hold
+
+ // Number of entries per-table
+ uint64 entryCount[7];
+
+ // Added by Phase 2:
+ byte* usedEntries[6]; // Used entries per each table.
+ // These are only used for tables 2-6 (inclusive).
+ // These buffers map to regions in yBuffer0.
+
+ DiskPlotWriter* plotWriter;
+
+ // The buffer used to write to disk the Phase 4 data.
+ // This may be metaBuffer0 or a an L/R buffer from
+ // table 3 and up, the highest one available to use.
+ // If null, then no buffer is in use.
+ byte* p4WriteBuffer;
+ byte* p4WriteBufferWriter;
+
+ // How many plots we've made so far
+ uint64 plotCount;
+};
+
diff --git a/src/PlotWriter.cpp b/src/PlotWriter.cpp
index 65b9b13c..471ccd73 100644
--- a/src/PlotWriter.cpp
+++ b/src/PlotWriter.cpp
@@ -1,450 +1,450 @@
-#include "PlotWriter.h"
-#include "ChiaConsts.h"
-#include "SysHost.h"
-#include "Config.h"
-
-//-----------------------------------------------------------
-DiskPlotWriter::DiskPlotWriter()
- : _writeSignal ( 0 )
- , _plotFinishedSignal( 0 )
-{
- #if BB_BENCHMARK_MODE
- return;
- #endif
- // Start writer thread
- _writerThread.Run( WriterMain, this );
-}
-
-//-----------------------------------------------------------
-DiskPlotWriter::~DiskPlotWriter()
-{
- #if BB_BENCHMARK_MODE
- return;
- #endif
-
- // Signal writer thread to exit, if it hasn't already
- _terminateSignal.store( true, std::memory_order_release );
- _writeSignal.Release();
-
- // Wait for thread to exit
- _plotFinishedSignal.Wait();
-
- if( _headerBuffer )
- SysHost::VirtualFree( _headerBuffer );
-
- if( _file )
- delete _file;
-}
-
-//-----------------------------------------------------------
-bool DiskPlotWriter::BeginPlot( const char* plotFilePath, FileStream& file, const byte plotId[32], const byte* plotMemo, const uint16 plotMemoSize )
-{
- #if BB_BENCHMARK_MODE
- _filePath = plotFilePath;
- return true;
- #endif
-
- ASSERT( plotMemo );
- ASSERT( plotMemoSize );
-
- // Make sure we're not still writing a plot
- if( _file || _error || !file.IsOpen() )
- return false;
-
- const size_t headerSize =
- ( sizeof( kPOSMagic ) - 1 ) +
- 32 + // plot id
- 1 + // k
- 2 + // kFormatDescription length
- ( sizeof( kFormatDescription ) - 1 ) +
- 2 + // Memo length
- plotMemoSize + // Memo
- 80 // Table pointers
- ;
-
- ASSERT( plotFilePath );
- _filePath = plotFilePath;
-
-
- const size_t paddedHeaderSize = RoundUpToNextBoundary( headerSize, (int)file.BlockSize() );
-
- byte* header = _headerBuffer;
-
- // Do we need to realloc?
- if( _headerSize )
- {
- ASSERT( _headerBuffer );
-
- const size_t currentPaddedHeaderSize = RoundUpToNextBoundary( _headerSize, (int)file.BlockSize() );
-
- if( currentPaddedHeaderSize != paddedHeaderSize )
- {
- SysHost::VirtualFree( header );
- header = nullptr;
- }
- }
-
- // Alloc the header buffer if we need to
- if( !header )
- {
- header = (byte*)SysHost::VirtualAlloc( paddedHeaderSize );
-
- // Zero-out padded portion and table pointers
- memset( header+headerSize-80, 0, paddedHeaderSize-headerSize-80 );
- }
-
-
- // Write the header
- {
- // Magic
- byte* headerWriter = header;
- memcpy( headerWriter, kPOSMagic, sizeof( kPOSMagic ) - 1 );
- headerWriter += sizeof( kPOSMagic ) - 1;
-
- // Plot Id
- memcpy( headerWriter, plotId, 32 );
- headerWriter += 32;
-
- // K
- *headerWriter++ = (byte)_K;
-
- // Format description
- *((uint16*)headerWriter) = Swap16( (uint16)(sizeof( kFormatDescription ) - 1) );
- headerWriter += 2;
- memcpy( headerWriter, kFormatDescription, sizeof( kFormatDescription ) - 1 );
- headerWriter += sizeof( kFormatDescription ) - 1;
-
- // Memo
- *((uint16*)headerWriter) = Swap16( plotMemoSize );
- headerWriter += 2;
- memcpy( headerWriter, plotMemo, plotMemoSize );
- headerWriter += plotMemoSize;
-
- // Tables will be copied at the end.
- }
-
- // Seek to the aligned position after the header
- if( !file.Seek( (int64)paddedHeaderSize, SeekOrigin::Begin ) )
- {
- _error = file.GetError();
- return false;
- }
-
- // Save header so that we can actually write it to the end of the file
- _headerBuffer = header;
- _headerSize = headerSize;
-
- // Store initial table offset
- _tablePointers[0] = paddedHeaderSize;
- _position = paddedHeaderSize;
-
- // Give ownership of the file to the writer thread and signal it
- _tableIndex = 0;
- _file = &file;
- _writeSignal.Release();
-
- return true;
-}
-
-//-----------------------------------------------------------
-bool DiskPlotWriter::WriteTable( const void* buffer, size_t size )
-{
- #if BB_BENCHMARK_MODE
- return true;
- #endif
-
- if( !SubmitTable( buffer, size ) )
- return false;
-
- // Signal the writer thread that there is a new table to write
- _writeSignal.Release();
-
- return true;
-}
-
-//-----------------------------------------------------------
-bool DiskPlotWriter::SubmitTable( const void* buffer, size_t size )
-{
- #if BB_BENCHMARK_MODE
- return true;
- #endif
-
- // Make sure the thread has already started.
- // We must have no errors
- if( !_file || _error )
- return false;
-
- const uint tableIndex = _tableIndex.load( std::memory_order_relaxed );
- ASSERT( tableIndex < 10 );
-
- // Can't overflow tables
- if( tableIndex >= 10 )
- return false;
-
- ASSERT( buffer );
- ASSERT( size );
-
- _tablebuffers[tableIndex].buffer = (byte*)buffer;
- _tablebuffers[tableIndex].size = size;
-
- // Store the value
- _tableIndex.store( tableIndex + 1, std::memory_order_release );
-
- return true;
-}
-
-// //-----------------------------------------------------------
-// bool DiskPlotWriter::FlushTables()
-// {
-// // Make sure the thread has already started.
-// if( _headerSize < 1 )
-// return false;
-
-// // We must have no errors
-// if( _error )
-// return false;
-
-// // Signal the writer thread for each table we have
-// const uint tableIndex = _tableIndex.load( std::memory_order_relaxed );
-
-// for( uint i = 0; i < tableIndex; i++ )
-// _writeSignal.Release();
-
-// return true;
-// }
-
-//-----------------------------------------------------------
-bool DiskPlotWriter::WaitUntilFinishedWriting()
-{
-#if BB_BENCHMARK_MODE
- return true;
-#else
-
- // For re-entry checks
- if( !_file && _plotFinishedSignal.GetCount() == 0 )
- return true;
-
- do {
- _plotFinishedSignal.Wait();
- } while( _file );
-
- ASSERT( _file == nullptr );
-
- return _error == 0;
-#endif
-}
-
-
-///
-/// Writer thread
-///
-//-----------------------------------------------------------
-void DiskPlotWriter::WriterMain( void* data )
-{
- SysHost::SetCurrentThreadAffinityCpuId( 0 );
-
- ASSERT( data );
- DiskPlotWriter* self = reinterpret_cast( data );
-
- self->WriterThread();
-}
-
-//-----------------------------------------------------------
-void DiskPlotWriter::WriterThread()
-{
- if( _terminateSignal.load( std::memory_order_relaxed ) )
- return;
-
- FileStream* file = nullptr;
-
- uint tableIndex = 0; // Local table index
-
- // Buffer for writing
- size_t blockBufferSize = 0;
- byte* blockBuffer = nullptr;
- size_t blockSize = 0;
-
- for( ;; )
- {
- // Wait to be signalled by the main thread
- _writeSignal.Wait();
-
- if( _terminateSignal.load( std::memory_order_relaxed ) )
- break;
-
- // Started writing a new table, ensure we have a file
- if( file == nullptr )
- {
- file = _file;
-
- // We may have been signalled multiple times to write tables
- // and we grabbed the tables without waiting for the signal,
- // so it might occurr that we don't have a file yet.
- if( !file )
- continue;
-
- // Reset table index
- tableIndex = 0;
- _lastTableIndexWritten.store( 0, std::memory_order_release );
-
- // Allocate a new block buffer, if we need to
- blockSize = file->BlockSize();
- if( blockSize > blockBufferSize )
- {
- if( blockBuffer )
- SysHost::VirtualFree( blockBuffer );
-
- blockBufferSize = blockSize;
- blockBuffer = (byte*)SysHost::VirtualAlloc( blockBufferSize );
-
- if( !blockBuffer )
- Fatal( "Failed to allocate buffer for writing to disk." );
- }
- }
-
- // See if we have a new table to write (should always be the case when we're signaled)
- uint newIndex = _tableIndex.load( std::memory_order_acquire );
-
- while( tableIndex < newIndex )
- {
- TableBuffer& table = _tablebuffers[tableIndex];
-
- const byte* writeBuffer = table.buffer;
-
- // Write as many blocks as we can,
- // then write the remainder by copying it to our own block-aligned buffer
- const size_t blockCount = table.size / blockSize;
- size_t sizeToWrite = blockCount * blockSize;
-
- const size_t remainder = table.size - sizeToWrite;
-
- while( sizeToWrite )
- {
- ssize_t sizeWritten = file->Write( writeBuffer, sizeToWrite );
- if( sizeWritten < 1 )
- {
- // Error occurred, stop writing.
- _error = file->GetError();
- break;
- }
- ASSERT( (size_t)sizeWritten <= sizeToWrite );
-
- sizeToWrite -= (size_t)sizeWritten;
- writeBuffer += sizeWritten;
- };
-
- // Break out if we got a write error
- if( _error )
- break;
-
- // Write remainder, if we have any
- if( remainder )
- {
- memset( blockBuffer, 0, blockSize );
- memcpy( blockBuffer, writeBuffer, remainder );
-
- ssize_t sizeWritten = file->Write( blockBuffer, blockSize );
- if( sizeWritten < 1 )
- {
- _error = file->GetError();
- break;
- }
-
- ASSERT( (size_t)sizeWritten == blockSize );
- }
-
- if( !file->Flush() )
- {
- _error = file->GetError();
- break;
- }
-
- // Go to the next table
- tableIndex ++;
- _lastTableIndexWritten.store( tableIndex, std::memory_order_release );
-
- _position += RoundUpToNextBoundary( table.size, (int)blockSize );
-
- // Save the table pointer
- _tablePointers[tableIndex] = _position;
- }
-
- if( _error )
- break;
-
- // Have we finished writing the last table?
- if( tableIndex >= 10 )
- {
- ASSERT( tableIndex == 10 );
-
- // We now need to seek to the beginning so that we can write the header
- // with the table pointers set
- if( file->Seek( 0, SeekOrigin::Begin ) )
- {
- const size_t alignedHeaderSize = _tablePointers[0];
-
- // Convert to BE
- for( uint i = 0; i < 10; i++ )
- _tablePointers[i] = Swap64( _tablePointers[i] );
-
- memcpy( _headerBuffer + (_headerSize-80), _tablePointers, 80 );
-
- if( file->Write( _headerBuffer, alignedHeaderSize ) != (ssize_t)alignedHeaderSize )
- _error = file->GetError();
- }
- else
- _error = file->GetError();
-
- // Plot data cleanup
- if( !file->Flush() )
- _error = file->GetError();
-
- file->Close();
- delete file;
- file = nullptr;
- _file = nullptr;
-
- _tableIndex = 0;
-
- // Signal that we've finished writing the plot
- _plotFinishedSignal.Release();
- }
- }
-
-
- ///
- /// Cleanup
- ///
- if( blockBuffer )
- SysHost::VirtualFree( blockBuffer );
-
- // Close the file in case we had an error
- if( file )
- {
- file->Close();
- delete file;
- }
-
- _file = nullptr;
-
- // Signal that this thread is finished
- _plotFinishedSignal.Release();
-}
-
-//-----------------------------------------------------------
-size_t DiskPlotWriter::AlignToBlockSize( size_t size )
-{
- #if BB_BENCHMARK_MODE
- return RoundUpToNextBoundary( size, 4096 );
- #endif
-
- ASSERT( _file );
-
- // Shoud never be called without a file
- if( !_file )
- return size;
-
- return RoundUpToNextBoundary( size, (int)_file->BlockSize() );
-}
-
-
+#include "PlotWriter.h"
+#include "ChiaConsts.h"
+#include "SysHost.h"
+#include "Config.h"
+
+//-----------------------------------------------------------
+DiskPlotWriter::DiskPlotWriter()
+ : _writeSignal ( 0 )
+ , _plotFinishedSignal( 0 )
+{
+ #if BB_BENCHMARK_MODE
+ return;
+ #endif
+ // Start writer thread
+ _writerThread.Run( WriterMain, this );
+}
+
+//-----------------------------------------------------------
+DiskPlotWriter::~DiskPlotWriter()
+{
+ #if BB_BENCHMARK_MODE
+ return;
+ #endif
+
+ // Signal writer thread to exit, if it hasn't already
+ _terminateSignal.store( true, std::memory_order_release );
+ _writeSignal.Release();
+
+ // Wait for thread to exit
+ _plotFinishedSignal.Wait();
+
+ if( _headerBuffer )
+ SysHost::VirtualFree( _headerBuffer );
+
+ if( _file )
+ delete _file;
+}
+
+//-----------------------------------------------------------
+bool DiskPlotWriter::BeginPlot( const char* plotFilePath, FileStream& file, const byte plotId[32], const byte* plotMemo, const uint16 plotMemoSize )
+{
+ #if BB_BENCHMARK_MODE
+ _filePath = plotFilePath;
+ return true;
+ #endif
+
+ ASSERT( plotMemo );
+ ASSERT( plotMemoSize );
+
+ // Make sure we're not still writing a plot
+ if( _file || _error || !file.IsOpen() )
+ return false;
+
+ const size_t headerSize =
+ ( sizeof( kPOSMagic ) - 1 ) +
+ 32 + // plot id
+ 1 + // k
+ 2 + // kFormatDescription length
+ ( sizeof( kFormatDescription ) - 1 ) +
+ 2 + // Memo length
+ plotMemoSize + // Memo
+ 80 // Table pointers
+ ;
+
+ ASSERT( plotFilePath );
+ _filePath = plotFilePath;
+
+
+ const size_t paddedHeaderSize = RoundUpToNextBoundary( headerSize, (int)file.BlockSize() );
+
+ byte* header = _headerBuffer;
+
+ // Do we need to realloc?
+ if( _headerSize )
+ {
+ ASSERT( _headerBuffer );
+
+ const size_t currentPaddedHeaderSize = RoundUpToNextBoundary( _headerSize, (int)file.BlockSize() );
+
+ if( currentPaddedHeaderSize != paddedHeaderSize )
+ {
+ SysHost::VirtualFree( header );
+ header = nullptr;
+ }
+ }
+
+ // Alloc the header buffer if we need to
+ if( !header )
+ {
+ header = (byte*)SysHost::VirtualAlloc( paddedHeaderSize );
+
+ // Zero-out padded portion and table pointers
+ memset( header+headerSize-80, 0, paddedHeaderSize-headerSize-80 );
+ }
+
+
+ // Write the header
+ {
+ // Magic
+ byte* headerWriter = header;
+ memcpy( headerWriter, kPOSMagic, sizeof( kPOSMagic ) - 1 );
+ headerWriter += sizeof( kPOSMagic ) - 1;
+
+ // Plot Id
+ memcpy( headerWriter, plotId, 32 );
+ headerWriter += 32;
+
+ // K
+ *headerWriter++ = (byte)_K;
+
+ // Format description
+ *((uint16*)headerWriter) = Swap16( (uint16)(sizeof( kFormatDescription ) - 1) );
+ headerWriter += 2;
+ memcpy( headerWriter, kFormatDescription, sizeof( kFormatDescription ) - 1 );
+ headerWriter += sizeof( kFormatDescription ) - 1;
+
+ // Memo
+ *((uint16*)headerWriter) = Swap16( plotMemoSize );
+ headerWriter += 2;
+ memcpy( headerWriter, plotMemo, plotMemoSize );
+ headerWriter += plotMemoSize;
+
+ // Tables will be copied at the end.
+ }
+
+ // Seek to the aligned position after the header
+ if( !file.Seek( (int64)paddedHeaderSize, SeekOrigin::Begin ) )
+ {
+ _error = file.GetError();
+ return false;
+ }
+
+ // Save header so that we can actually write it to the end of the file
+ _headerBuffer = header;
+ _headerSize = headerSize;
+
+ // Store initial table offset
+ _tablePointers[0] = paddedHeaderSize;
+ _position = paddedHeaderSize;
+
+ // Give ownership of the file to the writer thread and signal it
+ _tableIndex = 0;
+ _file = &file;
+ _writeSignal.Release();
+
+ return true;
+}
+
+//-----------------------------------------------------------
+bool DiskPlotWriter::WriteTable( const void* buffer, size_t size )
+{
+ #if BB_BENCHMARK_MODE
+ return true;
+ #endif
+
+ if( !SubmitTable( buffer, size ) )
+ return false;
+
+ // Signal the writer thread that there is a new table to write
+ _writeSignal.Release();
+
+ return true;
+}
+
+//-----------------------------------------------------------
+bool DiskPlotWriter::SubmitTable( const void* buffer, size_t size )
+{
+ #if BB_BENCHMARK_MODE
+ return true;
+ #endif
+
+ // Make sure the thread has already started.
+ // We must have no errors
+ if( !_file || _error )
+ return false;
+
+ const uint tableIndex = _tableIndex.load( std::memory_order_relaxed );
+ ASSERT( tableIndex < 10 );
+
+ // Can't overflow tables
+ if( tableIndex >= 10 )
+ return false;
+
+ ASSERT( buffer );
+ ASSERT( size );
+
+ _tablebuffers[tableIndex].buffer = (byte*)buffer;
+ _tablebuffers[tableIndex].size = size;
+
+ // Store the value
+ _tableIndex.store( tableIndex + 1, std::memory_order_release );
+
+ return true;
+}
+
+// //-----------------------------------------------------------
+// bool DiskPlotWriter::FlushTables()
+// {
+// // Make sure the thread has already started.
+// if( _headerSize < 1 )
+// return false;
+
+// // We must have no errors
+// if( _error )
+// return false;
+
+// // Signal the writer thread for each table we have
+// const uint tableIndex = _tableIndex.load( std::memory_order_relaxed );
+
+// for( uint i = 0; i < tableIndex; i++ )
+// _writeSignal.Release();
+
+// return true;
+// }
+
+//-----------------------------------------------------------
+bool DiskPlotWriter::WaitUntilFinishedWriting()
+{
+#if BB_BENCHMARK_MODE
+ return true;
+#else
+
+ // For re-entry checks
+ if( !_file && _plotFinishedSignal.GetCount() == 0 )
+ return true;
+
+ do {
+ _plotFinishedSignal.Wait();
+ } while( _file );
+
+ ASSERT( _file == nullptr );
+
+ return _error == 0;
+#endif
+}
+
+
+///
+/// Writer thread
+///
+//-----------------------------------------------------------
+void DiskPlotWriter::WriterMain( void* data )
+{
+ SysHost::SetCurrentThreadAffinityCpuId( 0 );
+
+ ASSERT( data );
+ DiskPlotWriter* self = reinterpret_cast( data );
+
+ self->WriterThread();
+}
+
+//-----------------------------------------------------------
+void DiskPlotWriter::WriterThread()
+{
+ if( _terminateSignal.load( std::memory_order_relaxed ) )
+ return;
+
+ FileStream* file = nullptr;
+
+ uint tableIndex = 0; // Local table index
+
+ // Buffer for writing
+ size_t blockBufferSize = 0;
+ byte* blockBuffer = nullptr;
+ size_t blockSize = 0;
+
+ for( ;; )
+ {
+ // Wait to be signalled by the main thread
+ _writeSignal.Wait();
+
+ if( _terminateSignal.load( std::memory_order_relaxed ) )
+ break;
+
+ // Started writing a new table, ensure we have a file
+ if( file == nullptr )
+ {
+ file = _file;
+
+ // We may have been signalled multiple times to write tables
+ // and we grabbed the tables without waiting for the signal,
+ // so it might occurr that we don't have a file yet.
+ if( !file )
+ continue;
+
+ // Reset table index
+ tableIndex = 0;
+ _lastTableIndexWritten.store( 0, std::memory_order_release );
+
+ // Allocate a new block buffer, if we need to
+ blockSize = file->BlockSize();
+ if( blockSize > blockBufferSize )
+ {
+ if( blockBuffer )
+ SysHost::VirtualFree( blockBuffer );
+
+ blockBufferSize = blockSize;
+ blockBuffer = (byte*)SysHost::VirtualAlloc( blockBufferSize );
+
+ if( !blockBuffer )
+ Fatal( "Failed to allocate buffer for writing to disk." );
+ }
+ }
+
+ // See if we have a new table to write (should always be the case when we're signaled)
+ uint newIndex = _tableIndex.load( std::memory_order_acquire );
+
+ while( tableIndex < newIndex )
+ {
+ TableBuffer& table = _tablebuffers[tableIndex];
+
+ const byte* writeBuffer = table.buffer;
+
+ // Write as many blocks as we can,
+ // then write the remainder by copying it to our own block-aligned buffer
+ const size_t blockCount = table.size / blockSize;
+ size_t sizeToWrite = blockCount * blockSize;
+
+ const size_t remainder = table.size - sizeToWrite;
+
+ while( sizeToWrite )
+ {
+ ssize_t sizeWritten = file->Write( writeBuffer, sizeToWrite );
+ if( sizeWritten < 1 )
+ {
+ // Error occurred, stop writing.
+ _error = file->GetError();
+ break;
+ }
+ ASSERT( (size_t)sizeWritten <= sizeToWrite );
+
+ sizeToWrite -= (size_t)sizeWritten;
+ writeBuffer += sizeWritten;
+ };
+
+ // Break out if we got a write error
+ if( _error )
+ break;
+
+ // Write remainder, if we have any
+ if( remainder )
+ {
+ memset( blockBuffer, 0, blockSize );
+ memcpy( blockBuffer, writeBuffer, remainder );
+
+ ssize_t sizeWritten = file->Write( blockBuffer, blockSize );
+ if( sizeWritten < 1 )
+ {
+ _error = file->GetError();
+ break;
+ }
+
+ ASSERT( (size_t)sizeWritten == blockSize );
+ }
+
+ if( !file->Flush() )
+ {
+ _error = file->GetError();
+ break;
+ }
+
+ // Go to the next table
+ tableIndex ++;
+ _lastTableIndexWritten.store( tableIndex, std::memory_order_release );
+
+ _position += RoundUpToNextBoundary( table.size, (int)blockSize );
+
+ // Save the table pointer
+ _tablePointers[tableIndex] = _position;
+ }
+
+ if( _error )
+ break;
+
+ // Have we finished writing the last table?
+ if( tableIndex >= 10 )
+ {
+ ASSERT( tableIndex == 10 );
+
+ // We now need to seek to the beginning so that we can write the header
+ // with the table pointers set
+ if( file->Seek( 0, SeekOrigin::Begin ) )
+ {
+ const size_t alignedHeaderSize = _tablePointers[0];
+
+ // Convert to BE
+ for( uint i = 0; i < 10; i++ )
+ _tablePointers[i] = Swap64( _tablePointers[i] );
+
+ memcpy( _headerBuffer + (_headerSize-80), _tablePointers, 80 );
+
+ if( file->Write( _headerBuffer, alignedHeaderSize ) != (ssize_t)alignedHeaderSize )
+ _error = file->GetError();
+ }
+ else
+ _error = file->GetError();
+
+ // Plot data cleanup
+ if( !file->Flush() )
+ _error = file->GetError();
+
+ file->Close();
+ delete file;
+ file = nullptr;
+ _file = nullptr;
+
+ _tableIndex = 0;
+
+ // Signal that we've finished writing the plot
+ _plotFinishedSignal.Release();
+ }
+ }
+
+
+ ///
+ /// Cleanup
+ ///
+ if( blockBuffer )
+ SysHost::VirtualFree( blockBuffer );
+
+ // Close the file in case we had an error
+ if( file )
+ {
+ file->Close();
+ delete file;
+ }
+
+ _file = nullptr;
+
+ // Signal that this thread is finished
+ _plotFinishedSignal.Release();
+}
+
+//-----------------------------------------------------------
+size_t DiskPlotWriter::AlignToBlockSize( size_t size )
+{
+ #if BB_BENCHMARK_MODE
+ return RoundUpToNextBoundary( size, 4096 );
+ #endif
+
+ ASSERT( _file );
+
+ // Shoud never be called without a file
+ if( !_file )
+ return size;
+
+ return RoundUpToNextBoundary( size, (int)_file->BlockSize() );
+}
+
+
diff --git a/src/PlotWriter.h b/src/PlotWriter.h
index c7504084..71e9e954 100644
--- a/src/PlotWriter.h
+++ b/src/PlotWriter.h
@@ -1,107 +1,107 @@
-#pragma once
-#include "io/FileStream.h"
-#include "threading/Thread.h"
-#include "threading/Semaphore.h"
-
-/**
- * Handles writing the final plot to disk
- *
- * Final file format is as follows:
- * [Header]
- * - "Proof of Space Plot" (utf-8) : 19 bytes
- * - unique plot id : 32 bytes
- * - k : 1 byte
- * - format description length : 2 bytes
- * - format description : * bytes
- * - memo length : 2 bytes
- * - memo : * bytes
- * - table pointers : 80 bytes (8 * 10 )
- * [(Optional_Padding)]
- * [Table1_Parks]
- * [Table2_Parks]
- * [Table3_Parks]
- * [Table4_Parks]
- * [Table5_Parks]
- * [Table6_Parks]
- * [Table7_Parks]
- * [C1_Table]
- * [C2_Table]
- * [C3_Table_Parks]
- */
-class DiskPlotWriter
-{
-public:
- DiskPlotWriter();
- ~DiskPlotWriter();
-
- // Begins writing a new plot. Any previous plot must have finished before calling this
- bool BeginPlot( const char* plotFilePath, FileStream& file, const byte plotId[32],
- const byte* plotMemo, const uint16 plotMemoSize );
-
- // Submits and signals the writing thread to write a table
- bool WriteTable( const void* buffer, size_t size );
-
- // Submits the table for writing, but does not actually write it to disk yet
- bool SubmitTable( const void* buffer, size_t size );
-
- // Flush pending tables to write
- // bool FlushTables();
-
- // Returns true if there's no errors.
- // If there are any errors, call GetError() to obtain the file write error.
- bool WaitUntilFinishedWriting();
-
- // Returns true if the plotter has finished writing the last queued plot.
- // (We nullify our reference when the file has been closed and finished.)
- inline bool HasFinishedWriting() { return _file == nullptr; }
-
- // If gotten after flush, they will be in big-endian format
- inline const uint64* GetTablePointers() { return _tablePointers; }
-
- template
- inline T* AlignPointerToBlockSize( void* pointer )
- {
- return (T*)(uintptr_t)AlignToBlockSize( (uintptr_t)pointer );
- }
-
- inline int GetError() { return _error; }
-
- inline const std::string& FilePath() { return _filePath; }
-
- // Number of tables written
- inline uint TablesWritten() { return _lastTableIndexWritten.load( std::memory_order_acquire ); }
-
-private:
- static void WriterMain( void* data );
- void WriterThread();
- size_t AlignToBlockSize( size_t size );
-
- struct TableBuffer
- {
- const byte* buffer;
- size_t size;
- };
-
-private:
- FileStream* _file = nullptr;
- std::string _filePath;
- size_t _headerSize = 0;
- byte* _headerBuffer = nullptr;
- size_t _position = 0; // Current write position
- uint64 _tablePointers[10] = { 0 }; // Pointers to the table begin position
- TableBuffer _tablebuffers [10]; // Table buffers passed to us for writing.
-
- std::atomic _tableIndex = 0; // Next table index to write
- std::atomic _lastTableIndexWritten = 10; // Index of the latest table that was fully written to disk. (Owned by writer thread.)
- // That is, index-1 is the index of the last table written.
- // We start it at 10 (all tables written), to denote that we have
- // no tables pending to write.
-
- int _error = 0; // Set if there was an error writing the plot file
-
- Thread _writerThread;
- Semaphore _writeSignal; // Main thread signals writer thread to write a new table
- Semaphore _plotFinishedSignal; // Writer thread signals that it's finished writing a plot
- std::atomic _terminateSignal = false; // Main thread signals us to exit
-};
-
+#pragma once
+#include "io/FileStream.h"
+#include "threading/Thread.h"
+#include "threading/Semaphore.h"
+
+/**
+ * Handles writing the final plot to disk
+ *
+ * Final file format is as follows:
+ * [Header]
+ * - "Proof of Space Plot" (utf-8) : 19 bytes
+ * - unique plot id : 32 bytes
+ * - k : 1 byte
+ * - format description length : 2 bytes
+ * - format description : * bytes
+ * - memo length : 2 bytes
+ * - memo : * bytes
+ * - table pointers : 80 bytes (8 * 10 )
+ * [(Optional_Padding)]
+ * [Table1_Parks]
+ * [Table2_Parks]
+ * [Table3_Parks]
+ * [Table4_Parks]
+ * [Table5_Parks]
+ * [Table6_Parks]
+ * [Table7_Parks]
+ * [C1_Table]
+ * [C2_Table]
+ * [C3_Table_Parks]
+ */
+class DiskPlotWriter
+{
+public:
+ DiskPlotWriter();
+ ~DiskPlotWriter();
+
+ // Begins writing a new plot. Any previous plot must have finished before calling this
+ bool BeginPlot( const char* plotFilePath, FileStream& file, const byte plotId[32],
+ const byte* plotMemo, const uint16 plotMemoSize );
+
+ // Submits and signals the writing thread to write a table
+ bool WriteTable( const void* buffer, size_t size );
+
+ // Submits the table for writing, but does not actually write it to disk yet
+ bool SubmitTable( const void* buffer, size_t size );
+
+ // Flush pending tables to write
+ // bool FlushTables();
+
+ // Returns true if there's no errors.
+ // If there are any errors, call GetError() to obtain the file write error.
+ bool WaitUntilFinishedWriting();
+
+ // Returns true if the plotter has finished writing the last queued plot.
+ // (We nullify our reference when the file has been closed and finished.)
+ inline bool HasFinishedWriting() { return _file == nullptr; }
+
+ // If gotten after flush, they will be in big-endian format
+ inline const uint64* GetTablePointers() { return _tablePointers; }
+
+ template
+ inline T* AlignPointerToBlockSize( void* pointer )
+ {
+ return (T*)(uintptr_t)AlignToBlockSize( (uintptr_t)pointer );
+ }
+
+ inline int GetError() { return _error; }
+
+ inline const std::string& FilePath() { return _filePath; }
+
+ // Number of tables written
+ inline uint TablesWritten() { return _lastTableIndexWritten.load( std::memory_order_acquire ); }
+
+private:
+ static void WriterMain( void* data );
+ void WriterThread();
+ size_t AlignToBlockSize( size_t size );
+
+ struct TableBuffer
+ {
+ const byte* buffer;
+ size_t size;
+ };
+
+private:
+ FileStream* _file = nullptr;
+ std::string _filePath;
+ size_t _headerSize = 0;
+ byte* _headerBuffer = nullptr;
+ size_t _position = 0; // Current write position
+ uint64 _tablePointers[10] = { 0 }; // Pointers to the table begin position
+ TableBuffer _tablebuffers [10]; // Table buffers passed to us for writing.
+
+ std::atomic _tableIndex = 0; // Next table index to write
+ std::atomic _lastTableIndexWritten = 10; // Index of the latest table that was fully written to disk. (Owned by writer thread.)
+ // That is, index-1 is the index of the last table written.
+ // We start it at 10 (all tables written), to denote that we have
+ // no tables pending to write.
+
+ int _error = 0; // Set if there was an error writing the plot file
+
+ Thread _writerThread;
+ Semaphore _writeSignal; // Main thread signals writer thread to write a new table
+ Semaphore _plotFinishedSignal; // Writer thread signals that it's finished writing a plot
+ std::atomic _terminateSignal = false; // Main thread signals us to exit
+};
+
diff --git a/src/SysHost.h b/src/SysHost.h
index 0176af31..b9e23121 100644
--- a/src/SysHost.h
+++ b/src/SysHost.h
@@ -1,85 +1,87 @@
-#pragma once
-
-enum class VProtect : uint
-{
- None = 0, // No protection / Clear protection
-
- Read = 1 << 0, // Allow reads. (Make pages read-only.)
- Write = 1 << 1, // Allow writes. (Make pages write-only.)
- NoAccess = 1 << 2, // No memory access allowed at all
-
- ReadWrite = Read | Write // Make pages read/writable
-};
-ImplementFlagOps( VProtect );
-
-struct NumaInfo
-{
- uint nodeCount; // How many NUMA nodes in the system
- uint cpuCount; // Total cpu count used by nodes
- Span* cpuIds; // CPU ids of each node
-
- #ifdef _WIN32
-// Span procGroup; // Processor group each cpu belongs to.
- #endif
-};
-
-class SysHost
-{
-public:
-
- // Get the system page size in bytes
- static size_t GetPageSize();
-
- // Get total physical system ram in bytes
- static size_t GetTotalSystemMemory();
-
- /// Gets the currently available (unused) system ram in bytes
- static size_t GetAvailableSystemMemory();
-
- /// Get the total number of logical CPUs in the system
- static uint GetLogicalCPUCount();
-
- /// Create an allocation in the virtual memory space
- /// If initialize == true, then all pages are touched so that
- /// the pages are actually assigned.
- static void* VirtualAlloc( size_t size, bool initialize = false );
-
- static void VirtualFree( void* ptr );
-
- static bool VirtualProtect( void* ptr, size_t size, VProtect flags = VProtect::NoAccess );
-
- /// Set the processor affinity mask for the current process
- // static uint64 SetCurrentProcessAffinityMask( uint64 mask );
-
- /// Set the processor affinity mask for the current thread
-// static uint64 SetCurrentThreadAffinityMask( uint64 mask );
-
- /// Set the processor affinity mask to a specific cpu id for the current thread
- static bool SetCurrentThreadAffinityCpuId( uint32 cpuId );
-
- /// Install a crash handler to dump stack traces upon crash
- static void InstallCrashHandler();
-
- /// Generate random data
- /// (We basically do what libsodium does here)
- static void Random( byte* buffer, size_t size );
-
- /// Get system's NUMA info, if it has any
- static const NumaInfo* GetNUMAInfo();
-
- /// Assign memory pages to a NUMA node
- static void NumaAssignPages( void* ptr, size_t size, uint node );
-
- /// Set interleave NUMA mode for allocations in the calling thread
- static bool NumaSetThreadInterleavedMode();
-
- /// Set interleave NUMA mode for the specified memory regions.
- /// NOTE: Pages must not yet be faulted.
- static bool NumaSetMemoryInterleavedMode( void* ptr, size_t size );
-
- /// Get the node a memory page belongs to.
- /// Returns a negative value upon failure.
- /// NOTE: Pages must first be faulted on linuz.
- static int NumaGetNodeFromPage( void* ptr );
-
+#pragma once
+
+enum class VProtect : uint
+{
+ NoAccess = 0, // No memory access allowed at all
+
+ Read = 1 << 0, // Allow reads. (Make pages read-only.)
+ Write = 1 << 1, // Allow writes. (Make pages write-only.) // NOTE: This is not guaranteed depending on implementation.
+
+ ReadWrite = Read | Write // Make pages read/writable
+};
+ImplementFlagOps( VProtect );
+
+struct NumaInfo
+{
+ uint nodeCount; // How many NUMA nodes in the system
+ uint cpuCount; // Total cpu count used by nodes
+ Span* cpuIds; // CPU ids of each node
+
+ #ifdef _WIN32
+// Span procGroup; // Processor group each cpu belongs to.
+ #endif
+};
+
+class SysHost
+{
+public:
+
+ // Get the system page size in bytes
+ static size_t GetPageSize();
+
+ // Get total physical system ram in bytes
+ static size_t GetTotalSystemMemory();
+
+ /// Gets the currently available (unused) system ram in bytes
+ static size_t GetAvailableSystemMemory();
+
+ /// Get the total number of logical CPUs in the system
+ static uint GetLogicalCPUCount();
+
+ /// Create an allocation in the virtual memory space
+ /// If initialize == true, then all pages are touched so that
+ /// the pages are actually assigned.
+ static void* VirtualAlloc( size_t size, bool initialize = false );
+
+ static void VirtualFree( void* ptr );
+
+ static bool VirtualProtect( void* ptr, size_t size, VProtect flags = VProtect::NoAccess );
+
+ /// Set the processor affinity mask for the current process
+ // static uint64 SetCurrentProcessAffinityMask( uint64 mask );
+
+ /// Set the processor affinity mask for the current thread
+// static uint64 SetCurrentThreadAffinityMask( uint64 mask );
+
+ /// Set the processor affinity mask to a specific cpu id for the current thread
+ static bool SetCurrentThreadAffinityCpuId( uint32 cpuId );
+
+ /// Install a crash handler to dump stack traces upon crash
+ static void InstallCrashHandler();
+
+ /// Dump stack trace to stderr
+ static void DumpStackTrace();
+
+ /// Generate random data
+ /// (We basically do what libsodium does here)
+ static void Random( byte* buffer, size_t size );
+
+ /// Get system's NUMA info, if it has any
+ static const NumaInfo* GetNUMAInfo();
+
+ /// Assign memory pages to a NUMA node
+ static void NumaAssignPages( void* ptr, size_t size, uint node );
+
+ /// Set interleave NUMA mode for allocations in the calling thread
+ static bool NumaSetThreadInterleavedMode();
+
+ /// Set interleave NUMA mode for the specified memory regions.
+ /// NOTE: Pages must not yet be faulted.
+ static bool NumaSetMemoryInterleavedMode( void* ptr, size_t size );
+
+ /// Get the node a memory page belongs to.
+ /// Returns a negative value upon failure.
+ /// NOTE: Pages must first be faulted on linux.
+ static int NumaGetNodeFromPage( void* ptr );
+
};
\ No newline at end of file
diff --git a/src/Types.h b/src/Types.h
index 4b7eb921..75e90074 100644
--- a/src/Types.h
+++ b/src/Types.h
@@ -1,54 +1,68 @@
-#pragma once
-
-typedef uint8_t byte;
-typedef uint8_t uint8;
-typedef uint16_t uint16;
-typedef uint32_t uint32;
-typedef unsigned long long int uint64;
-
-#if !uint
- typedef uint32 uint;
-#endif
-
-#if !ssize_t
- typedef int64_t ssize_t;
-#endif
-
-typedef uint8 u8;
-typedef uint16 u16;
-typedef uint32 u32;
-typedef uint64 u64;
-
-typedef int8_t sbyte;
-typedef int8_t int8;
-typedef int16_t int16;
-typedef int32_t int32;
-typedef long long int int64;
-
-typedef int8 i8;
-typedef int16 i16;
-typedef int32 i32;
-typedef int64 i64;
-
-typedef float float32;
-typedef double float64;
-typedef float32 f32;
-typedef float64 f64;
-
-typedef uint32 size_t32;
-typedef uint64 size_t64;
-
-static_assert( sizeof( byte ) == 1, "byte must be 1" );
-static_assert( sizeof( uint8 ) == 1, "uint8 must be 1" );
-static_assert( sizeof( uint16 ) == 2, "uint16 must be 2" );
-static_assert( sizeof( uint32 ) == 4, "uint32 must be 4" );
-static_assert( sizeof( uint64 ) == 8, "uint64 must be 8" );
-
-static_assert( sizeof( sbyte ) == 1, "sbyte must be 1" );
-static_assert( sizeof( int8 ) == 1, "int8 must be 1" );
-static_assert( sizeof( int16 ) == 2, "int16 must be 2" );
-static_assert( sizeof( int32 ) == 4, "int32 must be 4" );
-static_assert( sizeof( int64 ) == 8, "int64 must be 8" );
-
-static_assert( sizeof( float32 ) == 4, "float32 must be 4" );
-static_assert( sizeof( float64 ) == 8, "float64 must be 8" );
+#pragma once
+
+typedef uint8_t byte;
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef uint32_t uint32;
+typedef uint64_t uint64;
+
+// Prevent compiler whining about %llu when uint64:
+typedef long long unsigned int llu;
+
+#if !uint
+ typedef uint32 uint;
+#endif
+
+#if _WIN32
+ typedef int64_t ssize_t;
+#endif
+
+typedef uint8 u8;
+typedef uint16 u16;
+typedef uint32 u32;
+typedef uint64 u64;
+
+typedef int8_t sbyte;
+typedef int8_t int8;
+typedef int16_t int16;
+typedef int32_t int32;
+typedef long long int int64;
+
+typedef int8 i8;
+typedef int16 i16;
+typedef int32 i32;
+typedef int64 i64;
+
+typedef float float32;
+typedef double float64;
+typedef float32 f32;
+typedef float64 f64;
+
+typedef uint32 size_t32;
+typedef uint64 size_t64;
+
+static_assert( sizeof( byte ) == 1, "byte must be 1" );
+static_assert( sizeof( uint8 ) == 1, "uint8 must be 1" );
+static_assert( sizeof( uint16 ) == 2, "uint16 must be 2" );
+static_assert( sizeof( uint32 ) == 4, "uint32 must be 4" );
+static_assert( sizeof( uint64 ) == 8, "uint64 must be 8" );
+
+static_assert( sizeof( sbyte ) == 1, "sbyte must be 1" );
+static_assert( sizeof( int8 ) == 1, "int8 must be 1" );
+static_assert( sizeof( int16 ) == 2, "int16 must be 2" );
+static_assert( sizeof( int32 ) == 4, "int32 must be 4" );
+static_assert( sizeof( int64 ) == 8, "int64 must be 8" );
+
+static_assert( sizeof( float32 ) == 4, "float32 must be 4" );
+static_assert( sizeof( float64 ) == 8, "float64 must be 8" );
+
+#ifdef __SIZEOF_INT128__
+ typedef __uint128_t uint128_t;
+#else
+ #include "uint128_t/uint128_t.h"
+#endif
+
+typedef uint128_t uint128;
+
+typedef std::chrono::steady_clock::duration Duration;
+typedef std::chrono::steady_clock::time_point TimePoint;
diff --git a/src/Util.cpp b/src/Util.cpp
deleted file mode 100644
index 00988b7d..00000000
--- a/src/Util.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "Util.h"
-#include "util/Log.h"
-
-//-----------------------------------------------------------
-void VFatal( const char* message, va_list args )
-{
- Log::Error( "Fatal Error:" );
- Log::WriteError( " " );
- Log::Error( message, args );
- Log::FlushError();
-
- ASSERT( 0 );
- exit( 1 );
-}
-
-//-----------------------------------------------------------
-void Fatal( const char* message, ... )
-{
- va_list args;
- va_start( args, message );
- VFatal( message, args );
- va_end( args );
-}
-
-//-----------------------------------------------------------
-void FatalIf( bool condition, const char* message, ... )
-{
- if( condition )
- {
- va_list args;
- va_start( args, message );
- VFatal( message, args );
- va_end( args );
- }
-}
\ No newline at end of file
diff --git a/src/Util.h b/src/Util.h
deleted file mode 100644
index fd819d0c..00000000
--- a/src/Util.h
+++ /dev/null
@@ -1,309 +0,0 @@
-#pragma once
-
-#include
-#include
-
-#ifdef _MSC_VER
- #define Swap16( x ) _byteswap_ushort( x )
- #define Swap32( x ) _byteswap_ulong( x )
- #define Swap64( x ) _byteswap_uint64( x )
-#elif defined( __GNUC__ )
- #define Swap16( x ) __builtin_bswap16( x )
- #define Swap32( x ) __builtin_bswap32( x )
- #define Swap64( x ) __builtin_bswap64( x )
-#else
- #error Byte swapping intrinsics not configured for this compiler.
-#endif
-
-
-/// Byte size conversions
-#define KB *(1<<10)
-#define MB *(1<<20)
-#define GB *(1<<30)
-
-#define BtoKB /(1<<10)
-#define BtoMB /(1<<20)
-#define BtoGB /(1<<30)
-
-
-///
-/// Assorted utility functions
-///
-
-// Post a message and exit with error
-//-----------------------------------------------------------
-void Fatal( const char* message, ... );
-
-void FatalIf( bool condition, const char* message, ... );
-
-//-----------------------------------------------------------
-template
-inline void ZeroMem( T* ptr )
-{
- memset( ptr, 0, sizeof( T ) );
-}
-
-//-----------------------------------------------------------
-template
-inline void ZeroMem( T* ptr, size_t count )
-{
- ASSERT( count > 0 );
- memset( ptr, 0, sizeof( T ) * count );
-}
-
-// Like ceil div, but tells you how man times to multiply
-// a in order to fit into b-sized chunks
-//-----------------------------------------------------------
-template
-constexpr inline T CDiv( T a, int b )
-{
- return ( a + (T)b - 1 ) / (T)b;
-}
-
-/// Divides by and rounds
-/// it up to the next factor of
-//-----------------------------------------------------------
-template
-inline T CeildDiv( T dividend, T divisor )
-{
- return dividend + ( divisor - ( dividend % divisor ) ) % divisor;
-}
-
-// Round up a number to the next upper boundary.
-// For example, if we want to round up some bytes to the
-// next 8-byte boundary.
-// This is the same as CeilDiv, but with a more intuitive name.
-//-----------------------------------------------------------
-template
-inline T RoundUpToNextBoundary( T value, int boundary )
-{
- return CeildDiv( value, (T)boundary );
-}
-
-const char HEX_TO_BIN[256] = {
- 0, // 0 00 NUL
- 0, // 1 01 SOH
- 0, // 2 02 STX
- 0, // 3 03 ETX
- 0, // 4 04 EOT
- 0, // 5 05 ENQ
- 0, // 6 06 ACK
- 0, // 7 07 BEL
- 0, // 8 08 BS
- 0, // 9 09 HT
- 0, // 10 0A LF
- 0, // 11 0B VT
- 0, // 12 0C FF
- 0, // 13 0D CR
- 0, // 14 0E SO
- 0, // 15 0F SI
- 0, // 16 10 DLE
- 0, // 17 11 DC1
- 0, // 18 12 DC2
- 0, // 19 13 DC3
- 0, // 20 14 DC4
- 0, // 21 15 NAK
- 0, // 22 16 SYN
- 0, // 23 17 ETB
- 0, // 24 18 CAN
- 0, // 25 19 EM
- 0, // 26 1A SUB
- 0, // 27 1B ESC
- 0, // 28 1C FS
- 0, // 29 1D GS
- 0, // 30 1E RS
- 0, // 31 1F US
- 0, // 32 20 space
- 0, // 33 21 !
- 0, // 34 22 "
- 0, // 35 23 #
- 0, // 36 24 $
- 0, // 37 25 %
- 0, // 38 26 &
- 0, // 39 27 '
- 0, // 40 28 (
- 0, // 41 29 )
- 0, // 42 2A *
- 0, // 43 2B +
- 0, // 44 2C ,
- 0, // 45 2D -
- 0, // 46 2E .
- 0, // 47 2F /
- 0, // 48 30 0
- 1, // 49 31 1
- 2, // 50 32 2
- 3, // 51 33 3
- 4, // 52 34 4
- 5, // 53 35 5
- 6, // 54 36 6
- 7, // 55 37 7
- 8, // 56 38 8
- 9, // 57 39 9
- 0, // 58 3A :
- 0, // 59 3B ;
- 0, // 60 3C <
- 0, // 61 3D =
- 0, // 62 3E >
- 0, // 63 3F ?
- 0, // 64 40 @
- 10, // 65 41 A
- 11, // 66 42 B
- 12, // 67 43 C
- 13, // 68 44 D
- 14, // 69 45 E
- 15, // 70 46 F
- 0, // 71 47 G
- 0, // 72 48 H
- 0, // 73 49 I
- 0, // 74 4A J
- 0, // 75 4B K
- 0, // 76 4C L
- 0, // 77 4D M
- 0, // 78 4E N
- 0, // 79 4F O
- 0, // 80 50 P
- 0, // 81 51 Q
- 0, // 82 52 R
- 0, // 83 53 S
- 0, // 84 54 T
- 0, // 85 55 U
- 0, // 86 56 V
- 0, // 87 57 W
- 0, // 88 58 X
- 0, // 89 59 Y
- 0, // 90 5A Z
- 0, // 91 5B [
- 0, // 92 5C \ //
- 0, // 93 5D ]
- 0, // 94 5E ^
- 0, // 95 5F _
- 0, // 96 60 `
- 10, // 97 61 a
- 11, // 98 62 b
- 12, // 99 63 c
- 13, // 100 64 d
- 14, // 101 65 e
- 15, // 102 66 f
- 0, // 103 67 g
- 0, // 104 68 h
- 0, // 105 69 i
- 0, // 106 6A j
- 0, // 107 6B k
- 0, // 108 6C l
- 0, // 109 6D m
- 0, // 110 6E n
- 0, // 111 6F o
- 0, // 112 70 p
- 0, // 113 71 q
- 0, // 114 72 r
- 0, // 115 73 s
- 0, // 116 74 t
- 0, // 117 75 u
- 0, // 118 76 v
- 0, // 119 77 w
- 0, // 120 78 x
- 0, // 121 79 y
- 0, // 122 7A z
- 0, // 123 7B {
- 0, // 124 7C |
- 0, // 125 7D }
- 0, // 126 7E ~
- 0, // 127 7F DEL
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-};
-
-//-----------------------------------------------------------
-inline void HexStrToBytes( const char* str, const size_t strSize,
- byte* dst, size_t dstSize )
-{
- ASSERT( str && strSize );
- ASSERT( dst && dstSize );
-
- const size_t maxSize = (strSize / 2) * 2;
- const char* end = str + maxSize;
-
- ASSERT( dstSize >= maxSize / 2 );
-
- int i = 0;
- while( str < end )
- {
- byte msb = (byte)HEX_TO_BIN[(int)str[0]];
- byte lsb = (byte)HEX_TO_BIN[(int)str[1]];
-
- byte v = lsb + msb * 16u;
- dst[i++] = v;
- str += 2;
- }
-}
-
-//-----------------------------------------------------------
-// Encode bytes into hex format
-// Return:
-// 0 if OK
-// -1 if Needed more space in the dst buffer to write
-// -2 if the required dstSize would overflow
-//-----------------------------------------------------------
-inline int BytesToHexStr( const byte* src, size_t srcSize,
- char* dst, size_t dstSize,
- size_t& numEncoded,
- bool uppercase = false )
-{
- const char HEXUC[] = "0123456789ABCDEF";
- const char HEXLC[] = "0123456789abcdef";
-
- const char* HEX = uppercase ? HEXUC : HEXLC;
-
- const size_t MAX_SRC_SIZE = std::numeric_limits::max() / 2;
-
- numEncoded = 0;
- int ret = 0;
-
- if( dstSize == 0 )
- {
- return -1;
- }
-
- size_t maxEncode = srcSize;
- size_t dstRequired;
-
- // Check for overflow
- if( maxEncode > MAX_SRC_SIZE )
- {
- maxEncode = MAX_SRC_SIZE;
- dstRequired = std::numeric_limits::max();
- numEncoded = MAX_SRC_SIZE;
- ret = -2;
- }
- else
- {
- dstRequired = maxEncode * 2;
- numEncoded = maxEncode;
- }
-
- // Cap the encode count to the dst buffer size
- if( dstRequired > dstSize )
- {
- ret = -1;
- numEncoded = dstSize/2;
- }
-
- const byte* s = src;
- const byte* end = src + numEncoded;
- char* d = dst;
-
- while( s < end )
- {
- d[0] = (char)HEX[(*s >> 4) & 0x0F];
- d[1] = (char)HEX[*s & 15];
-
- s++;
- d += 2;
- }
-
- return ret;
-}
-
diff --git a/src/Version.h b/src/Version.h
index 9098d2ff..1f0e772a 100644
--- a/src/Version.h
+++ b/src/Version.h
@@ -1,10 +1,71 @@
#pragma once
-#define BLADEBIT_VERSION_MAJ 1
-#define BLADEBIT_VERSION_MIN 2
-#define BLADEBIT_VERSION_REV 0
+#ifndef BLADEBIT_VERSION_MAJ
+ #define BLADEBIT_VERSION_MAJ 0
+#endif
+
+#ifndef BLADEBIT_VERSION_MIN
+ #define BLADEBIT_VERSION_MIN 0
+#endif
+
+#ifndef BLADEBIT_VERSION_REV
+ #define BLADEBIT_VERSION_REV 0
+#endif
+
+#ifndef BLADEBIT_VERSION_SUFFIX
+ #define BLADEBIT_VERSION_SUFFIX "-dev"
+#endif
+
+#ifndef BLADEBIT_GIT_COMMIT
+ #define BLADEBIT_GIT_COMMIT "unknown"
+#endif
+
+// Record compiler version
+#if defined( __clang__ )
+ struct BBCompilerVer
+ {
+ static constexpr const char* compiler = "clang";
+ static constexpr uint32_t major = __clang_major__;
+ static constexpr uint32_t minor = __clang_minor__;
+ static constexpr uint32_t revision = __clang_patchlevel__;
+ };
+#elif defined( __GNUC__ )
+ struct BBCompilerVer
+ {
+ static constexpr const char* compiler = "gcc";
+ static constexpr uint32_t major = __GNUC__;
+ static constexpr uint32_t minor = __GNUC_MINOR__;
+ static constexpr uint32_t revision = __GNUC_PATCHLEVEL__;
+ };
+#elif defined( _MSC_VER )
+ struct BBCompilerVer
+ {
+ static constexpr const char* compiler = "msvc";
+ static constexpr uint32_t major = _MSC_VER / 100u;
+ static constexpr uint32_t minor = _MSC_VER - major * 100u;
+ static constexpr uint32_t revision = _MSC_FULL_VER - _MSC_VER * 100000u;
+ };
+
+#else
+ #warning "Unknown compiler"
+ struct BBCompilerVer
+ {
+ static constexpr const char* compiler = "unknown";
+ static constexpr uint32_t major = 0;
+ static constexpr uint32_t minor = 0;
+ static constexpr uint32_t revision = 0;
+ };
+#endif
+
+// #NOTE: Not thread safe
+inline const char* BBGetCompilerVersion()
+{
+ static char c[256] = {};
+ sprintf( c, "%s %u.%u.%u", BBCompilerVer::compiler, BBCompilerVer::major,
+ BBCompilerVer::minor, BBCompilerVer::revision );
+ return c;
+}
-#define BLADEBIT_GIT_COMMIT "dev"
#define BLADEBIT_VERSION \
((uint64)BLADEBIT_VERSION_MAJ) << 32 \
@@ -12,5 +73,6 @@
((uint64)BLADEBIT_VERSION_REV)
#define BLADEBIT_VERSION_STR \
- STR( BLADEBIT_VERSION_MAJ ) "." STR( BLADEBIT_VERSION_MIN ) "." STR( BLADEBIT_VERSION_REV )
+ STR( BLADEBIT_VERSION_MAJ ) "." STR( BLADEBIT_VERSION_MIN ) "." STR( BLADEBIT_VERSION_REV ) \
+ BLADEBIT_VERSION_SUFFIX
diff --git a/src/View.h b/src/View.h
index ce500f70..89767f68 100644
--- a/src/View.h
+++ b/src/View.h
@@ -1,32 +1,32 @@
-#pragma once
-
-template
-struct View
-{
- T* _ptr;
- size_t _count;
-
- //-----------------------------------------------------------
- inline View( T* ptr, size_t count )
- : _ptr ( ptr )
- , _count( count )
- {}
-
- //-----------------------------------------------------------
- inline View( T* ptr )
- : _ptr ( ptr )
- , _count( 0 )
- {}
-
-
- //-----------------------------------------------------------
- inline T* operator-> () const { return this->_ptr; }
-
- //-----------------------------------------------------------
- inline operator T* ( ) const { return this->_ptr; }
-
- // Returns true if the object ptr is not null
- inline operator bool() const { return this->_ptr != nullptr; }
-
-
+#pragma once
+
+template
+struct View
+{
+ T* _ptr;
+ size_t _count;
+
+ //-----------------------------------------------------------
+ inline View( T* ptr, size_t count )
+ : _ptr ( ptr )
+ , _count( count )
+ {}
+
+ //-----------------------------------------------------------
+ inline View( T* ptr )
+ : _ptr ( ptr )
+ , _count( 0 )
+ {}
+
+
+ //-----------------------------------------------------------
+ inline T* operator-> () const { return this->_ptr; }
+
+ //-----------------------------------------------------------
+ inline operator T* ( ) const { return this->_ptr; }
+
+ // Returns true if the object ptr is not null
+ inline operator bool() const { return this->_ptr != nullptr; }
+
+
};
\ No newline at end of file
diff --git a/src/algorithm/RadixSort.h b/src/algorithm/RadixSort.h
index 86dde153..e096ec39 100644
--- a/src/algorithm/RadixSort.h
+++ b/src/algorithm/RadixSort.h
@@ -1,326 +1,346 @@
-#pragma once
-#include "threading/ThreadPool.h"
-#include
-
-class RadixSort256
-{
- template
- struct SortJob
- {
- uint id; // Id 0 is in charge of performing the non-parallel steps.
- uint threadCount; // How many threads are participating in the sort
-
- // When All threads have finished, we can
- // thread 0 (the control thread) can calculate jobs and signal them to continue
- std::atomic* finishedCount;
- std::atomic* releaseLock;
-
- uint64* counts; // Counts array for each thread
- uint64* pfxSums; // Prefix sums for each thread. We use a different buffers to avoid copying to tmp buffers.
-
- uint64 startIndex; // Scan start index
- uint64 length; // entry count in our scan region
-
- T1* input;
- T1* tmp;
-
- // For sort key gen jobs
- T2* keyInput;
- T2* keyTmp;
- };
-
- enum SortMode
- {
- Void = 0,
- ModeSingle = 1 << 0,
- SortAndGenKey = 1 << 1, // Sort input and generate a key in keyInput at the same time
- };
-
-public:
- template
- static void Sort( ThreadPool& pool, T1* input, T1* tmp, uint64 length );
-
- template
- static void SortWithKey( ThreadPool& pool, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length );
-
- template
- static void SortY( ThreadPool& pool, uint64* input, uint64* tmp, uint64 length );
-
- template
- static void SortYWithKey( ThreadPool& pool, uint64* input, uint64* tmp, uint32* keyInput, uint32* keyTmp, uint64 length );
-
-private:
-
- template
- static void DoSort( ThreadPool& pool, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length );
-
- template
- static void RadixSortThread( SortJob* job );
-};
-
-
-//-----------------------------------------------------------
-template
-inline void RadixSort256::Sort( ThreadPool& pool, T1* input, T1* tmp, uint64 length )
-{
- DoSort( pool, input, tmp, nullptr, nullptr, length );
-}
-
-//-----------------------------------------------------------
-template
-inline void RadixSort256::SortWithKey( ThreadPool& pool, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length )
-{
- DoSort( pool, input, tmp, keyInput, keyTmp, length );
-}
-
-//-----------------------------------------------------------
-template
-inline void RadixSort256::SortY( ThreadPool& pool, uint64* input, uint64* tmp, uint64 length )
-{
- DoSort( pool, input, tmp, nullptr, nullptr, length );
-}
-
-//-----------------------------------------------------------
-template
-inline void RadixSort256::SortYWithKey( ThreadPool& pool, uint64* input, uint64* tmp, uint32* keyInput, uint32* keyTmp, uint64 length )
-{
- DoSort( pool, input, tmp, keyInput, keyTmp, length );
-}
-
-//-----------------------------------------------------------
-template
-void inline RadixSort256::DoSort( ThreadPool& pool, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length )
-{
- const uint threadCount = ThreadCount > pool.ThreadCount() ? pool.ThreadCount() : ThreadCount;
- const uint64 entriesPerThread = length / threadCount;
- const uint64 trailingEntries = length - ( entriesPerThread * threadCount );
-
- // #TODO: Make sure we have enough stack space for this.
- // Create a large stack, or allocate this on the heap...
- // In which case, make this an instance method and have preallocated buffers for the jobs too
- // Since we don't know the thread count ahead of time, maybe we should just make sure we allocate enough space for the jobs
- // and use an instance instead...
- uint64 counts [ThreadCount*256];
- uint64 prefixSums[ThreadCount*256];
-
- std::atomic finishedCount = 0;
- std::atomic releaseLock = 0;
- SortJob jobs[ThreadCount];
-
- for( uint i = 0; i < threadCount; i++ )
- {
- auto& job = jobs[i];
-
- job.id = i;
- job.threadCount = threadCount;
- job.finishedCount = &finishedCount;
- job.releaseLock = &releaseLock;
- job.counts = counts;
- job.pfxSums = prefixSums;
- job.startIndex = i * entriesPerThread;
- job.length = entriesPerThread;
- job.input = input;
- job.tmp = tmp;
-
- job.keyInput = keyInput;
- job.keyTmp = keyTmp;
- }
-
- jobs[threadCount-1].length += trailingEntries;
-
- if constexpr ( Mode == SortAndGenKey )
- pool.RunJob( RadixSortThread, jobs, threadCount );
- else
- pool.RunJob( RadixSortThread, jobs, threadCount );
-}
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
-
-//-----------------------------------------------------------
-template
-void RadixSort256::RadixSortThread( SortJob* job )
-{
- constexpr uint Radix = 256;
-
- constexpr uint32 iterations = MaxIter > 0 ? MaxIter : sizeof( T1 );
- const uint32 shiftBase = 8;
-
- uint32 shift = 0;
-
- const uint id = job->id;
- const uint threadCount = job->threadCount;
- std::atomic& finishedCount = *job->finishedCount;
- std::atomic& releaseLock = *job->releaseLock;
-
- uint64* counts = job->counts + id * Radix;
- uint64* prefixSum = job->pfxSums + id * Radix;
- const uint64 length = job->length;
- const uint64 offset = job->startIndex;
- T1* input = job->input;
- T1* tmp = job->tmp;
-
- T2* keyInput;
- T2* keyTmp;
-
- if constexpr ( IsKeyed )
- {
- keyInput = job->keyInput;
- keyTmp = job->keyTmp;
- }
-
- for( uint32 iter = 0; iter < iterations ; iter++, shift += shiftBase )
- {
- // Zero-out the counts
- memset( counts, 0, sizeof( uint64 ) * Radix );
-
- // Grab our scan region from the input
- const T1* src = input + offset;
-
- const T2* keySrc;
- if constexpr ( IsKeyed )
- keySrc = keyInput + offset;
-
-
- // Store the occurrences of the current 'digit'
- for( uint64 i = 0; i < length; i++ )
- counts[(src[i] >> shift) & 0xFF]++;
-
- // Synchronize with other threads to comput the correct prefix sum
- if( id == 0 )
- {
- // This is the control thread, it is in charge of computing the shared prefix sums.
-
- // Wait for all threads to finish
- while( finishedCount.load( std::memory_order_relaxed ) != threadCount-1 );
-
- uint64* allCounts = job->counts;
- uint64* allPfxSums = job->pfxSums;
-
- // Use the last thread's prefix sum buffer as it will use
- // it does not require a second pass
- uint64* prefixSumBuffer = allPfxSums + (threadCount - 1) * Radix;
-
- // First sum all the counts. Start by copying ours to the last
- memcpy( prefixSumBuffer, counts, sizeof( uint64 ) * Radix );
-
- // Now add the rest of the thread's counts
- for( uint i = 1; i < threadCount; i++ )
- {
- uint64* tCounts = allCounts + i * Radix;
-
- for( uint32 j = 0; j < Radix; j++ )
- prefixSumBuffer[j] += tCounts[j];
- }
-
- // Now we have the sum of all thread's counts,
- // we can calculate the prefix sum, which is
- // equivalent to the last thread's prefix sum
- for( uint32 j = 1; j < Radix; j++ )
- prefixSumBuffer[j] += prefixSumBuffer[j-1];
-
- const uint64* nextThreadCountBuffer = allCounts + (threadCount - 1) * Radix;
-
- // Now assign the adjusted prefix sum to each thread below the last thread
- // NOTE: We are traveling backwards from the last thread
- for( uint i = 1; i < threadCount; i++ )
- {
- uint64* tPrefixSum = prefixSumBuffer - Radix;
-
- // This thread's prefix sum is equal to the next thread's
- // prefix sum minus the next thread's count
- for( uint32 j = 0; j < Radix; j++ )
- tPrefixSum[j] = prefixSumBuffer[j] - nextThreadCountBuffer[j];
-
- prefixSumBuffer = tPrefixSum;
- nextThreadCountBuffer -= Radix;
- }
-
- // Finished, init release lock & signal other threads
- releaseLock .store( 0, std::memory_order_release );
- finishedCount.store( 0, std::memory_order_release );
- }
- else
- {
- // Signal we've finished so we can calculate the shared prefix sum
- uint count = finishedCount.load( std::memory_order_acquire );
-
- while( !finishedCount.compare_exchange_weak( count, count+1, std::memory_order_release, std::memory_order_relaxed ) );
-
- // Wait for the control thread (id == 0 ) to signal us so
- // that we can continue working.
- while( finishedCount.load( std::memory_order_relaxed ) != 0 );
-
- // Ensure all threads have been released
- count = releaseLock.load( std::memory_order_acquire );
- while( !releaseLock.compare_exchange_weak( count, count+1, std::memory_order_release, std::memory_order_relaxed ) );
- while( releaseLock.load( std::memory_order_relaxed ) != threadCount-1 );
- }
-
- // Populate output array (access input in reverse now)
- // This writes to the whole output array, not just our section.
- // This can cause false sharing, but given that our inputs are
- // extremely large, and the accesses are random, we don't expect
- // a lot of this to be happening.
- for( uint64 i = length; i > 0; )
- {
- // Read the value & prefix sum index
- const T1 value = src[--i];
-
- const uint64 idx = (value >> shift) & 0xFF;
-
- // Store it at the right location by reading the count
- const uint64 dstIdx = --prefixSum[idx];
- tmp[dstIdx] = value;
-
- if constexpr ( IsKeyed )
- keyTmp[dstIdx] = keySrc[i];
- }
-
- // Swap arrays
- T1* t = input;
- input = tmp;
- tmp = t;
-
- if constexpr ( IsKeyed )
- {
- T2* tk = keyInput;
- keyInput = keyTmp;
- keyTmp = tk;
- }
-
- // If not the last iteration, signal we've finished so we can
- // safely read from the arrays after swapped. (all threads must finish writing)
- if( (iter+1) < iterations )
- {
- if( id == 0 )
- {
- // Wait for all threads
- while( finishedCount.load( std::memory_order_relaxed ) != (threadCount-1) );
-
- // Finished, init release lock & signal other threads
- releaseLock .store( 0, std::memory_order_release );
- finishedCount.store( 0, std::memory_order_release );
- }
- else
- {
- // Signal control thread
- uint count = finishedCount.load( std::memory_order_acquire );
-
- while( !finishedCount.compare_exchange_weak( count, count+1, std::memory_order_release, std::memory_order_relaxed ) );
-
- // Wait for control thread to signal us
- while( finishedCount.load( std::memory_order_relaxed ) != 0 );
-
- // Ensure all threads have been released
- count = releaseLock.load( std::memory_order_acquire );
- while( !releaseLock.compare_exchange_weak( count, count+1, std::memory_order_release, std::memory_order_relaxed ) );
- while( releaseLock.load( std::memory_order_relaxed ) != threadCount-1 );
- }
- }
- }
-}
-
-#pragma GCC diagnostic pop
-
-
+#pragma once
+#include "threading/ThreadPool.h"
+#include
+
+class RadixSort256
+{
+ template
+ struct SortJob
+ {
+ uint id; // Id 0 is in charge of performing the non-parallel steps.
+ uint threadCount; // How many threads are participating in the sort
+
+ // When All threads have finished, we can
+ // thread 0 (the control thread) can calculate jobs and signal them to continue
+ std::atomic* finishedCount;
+ std::atomic* releaseLock;
+
+ uint64* counts; // Counts array for each thread
+ uint64* pfxSums; // Prefix sums for each thread. We use a different buffers to avoid copying to tmp buffers.
+
+ uint64 startIndex; // Scan start index
+ uint64 length; // entry count in our scan region
+
+ T1* input;
+ T1* tmp;
+
+ // For sort key gen jobs
+ T2* keyInput;
+ T2* keyTmp;
+ };
+
+ enum SortMode
+ {
+ Void = 0,
+ ModeSingle = 1 << 0,
+ SortAndGenKey = 1 << 1, // Sort input and generate a key in keyInput at the same time
+ };
+
+public:
+ template
+ static void Sort( ThreadPool& pool, T1* input, T1* tmp, uint64 length );
+
+ template
+ static void Sort( ThreadPool& pool, const uint32 threadCount, T1* input, T1* tmp, uint64 length );
+
+ template
+ static void SortWithKey( ThreadPool& pool, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length );
+
+ template
+ static void SortWithKey( ThreadPool& pool, const uint32 threadCount, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length );
+
+ template
+ static void SortY( ThreadPool& pool, uint64* input, uint64* tmp, uint64 length );
+
+ template
+ static void SortYWithKey( ThreadPool& pool, uint64* input, uint64* tmp, uint32* keyInput, uint32* keyTmp, uint64 length );
+
+private:
+
+ template
+ static void DoSort( ThreadPool& pool, const uint32 desiredThreadCount, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length );
+
+ template
+ static void RadixSortThread( SortJob* job );
+};
+
+
+//-----------------------------------------------------------
+template
+inline void RadixSort256::Sort( ThreadPool& pool, T1* input, T1* tmp, uint64 length )
+{
+ DoSort( pool, 0, input, tmp, nullptr, nullptr, length );
+}
+
+//-----------------------------------------------------------
+template
+inline void RadixSort256::Sort( ThreadPool& pool, const uint32 threadCount, T1* input, T1* tmp, uint64 length )
+{
+ DoSort( pool, threadCount, input, tmp, nullptr, nullptr, length );
+}
+
+//-----------------------------------------------------------
+template
+inline void RadixSort256::SortWithKey( ThreadPool& pool, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length )
+{
+ DoSort( pool, 0, input, tmp, keyInput, keyTmp, length );
+}
+
+//-----------------------------------------------------------
+template
+inline void RadixSort256::SortWithKey( ThreadPool& pool, const uint32 threadCount, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length )
+{
+ DoSort( pool, threadCount, input, tmp, keyInput, keyTmp, length );
+}
+
+//-----------------------------------------------------------
+template
+inline void RadixSort256::SortY( ThreadPool& pool, uint64* input, uint64* tmp, uint64 length )
+{
+ DoSort( pool, 0, input, tmp, nullptr, nullptr, length );
+}
+
+//-----------------------------------------------------------
+template
+inline void RadixSort256::SortYWithKey( ThreadPool& pool, uint64* input, uint64* tmp, uint32* keyInput, uint32* keyTmp, uint64 length )
+{
+ DoSort( pool, 0, input, tmp, keyInput, keyTmp, length );
+}
+
+//-----------------------------------------------------------
+template
+void inline RadixSort256::DoSort( ThreadPool& pool, const uint32 desiredThreadCount, T1* input, T1* tmp, TK* keyInput, TK* keyTmp, uint64 length )
+{
+ const uint32 threadCount = desiredThreadCount == 0 ? pool.ThreadCount() : std::min( desiredThreadCount, pool.ThreadCount() );
+ const uint64 entriesPerThread = length / threadCount;
+ const uint64 trailingEntries = length - ( entriesPerThread * threadCount );
+
+ // #TODO: Make sure we have enough stack space for this.
+ // Create a large stack, or allocate this on the heap...
+ // In which case, make this an instance method and have preallocated buffers for the jobs too
+ // Since we don't know the thread count ahead of time, maybe we should just make sure we allocate enough space for the jobs
+ // and use an instance instead...
+ uint64 counts [ThreadCount*256];
+ uint64 prefixSums[ThreadCount*256];
+
+ std::atomic finishedCount = 0;
+ std::atomic