This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------------------- | |
// c++ -std=c++11 -Wall -Wextra -Wshadow -Wunused -pedantic -fsanitize=address -fno-omit-frame-pointer asan_guarded_allocator.cpp | |
#include <cassert> | |
#include <cstdio> | |
#include <cstdint> | |
#include <cstdlib> | |
#include <unordered_map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
#include <cstdint> | |
#include <cstdarg> | |
#include <cstdio> | |
#include <cmath> | |
#define WIN32_LEAN_AND_MEAN | |
#include <Windows.h> | |
#include <intrin.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------------------- | |
// Least Recently Used cache backed by a hash table | |
// (unprdered_map) and a fixed-size circular queue. | |
// | |
// License: | |
// Public Domain. | |
// Feel free to copy, distribute, and modify this file as you see fit. | |
// ---------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdint> | |
#include <cassert> | |
#include <xmmintrin.h> | |
/////////////////////////////////////////////////////////////////////////////// | |
namespace detail | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Simple stack-based virtual machine tests. | |
// | |
// I use two slightly different strategies to manage the | |
// interpreter stack: First is using the "naive" approach | |
// of keeping a stack pointer that is bumped/decremented | |
// for every instruction that has stack operands. The second | |
// approach uses a "stack cache" register to cache the | |
// Top-of-Stack (TOS) value. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================ | |
// This code is in the Public Domain - I claim no copyrights over it. | |
// Use at your own leisure and risk. | |
// | |
// Compiled and tested with: | |
// c++ -std=c++11 -fno-exceptions -Wall -Wextra -pedantic -O3 linear_allocator.cpp | |
// ============================================================================ | |
#include <cassert> | |
#include <cstdint> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mostly complete and usable C++ version of Rust's Option<T> and Result<T,E> using only standard C++14, for fun. | |
// This code is in the public domain. | |
/////////////////////////////////////////////////////////////////////////////// | |
// Option.hpp | |
/////////////////////////////////////////////////////////////////////////////// | |
#pragma once | |
// ---------------------------------------------------------------------------- | |
// Includes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------------------------------------------- | |
// Atomic singly-linked intrusive list using 128-bits Compare And Swap (AKA: DCAS). | |
// Keeps a version counter with the list head to prevent the A-B-A problem. | |
// | |
// Based on the implementation found in moodycamel.com: | |
// http://moodycamel.com/blog/2014/solving-the-aba-problem-for-lock-free-free-lists | |
// | |
// My implementation uses raw GCC/Clang atomics intrinsics. While in theory | |
// std::atomic of a struct of exactly 16 bytes and properly aligned could |
OlderNewer