libcsdbg  1.28
C++ exception (and generic) stack trace debug library
void * csdbg::util::memswap ( void *  mem,
u32  sz 
)
static

Reverse the byte order of a memory block.

Parameters
[in,out]memthe base address of the block
[in]szthe block size
Returns
the first argument
Note
Used to convert big endian data to little endian and vice versa

Definition at line 374 of file util.cpp.

References __D_ASSERT, likely, and unlikely.

375 {
376  __D_ASSERT(mem != NULL);
377  if ( unlikely(mem == NULL) )
378  return mem;
379 
380  u8 *l = static_cast<u8*> (mem);
381  u8 *r = l + sz - 1;
382  while ( likely(l < r) ) {
383  u8 tmp = *l;
384  *(l++) = *r;
385  *(r--) = tmp;
386  }
387 
388  return mem;
389 }
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
unsigned char u8
8-bit unsigned integer
Definition: config.hpp:92
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
#define __D_ASSERT(x)
Assertion macro.
Definition: config.hpp:268