Skip to content

Instantly share code, notes, and snippets.

View DrPizza's full-sized avatar
🙄
they see me rollin'. they hatin'.

Peter Bright DrPizza

🙄
they see me rollin'. they hatin'.
View GitHub Profile
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <ucontext.h>
@DrPizza
DrPizza / gc.cpp
Last active December 4, 2017 23:31
struct real_gc_base {
virtual ~real_gc_base() {}
};
struct gc : virtual real_gc_base {
};
struct b1 : gc {
};
//http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0009r4.html
#include <utility>
#include <array>
#include <algorithm>
#include <functional>
#include <type_traits>
#include <memory>
#include <exception>
@DrPizza
DrPizza / thunks.cpp
Last active November 22, 2017 19:02
__pragma(optimize("", off))
__pragma(runtime_checks("", off))
__pragma(check_stack(off))
__pragma(strict_gs_check(push, off))
// anonymous namespace to ensure that the function names are not exported,
// and hence that I can take their address without suffering indirections
namespace {
__pragma(code_seg(push, "thunks"))
@DrPizza
DrPizza / json.cpp
Last active September 14, 2017 20:02
#include <variant>
#include <string_view>
#include <vector>
#include <unordered_map>
#include <utility>
namespace json {
struct Value;
using Null = std::nullptr_t;
using Bool = bool;
Intel(R) Core(TM) i7-7900X CPU @ 3.30GHz
Maximum frequency: 3301 MHz (as reported to/by Windows, which seems in fact to be the base frequency at P0)
rdtsc ticks at 3311999074 ticks per second
measurement overhead in ticks: 11
\ core-to-core ping time/ns
\ destination
source \ 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19|
__________\_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
0 | -| 16| 91| 91| 98| 99| 98| 96| 84| 87| 104| 93| 96| 97| 91| 97| 97| 90| 82| 81|
1 | 20| -| 93| 93| 100| 100| 99| 97| 87| 89| 106| 94| 98| 98| 92| 99| 98| 92| 84| 83|
template<typename T> // fuck anyone who writes 'class T'
struct alignas(T) speculative_buffer {
static_assert(std::is_default_constructible_v<T>, "T must be DefaultConstructible");
static_assert(std::is_trivially_copyable_v<T>, "T must be TriviallyCopyable");
speculative_buffer(T* src) {
unsafe_read(src);
}
void unsafe_read(T* src) { // nb: can read from any pointer, does not need to be atomic etc.
#pragma once
// Copyright(c) 2017 Peter Bright
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
#include <SDKDDKVer.h>
#pragma warning(disable: 4710) // warning C4710: '%s': function not inlined
#pragma warning(disable: 4668) // warning C4668: '%s' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
#pragma warning(disable: 4820) // warning C4820: '%s': '%d' bytes padding added after data member '%s'
#define STRICT
#define NOMINMAX
#include <Windows.h>
// positive rotations go left, negative go right
void rotate(int arr[], const ptrdiff_t len, const ptrdiff_t m) {
if(0 == m || m >= len) {
return;
}
ptrdiff_t dst = 0;
ptrdiff_t first_in_cycle = 0;
int tmp = arr[first_in_cycle];
for(ptrdiff_t i = 0; i < len; ++i) {