Skip to content

Instantly share code, notes, and snippets.

View kusma's full-sized avatar

Erik Faye-Lund kusma

View GitHub Profile
@kusma
kusma / mag.cpp
Last active January 31, 2017 13:47
compile-time calculate the magnitude (the number of bits needed to store a number) of a given number
template <unsigned int n, unsigned int bit = 31>
struct mag
{
enum {
lval = (n & (1UL << bit)) != 0 ? bit : 0,
rval = mag<n, bit - 1>::value,
value = lval > rval ? lval : rval // max
};
};
THE FLIPCODE "TEAM WANTED" FORM, VERSION 1.0
HELLO my name is __________________. I am looking for new members to fill out my team.
I'm designing a revolutionary new
[ ] MMORPG
[ ] FPS
[ ] RPG
that will change the world forever!
#include "math.h"
const
unsigned char
math::clz_lut[256] =
{
8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
#ifdef USE_ASM
#ifdef ARM
inline __attribute__((const))
unsigned int
clz_iasm(unsigned int num)
{
unsigned int ret, tmp;
const unsigned char *lut = &math::clz8_lut[0];
static DWORD GetProcessId(HANDLE hProcess)
{
typedef DWORD (WINAPI *pfnGPI)(HANDLE);
typedef ULONG (WINAPI *pfnNTQIP)(HANDLE, ULONG, PVOID, ULONG, PULONG);
static int first = 1;
static pfnGPI GetProcessId;
static pfnNTQIP ZwQueryInformationProcess;
if (first) {
DWORD SetThreadExecutionState(DWORD flags)
{
typedef DWORD (WINAPI *T)(DWORD);
static T SetThreadExecutionState = NULL;
static int first = 1;
if (first) {
first = 0;
SetThreadExecutionState = (T)GetProcAddress(
GetModuleHandle("KERNEL32.DLL"), "SetThreadExecutionState");
#include <stdio.h>
#define MAG 3
#define SIZE (1 << MAG)
const int seed[2][2] = {{0, 2}, {3, 1}};
int main()
{
int x, y;
for (y = 0; y < SIZE; ++y, putchar('\n'))
@kusma
kusma / clip.c
Last active February 19, 2016 01:57
#include "clip.h"
#include <math.h>
#include <stdio.h>
void clip_polygon(polygon *in, polygon *out, Vector4 eq)
{
int edge;
out->vertex_count = 0;
#include <stdio.h>
#include <stdint.h>
#include <mint/falcon.h>
unsigned char buf[320 * 200];
int main(int argc, char *argv[])
{
void *logbase = Logbase(), *physbase = Physbase();
uint16_t old_mode = VsetMode(-1);
@kusma
kusma / srgb-lut.c
Created November 6, 2012 01:41
Attempt on branch-free sRGB conversion by LUT without excessive range
#include <stdio.h>
#include <math.h>
#define LUT_LOG2_SIZE 8
#define LUT_SIZE ((1 << LUT_LOG2_SIZE) + 1)
float lut[LUT_SIZE];
float convert(float f)
{
union {