Skip to content

Instantly share code, notes, and snippets.

View madmann91's full-sized avatar

Arsène Pérard-Gayot madmann91

View GitHub Profile
@madmann91
madmann91 / Simplify.hs
Last active April 29, 2019 16:52
Simplification of a simple boolean + Comparison language
-- Compile and run with:
-- ghc Simplify.hs
-- ./Simplify
import Data.Bits
import Data.List
import Data.Maybe
import Data.Function
import System.Random
import Control.Monad
import Debug.Trace
@madmann91
madmann91 / ir.cpp
Last active July 23, 2019 13:34
Current plan to make Thorin an extensible IR
// g++ -std=c++17 ir.cpp -pedantic -Wall -Wextra -g -o ir
#include <type_traits>
#include <unordered_set>
#include <cassert>
#include <cstdint>
#include <iostream>
// Def is just exposing the data, nothing more
struct Def {
uint32_t gid;
@madmann91
madmann91 / sort.cpp
Last active February 21, 2020 15:15
Sorting routines for C99 (with testbed in C++11)
#include <memory>
#include <iostream>
#include <algorithm>
#include <climits>
#define SWAP(T, x, y) \
{ \
T z = x; \
(x) = y; \
(y) = z; \
@madmann91
madmann91 / morton_encoder_generator.c
Last active February 27, 2020 15:24
Morton code encoder generator. Generates C code that encodes the X dimension of a 3D morton code. Other dimensions can be obtained by shifting by 1 or 2.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
#include <limits.h>
#include <assert.h>
typedef struct op_s op_t;
@madmann91
madmann91 / morton.c
Last active February 27, 2020 15:25
Fast, vectorized morton code encoding. Completely portable and only relies on compiler optimizations.
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
static inline uint64_t split(uint64_t x, int log_bits) {
uint64_t mask = (UINT64_C(1) << (1 << log_bits)) - 1;
for (int i = log_bits, n = 1 << log_bits; i > 0; --i, n >>= 1) {
mask = (mask | (mask << n)) & ~(mask << (n / 2));
x = (x | (x << n)) & mask;
@madmann91
madmann91 / ale-local.vimrc
Last active September 14, 2020 12:11
Local ALE setup for C++ projects
" Lint .h files as C++, not C
let g:ale_pattern_options_enabled = 1
let g:ale_pattern_options = { '\.h$': { 'ale_linters': { 'cpp' : ['cc', 'gcc', 'clang'] } } }
" Set flags for gcc/clang
let opts = '-std=c++17 -Wall -Wextra'
let g:ale_linters = { 'cpp': ['cc', 'gcc', 'clang'] }
let g:ale_cpp_cc_options = opts
let g:ale_cpp_gcc_options = opts
let g:ale_cpp_clang_options = opts
@madmann91
madmann91 / bench_renderline.cpp
Last active December 9, 2020 14:49
Benchmark for devilutionX's RenderLine function
// g++ bench_renderline.cpp -std=c++17 -O3 -march=native -o bench_renderline
// The benchmarked functions (RenderLine, ...) where taken from
// diasurgical/devilutionX
// Copyrights to their respective authors, license is "The Unlicense"
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <climits>
@madmann91
madmann91 / vm.c
Created February 14, 2021 14:26
Small VM example
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include <assert.h>
#define REG_COUNT 64
#define OPCODE_LIST(f) \
@madmann91
madmann91 / audio_fixes.sh
Created February 15, 2021 16:02
Small fixes for audio issues on Linux
#!/bin/sh
# Disables notification sounds from gnome
dconf write /org/gnome/desktop/sound/event-sounds "false"
# Disables PulseAudio's suspend-on-idle to avoid cracks and pops
echo "
.include /etc/pulse/default.pa
.nofail
unload-module module-suspend-on-idle
@madmann91
madmann91 / dist.c
Last active June 14, 2021 21:53
Sampling from a discrete probability distribution
#include <tgmath.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
// Discrete probability distribution sampling according to the method named
// "Squared Histogram" in "Fast Generation of Discrete Random Variables",