Skip to content

Instantly share code, notes, and snippets.

@optimizedaway
optimizedaway / div128.h
Last active May 6, 2020 10:24
128 by 64 bit integer division for gcc and clang
#include <stdint.h>
// 128 by 64 bit integer division for gcc and clang
inline uint64_t udiv128_64(unsigned __int128 a, uint64_t b)
{
// We don't want 128 bit software division
uint64_t alo = (uint64_t)a;
uint64_t ahi = (a >> 64);
uint64_t d, e;
__asm__("divq %[b]"
/// Build orthonormal frame from normalized dir
/// Hughes and Moeller http://cs.brown.edu/~jfh/papers/Moller-BAO-1999/main.htm
inline float3x3 FrameFromDirHughes(float3 dir)
{
float3 dx0 = float3(0, dir.z, -dir.y);
float3 dx1 = float3(-dir.z, 0, dir.x);
float3 dx = normalize(dot(dx0, dx0) > dot(dx1, dx1) ? dx0 : dx1);
float3 dy = cross(dir, dx);
return float3x3(dx, dy, dir);
}
@optimizedaway
optimizedaway / pdb_compilands.cpp
Created December 13, 2018 20:14
List compilands (OBJ files) in PDB file
HRESULT hot_init(hot_ctx **out)
{
*out = nullptr;
std::unique_ptr<hot_ctx> ctx(new hot_ctx);
// Obtain base address of main executable
// 1. Module info
//MODULEINFO mod_info;
//GetModuleInformation(GetCurrentProcess(), hmod, &mod_info, sizeof(mod_info));
//void *baseaddr = mod_info.lpBaseOfDll;