This file contains hidden or 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
#pragma once | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <assert.h> | |
#include <atomic> | |
inline static uint32_t _string_pool_find_last_set_bit64(uint64_t num); |
This file contains hidden or 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 <stdbool.h> | |
#include <stdint.h> | |
typedef union Cpuid_Registers | |
{ | |
struct { | |
uint32_t eax; | |
uint32_t ebx; | |
uint32_t ecx; |
This file contains hidden or 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
//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" { |
This file contains hidden or 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 <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; |
This file contains hidden or 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
//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 <pmttavara@protonmail.com> | |
// SPDX-License-Identifier: 0BSD | |
// https://linux.die.net/man/2/perf_event_open |
This file contains hidden or 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 <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 |
This file contains hidden or 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 <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(); | |
} |
This file contains hidden or 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 <stdint.h> | |
#include <assert.h> | |
#include <math.h> | |
#include <string.h> | |
#include <stdio.h> | |
#ifndef _cplusplus | |
#include <stdbool.h> | |
#endif |
This file contains hidden or 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 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. | |
// |
This file contains hidden or 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 <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 |
NewerOlder