ECB(1)

๐Ÿ“ฆ
version 0.20230911 ยท 4 versions
, in fedora 43

๐Ÿ’– ECB(1) ๐Ÿ’– โ€” LIBECB - e-C-Builtins

ok bestie, gather round ๐Ÿซถ this one comes straight from the User Contributed Perl Documentation corner of your man setup, and it's the whole entire manual for LIBECB - e-C-Builtins. Yes, the header file. It's giving "C, but make it cute" and honestly? obsessed. ๐Ÿ’…


โœจ ABOUT LIBECB โœจ

Libecb is currently a simple header file that doesn't require any configuration to use or include in your project. like, zero setup, no build step, no drama. we love that for us. ๐ŸŒธ

It's part of the e-suite of libraries, other members of which include libev and libeio.

Its homepage can be found here:

http://software.schmorp.de/pkg/libecb

It mainly provides a number of wrappers around many compiler built-ins, together with replacement functions for other compilers. On top of that, it also hands you a bunch of other low-level C utilities, such as endianness detection, byte swapping or bit rotations. ๐Ÿ”ฅ

Or, in other words: things that should be built into any standard C system, but aren't, implemented as efficiently as possible with GCC (clang, MSVC...), and still correct with other compilers. no cap.

More might come. ๐Ÿ‘€


๐ŸŽ€ ABOUT THE HEADER ๐ŸŽ€

Right now, all you have to do is copy ecb.h somewhere where your compiler can find it and include it:

#include <ecb.h>

The header should work fine for both C and C++ compilation, and gives you all of inttypes.h in addition to the ECB symbols.

There are currently no object files to link to โ€” future versions might come with an (optional) object code library to link against, to reduce code size or gain access to additional features.

