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
| #ifndef NSL_BIT_WIDTH_H | |
| #define NSL_BIT_WIDTH_H | |
| // most efficient calcualtion of bit width of any size of integer (in c23) | |
| // O(log2(n)) where n is the number of bits of the type, | |
| // the below bound is clangs limit meaning for any integer its evaluated in 23 steps, | |
| // (constant time) (computed dynamically, walking down and collecting each entry) | |
| // NOTE: sadly, there is nothing you can do on bitfields | |
| // NOTE: _Decimal not included, long double gets evaluated as 128bit, but well you cant really |
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
| local OS = vim.loop.os_uname().sysname | |
| local get_caps_fn = nil | |
| if OS == "Linux" then | |
| get_caps_fn = require("linux") | |
| elseif OS == "Darwin" then | |
| get_caps_fn = require("macos") | |
| elseif vim.fn.has("win32") == 1 then | |
| get_caps_fn = require("windows") | |
| else | |
| error("capsdetect: unsupported OS", 0) |
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
| #ifndef META_SWAP_H | |
| #define META_SWAP_H | |
| // if any of them is const, than there is a warning (discarding const) | |
| // if 2 different types, than dereferencing an incomplete type fails to compile | |
| // same thing for void* | |
| #define META_SWAP(p1, p2) \ | |
| ((void)_Generic((p1), \ | |
| void*: (*(struct meta_swap_incompatible*)0), \ | |
| typeof((p2)): meta_sw((p1), (p2), (char[sizeof(*(p1))]){}, \ |