Skip to content

Instantly share code, notes, and snippets.

@Boostibot
Boostibot / cpuid_tsc_freq.c
Last active May 7, 2025 15:20
Get RDTSC frequency from cpuid
#include <stdbool.h>
#include <stdint.h>
typedef union Cpuid_Registers
{
struct {
uint32_t eax;
uint32_t ebx;
uint32_t ecx;
@Boostibot
Boostibot / rdtsc.h
Last active May 3, 2025 03:17
cross platform/compiler/isa RDTSC frequency with platform specific fallback C/++
//so that the implementation compiles.
//If you are using this file as .h remove this
#define MODULE_IMPL_ALL
//rdtsc.h
#ifndef MODULE_TSC
#define MODULE_TSC
#ifdef __cplusplus
extern "C" {
@Boostibot
Boostibot / clock_realtime.c
Last active January 31, 2025 18:38
custom implementation of CLOCK_REALTIME to show whats actually going on
#include <stdatomic.h>
#include <stdint.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
typedef struct vdso_timestamp_t {
uint64_t sec;
uint64_t nsec;
} vdso_timestamp_t;
@Boostibot
Boostibot / rdtsc_frequency.c
Last active February 1, 2025 00:12
Get RDTSC frequency on linux x86
//Combination of the following:
// original gist: https://gist.github.com/pmttavara/6f06fc5c7679c07375483b06bb77430c
// discussion here: https://hero.handmade.network/forums/code-discussion/t/7485-queryperformancefrequency_returning_10mhz_bug/2#23567
// dump_vdso_data.c: https://gist.github.com/mildsunrise/c63505931534bd3c0e143c0db8cad3f3
//
// Original license:
// SPDX-FileCopyrightText: © 2022 Phillip Trudeau-Tavara <[email protected]>
// SPDX-License-Identifier: 0BSD
// https://linux.die.net/man/2/perf_event_open
@Boostibot
Boostibot / xxhash64.c
Created June 27, 2024 17:03
Small implementation of xxhash64
#include <stdint.h>
#include <assert.h>
#include <string.h>
#define XXHASH64_PRIME_1 0x9E3779B185EBCA87ULL
#define XXHASH64_PRIME_2 0xC2B2AE3D27D4EB4FULL
#define XXHASH64_PRIME_3 0x165667B19E3779F9ULL
#define XXHASH64_PRIME_4 0x85EBCA77C2B2AE63ULL
#define XXHASH64_PRIME_5 0x27D4EB2F165667C5ULL
@Boostibot
Boostibot / profile.h
Created March 2, 2024 18:15
A tiny c++ profiler
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <chrono>
static int64_t perf_counter_ns()
{
using namespace std::chrono;
return (int64_t) duration_cast<nanoseconds>(system_clock::now().time_since_epoch()).count();
}
@Boostibot
Boostibot / gauss_matrix_inverse.c
Last active February 26, 2024 14:01
Gauss elimination matrix inverse
#include <stdint.h>
#include <assert.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#ifndef _cplusplus
#include <stdbool.h>
#endif
@Boostibot
Boostibot / array.h
Created January 23, 2024 11:34
Typesafe generic array in C
// This file introduces a simple but powerful generic dynamic array concept.
// It works by defining struct for each type and then using type generic macros to work
// with these structs.
//
// This approach was chosen because:
// 1) Type safety: Array of int should be distinct type from Array of char.
// Not only does it require more state management it is also a mjor pain to work with because we always
// need to cast to our desired type (or pass the type to some acessor macro).
// This discvalified the one Array struct for all types holding the size of the type currently used.
//
@Boostibot
Boostibot / win32_stack_trace.c
Last active February 2, 2025 23:51
win32 stack trace
#include <stdint.h>
typedef struct {
char function[256]; //mangled or unmangled function name
char module[256]; //mangled or unmangled module name ie. name of dll/executable
char file[256]; //file or empty if not supported
int64_t line; //0 if not supported
} Platform_Stack_Trace_Entry;
//Captures the current stack frame pointers.
//Saves up to stack_size pointres into the stack array and returns the number of
@Boostibot
Boostibot / Antonyms.md
Created August 22, 2020 10:25 — forked from maxtruxa/Antonyms.md
A list of common terms used in programming and their respective antonyms.

Antonym List

Note: The table headings (positive/negative) are not necessarily meaningful.

Positive Negative
acquire release
add remove (e.g. an item), subtract (arithmetic)
advance retreat
allocate deallocate (correct), free (common)
allow deny