--- cvsroot/libecb/ecb.pod 2014/06/09 17:31:57 1.56 +++ cvsroot/libecb/ecb.pod 2015/02/18 20:48:59 1.64 @@ -70,7 +70,7 @@ For C and C use C. -=head2 LANGUAGE/COMPILER VERSIONS +=head2 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 C to @@ -106,7 +106,7 @@ True if the implementation claims to be compliant to ISO/IEC 14882:2011 (C++11) or any later version. -=item ECB_GCC_VERSION(major,minor) +=item ECB_GCC_VERSION (major, minor) Expands to a true value (suitable for testing in by the preprocessor) if the compiler used is GNU C and the version is the given version, or @@ -165,35 +165,60 @@ =back -=head2 GCC ATTRIBUTES +=head2 MACRO TRICKERY -A major part of libecb deals with GCC attributes. These are additional -attributes that you can assign to functions, variables and sometimes even -types - much like C or C in C. - -While GCC allows declarations to show up in many surprising places, -but not in many expected places, the safest way is to put attribute -declarations before the whole declaration: +=over 4 - ecb_const int mysqrt (int a); - ecb_unused int i; +=item ECB_CONCAT (a, b) -For variables, it is often nicer to put the attribute after the name, and -avoid multiple declarations using commas: +Expands any macros in C and C, then concatenates the result to form +a single token. This is mainly useful to form identifiers from components, +e.g.: - int i ecb_unused; + #define S1 str + #define S2 cpy -=over 4 + ECB_CONCAT (S1, S2)(dst, src); // == strcpy (dst, src); + +=item ECB_STRINGIFY (arg) + +Expands any macros in C 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)); -=item ecb_attribute ((attrs...)) +=item ECB_STRINGIFY_EXPR (expr) -A simple wrapper that expands to C<__attribute__((attrs))> on GCC, and to -nothing on other compilers, so the effect is that only GCC sees these. +Like C, but additionally evaluates C to make sure it +is a valid expression. This is useful to catch typos or cases where the +macro isn't available: -Example: use the C attribute on a function. + #include - ecb_attribute((__deprecated__)) void - do_not_use_me_anymore (void); + 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 + +=back + +=head2 ATTRIBUTES + +A major part of libecb deals with additional attributes that can be +assigned to functions, variables and sometimes even types - much like +C or C in C. They are implemented using either GCC +attributes or other compiler/language specific features. Attributes +declarations must be put before the whole declaration: + + ecb_const int mysqrt (int a); + ecb_unused int i; + +=over 4 =item ecb_unused @@ -202,7 +227,7 @@ declare a variable but do not always use it: { - int var ecb_unused; + ecb_unused int var; #ifdef SOMECONDITION var = ...; @@ -217,12 +242,17 @@ Similar to C, but marks a function, variable or type as deprecated. This makes some compilers warn when the type is used. +=item ecb_deprecated_message (message) + +Same as C, but if possible, supply a diagnostic that is +used instead of a generic depreciation message when the object is being +used. + =item ecb_inline -This is not actually an attribute, but you use it like one. It expands -either to C or to just C, if inline isn't -supported. It should be used to declare functions that should be inlined, -for code size or speed reasons. +Expands either to C or to just C, 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 codesize. @@ -265,8 +295,8 @@ loop, because it knows it doesn't overwrite input values. void - multiply (float *ecb_restrict src, - float *ecb_restrict dst, + multiply (ecb_restrict float *src, + ecb_restrict float *dst, int len, float factor) { int i; @@ -374,7 +404,7 @@ =over 4 -=item bool ecb_is_constant(expr) +=item bool ecb_is_constant (expr) Returns true iff the expression can be deduced to be a compile-time constant, and false otherwise. @@ -402,7 +432,7 @@ : (n * (uint32_t)rndm16 ()) >> 16; } -=item bool ecb_expect (expr, value) +=item ecb_expect (expr, value) Evaluates C and returns it. In addition, it tells the compiler that the C evaluates to C a lot, which can be used for static @@ -459,7 +489,7 @@ real_reserve_method (size); /* presumably noinline */ } -=item bool ecb_assume (cond) +=item ecb_assume (cond) Try to tell the compiler that some condition is true, even if it's not obvious. @@ -489,13 +519,13 @@ completely, as it knows that C<< current + 1 > end >> is false and the call will never be executed. -=item bool ecb_unreachable () +=item 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 C or similar functions. -=item bool ecb_prefetch (addr, rw, locality) +=item ecb_prefetch (addr, rw, locality) Tells the compiler to try to prefetch memory at the given Cess for either reading (C = 0) or writing (C = 1). A C of @@ -654,6 +684,20 @@ =over 4 +=item ECB_INFINITY + +Evaluates to positive infinity if supported by the platform, otherwise to +a truly huge number. + +=item ECB_NAN + +Evaluates to a quiet NAN if supported by the platform, otherwise to +C. + +=item float ecb_ldexpf (float x, int exp) + +Same as C, but always available. + =item uint32_t ecb_float_to_binary32 (float x) [-UECB_NO_LIBM] =item uint64_t ecb_double_to_binary64 (double x) [-UECB_NO_LIBM] @@ -686,13 +730,15 @@ x = ecb_binary32_to_float (ecb_float_to_binary32 (x) ^ 0x80000000U) +=item float ecb_binary16_to_float (uint16_t x) [-UECB_NO_LIBM] + =item float ecb_binary32_to_float (uint32_t x) [-UECB_NO_LIBM] =item double ecb_binary32_to_double (uint64_t x) [-UECB_NO_LIBM] -The reverse operation of the previos function - takes the bit representation -of an IEEE binary32 or binary64 number and converts it to the native C -or C format. +The reverse operation of the previous function - takes the bit +representation of an IEEE binary16, binary32 or binary64 number and +converts it to the native C or C format. This function should work even when the native floating point format isn't IEEE compliant, of course at a speed and code size penalty, and of course