Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

intutils.h File Reference

#include <string.h>
#include "base/inttypes.h"

Go to the source code of this file.

Functions

static uint32_t base_subu32 (uint32_t a, uint32_t b, uint32_t *cp)
 Unsigned 32-bit subtraction with borrow.
void base_copySmall (void *dst, const void *src, size_t intSize)
 Best compromise for copy:
  • for Intel, it is better to define our own copy function for small copies memcpy is better for sizes over 120-150
  • for Sun, memcpy is always worse.

static void base_copyLarge (void *dst, const void *src, size_t intSize)
static void base_copyBest (void *dst, const void *src, size_t intSize)
 Try to choose best copy dynamically.
void base_fill (void *mem, size_t intSize, uint32_t intValue)
 Fill memory with a given value.
uint32_t base_diff (const void *mem, size_t intSize, uint32_t intValue)
 Check if memory differs with a given value.
static void base_resetSmall (void *mem, size_t intSize)
 Reset memory: tests on Intel and Sun show that memset is always slower on Sun and it becomes faster than a custom function on Intel after a threshold between 120 and 150 ints.
static void base_resetLarge (void *mem, size_t intSize)
static void base_resetBest (void *mem, size_t intSize)
 Try to choose best reset dynamically.
BOOL base_areEqual (const void *data1, const void *data2, size_t intSize)
 Test equality.
static int32_t base_abs (int32_t x)
static int32_t base_absNot (int32_t x)
void base_sort (uint32_t *values, size_t n)
 Quick sort: from lower to higher ints.


Function Documentation

static int32_t base_abs int32_t  x  )  [inline, static]
 

Returns:
abs(x) without a jump!
Parameters:
x,: int to test.

static int32_t base_absNot int32_t  x  )  [inline, static]
 

Returns:
(x < 0 ? ~x : x) without a jump!
Parameters:
x,: int to test.

BOOL base_areEqual const void *  data1,
const void *  data2,
size_t  intSize
 

Test equality.

(optimistic implementation)

Parameters:
data1,data2,: data to be compared.
intSize,: size in int to compare.
Returns:
TRUE if the contents are the same.
Precondition:
data1 and data2 are of size int32_t[intSize] null pointers are accepted as argument

static void base_copyBest void *  dst,
const void *  src,
size_t  intSize
[inline, static]
 

Try to choose best copy dynamically.

static void base_copyLarge void *  dst,
const void *  src,
size_t  intSize
[inline, static]
 

void base_copySmall void *  dst,
const void *  src,
size_t  intSize
 

Best compromise for copy:

  • for Intel, it is better to define our own copy function for small copies memcpy is better for sizes over 120-150
  • for Sun, memcpy is always worse.

As the cost of a function call is negligible we prefer to reduce code size by not inlining the code.

Parameters:
src,: source
dst,: destination
intSize,: size in int to copy
Precondition:
src and dst are int32_t[intsize].

uint32_t base_diff const void *  mem,
size_t  intSize,
uint32_t  intValue
 

Check if memory differs with a given value.

Parameters:
mem,: memory to check
intSize,: size in int to fill
intValue,: value to check
Returns:
0 if mem[0..intSize-1] == intValue, or !=0 otherwise.

void base_fill void *  mem,
size_t  intSize,
uint32_t  intValue
 

Fill memory with a given value.

Parameters:
mem,: memory to fill
intSize,: size in int to fill
intValue,: value to use to fill
Postcondition:
int[0..intSize-1] at mem is filled with intValue

static void base_resetBest void *  mem,
size_t  intSize
[inline, static]
 

Try to choose best reset dynamically.

static void base_resetLarge void *  mem,
size_t  intSize
[inline, static]
 

static void base_resetSmall void *  mem,
size_t  intSize
[inline, static]
 

Reset memory: tests on Intel and Sun show that memset is always slower on Sun and it becomes faster than a custom function on Intel after a threshold between 120 and 150 ints.

In practice reset is used for 2 very different purposes:

  • reset of small size for control vector or similar
  • reset of large size for hash tables

Parameters:
mem,: memory to reset
intSize,: size in int to reset
Precondition:
mem is a int32_t[intSize]

void base_sort uint32_t *  values,
size_t  n
 

Quick sort: from lower to higher ints.

Parameters:
values,: values to sort
n,: number of values
Precondition:
values is a uint32_t[n]

static uint32_t base_subu32 uint32_t  a,
uint32_t  b,
uint32_t *  cp
[inline, static]
 

Unsigned 32-bit subtraction with borrow.

Function that subtracts two unsigned 32-bit numbers. For x86-processors this function is implemented in assembler. This saves around 50 instructions of which several are branches.

Parameters:
a,: the first term.
b,: the second term.
cp,: pointer to carry/borrow. (in/out).
Returns:
the lower 32-bits of a - (b + *cp).
Precondition:
:
  • *cp is either 0 or 1.
Postcondition:
:
  • *cp is 1 if borrow was necessary, 0 otherwise.


Generated on Fri Jun 30 00:02:30 2006 for Module base by  doxygen 1.4.2