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 / clz.cpp
Created September 13, 2018 14:22
Count leading zeros in a portable manner
#include <iostream>
#include <limits>
#include <algorithm>
#include <cstdint>
int clz(uint32_t u) {
uint32_t a = 0;
uint32_t b = 32;
uint32_t all = 0xFFFFFFFF;
#pragma unroll
@madmann91
madmann91 / huff.c
Created March 15, 2018 13:03
Simple huffman byte encoding/decoding
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
typedef struct symb_s symb_t;
typedef struct queue_s queue_t;
typedef struct dict_s dict_t;
@madmann91
madmann91 / fastdiv.c
Created March 8, 2018 10:44
Fast division using precomputed multiplicative inverse
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#define PAGE_SIZE 4096
typedef struct asmbuf_s asmbuf_t;
struct asmbuf_s {
@madmann91
madmann91 / setupenv.sh
Last active March 29, 2024 12:06
Setup environment (requires fish + git + curl + Fira Code)
#!/bin/sh
# Install vim-plug and create vim config
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
echo "syntax enable
"\"" Avoid problems when pressing Q by error (Dvorak layout)
map Q <Nop>
"\"" Allow executing local .vimrc files
set exrc
set secure
@madmann91
madmann91 / ieee.c
Last active July 22, 2016 13:56
Manipulation of the IEEE floating point representation.
#include <stdio.h>
int as_int(float f) {
union { float f; int i; } u;
u.f = f;
return u.i;
}
float as_float(int i) {
union { float f; int i; } u;
@madmann91
madmann91 / gen_sort.py
Last active May 31, 2016 16:28
Creates a sequence of compare-swap operations that perform a sort.
#!/usr/bin/python3
import sys
# Returns a list of compare-swap tuples that merges two lists
def gen_merge(a, b):
return [(x, y) for x in a for y in b]
# Returns a list of compare-swap tuples that performs a merge sort
# Generates n^2/2 - n/2 = O(n^2) compare-swaps
def gen_sort(l):