It also currently includes everything from inttypes.h. (yes, again. it's just that generous. ๐Ÿ’–)


๐Ÿฆ‹ ABOUT THIS MANUAL / CONVENTIONS ๐Ÿฆ‹

This manual mainly describes each (public) function available after including the ecb.h header. The header might define other symbols than these, but those are not part of the public API, and not supported in any way. so don't come for them. ๐Ÿ™ˆ

When the manual mentions a "function" then this could be defined either as an inline function, a macro, or an external symbol.

When functions use a concrete standard type, such as int or uint32_t, then the corresponding function works only with that type. If only a generic name is used (expr, cond, value and so on), then the corresponding function relies on C to implement the correct types, and is usually implemented as a macro. Specifically, a bool in this manual refers to any kind of boolean value, not a specific type.


๐ŸŒˆ TYPES / TYPE SUPPORT ๐ŸŒˆ

ecb.h makes sure that the following types are defined (in the expected way):

int8_t       uint8_
int16_t      uint16_t
int32_t      uint32_
int64_t      uint64_t
int_fast8_t  uint_fast8_t
int_fast16_t uint_fast16_t
int_fast32_t uint_fast32_t
int_fast64_t uint_fast64_t
intptr_t     uintptr_t

The macro ECB_PTRSIZE is defined to the size of a pointer on this platform (currently 4 or 8) and can be used in preprocessor expressions.

For ptrdiff_t and size_t use stddef.h/cstddef.


๐Ÿ’œ LANGUAGE/ENVIRONMENT/COMPILER VERSIONS ๐Ÿ’œ

All the following symbols expand to an expression that can be tested in preprocessor instructions as well as treated as a boolean (use !! to ensure it's either 0 or 1 if you need that).

  • ECB_C โ€” True if the implementation defines the __STDC__ macro to a true value, while not claiming to be C++, i..e C, but not C++.
  • ECB_C99 โ€” True if the implementation claims to be compliant to C99 (ISO/IEC 9899:1999) or any later version, while not claiming to be C++.
Heads up bestie: later versions (ECB_C11) remove core features again (for example, variable length arrays). ๐Ÿ˜ญ
  • ECB_C11, ECB_C17 โ€” True if the implementation claims to be compliant to C11/C17 (ISO/IEC 9899:2011, :20187) or any later version, while not claiming to be C++.
  • ECB_CPP โ€” True if the implementation defines the __cplusplus__ macro to a true value, which is typically true for C++ compilers.
  • ECB_CPP11, ECB_CPP14, ECB_CPP17 โ€” True if the implementation claims to be compliant to C++11/C++14/C++17 (ISO/IEC 14882:2011, :2014, :2017) or any later version.
Note that many C++20 features will likely have their own feature test macros (see e.g. <http://eel.is/c++draft/cpp.predefined#1.8>).
  • ECB_OPTIMIZE_SIZE โ€” Is 1 when the compiler optimizes for size, 0 otherwise. This symbol can also be defined before including ecb.h, in which case it will be unchanged.
  • ECB_GCC_VERSION (major, minor) โ€” Expands to a true value (suitable for testing by the preprocessor) if the compiler used is GNU C and the version is the given version, or higher.

This macro tries to return false on compilers that claim to be GCC compatible but aren't. (looking at you, impostors ๐Ÿ’€)

  • ECB_EXTERN_C โ€” Expands to extern "C" in C++, and a simple extern in C.

This can be used to declare a single external C function:

ECB_EXTERN_C int printf (const char *format, ...);
  • ECB_EXTERN_C_BEG / ECB_EXTERN_C_END โ€” These two macros can be used to wrap multiple extern "C" definitions โ€” they expand to nothing in C.

They are most useful in header files:

ECB_EXTERN_C_BEG

int mycfun1 (int x);
int mycfun2 (int x);

ECB_EXTERN_C_END
  • ECB_STDFP โ€” If this evaluates to a true value (suitable for testing by the preprocessor), then float and double use IEEE 754 single/binary32 and double/binary64 representations internally and the endianness of both types match the endianness of uint32_t and uint64_t.

This means you can just copy the bits of a float (or double) to an uint32_t (or uint64_t) and get the raw IEEE 754 bit representation without having to think about format or endianness. iconic behaviour, honestly.

This is true for basically all modern platforms, although ecb.h might not be able to deduce this correctly everywhere and might err on the safe side.

  • ECB_64BIT_NATIVE โ€” Evaluates to a true value (suitable for both preprocessor and C code testing) if 64 bit integer types on this architecture are evaluated "natively", that is, with similar speeds as 32 bit integers. While 64 bit integer support is very common (and in fact required by libecb), 32 bit CPUs have to emulate operations on them, so you might want to avoid them.
  • ECB_AMD64, ECB_AMD64_X32 โ€” These two macros are defined to 1 on the x86_64/amd64 ABI and the X32 ABI, respectively, and undefined elsewhere.

The designers of the new X32 ABI for some inexplicable reason decided to make it look exactly like amd64, even though it's completely incompatible to that ABI, breaking about every piece of software that assumed that __x86_64 stands for, well, the x86-64 ABI, making these macros necessary. not them causing chaos and leaving us to clean it up ๐Ÿ˜ญ


๐Ÿงš MACRO TRICKERY ๐Ÿงš

  • ECB_CONCAT (a, b) โ€” Expands any macros in a and b, then concatenates the result to form a single token. This is mainly useful to form identifiers from components, e.g.:
#define S1 str
#define S2 cpy

ECB_CONCAT (S1, S2)(dst, src); // == strcpy (dst, src);
  • ECB_STRINGIFY (arg) โ€” Expands any macros in arg and returns the stringified version of it. This is mainly useful to get the contents of a macro in string form, e.g.:
#define SQL_LIMIT 100
sql_exec ("select * from table limit " ECB_STRINGIFY (SQL_LIMIT));
  • ECB_STRINGIFY_EXPR (expr) โ€” Like ECB_STRINGIFY, but additionally evaluates expr to make sure it is a valid expression. This is useful to catch typos or cases where the macro isn't available:
#include <errno.h>

ECB_STRINGIFY      (EDOM); // "33" (on my system at least)
ECB_STRINGIFY_EXPR (EDOM); // "33"

// now imagine we had a typo:

ECB_STRINGIFY      (EDAM); // "EDAM"
ECB_STRINGIFY_EXPR (EDAM); // error: EDAM undefined

๐Ÿ‘‘ ATTRIBUTES ๐Ÿ‘‘

A major part of libecb deals with additional attributes that can be assigned to functions, variables and sometimes even types โ€” much like const or volatile in C. They are implemented using either GCC attributes or other compiler/language specific features. Attribute declarations must be put before the whole declaration:

ecb_const int mysqrt (int a);
ecb_unused int i;
  • ecb_unused โ€” Marks a function or a variable as "unused", which simply suppresses a warning by the compiler when it detects it as unused. This is useful when you e.g. declare a variable but do not always use it:
{
  ecb_unused int var;

  #ifdef SOMECONDITION
     var = ...;
     return var;
  #else
     return 0;
  #endif
}
  • ecb_deprecated โ€” Similar to ecb_unused, but marks a function, variable or type as deprecated. This makes some compilers warn when the type is used.
  • ecb_deprecated_message (message) โ€” Same as ecb_deprecated, but if possible, the specified diagnostic is used instead of a generic depreciation message when the object is being used.
  • ecb_inline โ€” Expands either to (a compiler-specific equivalent of) static inline or to just static, if inline isn't supported. It should be used to declare functions that should be inlined, for code size or speed reasons.

Example: inline this function, it surely will reduce code size.

ecb_inline int
negmul (int a, int b)
{
  return - (a * b);
}
  • ecb_noinline โ€” Prevents a function from being inlined โ€” it might be optimised away, but not inlined into other functions. This is useful if you know your function is rarely called and large enough for inlining not to be helpful.
  • ecb_noreturn โ€” Marks a function as "not returning, ever". Some typical functions that don't return are exit or abort (which really works hard to not return), and now you can make your own:
ecb_noreturn void
my_abort (const char *errline)
{
  puts (errline);
  abort ();
}

In this case, the compiler would probably be smart enough to deduce it on its own, so this is mainly useful for declarations.

  • ecb_restrict โ€” Expands to the restrict keyword or equivalent on compilers that support them, and to nothing on others. Must be specified on a pointer type or an array index to indicate that the memory doesn't alias with any other restricted pointer in the same scope.

Example: multiply a vector, and allow the compiler to parallelise the loop, because it knows it doesn't overwrite input values.

void
multiply (ecb_restrict float *src,
          ecb_restrict float *dst,
          int len, float factor)
{
  int i;

  for (i = 0; i < len; ++i)
    dst [i] = src [i] * factor;
}

ecb_const</p> ๐Ÿ’–

Okay so this one is a promise, bestie. You're declaring that your function only depends on the values of its arguments โ€” like, a real mathematical function, no strings attached. Specifically: it does not read or write any memory that any of its arguments might point to, it does not touch global variables, and it does not call any non-const functions. And it also must not have any side effects. Periodt.

Why do we care? Because a function like this can be optimised much more aggressively by the compiler โ€” for example, multiple calls with the same arguments can be optimised into a single call, which wouldn't be possible if the compiler had to expect any side effects. slay

It's best suited for functions in the sense of mathematical functions, such as a function returning the square root of its input argument. ๐Ÿงฎ

Not suited would be a function that calculates the hash of some memory area you pass in, prints some messages, or looks at a global variable to decide on rounding. Those are giving liar energy if you slap ecb_const on them. ๐Ÿ™ˆ

See ecb_pure for a slightly less restrictive class of functions.

ecb_pure</p> ๐Ÿฆ‹

Similar to ecb_const, this declares a function that has no side effects. The difference? Unlike ecb_const, the function is allowed to examine global variables and any other memory areas (such as the ones passed to it via pointers). So it can look, it just can't touch. ๐Ÿ‘€

While these functions cannot be optimised as aggressively as ecb_const functions, they can still be optimised away in many occasions, and the compiler has more freedom in moving calls to them around. Still a win.

Typical examples for such functions would be strlen or memcmp. A function that calculates the MD5 sum of some input and updates some MD5 state passed as argument would NOT be pure, however, as it would modify some memory area that is not the return value. ๐Ÿšซ

ecb_hot</p> ๐Ÿ”ฅ

This declares a function as "hot" with regards to the cache โ€” meaning the function is used so often that it is very beneficial to keep it in the cache if possible. It's giving main character energy in your instruction cache.

The compiler reacts by trying to place hot functions near to each other in memory. BFFs, basically, but for your CPU. ๐Ÿ’…

Whether a function is hot or not often depends on the whole program, and less on the function itself. So likeโ€ฆ ecb_cold is likely more useful in practise.

ecb_cold</p> ๐ŸงŠ

The opposite of ecb_hot โ€” declares a function as "cold" with regards to the cache, or in other words, this function is not called often, or not at speed-critical times, and keeping it in the cache might be a waste of said cache. Not everything deserves a spot in the group chat, you know? ๐Ÿ’€

In addition to placing cold functions together (or at least away from hot functions), this knowledge can be used in other ways, for example, the function will be optimised for size, as opposed to speed, and code paths leading to calls to those functions can automatically be marked as if ecb_expect_false had been used to reach them.

Good examples for such functions would be error reporting functions, or functions only called in exceptional or rare cases. Exactly โ€” the "hey bestie something went wrong" functions. ๐ŸŒธ

ecb_artificial</p> ๐ŸŽ€

Declares the function as "artificial", in this case meaning that this function is not really meant to be a function, but more like an accessor โ€” many methods in C++ classes are mere accessor functions, and having a crash reported in such a method, or single-stepping through them, is not usually so helpful, especially when it's inlined to just a few instructions. ๐Ÿ˜ญ

Marking them as artificial will instruct the debugger about just this, leading to happier debugging and thus happier lives. No cap.

Example: in some kind of smart-pointer class, mark the pointer accessor as artificial, so that the whole class acts more like a pointer and less like some C++ abstraction monster. ๐Ÿ‘‘

template<typename T>
struct my_smart_ptr
{
  T *value;

  ecb_artificial
  operator T *()
  {
    return value;
  }
};

โœจ OPTIMISATION HINTS โœจ

bool ecb_is_constant (expr) โญ

Returns true iff the expression can be deduced to be a compile-time constant, and false otherwise.

For example, when you have a rndm16 function that returns a 16 bit random number, and you have a function that maps this to a range from 0..n-1, then you could use this inline function in a header file:

ecb_inline uint32_t
rndm (uint32_t n)
{
  return (n * (uint32_t)rndm16 ()) >> 16;
}

However, for powers of two, you could use a normal mask, but that is only worth it if, at compile time, you can detect this case. This is the case when the passed number is a constant and also a power of two (n & (n - 1) == 0):

ecb_inline uint32_t
rndm (uint32_t n)
{
  return is_constant (n) && !(n & (n - 1))
    ? rndm16 () & (num - 1)
    : (n * (uint32_t)rndm16 ()) >> 16;
}

ecb_expect (expr, value) ๐ŸŒˆ

Evaluates expr and returns it. In addition, it tells the compiler that the expr evaluates to value a lot, which can be used for static branch optimisations.

Usually, you want to use the more intuitive ecb_expect_true and ecb_expect_false functions instead. iykyk ๐Ÿ’…

bool ecb_expect_true (cond)

bool ecb_expect_false (cond) ๐ŸŒŸ

These two functions expect a expression that is true or false and return 1 or 0, respectively, so when used in the condition of an if or other conditional statement, it will not change the program:

/* these two do the same thing */
if (some_condition) ...;
if (ecb_expect_true (some_condition)) ...;

However, by using ecb_expect_true, you tell the compiler that the condition is likely to be true (and for ecb_expect_false, that it is unlikely to be true).

For example, when you check for a null pointer and expect this to be a rare, exceptional, case, then use ecb_expect_false:

void my_free (void *ptr)
{
  if (ecb_expect_false (ptr == 0))
    return;
}

Consequent use of these functions to mark away exceptional cases or to tell the compiler what the hot path through a function is can increase performance considerably. ๐Ÿ”ฅ

You might know these functions under the name likely and unlikely โ€” while these are common aliases, we find that the expect name is easier to understand when quickly skimming code. If you wish, you can use ecb_likely instead of ecb_expect_true and ecb_unlikely instead of ecb_expect_false โ€” these are simply aliases. โœจ

A very good example is in a function that reserves more space for some memory block (for example, inside an implementation of a string stream) โ€” each time something is added, you have to check for a buffer overrun, but you expect that most checks will turn out to be false:

/* make sure we have "size" extra room in our buffer */
ecb_inline void
reserve (int size)
{
  if (ecb_expect_false (current + size > end))
    real_reserve_method (size); /* presumably noinline */
}

ecb_assume (cond) ๐Ÿซถ

Tries to tell the compiler that some condition is true, even if it's not obvious. This is not a function, but a statement: it cannot be used in another expression. So don't try to be cute with it. ๐Ÿ™ˆ

This can be used to teach the compiler about invariants or other conditions that might improve code generation, but which are impossible to deduce form the code itself.

For example, the example reservation function from the ecb_expect_false description could be written thus (only ecb_assume was added):

ecb_inline void
reserve (int size)
{
  if (ecb_expect_false (current + size > end))
    real_reserve_method (size); /* presumably noinline */

  ecb_assume (current + size <= end);
}

If you then call this function twice, like this:

reserve (10);
reserve (1);

Then the compiler might be able to optimise out the second call completely, as it knows that current + 1 > end is false and the call will never be executed. Not me being obsessed with a whole call just vanishing ๐Ÿ’€โœจ

ecb_unreachable () ๐Ÿงš

This function does nothing itself, except tell the compiler that it will never be executed. Apart from suppressing a warning in some cases, this function can be used to implement ecb_assume or similar functionality.

ecb_prefetch (addr, rw, locality) ๐Ÿ“

Tells the compiler to try to prefetch memory at the given address for either reading (rw = 0) or writing (rw = 1). A locality of 0 means that there will only be one access later, 3 means that the data will likely be accessed very often, and values in between mean something... in between. The memory pointed to by the address does not need to be accessible (it could be a null pointer for example), but rw and locality must be compile-time constants.

This is a statement, not a function: you cannot use it as part of an expression. ๐Ÿ“ข

An obvious way to use this is to prefetch some data far away, in a big array you loop over. This prefetches memory some 128 array elements later, in the hope that it will be ready when the CPU arrives at that location.

int sum = 0;

for (i = 0; i < N; ++i)
  {
    sum += arr [i]
    ecb_prefetch (arr + i + 128, 0, 0);
  }

It's hard to predict how far to prefetch, and most CPUs that can prefetch are often good enough to predict this kind of behaviour themselves. It gets more interesting with linked lists, especially when you do some fair processing on each list element:

for (node *n = start; n; n = n->next)
  {
    ecb_prefetch (n->next, 0, 0);
    ... do medium amount of work with *n
  }

After processing the node, (part of) the next node might already be in cache. Manifesting it for you bestie ๐Ÿฆ‹


๐Ÿ’œ BIT FIDDLING / BIT WIZARDRY ๐Ÿ’œ

bool ecb_big_endian ()

bool ecb_little_endian () ๐ŸŒธ

These two functions return true if the byte order is big endian (most-significant byte first) or little endian (least-significant byte first) respectively.

On systems that are neither, their return values are unspecified. So likeโ€ฆ unspecified unspecified. Don't come for me. ๐Ÿ’€

int ecb_ctz32 (uint32_t x)

int ecb_ctz64 (uint64_t x)

int ecb_ctz (T x) [C++] ๐ŸŽ€

Returns the index of the least significant bit set in x (or equivalently the number of bits set to 0 before the least significant bit set), starting from 0. If x is 0 the result is undefined.

๐Ÿšจ okay bestie listen: x = 0 is undefined behaviour here. Do not pass zero. Do not collect $200. Just don't.

For smaller types than uint32_t you can safely use ecb_ctz32. ๐Ÿ‘‘

The overloaded C++ ecb_ctz function supports uint8_t, uint16_t, uint32_t and uint64_t types. slay โœจ

Like, for example:

ecb_ctz32 (3) = 0
ecb_ctz32 (6) = 1

  • int ecb_clz32 (uint32_t x)
  • int ecb_clz64 (uint64_t x)

Counts the number of leading zero bits in x. And bestie, if x is 0 the result is undefined ๐Ÿ˜ญ like, do not.

ngl it's often simpler to just use one of the ecb_ld* functions instead, because their result only depends on the value and not the size of the type โ€” and that is literally the reason there's no C++ overload here. iykyk ๐Ÿ’…

For example:

ecb_clz32 (3) = 30
ecb_clz32 (6) = 29
  • bool ecb_is_pot32 (uint32_t x)
  • bool ecb_is_pot64 (uint32_t x)
  • bool ecb_is_pot (T x) [C++]

Returns true iff x is a power of two or x == 0. Periodt โœจ

For smaller types than uint32_t you can safely use ecb_is_pot32. ๐Ÿซถ

The overloaded C++ ecb_is_pot function supports uint8_t, uint16_t, uint32_t and uint64_t types.

  • int ecb_ld32 (uint32_t x)
  • int ecb_ld64 (uint64_t x)
  • int ecb_ld64 (T x) [C++]

Returns the index of the most significant bit set in x, or the number of digits the number requires in binary (so that 2**ld <= x < 2**(ld+1)). If x is 0 the result is undefined ๐Ÿ™ˆ. A common use case is to compute the integer binary logarithm, i.e. floor (log2 (n)) โ€” for example to see how many bits a certain number requires to be encoded. iconic.

This function is similar to the "count leading zero bits" function, except that that one returns how many zero bits are "in front" of the number (in the given data type), while ecb_ld returns how many bits the number itself requires. ๐Ÿ’…

For smaller types than uint32_t you can safely use ecb_ld32.

The overloaded C++ ecb_ld function supports uint8_t, uint16_t, uint32_t and uint64_t types.

  • int ecb_popcount32 (uint32_t x)
  • int ecb_popcount64 (uint64_t x)
  • int ecb_popcount (T x) [C++]

Returns the number of bits set to 1 in x. ๐Ÿ“

For smaller types than uint32_t you can safely use ecb_popcount32.

The overloaded C++ ecb_popcount function supports uint8_t, uint16_t, uint32_t and uint64_t types.

For example:

ecb_popcount32 (7) = 3
ecb_popcount32 (255) = 8
  • uint8_t ecb_bitrev8 (uint8_t x)
  • uint16_t ecb_bitrev16 (uint16_t x)
  • uint32_t ecb_bitrev32 (uint32_t x)
  • T ecb_bitrev (T x) [C++]

Reverses the bits</purl> in x, i.e. the MSB becomes the LSB, MSB-1 becomes LSB+1 and so on. it's giving mirror selfie ๐Ÿชž

The overloaded C++ ecb_bitrev function supports uint8_t, uint16_t and uint32_t types.

Example:

ecb_bitrev8 (0xa7) = 0xea
ecb_bitrev32 (0xffcc4411) = 0x882233ff
  • T ecb_bitrev (T x) [C++]

Overloaded C++ bitrev function. โœจ

T must be one of uint8_t, uint16_t or uint32_t.

  • uint32_t ecb_bswap16 (uint32_t x)
  • uint32_t ecb_bswap32 (uint32_t x)
  • uint64_t ecb_bswap64 (uint64_t x)
  • T ecb_bswap (T x)

These functions return the value of the 16-bit (32-bit, 64-bit) value x after reversing the order of bytes (0x11223344 becomes 0x44332211 in ecb_bswap32). byte order flip ๐Ÿ”„

The overloaded C++ ecb_bswap function supports uint8_t, uint16_t, uint32_t and uint64_t types.

  • uint8_t ecb_rotl8 (uint8_t x, unsigned int count)
  • uint16_t ecb_rotl16 (uint16_t x, unsigned int count)
  • uint32_t ecb_rotl32 (uint32_t x, unsigned int count)
  • uint64_t ecb_rotl64 (uint64_t x, unsigned int count)
  • uint8_t ecb_rotr8 (uint8_t x, unsigned int count)
  • uint16_t ecb_rotr16 (uint16_t x, unsigned int count)
  • uint32_t ecb_rotr32 (uint32_t x, unsigned int count)
  • uint64_t ecb_rotr64 (uint64_t x, unsigned int count)

These two families of functions return the value of x after rotating all the bits by count positions to the right (ecb_rotr) or left (ecb_rotl). There are no restrictions on the value count, i.e. both zero and values equal or larger than the word width work correctly. Also, notwithstanding count being unsigned, negative numbers work and shift to the opposite direction. ๐Ÿ˜Œ

Current GCC/clang versions understand these functions and usually compile them to "optimal" code (e.g. a single rol or a combination of shld on x86). ๐Ÿ”ฅ

  • T ecb_rotl (T x, unsigned int count) [C++]
  • T ecb_rotr (T x, unsigned int count) [C++]

Overloaded C++ rotl/rotr functions.

T must be one of uint8_t, uint16_t, uint32_t or uint64_t.

  • uint_fast8_t ecb_gray_encode8 (uint_fast8_t b)
  • uint_fast16_t ecb_gray_encode16 (uint_fast16_t b)
  • uint_fast32_t ecb_gray_encode32 (uint_fast32_t b)
  • uint_fast64_t ecb_gray_encode64 (uint_fast64_t b)

Encode an unsigned into its corresponding (reflective) gray code โ€” the kind of gray code meant when just talking about "gray code". These functions are very fast and all have identical implementation, so there is no need to use a smaller type, as long as your CPU can handle it natively. ๐Ÿงš

  • T ecb_gray_encode (T b) [C++]

Overloaded C++ version of the above, for uint{8,16,32,64}_t.

  • uint_fast8_t ecb_gray_decode8 (uint_fast8_t b)
  • uint_fast16_t ecb_gray_decode16 (uint_fast16_t b)
  • uint_fast32_t ecb_gray_decode32 (uint_fast32_t b)
  • uint_fast64_t ecb_gray_decode64 (uint_fast64_t b)

Decode a gray code back into linear index form (the reverse of ecb_gray*_encode). Unlike the encode functions, the decode functions have higher time complexity for larger types, so it can pay off to use a smaller type here. bestie, pick the small one, your CPU will thank you ๐Ÿ’–

  • T ecb_gray_decode (T b) [C++]

Overloaded C++ version of the above, for uint{8,16,32,64}_t.


๐ŸŒ€ HILBERT CURVES ๐ŸŒ€

These functions deal with (square, pseudo) Hilbert curves. The parameter order indicates the size of the square and is specified in bits โ€” that means for order 8, the coordinates range from 0..255, and the curve index ranges from 0..65535. ๐Ÿ“

The 32 bit variants of these functions map a 32 bit index to two 16 bit coordinates, stored in a 32 bit variable, where the high order bits are the x-coordinate, and the low order bits are the y-coordinate โ€” thus, these functions map 32 bit linear index on the curve to a 32 bit packed coordinate pair, and vice versa. ๐Ÿ”

The 64 bit variants work similarly.

The order can go from 1 to 16 for the 32 bit curve, and 1 to 32 for the 64 bit curve.

When going from one order to the next higher order, these functions replace the curve segments by smaller versions of the generating shape, while doubling the size (since they use integer coordinates), which is what you would expect mathematically. This means that the curve will be mirrored at the diagonal. If your goal is to simply cover more area while retaining existing point coordinates you should increase or decrease the order by 2 or, in the case of ecb_hilbert2d_index_to_coord, simply specify the maximum order of 16 or 32, respectively, as these are constant-time. ๐Ÿ’…

  • uint32_t ecb_hilbert2d_index_to_coord32 (int order, uint32_t index)
  • uint64_t ecb_hilbert2d_index_to_coord64 (int order, uint64_t index)

Map a point on a pseudo Hilbert curve from its linear distance from the origin on the curve to a x|y coordinate pair. The result is a packed coordinate pair โ€” to get the actual x and y coordinates, you could do something like this:

uint32_t xy = ecb_hilbert2d_index_to_coord32 (16, 255);
uint16_t x = xy >> 16;
uint16_t y = xy & 0xffffU;

uint64_t xy = ecb_hilbert2d_index_to_coord64 (32, 255);
uint32_t x = xy >> 32;
uint32_t y = xy & 0xffffffffU;

These functions work in constant time, so for many applications it is preferable to simply hard-code the order to the maximum (16 or 32).

This (production-ready, i.e. never run ๐Ÿ˜ญ) example generates an SVG image of an order 8 pseudo Hilbert curve:

printf ("<svg xmlns='http://www.w3.org/2000/svg' width='%d' height='%d'>\n", 64 * 8, 64 * 8);
printf ("<g transform='translate(4) scale(8)' stroke-width='0.25' stroke='black'>\n");
for (uint32_t i = 0; i < 64*64 - 1; ++i)
  {
    uint32_t p1 = ecb_hilbert2d_index_to_coord32 (6, i    );
    uint32_t p2 = ecb_hilbert2d_index_to_coord32 (6, i + 1);
    printf ("<line x1='%d' y1='%d' x2='%d' y2='%d'/>\n",
      p1 >> 16, p1 & 0xffff,
      p2 >> 16, p2 & 0xffff);
  }
printf ("</g>\n");
printf ("</svg>\n");
  • uint32_t ecb_hilbert2d_coord_to_index32 (int order, uint32_t xy)
  • uint64_t ecb_hilbert2d_coord_to_index64 (int order, uint64_t xy)

The reverse of ecb_hilbert2d_index_to_coord โ€” map a packed pair of coordinates to their linear index on the pseudo Hilbert curve of order order. ๐Ÿ”„

They are an exact inverse of the ecb_hilbert2d_coord_to_index functions for the same order:

assert (
   u == ecb_hilbert2d_coord_to_index (32,
          ecb_hilbert2d_index_to_coord32 (32,
            u)));

Packing coordinates is done the same way, as well, from x and y:

uint32_t xy = ((uint32_t)x << 16) | y; // for ecb_hilbert2d_coord_to_index32
uint64_t xy = ((uint64_t)x << 32) | y; // for ecb_hilbert2d_coord_to_index64

Unlike ecb_hilbert2d_coord_to_index, these functions are O(order), so it is preferable to use the lowest possible order. ๐Ÿ‘‘


๐Ÿงฌ BIT MIXING, HASHING ๐Ÿงฌ

Sometimes you have an integer and want to distribute its bits well โ€” for example, to use it as a hash in a hash table. A common example is pointer values, which often only have a limited range (e.g. low and high bits are often zero). ๐Ÿ˜ญ

The following functions try to mix the bits to get a good bias-free distribution. They were mainly made for pointers, but the underlying integer functions are exposed as well. โœจ

As an added benefit, the functions are reversible โ€” so if you find it convenient to store only the hash value, you can recover the original pointer from the hash (unmix), as long as your pointers are 32 or 64 bit (if this isn't the case on your platform, drop us a note and we will add functions for other bit widths). ๐Ÿซถ

The unmix functions are very slightly slower than the mix functions, so it is equally very slightly preferable to store the original values wehen convenient. ๐Ÿ˜Œ

The underlying algorithm if subject to change, so currently these functions are not suitable for persistent hash tables, as their result value can change between different versions of libecb. ๐Ÿ’€
  • uintptr_t ecb_ptrmix (void *ptr)

Mixes the bits of a pointer so the result is suitable for hash table lookups. In other words, this hashes the pointer value. ๐ŸŽ€

  • uintptr_t ecb_ptrmix (T *ptr) [C++] โ€” the C++ overload that lets ecb_ptrmix work on literally any pointer type, no cap ๐Ÿ’…
  • void *ecb_ptrunmix (uintptr_t v) โ€” un-mixes the hash and hands you back the original pointer. Heads up bestie: this only works if the hash value was never truncated, meaning you kept it in uintptr_t (or something equivalent) the whole entire time. Trim it and it's giving garbage โœจ
  • T *ecb_ptrunmix<T> (uintptr_t v) [C++] โ€” the template version of ecb_ptrunmix, which is lowkey less useful but here for the vibes. Example:
sometype *myptr;
uintptr_t hash = ecb_ptrmix (myptr);
sometype *orig = ecb_ptrunmix<sometype> (hash);
  • uint32_t ecb_mix32 (uint32_t v)
  • uint64_t ecb_mix64 (uint64_t v)

Sometimes you don't have a pointer at all, you just have an integer whose values are badly distributed (tragic, honestly). That's the moment for these integer versions of the mixing function. No C++ template for these ones currently, so don't ask ๐Ÿซถ

  • uint32_t ecb_unmix32 (uint32_t v)
  • uint64_t ecb_unmix64 (uint64_t v)

The reverse of the ecb_mix girlies โ€” hand them a mixed/hashed value and they recover the original. Undo era ๐Ÿ”ฅ


๐ŸŒ HOST ENDIANNESS CONVERSION ๐ŸŒ

  • uint_fast16_t ecb_be_u16_to_host (uint_fast16_t v)
  • uint_fast32_t ecb_be_u32_to_host (uint_fast32_t v)
  • uint_fast64_t ecb_be_u64_to_host (uint_fast64_t v)
  • uint_fast16_t ecb_le_u16_to_host (uint_fast16_t v)
  • uint_fast32_t ecb_le_u32_to_host (uint_fast32_t v)
  • uint_fast64_t ecb_le_u64_to_host (uint_fast64_t v)

These take an unsigned 16, 32 or 64 bit value and convert it from big or little endian into host byte order. Byte order glow-up โœจ

The naming convention is ecb_ + (be|le) + _u + 16|32|64 + _to_host, where be and le stand for big endian and little endian, respectively. iykyk

  • uint_fast16_t ecb_host_to_be_u16 (uint_fast16_t v)
  • uint_fast32_t ecb_host_to_be_u32 (uint_fast32_t v)
  • uint_fast64_t ecb_host_to_be_u64 (uint_fast64_t v)
  • uint_fast16_t ecb_host_to_le_u16 (uint_fast16_t v)
  • uint_fast32_t ecb_host_to_le_u32 (uint_fast32_t v)
  • uint_fast64_t ecb_host_to_le_u64 (uint_fast64_t v)

Like the ones above, but the other direction โ€” host byte order out to the endianness you named.

In C++ you also get these extra template functions, and they are so main character:

T ecb_be_to_host (T v)
T ecb_le_to_host (T v)
T ecb_host_to_be (T v)
T ecb_host_to_le (T v)

These work like their C counterparts up above, but they're templated, which makes them actually usable in generic code. Obsessed ๐Ÿ’œ

T must be one of uint8_t, uint16_t, uint32_t or uint64_t โ€” so unlike their C counterparts, there is a version for uint8_t, which again can be useful in generic code. Not them being more inclusive than C ๐Ÿ˜Œ


๐Ÿซง UNALIGNED LOAD/STORE ๐Ÿซง

These functions load or store unaligned multi-byte values. Unaligned? Unbothered ๐Ÿ’…

  • uint_fast16_t ecb_peek_u16_u (const void *ptr)
  • uint_fast32_t ecb_peek_u32_u (const void *ptr)
  • uint_fast64_t ecb_peek_u64_u (const void *ptr)

These load an unaligned, unsigned 16, 32 or 64 bit value straight out of memory. Peek at it, bestie ๐Ÿ‘€

  • uint_fast16_t ecb_peek_be_u16_u (const void *ptr)
  • uint_fast32_t ecb_peek_be_u32_u (const void *ptr)
  • uint_fast64_t ecb_peek_be_u64_u (const void *ptr)
  • uint_fast16_t ecb_peek_le_u16_u (const void *ptr)
  • uint_fast32_t ecb_peek_le_u32_u (const void *ptr)
  • uint_fast64_t ecb_peek_le_u64_u (const void *ptr)

Like above, but they also convert from big endian (be) or little endian (le) byte order to host byte order while doing it. Multitasking queen ๐ŸŒธ

  • ecb_poke_u16_u (void *ptr, uint16_t v)
  • ecb_poke_u32_u (void *ptr, uint32_t v)
  • ecb_poke_u64_u (void *ptr, uint64_t v)

These store an unaligned, unsigned 16, 32 or 64 bit value into memory. Poke, don't peek ๐ŸŽ€

  • ecb_poke_be_u16_u (void *ptr, uint_fast16_t v)
  • ecb_poke_be_u32_u (void *ptr, uint_fast32_t v)
  • ecb_poke_be_u64_u (void *ptr, uint_fast64_t v)
  • ecb_poke_le_u16_u (void *ptr, uint_fast16_t v)
  • ecb_poke_le_u32_u (void *ptr, uint_fast32_t v)
  • ecb_poke_le_u64_u (void *ptr, uint_fast64_t v)

Like above, but they also convert from host byte order to big endian (be) or little endian (le) byte order while doing it. Two jobs, one function ๐Ÿ’–

In C++ you also get these extra template functions:

T ecb_peek<T>      (const void *ptr)
T ecb_peek_be<T>   (const void *ptr)
T ecb_peek_le<T>   (const void *ptr)
T ecb_peek_u<T>    (const void *ptr)
T ecb_peek_be_u<T> (const void *ptr)
T ecb_peek_le_u<T> (const void *ptr)

Just like their C counterparts, these load an unsigned 8, 16, 32 or 64 bit value from memory, with optional conversion from big/little endian.

Since the type can't be deduced, you have to specify it explicitly, like:

uint_fast16_t v = ecb_peek<uint16_t> (ptr);

T must be one of uint8_t, uint16_t, uint32_t or uint64_t.

Unlike their C counterparts, these functions support 8 bit quantities (uint8_t) and also have an aligned version (the one without the _u prefix) โ€” all of which, hopefully, makes them more useful in generic code. SLAY ๐ŸŒŸ

ecb_poke      (void *ptr, T v)
ecb_poke_be   (void *ptr, T v)
ecb_poke_le   (void *ptr, T v)
ecb_poke_u    (void *ptr, T v)
ecb_poke_be_u (void *ptr, T v)
ecb_poke_le_u (void *ptr, T v)

Again, same energy as their C counterparts โ€” these store an unsigned 8, 16, 32 or 64 bit value to memory, with optional conversion to big/little endian.

T must be one of uint8_t, uint16_t, uint32_t or uint64_t.

Unlike their C counterparts, these functions support 8 bit quantities (uint8_t) and also have an aligned version (without the _u prefix), all of which hopefully makes them more useful in generic code. Consistent across the board, as they should be. โœจ


โšก FAST INTEGER TO STRING โšก

Libecb defines a set of very fast integer to decimal string (or integer to ASCII, short "i2a") functions. They work by converting the integer to a fixed point representation and then successively multiplying out the topmost digits. And unlike some other, also very fast, libraries, ecb's algorithm should be completely branchless per digit and does not rely on the presence of special CPU functions (such as clz). No special hardware, no problem ๐Ÿฆ‹

There's a high level API that takes an int32_t, uint32_t, int64_t or uint64_t as argument, and a low-level API which is harder to use but supports slightly more formatting options.

โœจ HIGH LEVEL API โœจ

The high level API is four functions, one each for int32_t, uint32_t, int64_t and uint64_t:

Example:

char buf[ECB_I2A_MAX_DIGITS + 1];
char *end = ecb_i2a_i32 (buf, 17262);
*end = 0;
// buf now contains "17262"
  • ECB_I2A_I32_DIGITS (=11)
  • char *ecb_i2a_u32 (char *ptr, uint32_t value)

Takes an uint32_t value and formats it as a decimal number starting at ptr, using at most ECB_I2A_I32_DIGITS characters. Returns a pointer to just after the generated string, which is exactly where you'd normally put the terminating 0 character. This function outputs the minimum number of digits โ€” no leading zeroes, no filler, just the digits periodt ๐Ÿ’…

  • ECB_I2A_U32_DIGITS (=10)
  • char *ecb_i2a_i32 (char *ptr, int32_t value)

Same as ecb_i2a_u32, but formats an int32_t value, including a minus sign if needed. Negativity is valid ๐Ÿ’€

  • ECB_I2A_I64_DIGITS (=20)
  • char *ecb_i2a_u64 (char *ptr, uint64_t value)
  • ECB_I2A_U64_DIGITS (=21)
  • char *ecb_i2a_i64 (char *ptr, int64_t value)

Similar to their 32 bit counterparts, these take a 64 bit argument. Big numbers, big energy ๐Ÿ‘‘

  • ECB_I2A_MAX_DIGITS (=21)

Instead of using a type specific length macro, you can just use ECB_I2A_MAX_DIGITS, which is good enough for any ecb_i2a function. One macro to rule them all ๐ŸŒˆ

๐Ÿ’œ LOW-LEVEL API ๐Ÿ’œ

The functions above use a number of low-level APIs which have some strict limitations, but can be used as building blocks (studying ecb_i2a_i32 and related functions is recommended).

There are three families of functions: functions that convert a number to a fixed number of digits with leading zeroes (ecb_i2a_0N, 0 for "leading zeroes"), functions that generate up to N digits, skipping leading zeroes (_N), and functions that can generate more digits, but where the leading digit has limited range (_xN).

None of the functions deal with negative numbers. Not one. They said no to negativity ๐Ÿšซ

Example: convert an IP address in an uint32_t into dotted-quad:

uint32_t ip = 0x0a000164; // 10.0.1.100
char ips[3 * 4 + 3 + 1];
char *ptr = ips;
ptr = ecb_i2a_3 (ptr,  ip >> 24        ); *ptr++ = '.';
ptr = ecb_i2a_3 (ptr, (ip >> 16) & 0xff); *ptr++ = '.';
ptr = ecb_i2a_3 (ptr, (ip >>  8) & 0xff); *ptr++ = '.';
ptr = ecb_i2a_3 (ptr,  ip        & 0xff); *ptr++ = 0;
printf ("ip: %s\n", ips); // prints "ip: 10.0.1.100"
char *ecb_i2a_02  (char *ptr, uint32_t value) // 32 bit
char *ecb_i2a_03  (char *ptr, uint32_t value) // 32 bit
char *ecb_i2a_04  (char *ptr, uint32_t value) // 32 bit
char *ecb_i2a_05  (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_06  (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_07  (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_08  (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_09  (char *ptr, uint32_t value) // 64 bit

The ecb_i2a_0N functions take an unsigned value and convert it to exactly N digits, returning a pointer to the first character after the digits. The value must be in range. The functions marked with 32 bit do their calculations internally in 32 bit; the ones marked with 64 bit internally use 64 bit integers, which might be slow on 32 bit architectures (the high level API decides on 32 vs. 64 bit versions using ECB_64BIT_NATIVE). Choose wisely, bestie ๐Ÿงš

char *ecb_i2a_2   (char *ptr, uint32_t value) // 32 bit
char *ecb_i2a_3   (char *ptr, uint32_t value) // 32 bit
char *ecb_i2a_4   (char *ptr, uint32_t value) // 32 bit
char *ecb_i2a_5   (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_6   (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_7   (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_8   (char *ptr, uint32_t value) // 64 bit
char *ecb_i2a_9   (char *ptr, uint32_t value) // 64 bit

Similarly, the ecb_i2a_N functions take an unsigned value and convert it to at most N digits, suppressing leading zeroes, and return a pointer to the first character after the digits. Minimalism, but make it fast โœจ

  • ECB_I2A_MAX_X5 (=59074)
  • char *ecb_i2a_x5 (char *ptr, uint32_t value) // 32 bit
  • ECB_I2A_MAX_X10 (=2932500665)
  • char *ecb_i2a_x10 (char *ptr, uint32_t value) // 64 bit

The ecb_i2a_xN functions are similar to the ecb_i2a_N functions, but they can generate one digit more, as long as the number is within range, which is given by the symbols ECB_I2A_MAX_X5 (almost 16 bit range) and ECB_I2A_MAX_X10 (a bit more than 31 bit range), respectively.

For example, the digit part of a 32 bit signed integer just fits into the ECB_I2A_MAX_X10 range, so while ecb_i2a_x10 cannot convert a 10 digit number, it can convert all 32 bit signed numbers. Sadly, it's not good enough for 32 bit unsigned numbers. So close, and yet so far ๐Ÿ˜ญ

๐ŸŒธ FLOATING POINT FIDDLING ๐ŸŒธ

ok bestie this is where the float girlies live ๐Ÿ’…

  • ECB_INFINITY [-UECB_NO_LIBM] โ€” this one gives you positive infinity if your platform actually supports it, and if it doesn't? it still gives you a truly huge number. slay, we improvise. โœจ
  • ECB_NAN [-UECB_NO_LIBM] โ€” a quiet NAN if the platform's got your back, and if not, it just evaluates to ECB_INFINITY. iconic fallback behaviour honestly.
  • float ecb_ldexpf (float x, int exp) [-UECB_NO_LIBM] โ€” literally the same as ldexpf, except this one is always available. no cap. ๐Ÿซถ
  • uint32_t ecb_float_to_binary16 (float x) [-UECB_NO_LIBM]
  • uint32_t ecb_float_to_binary32 (float x) [-UECB_NO_LIBM]
  • uint64_t ecb_double_to_binary64 (double x) [-UECB_NO_LIBM]

These three take an argument in the native float or double type and hand you back the IEEE 754 bit representation of it โ€” that's binary16/half, binary32/single, or binary64/double precision, depending on which one you called.

The bit representation is exactly what IEEE 754 says it is: the sign bit is the most significant bit, then exponent, then mantissa. in that order. periodt.

This should work even when the native floating point format isn't IEEE compliant โ€” of course you pay a speed and code size penalty for that, and of course only within reasonable limits. it tries to convert NaNs, infinities and denormals, but it will likely turn negative zero into positive zero. ๐Ÿ˜ญ we did our best.

On all modern platforms (where ECB_STDFP is true), the compiler should be able to completely optimise away the 32 and 64 bit functions. free real estate.

These are lowkey so useful when you're serialising floats to the network โ€” you can serialise the return value like a normal uint16_t/uint32_t/uint64_t. and another whole use case is manipulating floating point values directly. main character behaviour tbh.

Silly example: toggle the sign bit of a float. ๐ŸŽ€

/* On gcc-4.7 on amd64, */
/* this results in a single add instruction to toggle the bit, and 4 extra */
/* instructions to move the float value to an integer register and back. */

x = ecb_binary32_to_float (ecb_float_to_binary32 (x) ^ 0x80000000U)
  • float ecb_binary16_to_float (uint16_t x) [-UECB_NO_LIBM]
  • float ecb_binary32_to_float (uint32_t x) [-UECB_NO_LIBM]
  • double ecb_binary64_to_double (uint64_t x) [-UECB_NO_LIBM]

The reverse operation of the previous function โ€” takes the bit representation of an IEEE binary16, binary32 or binary64 number (half, single or double precision) and converts it to the native float or double format. โœจ

This should work even when the native floating point format isn't IEEE compliant โ€” again, speed and code size penalty, again within reasonable limits. it tries to convert normals and denormals, and it might be lucky for infinities, and with extraordinary luck, also for negative zero. fingers crossed bestie ๐Ÿคž

On all modern platforms (where ECB_STDFP is true), the compiler should be able to optimise away this function completely. gone. not even there. ๐Ÿ’€

  • uint16_t ecb_binary32_to_binary16 (uint32_t x)
  • uint32_t ecb_binary16_to_binary32 (uint16_t x)

Convert an IEEE binary32/single precision to binary16/half format, and vice versa โ€” and it handles all the details correctly (round-to-nearest-even, subnormals, infinity and NaNs). every single one. obsessed. ๐Ÿ‘‘

These are available under -DECB_NO_LIBM, since they do not rely on the platform floating point format. but the ecb_float_to_binary16 and ecb_binary16_to_float functions are usually what you actually want.


๐Ÿงฎ ARITHMETIC ๐Ÿงฎ

  • x = ecb_mod (m, n) โ€” returns m modulo n, which is the same as the positive remainder of the division between m and n, using floored division. unlike C's % operator, this one makes sure the return value is always positive, and that the two numbers m and m' = m + i * n give you the same value modulo n. in other words, ecb_mod implements the mathematical modulo operation, which the language is just... missing. wild. ๐Ÿ˜ค

n must be strictly positive (i.e. >= 1), and m must be negatable โ€” meaning both m and -m have to be representable in its type. this typically excludes the minimum signed integer value, same limitation as / and % in C. noted. ๐Ÿ“

Current GCC/clang versions compile this into an efficient branchless sequence on almost all CPUs. we love a glow-up.

For example, when you want to rotate forward through the members of an array for increasing m (which might be negative), you should use ecb_mod, because the % operator might give either negative results, or change direction for negative values:

for (m = -100; m <= 100; ++m)
  int elem = myarray [ecb_mod (m, ecb_array_length (myarray))];
  • x = ecb_div_rd (val, div)
  • x = ecb_div_ru (val, div)

Returns val divided by div, rounded down or up respectively. val and div must have integer types, and div must be strictly positive. heads up: these are implemented with macros in C and with function templates in C++. iykyk. ๐Ÿ’–


๐Ÿงฐ UTILITY ๐Ÿงฐ

  • element_count = ecb_array_length (name) โ€” returns the number of elements in the array name. For example:
int primes[] = { 2, 3, 5, 7, 11 };
int sum = 0;

for (i = 0; i < ecb_array_length (primes); i++)
  sum += primes [i];

no more manual counting bestie, we let the code do the math ๐Ÿฆ‹


โš™๏ธ SYMBOLS GOVERNING COMPILATION OF ECB.H ITSELF โš™๏ธ

These symbols need to be defined before including ecb.h the first time. first time only, don't be late. โฐ

  • ECB_NO_THREADS โ€” if ecb.h is never used from multiple threads, you can define this symbol, and then memory fences (and similar constructs) get completely removed, leading to more efficient code and fewer dependencies. โœจ

Setting this symbol to a true value implies ECB_NO_SMP.

  • ECB_NO_SMP โ€” the weaker version of ECB_NO_THREADS. if ecb.h is used from multiple threads, but never concurrently (like, say, the system your program runs on has only a single CPU with a single core, no hyper-threading, and so on), then you can define this symbol, leading to more efficient code and fewer dependencies. ๐Ÿซถ
  • ECB_NO_LIBM โ€” when defined to 1, do not export any functions that might introduce dependencies on the math library (usually called -lm) โ€” those are the ones marked with [-UECB_NO_LIBM]. ๐Ÿ’…

๐Ÿ™ˆ UNDOCUMENTED FUNCTIONALITY ๐Ÿ™ˆ

ecb.h is full of undocumented functionality as well. some of it is intended to be internal-use only, some of it we forgot to document (not me, i would never ๐Ÿ˜ญ), and some of it we hide because we are not sure we will keep the interface stable.

While you are welcome to rummage around and use whatever you find useful โ€” we don't want to stop you โ€” keep in mind that we will change undocumented functionality in incompatible ways without thinking twice, while we are considerably more conservative with documented things.

so like... go off, explore, but don't build your whole house on the undocumented stuff, okay? it's giving "no promises" energy. ๐Ÿ’€

๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

libecb is designed and maintained by:

  • Emanuele Giaquinta <e.giaquinta@glauco.it>
  • Marc Alexander Lehmann <schmorp@schmorp.de>

and that's the whole page bestie, we ate and left no crumbs ๐Ÿ“ this one's from perl v5.42.0, dated 2025-07-24, and it's the ECB(1) page โ€” go forth and modulo responsibly ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from