Skip to content

Instantly share code, notes, and snippets.

/* gcc -Wall -g -O3 a.c -pthread */
/* perf stat -e LLC-store-misses,LLC-store,LLC-load-misses,LLC-load ./a.out */
#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
@jigsawecho
jigsawecho / pp.sml
Created January 25, 2014 13:07
Profile guided code positioning
(* Profile guided code positioning
* http://dl.acm.org/citation.cfm?id=93550
* http://pages.cs.wisc.edu/~fischer/cs701.f06/code.positioning.pdf
*
* Implementation of Procedure ordering
*)
(* Two nodes and weight. Each node consists of a list of items, which
* are nodes in original graph. A graph consits of a list of edges.
fun preds (_, [], result) = result
| preds (x, n :: ns, result) =
let val (from, to) = n
in
if x = to then preds (x, ns, from :: result)
else preds (x, ns, result)
end;
fun mem (_, []) = false
| mem (x, n :: ns) =
import sys
import numpy as np
"""
0. dump given .text sym from ELF
1. handles only obj files (not linked) for now
2. usage: havefun.py a.o main
"""
"""
http://en.wikipedia.org/wiki/Path-based_strong_component_algorithm
"""
class Vertex:
def __init__(self, index):
self.index = index
class Edge:
def __init__(self, start, end):
self.start = start
(* Util functions for MIPS instruction parsing *)
fun is_jal x =
Word32.compare (Word32.andb (x, 0wxfc000000), 0wx0c000000) = EQUAL;
fun is_j x = Word32.compare (Word32.andb (x, 0wxfc000000), 0wx08000000) = EQUAL;
fun is_jalr x = Word32.compare (Word32.andb (x, 0wxfc1f003f), 0wx9) = EQUAL;
val make_icache_flush : Word32.word = 0wx041f0000; (* synci 0($0) *)