Useful inline functions for assembler-optimised common operations


Detailed Description

There are little operations which one needs from time to time which can be relatively expensive or impossible to do in C. For these situations, TnFOX provides a series of small inline functions capable of providing them written in assembler on x86 (i486 or later only) and x64 but with fallback generic implementations in C. For x86 and x64 architectures, the relevent intrinsics for SSE and SSE2 are defined if the compiler is not compiling for a non-supporting processor.

Using these functions can seriously improve the speed of your code. You should also check out FX::Maths for SIMD optimised maths.


Functions

void FX::fxprefetchmemT (const void *ptr) throw ()
void FX::fxprefetchmemNT (const void *ptr) throw ()
FXuint FX::fxbitscan (FXuint x) throw ()
FXuint FX::fxbitscanrev (FXuint x) throw ()
void FX::fxendianswap (FXushort &v) throw ()
void FX::fxendianswap (FXuint &v) throw ()
void FX::fxendianswap (FXulong &v) throw ()


Function Documentation

void FX::fxprefetchmemT ( const void *  ptr  )  throw () [inline]

Pretches a cache line into the processor cache temporally (ie; it will be used multiple times)

void FX::fxprefetchmemNT ( const void *  ptr  )  throw () [inline]

Pretches a cache line into the processor cache non-temporally (ie; it will be used only once)

FXuint FX::fxbitscan ( FXuint  x  )  throw () [inline]

Forward scans an unsigned integer, returning the index of the first set bit. Compiles into 21 x86 cycles with no branching, though on x86 and x64 it directly uses the bsl instruction

References FX::fxbitscan().

Referenced by FX::TnFXSQLDBColumn::effectiveType(), and FX::fxbitscan().

FXuint FX::fxbitscanrev ( FXuint  x  )  throw () [inline]

Backward scans an unsigned integer, returning the index of the first set bit. Compiles into roughly 24 x86 cycles with no branching, though on x86 and x64 it directly uses the bsr instruction. You should note that this implementation uses illegal C++ which may fail with aggressive enough optimisation - in this situation, enable the alternative 36 x86 cycle implementation in the source code.

References FX::fxbitscanrev().

Referenced by FX::fxbitscanrev().

void FX::fxendianswap ( FXushort &  v  )  throw () [inline]

Endian swaps the two bytes at v

void FX::fxendianswap ( FXuint &  v  )  throw () [inline]

Endian swaps the four bytes at v

void FX::fxendianswap ( FXulong &  v  )  throw () [inline]

Endian swaps the eight bytes at v


(C) 2002-2008 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Jun 13 21:55:18 2008 for TnFOX by doxygen v1.5.6