Skip to content

Instantly share code, notes, and snippets.

@nkurz
nkurz / constant_division.c
Created September 25, 2014 20:54
Test how well compilers optimize division by constants
// Code to test how well compilers optimize division by constants
// See: http://ridiculousfish.com/blog/posts/labor-of-division-episode-iii.html
// gcc -std=gnu11 -Wall -Wextra -O3 constant_division.c -o constant_division
// objdump -d constant_division | less
#ifndef COUNT
#define COUNT (1000 * 1000)
#endif
@nkurz
nkurz / align.c
Created September 21, 2014 05:12
Sample file showing timings for several alignment implementations.
// gcc -fno-inline -std=gnu99 -Wall -O3 align.c -o align -lm -DLIKWID -llikwid -lpthread
// objdump -d align | less (to confirm that the code hasn't been optimized out)
// likwid -m -C2 -g BRANCH align
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef ALIGN
#define ALIGN 8