Skip to content

Instantly share code, notes, and snippets.

View davmac314's full-sized avatar

Davin McCall davmac314

View GitHub Profile
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <assert.h>
// Test program to ensure OS correctly returns full exit status in si_status member
// of siginfo_t in SIGCHLD handler, as required by POSIX. Linux fails, FreeBSD succeeds.
sig_atomic_t exit_status;
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
// Program to demonstrate kqueue bug on macOS (Sierra, possibly others). The
#include <iostream>
#include <fstream>
#include <utility>
#include <regex>
#include <experimental/filesystem>
// Recursively replace shebang lines with correct interpreter paths according to regex rules
namespace fs = std::experimental::filesystem;
@davmac314
davmac314 / ffdiv.cc
Last active October 18, 2016 22:37
// Fast fixed-dividend divider generator in C++11
// by Davin McCall <davmac@davmac.org>
//
// Division is a relatively very slow operation even on modern processors. This
// template (ffdiv) produces a divider that will divide any number up to a fixed
// limit by a fixed dividend, using a multiplication and shift operation. I
// measured this as more than twice as fast as using ordinary division.
//
// Compile with (for eg) "gcc -std=c++11".
//