View perm.c
This file contains 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
#define xglue(x, y) x##y | |
#define glue(x, y) xglue(x, y) | |
#define uniqid(name) glue(name, __LINE__) | |
#ifdef _MSC_VER | |
#define swap(a,b) do { decltype((a) + 0) _t = (a); (a) = (b); (b) = _t; } while(0) | |
#else | |
#define swap(a,b) do {__typeof__((a) + 0) _t = (a); (a) = (b); (b) = _t; } while(0) | |
#endif |
View day_2.c
This file contains 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
/** | |
* Advent of Code 2022 | |
* Day 2: Rock Paper Scissors | |
* https://adventofcode.com/2022/day/2 | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
extern int | |
main(int argc, char *argv[]) { |
View diag.c
This file contains 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
static void | |
qdiag(float *restrict qres, const float *restrict A) { | |
/* Diagonalizer: http://melax.github.io/diag.html | |
'A' must be a symmetric matrix. | |
Returns quaternion q such that corresponding matrix Q | |
can be used to Diagonalize 'A' | |
Diagonal matrix D = Q * A * Transpose(Q); and A = QT*D*Q | |
The rows of q are the eigenvectors D's diagonal is the eigenvalues | |
As per 'row' convention if float3x3 Q = q.getmatrix(); then v*Q = q*v*conj(q) | |
*/ |
View sqrt.c
This file contains 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
/* | |
Enable FMA support: | |
clang -O2 -Wall -mfma | |
*/ | |
static inline float | |
rsqrta(float x) { | |
/* Exact bits: 13.71 */ | |
/* δ+max = 7.459289×10^−5 */ | |
/* δ−max = −7.450387×10^−5 */ | |
union { float f; int i; } v = {x}; |
View nn.c
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <limits.h> | |
#include <float.h> | |
#include <string.h> | |
#include <assert.h> | |
#include <stdint.h> | |
#include <stdarg.h> | |
#include <math.h> |
View graph.c
This file contains 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
// Symbols: | |
// Dropdowns rendering: [|----------------[v]|] | |
// Right Click -> New State Machine -> Name: "blnd_tree_loco_walk" | |
static struct anim_pose* | |
blnd_tree_loco_walk(struct anim_ctx *ctx, struct anim_sm *sm) { | |
struct anim_pose *res = 0; | |
{ | |
// Right Click -> New Node -> Animation -> Walk Left | |
struct anim *walk_l = [|----------------[v]|]; |
View sort.c
This file contains 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
// ref: http://www.codercorner.com/RadixSortRevisited.htm | |
// http://stereopsis.com/radix.html | |
// int/float: https://github.com/lshamis/FloatRadixSort | |
// string: https://github.com/rantala/string-sorting/blob/master/src/msd_ce.cpp | |
struct str { | |
const char *str; | |
const char *end; | |
int len; | |
}; |
View with.c
This file contains 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 <stdio.h> | |
#define xglue(x, y) x##y | |
#define glue(x, y) xglue(x, y) | |
#define uniqid(name) glue(name, __LINE__) | |
#define scp_brk(name) goto xglue(___SCOPE___,name) | |
#define scp_file(name,f,p,fmt)\ | |
xglue(___SCOPE___,name): for(int uniqid(_i_) = (f) ? 1 : ((((f) = fopen(p,fmt)) == 0) ? 1 : 0);\ | |
(uniqid(_i_) == 0) ? 1 : ((f) ? (fclose(f), 0): 0); ++uniqid(_i_)) |
View poly_dir_max_sse.c
This file contains 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
// http://0x80.pl/notesen/2018-10-03-simd-index-of-min.html | |
#define cpy3(d,s) ((d)[0]=(s)[0],(d)[1]=(s)[1],(d)[2]=(s)[2]) | |
#define dot3(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) | |
#if defined(__GNUC__) || defined(__clang__) | |
#define alignto(x) __attribute__((aligned(x))) | |
#elif defined(_MSC_VER) | |
#define alignto(x) __declspec(align(x)) | |
#else | |
#define alignto(x) _Alignas(x) |
View row_lay.c
This file contains 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
enum gui_lay_type { | |
GUI_LAY_ROW, | |
GUI_LAY_COL | |
}; | |
struct gui_lay { | |
struct gui_box box; /* in */ | |
/* internal */ | |
enum gui_lay_type type; | |
struct gui_box sub; | |
int idx, cnt; |
NewerOlder