Skip to content

Instantly share code, notes, and snippets.

View mayeths's full-sized avatar

Haopeng Huang mayeths

View GitHub Profile
@mayeths
mayeths / commons.h
Created October 15, 2020 01:42
C header including Timer, Unroll, etc
#pragma once
#include <stdint.h>
/* -------------------- UNROLL ---------------------- */
/* DO NOT use unroll without braces. */
#define X5(inst) inst inst inst inst inst
#define X10(inst) X5(inst) X5(inst)
#define X50(inst) X10(inst) X10(inst) X10(inst) X10(inst) X10(inst)
#define X100(inst) X50(inst) X50(inst)
#define X500(inst) X100(inst) X100(inst) X100(inst) X100(inst) X100(inst)
@mayeths
mayeths / fmt.h
Created July 27, 2021 09:48
C++11 format library, {fmt}. (All-in-one header only mode)
// https://github.com/fmtlib/fmt
// Usage: g++ main.c && ./a.out
// -- #include <fmt.h>
// -- int main() {
// -- fmt::print("hello {}\n", 123);
// -- }
#define FMT_HEADER_ONLY
/*
@mayeths
mayeths / Makefile
Created October 12, 2021 10:14
Creating custom gcc attribute to instrument specific functions: whitelisting, not blacklisting /* https://stackoverflow.com/a/57242241/11702338 */
PLUGIN=instrumentx
TEST=test
PLUGIN_CXX=g++
PLUGIN_CXXFLAGS= -std=c++11 -Wall -fno-rtti -fPIC -I`$(PLUGIN_CXX) -print-file-name=plugin`/include
PLUGIN_LDFLAGS= -std=c++11 -Wall -shared
TEST_CC=gcc
TEST_CFLAGS= -Wall -finstrument-functions -fplugin=$(PLUGIN).so -fplugin-arg-$(PLUGIN)-config=./instrument-function-list.txt