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
| // https://www.rfleury.com/p/multi-core-by-default | |
| // https://github.com/EpicGamesExt/raddebugger/blob/c738768e41153b8e598ef51aa57530cf71c19880/src/base/base_entry_point.c#L179 | |
| // https://github.com/EpicGamesExt/raddebugger/blob/master/src/radbin/radbin.c#L37 | |
| #include <pthread.h> | |
| #ifdef __linux__ | |
| #define _GNU_SOURCE // For pthread_setaffinity_np and sched.h extensions | |
| #include <sched.h> // For sched_param, SCHED_FIFO, sched_yield | |
| #include <sys/sysinfo.h> // For fallback cpu_cnt | |
| #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
| #include <immintrin.h> // For AVX2 intrinsics | |
| #include <stdio.h> | |
| #include <float.h> // For FLT_MAX and FLT_MIN | |
| #include <string.h> // For memset | |
| #include <stdlib.h> // For exit | |
| #include <math.h> // For fmaxf, fminf | |
| #include <pthread.h> // For pthreads (example, assuming your pool uses similar mechanisms) | |
| #include <assert.h> | |
| #define EPSILON 1e-6f // Define a small epsilon to handle floating point inaccuracies |
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
| // https://danglingpointers.com/post/spinlock-implementation/ | |
| void Lock(AtomicI32& _spinLock) | |
| { | |
| for (;;) | |
| { | |
| if (_spinLock.load_Acquire() == 0) | |
| { | |
| i32 expected = 0; | |
| i32 store = 1; | |
| if (_spinLock.compareExchange_Acquire(expected, store)) |
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
| // based on | |
| // https://www.youtube.com/watch?v=hUZbkqLRYus | |
| // https://www.youtube.com/watch?v=NAVbI1HIzCE | |
| #include <stdint.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <assert.h> | |
| #include <arm_neon.h> | |
| #include <limits.h> |
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 <immintrin.h> | |
| #include <math.h> | |
| #include <assert.h> | |
| #include <string.h> | |
| #include <float.h> | |
| #define MAX_MOTION_RADIUS 1000000.0f | |
| enum { | |
| MAX_CHNS = 128, |
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
| The PdfTree is a hierarchical data structure that stores values and their associated probabilities, organized in a way that resembles a binary tree or mip-map pyramid. It allows for efficient random selection of values proportional to their probabilities (e.g., for Monte Carlo sampling in rendering or procedural generation). The tree is built as a "summed probability tree," where each level aggregates probabilities from the level below it, enabling fast traversal for sampling. | |
| The tree is laid out linearly in probabilities, with each level concatenated. For example: | |
| Mip 0: Original probabilities [p0, p1, p2, p3] | |
| Mip 1: Pairwise sums [p0+p1, p2+p3] | |
| Mip 2: Sum of mip 1 [p0+p1+p2+p3] | |
| Mip Level Calculation: | |
| Computes the total number of elements across all mip levels. |
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 <immintrin.h> // AVX, includes SSE2-SSE4.2 | |
| #include <assert.h> | |
| #include <math.h> | |
| #include <stdint.h> | |
| #include <pthread.h> | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #define MAX_ANIM 1024 | |
| #define MAX_ANM_CLIPS 256 |
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 <immintrin.h> // For AVX2 | |
| #define MAX_SIZE (64*1024) | |
| #define BITS_PER_WORD 64 | |
| #define WORD_CNT ((MAX_SIZE + BITS_PER_WORD - 1) / BITS_PER_WORD) // 1024 words | |
| #define BIT_MAP_CNT ((WORD_CNT + BITS_PER_WORD - 1) / BITS_PER_WORD) // 16 words | |
| #define WORD_SHIFT 6 // log2(BITS_PER_WORD) | |
| #define WORD_MSK (BITS_PER_WORD - 1) // 63 | |
| #define CHUNK_CNT (BIT_MAP_CNT/4) | |
| #define CACHE_LINE_SIZE 64 |
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
| /* --------------------------------------------------------------------------- | |
| * Vector | |
| * --------------------------------------------------------------------------- | |
| */ | |
| /* vector */ | |
| #define opI(r,e,a,p,b,i,s,I)((r)[I]e(a)[I]p((b)[I]i(s))) | |
| #define opsI(r,e,a,p,s,I) ((r)[I]e(a)[I]p(s)) | |
| #define setI(d,x,I) (d)[I]=(x) | |
| #define dotI(a,b,I) (a)[I]*(b)[I] | |
| #define lerpI(r,a,b,t,I) lerp((r)[I],(a)[I],(b)[I],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
| #include <assert.h> | |
| #include <math.h> | |
| #include <stdio.h> | |
| /* Alternative design: Iterate over path and at each point i check distance to line with points | |
| i + 1 and i + 2 and skip i + 1 when distance is small than epsilon. */ | |
| static float | |
| line_dist(const float *p, const float *p1, const float *p2) { | |
| float dx = p2[0] - p1[0]; | |
| float dy = p2[1] - p1[1]; |
NewerOlder