A MLNS is a
For small values of
Alternatively, an MLNS can also be used as the foundational building block of a
| template <typename T> | |
| static void sort(T* a, int l) { | |
| #define S(i, j) { \ | |
| T t1 = a[i], t2 = a[j]; \ | |
| if (t1 > t2) { T t = t1; t1 = t2; t2 = t; } \ | |
| a[i] = t1, a[j] = t2;\ | |
| } | |
| // Sorting networks from https://bertdobbelaere.github.io/sorting_networks.html | |
| // Using the ones with lower CEs because every S(...) requires two CMOVxx or a | |
| // VMINSS+VMAXSS pair, and it seems that's the limit per cycle on current |
A MLNS is a
For small values of
Alternatively, an MLNS can also be used as the foundational building block of a
| /* | |
| Fast, branchless count of decimal digits in a uint64 | |
| (C) 2025 Carlo Alberto Ferraris (CAFxX) | |
| This compiles down on x86-64 to something like | |
| lzcnt rcx, rdi | |
| lea rax, [rip + countDigits.lut1] | |
| movzx eax, byte ptr [rcx + rax] | |
| lea rdx, [rip + countDigits.lut2] |
| package xruntime | |
| import ( | |
| "runtime" | |
| "sync" | |
| "sync/atomic" | |
| "time" | |
| ) | |
| var gmp atomic.Int32 |
| // https://godbolt.org/z/63Ebd37vz | |
| #include <immintrin.h> | |
| #include <stdint.h> | |
| #include <string.h> | |
| void* memchrs(const void* haystack, int len, const char* needles, int n) { | |
| if (len <= 0 || n <= 0) { | |
| return NULL; | |
| } |
| package io | |
| import ( | |
| "iter" | |
| "math" | |
| ) | |
| type Writable interface { | |
| ~string | ~[]byte | ~byte | ~rune | ~[]rune | | |
| iter.Seq[byte] | iter.Seq[rune] | iter.Seq2[byte, error] | iter.Seq2[rune, error] | |
| package context | |
| import ( | |
| "context" | |
| "sync" | |
| ) | |
| func WithValueFunc(ctx context.Context, key any, valFn func() any) context.Context { | |
| return &valFunc{Context: ctx, key: key, valFn: valFn} | |
| } |
| package textproto | |
| import ( | |
| "net/textproto" | |
| "runtime" | |
| "sync" | |
| ) | |
| // CanonincalMIMEHeaderKey is like textproto.CanonicalMIMEHeaderKey but it | |
| // memoizes results to avoid repeated allocations of the same string. |
| package maps | |
| type ReadMostlyMap[K comparable, V any] struct { | |
| mu sync.Mutex | |
| m atomic.Pointer // map[K]V | |
| } | |
| func map2ptr[K comparable, V any](m map[K]V) unsafe.Pointer { | |
| im := any(m) | |
| return *(*unsafe.Pointer)(unsafe.Pointer(&im)) |
| Verifying that I control the following Nostr public key: npub1j67s9mwffj6ue909esy4ldyhte9xheu5nh2lwed2qycqfdmfjmuq40chpa |