Skip to content

Instantly share code, notes, and snippets.

View catid's full-sized avatar

Chris Taylor catid

View GitHub Profile
Spinal Codes (totally metal name)
Paper: http://nms.csail.mit.edu/papers/fp049-perry.pdf
This is a bitwise error correction code that can correct bit errors anywhere in the message.
It is not MDS and the strength of the code includes the processing time allowed for decoding.
More discussion at the end.
Simple version of the algorithm:
q = x >> 32
r = x - (q << 32)
i = 0
while (q > 0) {
t = (q << 4) - q
q = t >> 32
r_i = t - (q << 32)
if (++i % 2 == 1)
r -= r_i
uint64_t f64(uint64_t x, uint64_t y) {
return y * (2 - y * x);
}
static uint64_t inverse64(uint64_t x) {
uint64_t y = x;
y = f64(x, y);
y = f64(x, y);
y = f64(x, y);
y = f64(x, y);
@catid
catid / fast_field_65.cpp
Created July 24, 2018 16:21
Fast 64-bit almost-finite field
#include <stdint.h>
/*
65-bit multiplication of two 64-bit values a, b
with low bits set to 1 (implicitly):
(2a + 1)(2b + 1)
= 4ab + 2a + 2b + 1
Stuffing it back into a 64-bit value:
@catid
catid / bad_ecc_64.cpp
Created July 26, 2018 06:00
This is a bad erasure code where it has to send some number of extra bits for each 32-bit word of input data. But it does work, which is neat.
/*
// Convolutional encoder:
s = a * x + b * y;
t = c * x + d * y;
The problem with this one is that the "ezc" number of low bit zeros in e is also a number of additional bits that must be sent with each recovery word.
Specifically in the decoder this line:
> uint64_t yr = ei * t >> ezc;
So to tolerate ezc = 4 zero bits, we need to make t 4 bits longer.
@catid
catid / solinas_primes.txt
Created July 28, 2018 02:42
64-bit Solinas prime Fp modular multiplication
Reduction as in "Generalized Mersenne Numbers" J. Solinas (NSA).
Prime from "Solinas primes of small weight for fixed sizes" J. Angel.
Fp = 2^64-2^32+1
t = 2^32
d = 2
f(t) = t^2 - c_1 * t - c_2
@catid
catid / fp61.cpp
Created July 29, 2018 09:08
Fp=2^61-1 Mersenne prime field - Somewhat tested, somewhat optimized
//------------------------------------------------------------------------------
// Integer Arithmetic Modulo Mersenne Prime 2^61-1
// p = 2^61 - 1
static const uint64_t kFp61Prime = ((uint64_t)1 << 61) - 1;
// x + y (without reduction modulo p)
// For x,y < p this can be done up to 7 times (adding 8 values) without overflow
static inline uint64_t fp61_add(uint64_t x, uint64_t y)
{
@catid
catid / HolographicInputBanner.cpp
Created May 25, 2019 23:16
Code to detect and dismiss the Windows Holographic "Win + Y" blue input banner
bool IsWinYPromptOpen()
{
return (FindWindowA("HolographicInputBannerWndClass", nullptr) != nullptr);
}
void DismissWinY()
{
// Press: Win, Y
keybd_event(
Some experiment results from today:
(0) Using NVENC directly is much more advantageous than using NvPipe library, which uses it indirectly.
(1) NVENC lossless video encode mode does worse than the prior open source lossless library (6-8 Mbps versus 4-5)
(2) NVENC only allows for one encoding context at a time, since the second available context must be used for color images. So multiple depth images need to be combined before encoding, or it must be paired with software encoding. Still not sure how to make this practical.
(3) Using Zstd for high bits is best done the naive way without any filtering. Tried a few options and found that works best.
(4) Rescaling the input data to 0...2047 (as wide as possible) to reduce the impact of low bit errors ends up introducing more high bit errors.
(5) Using Zstd for high bits + NVENC for low bits produces files that can be arbitrarily small, in trade for errors in the output. It's hard to judge however the impact of the errors it introduces. If the bandwidth requir
// Copyright 2019 (c) Christopher A. Taylor. All rights reserved.
/*
Xrcap capture client C API for the RGBD Capture Server.
Built on top of CaptureClient.hpp
*/
//------------------------------------------------------------------------------
// C Boilerplate