FARGOS/VISTA Object Management Environment Core
..
|
Compiler-specific macros to provide performance-related hints. More...
#include <typeinfo>
#include <stdlib.h>
#include <unistd.h>
#include <cxxabi.h>
#include <string.h>
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | NONNULL_PARAMETERS(...) __attribute__((nonnull(__VA_ARGS__))) |
Mark parameters to a function as not permitting null pointers. More... | |
#define | NONNULL_CLASS_PARAMETERS(...) __attribute__((nonnull(__VA_ARGS__))) |
Mark a function as never returning a null pointer. More... | |
#define | NONNULL_RETURN __attribute__((returns_nonnull)) |
Mark a function as never returning a null pointer. More... | |
#define | OME_EXPECT(expr, expected) __builtin_expect((expr), expected) |
Annotation macro for conditional expression to indicate expected Boolean outcome. More... | |
#define | OME_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality) |
Macro to request prefetch. More... | |
#define | OME_ALWAYS_INLINE __attribute__((always_inline)) |
Tell the compiler to alway inline a function, regardless of optimization level. More... | |
#define | OME_NEVER_INLINE __attribute__((noinline)) |
Tell the compiler to not inline a function, regardless of optimization level. More... | |
#define | OME_ALWAYS_FLATTEN __attribute__((flatten)) |
Annotation macro to request compiler to always inline body and any called routines. More... | |
#define | OME_COLD_ROUTINE __attribute__((cold)) |
Annotation macro to tell compiler a routine may never be used. More... | |
#define | OME_INIT_PRIORITY(n) __attribute__((init_priority(n))) |
Override initialization priority of a C++ variable. More... | |
#define | OME_DEPRECATED __attribute__((deprecated)) |
Mark interface as deprecated. More... | |
#define | OME_USAGE_WARNING(msg) __attribute__((warning(msg))) |
Emit a warning if the element is used. More... | |
#define | OME_USAGE_ERROR(msg) __attribute__((error(msg))) |
Emit an error if the element is used. More... | |
#define | OME_USED __attribute__((used)) |
Tell the compiler an element is used to prevent it from being optimized away. More... | |
#define | OME_UNUSED __attribute__((unused)) |
Tell the compiler it is known that an element is not used. More... | |
#define | OME_WEAK __attribute__((weak)) |
Force generation of weak symbol. More... | |
#define | OME_PURE_FUNCTION __attribute__((pure)) |
Mark as an idempotent function that can access global variables. More... | |
#define | OME_CONST_FUNCTION __attribute__((const)) |
Mark as an idempotent function that only accesses arguments – no global data. More... | |
#define | AN_ENUM(x) x |
Label an enum expression to avoid ambiguity. More... | |
#define | OME_DEPRECATED_BECAUSE(msg) __attribute__((deprecated(msg))) |
Mark interface as deprecated and provide reason or suggested alternative. More... | |
#define | OME_ALWAYS_OPTIMIZE(level) __attribute__((optimize(level))) |
Mark a function to be compiled with a specific level of optimization. More... | |
#define | EXPLICIT_CONVERSION explicit |
Generates explicit if the compiler supports it. More... | |
#define | CONSTEXPR constexpr |
Generates constexpr if the compiler supports it. More... | |
#define | VIRTUAL_OVERRIDE override |
Generates override if the compiler supports it. More... | |
#define | NOEXCEPT_SPECIFIER noexcept |
Generates noexcept if the compiler supports it. More... | |
#define | OME_DLL_EXPORT /* nothing */ |
#define | OME_FAST_CALL /* nothing */ |
#define | OME_CORE_CALL /* nothing */ |
#define | OME_EXPECT_FALSE(expr) OME_EXPECT(expr, false) |
Annotation macro for conditional expression expected to be false. More... | |
#define | OME_EXPECT_TRUE(expr) OME_EXPECT(expr, true) |
Annotation macro for conditional expression expected to be true. More... | |
#define | OME_YIELD_THREAD() sched_yield() |
Macro for platform-specific yield of thread's time slice. More... | |
#define | USE_GCC_PREFETCH 1 |
#define | MemoryBarrier() __sync_synchronize() |
#define | CACHE_LINE_LENGTH 64 |
Definition for target system's cache line length. More... | |
#define | MAX_PREFETCH_REQUESTS 8 |
Maximum number of prefetch requests supported by the hardware. More... | |
#define | DO_PREFETCH(a) OME_PREFETCH(a, 0, 1) |
Prefetch an address line for read. More... | |
#define | OME_PREFETCH_OBJECT_VTABLE(obj, relativeFunction) |
Prefetch the v-table entry for an object. More... | |
#define | safe_strcpy(d, s, l) ((memccpy(d, s, 0, (l)) == 0) ? (*(d + (l) -1) = 0) : 1) |
Safe strcpy() routine that will not copy more than l bytes and always ensures that a null is present to mark the end of the string. More... | |
#define | demangledTypeIdName(typeid_var, bfr) demangleEncodedTypeName((typeid_var).name(), bfr, sizeof(bfr)) |
Convenience macro to return the demangled type provided by a std::typeinfo value. More... | |
Functions | |
int | prefetch_memory_block (const void *addr, const unsigned int len) |
Prefetch a memory block into the CPU's cache. More... | |
template<uint_fast8_t N> | |
char * | do_copyShortStringUntil (char *bfr, const char *src, const char stopAt='\0', const char altStopAt='\0') OME_ALWAYS_INLINE OME_ALWAYS_FLATTEN OME_ALWAYS_OPTIMIZE("-O3") NONNULL_PARAMETERS(1 |
Templated C++-only routine similar to memccpy() that is suitable for handling short strings that are being copied into buffers whose size is known at compile time. The maximum number of characters to be copied from the source is specified as the template parameter. More... | |
template<> | |
char * | do_copyShortStringUntil< 0 > (char *bfr, const char *src, const char stopAt, const char altStopAt) OME_ALWAYS_INLINE OME_ALWAYS_FLATTEN OME_ALWAYS_OPTIMIZE("-O3") NONNULL_PARAMETERS(1 |
template<uint_fast8_t N> | |
char * | copyShortStringUntil (char *bfr, const char *src, const char stopAt='\0', const char altStopAt='\0', const bool truncateIfNeeded=false) OME_ALWAYS_INLINE OME_ALWAYS_FLATTEN OME_ALWAYS_OPTIMIZE("-O3") NONNULL_PARAMETERS(1 |
Templated C++-only variant of safe_strcpy() suitable for handling small-sized strings that are being copied into buffers whose size is known at compile time. More... | |
template<uint_fast8_t N> | |
uint_fast32_t | copyShortStringUntilAndReturnLength (char *bfr, const char *src, const char stopAt='\0', const char altStopAt='\0', const bool truncateIfNeeded=false) OME_ALWAYS_INLINE OME_ALWAYS_FLATTEN OME_ALWAYS_OPTIMIZE("-O3") NONNULL_PARAMETERS(1 |
Similar to copyShortStringUntil<>(), but returns the number of bytes before the trailing null. This would be the equivalent of strlen(bfr) . More... | |
template<uint_fast8_t N> | |
uint_fast32_t uint_fast32_t | copyShortStringUntilAndReturnLength (char *bfr, const char *src, const char stopAt, const char altStopAt, const bool truncateIfNeeded) |
const char * | demangleEncodedTypeName (const char *name, char *bfr, uint32_t bfrLen) NONNULL_PARAMETERS(1 |
Demangles a C++ encoded type name into its human-readable name. More... | |
template<typename TYPENAME > | |
const char * | demangledTypeName (char *bfr, uint32_t bfrLen) |
Templated convenience function that obtains the demangled type name of a C++ type. More... | |
Variables | |
char | NONNULL_RETURN |
Compiler-specific macros to provide performance-related hints.
To generate list of predefined macros:
#define AN_ENUM | ( | x | ) | x |
Label an enum expression to avoid ambiguity.
#define CACHE_LINE_LENGTH 64 |
Definition for target system's cache line length.
Note: Assume 64 bytes per cache line, which is appropriate for modern CPUs.
#define CONSTEXPR constexpr |
Generates constexpr
if the compiler supports it.
#define demangledTypeIdName | ( | typeid_var, | |
bfr | |||
) | demangleEncodedTypeName((typeid_var).name(), bfr, sizeof(bfr)) |
Convenience macro to return the demangled type provided by a std::typeinfo
value.
typeid_var | specifies the std::typeinfo content, typically obtained from the typeid() operator. |
bfr | specifies the output buffer into which the demangled name will be placed. It is expected to be passed as char array, not a pointer to a buffer. |
No length is specified as it is taken from the sizeof(bfr)
.
This macro is useful in code that has no idea what it was provided.
#define DO_PREFETCH | ( | a | ) | OME_PREFETCH(a, 0, 1) |
Prefetch an address line for read.
a | specifies the address line to be fetched |
#define EXPLICIT_CONVERSION explicit |
Generates explicit
if the compiler supports it.
#define MAX_PREFETCH_REQUESTS 8 |
Maximum number of prefetch requests supported by the hardware.
#define MemoryBarrier | ( | ) | __sync_synchronize() |
#define NOEXCEPT_SPECIFIER noexcept |
Generates noexcept
if the compiler supports it.
#define NONNULL_CLASS_PARAMETERS | ( | ... | ) | __attribute__((nonnull(__VA_ARGS__))) |
Mark a function as never returning a null pointer.
The arguments to this macro are a comma-separated list of integers, starting from 2, that identify the parameter positions of interest. Parameter position 1 refers to the this
pointer.
#define NONNULL_PARAMETERS | ( | ... | ) | __attribute__((nonnull(__VA_ARGS__))) |
Mark parameters to a function as not permitting null pointers.
The arguments to this macro are a comma-separated list of integers, starting from 1, that identify the parameter positions of interest.
const char NONNULL_RETURN __attribute__((returns_nonnull)) |
Mark a function as never returning a null pointer.
#define OME_ALWAYS_FLATTEN __attribute__((flatten)) |
Annotation macro to request compiler to always inline body and any called routines.
#define OME_ALWAYS_INLINE __attribute__((always_inline)) |
Tell the compiler to alway inline a function, regardless of optimization level.
This attribute is best used with trivial routines for which it would be a waste to ever incur the overhead of a function call, even in unoptimized code.
#define OME_ALWAYS_OPTIMIZE | ( | level | ) | __attribute__((optimize(level))) |
Mark a function to be compiled with a specific level of optimization.
level | is a string that specifies the optimization level, such as "-O3" . |
#define OME_COLD_ROUTINE __attribute__((cold)) |
Annotation macro to tell compiler a routine may never be used.
#define OME_CONST_FUNCTION __attribute__((const)) |
Mark as an idempotent function that only accesses arguments – no global data.
This is similar to declaring a C++ function as constexpr
. Few functions will qualify for this treatment.
#define OME_CORE_CALL /* nothing */ |
#define OME_DEPRECATED __attribute__((deprecated)) |
Mark interface as deprecated.
#define OME_DEPRECATED_BECAUSE | ( | msg | ) | __attribute__((deprecated(msg))) |
Mark interface as deprecated and provide reason or suggested alternative.
msg | specifies a string of informational content to be emitted with the warning message |
#define OME_DLL_EXPORT /* nothing */ |
#define OME_EXPECT | ( | expr, | |
expected | |||
) | __builtin_expect((expr), expected) |
Annotation macro for conditional expression to indicate expected Boolean outcome.
expr | specifies the expression being evaluated |
expected | is a Boolean that indicates the expected result of the expression |
Useful to give the compiler a hint as to the expected outcome of an conditional expression to assist with layout of the object code.
#define OME_EXPECT_FALSE | ( | expr | ) | OME_EXPECT(expr, false) |
Annotation macro for conditional expression expected to be false.
expr | specifies the expression being evaluated |
#define OME_EXPECT_TRUE | ( | expr | ) | OME_EXPECT(expr, true) |
Annotation macro for conditional expression expected to be true.
expr | specifies the expression being evaluated |
#define OME_FAST_CALL /* nothing */ |
#define OME_INIT_PRIORITY | ( | n | ) | __attribute__((init_priority(n))) |
Override initialization priority of a C++ variable.
n | specifies the priority; lower values have higher priority. |
#define OME_NEVER_INLINE __attribute__((noinline)) |
Tell the compiler to not inline a function, regardless of optimization level.
This attribute is best used with routines for which there should be a single implementation.
#define OME_PREFETCH | ( | addr, | |
rw, | |||
locality | |||
) | __builtin_prefetch(addr, rw, locality) |
Macro to request prefetch.
addr | is the address of the memory block |
rw | is 0 for read-only, 1 for to be updated |
locality | is an integer value 0 to 3, where 0 means no further use and 3 for retain if at all possible. |
#define OME_PREFETCH_OBJECT_VTABLE | ( | obj, | |
relativeFunction | |||
) |
Prefetch the v-table entry for an object.
obj | is the pointer to the object. |
relativeFunction | is an integer corresponding to the relative index of the virtual function associated with the class. |
Sometimes the easiest mechanism to determine the relativeFunction value is by disassembling the source. An alternative would be to scan the v-table for the function of interest to derive the relative index.
#define OME_PURE_FUNCTION __attribute__((pure)) |
Mark as an idempotent function that can access global variables.
For a given set of argument values, the function must always return the same value. It may access data other than that provided by the arguments, such as looking up an entry in table, but the external data cannot have a variable influence on the result to be returned. The intent is to indicate to the compiler when a single call to the routine can be made; this is used for common sub-expression elimination and potentially hoisting a call out of a loop body.
#define OME_UNUSED __attribute__((unused)) |
Tell the compiler it is known that an element is not used.
This rarely used attribute is intended to silence compiler complaints.
#define OME_USAGE_ERROR | ( | msg | ) | __attribute__((error(msg))) |
Emit an error if the element is used.
msg | specifies a string of informational content to be emitted with the error message |
#define OME_USAGE_WARNING | ( | msg | ) | __attribute__((warning(msg))) |
Emit a warning if the element is used.
msg | specifies a string of informational content to be emitted with the warning message |
#define OME_USED __attribute__((used)) |
Tell the compiler an element is used to prevent it from being optimized away.
#define OME_WEAK __attribute__((weak)) |
Force generation of weak symbol.
#define OME_YIELD_THREAD | ( | ) | sched_yield() |
Macro for platform-specific yield of thread's time slice.
Safe strcpy()
routine that will not copy more than l
bytes and always ensures that a null is present to mark the end of the string.
d | speciries the destination to which the string will be copied |
s | specifies the source of the string content |
l | specifies the length of the destination |
0 | indicates the string had to be truncated |
1 | indicates the string was copied in its entirety. |
#define USE_GCC_PREFETCH 1 |
#define VIRTUAL_OVERRIDE override |
Generates override
if the compiler supports it.
|
inline |
Templated C++-only variant of safe_strcpy() suitable for handling small-sized strings that are being copied into buffers whose size is known at compile time.
When used as intended and inlined, the tail recursion will be flattened into a sequence of test and jumps and register pressure will be reduced.
bfr | points to the output buffer. The output buffer must be at least N bytes long. If truncateIfNeeded is false, then the output buffer must be at least N + 1 bytes long to hold the null marker. |
src | points to the source buffer. |
stopAt | specifies a character that marks the end of the source string. It defaults to the null character. |
altStopAt | specifies an alternate character that can be tested as a stop character. It defaults to the null character. |
truncateIfNeeded | is a Boolean that indicates if the destination buffer only has N characters and N characters were copied from the source, then the last character must be replaced by a null. This is not an issue if the destination buffer can hold at least N + 1 characters. |
|
inline |
uint_fast32_t copyShortStringUntilAndReturnLength | ( | char * | bfr, |
const char * | src, | ||
const char | stopAt = '\0' , |
||
const char | altStopAt = '\0' , |
||
const bool | truncateIfNeeded = false |
||
) |
Similar to copyShortStringUntil<>(), but returns the number of bytes before the trailing null. This would be the equivalent of strlen(bfr)
.
bfr | points to the output buffer. The output buffer must be at least N bytes long. If truncateIfNeeded is false, then the output buffer must be at least N + 1 bytes long to hold the null marker. |
src | points to the source buffer. |
stopAt | specifies a character that marks the end of the source string. It defaults to the null character. |
altStopAt | specifies an alternate character that can be tested as a stop character. It defaults to the null character. |
truncateIfNeeded | is a Boolean that indicates if the destination buffer only has N characters and N characters were copied from the source, then the last character must be replaced by a null. This is not an issue if the destination buffer can hold at least N + 1 characters. |
strlen()
call of their own.
|
inline |
Templated convenience function that obtains the demangled type name of a C++ type.
bfr | points to an output buffer into which the demangled name will be placed. |
bfrLen | specifies the length of the output buffer. |
References demangleEncodedTypeName().
|
inline |
Demangles a C++ encoded type name into its human-readable name.
name | specifies the encoded type name. |
bfr | points to an output buffer into which the demangled name will be placed. |
bfrLen | specifies the length of the output buffer. |
References free(), and safe_strcpy.
Referenced by demangledTypeName().
|
inline |
Templated C++-only routine similar to memccpy()
that is suitable for handling short strings that are being copied into buffers whose size is known at compile time. The maximum number of characters to be copied from the source is specified as the template parameter.
When used as intended, the tail recursion will be flattened into a sequence of test and jumps and register pressure will be reduced. The number of instructions generated will be proportional to the length of the string. On hardware that supports a load-from-immediate-offset, no register is needed to traverse the length of the string, nor do the pointers to the source and destination need to be modified.
bfr | points to the output buffer. |
src | points to the source buffer. |
stopAt | specifies a character that marks the end of the source string. It defaults to the null character. |
altStopAt | specifies an alternate character that can be tested as a stop character in addition to a null. The default is a null character. If both stopAt and altStopAt are the same character, the redundant test will be optimized away at compile-time. |
No trailing null or stop character is added to mark the end of the string. See copyShortStringUntil<>() for a routine which enforces returning a null-terminated string.
References OME_EXPECT.
|
inline |
|
inline |
Prefetch a memory block into the CPU's cache.
addr | points to the base of the memory block |
len | is the number of bytes in the block |
Note: the AMD Opteron/Athlon's have 64-byte cache lines and can perform a maximum of 8 outstanding prefetch requests. These CPU-specific attributes are represented by the use of the CACHE_LINE_LENGTH and MAX_PREFETCH_REQUESTS. With their normal values, a maximum amount of 64 * 8 = 512 bytes can be prefetched by this call.
References CACHE_LINE_LENGTH, CACHE_LINE_LENGTH_IN_WORDS, DO_PREFETCH, and MAX_PREFETCH_REQUESTS.
const char NONNULL_RETURN |
![]() | Generated: Fri Jul 31 2020 18:19:15
Support Information |