Click
Loading...
Searching...
No Matches
Macros | Functions
integers.hh File Reference

Functions for manipulating integers. More...

#include <click/glue.hh>
#include <click/type_traits.hh>

Go to the source code of this file.

Macros

#define NEED_FFS_MSB_UINT64_T   1
 
#define NEED_FFS_LSB_UINT64_T   1
 

Functions

uint64_t htonq (uint64_t x)
 Return x translated from host to network byte order.
 
uint64_t ntohq (uint64_t x)
 Return x translated from network to host byte order.
 
unsigned char host_to_net_order (unsigned char x)
 Translate x to network byte order.
 
signed char host_to_net_order (signed char x)
 
char host_to_net_order (char x)
 
short host_to_net_order (short x)
 
unsigned short host_to_net_order (unsigned short x)
 
int host_to_net_order (int x)
 
unsigned host_to_net_order (unsigned x)
 
int64_t host_to_net_order (int64_t x)
 
uint64_t host_to_net_order (uint64_t x)
 
unsigned char net_to_host_order (unsigned char x)
 Translate x to host byte order.
 
signed char net_to_host_order (signed char x)
 
char net_to_host_order (char x)
 
short net_to_host_order (short x)
 
unsigned short net_to_host_order (unsigned short x)
 
int net_to_host_order (int x)
 
unsigned net_to_host_order (unsigned x)
 
int64_t net_to_host_order (int64_t x)
 
uint64_t net_to_host_order (uint64_t x)
 
int ffs_msb (unsigned x)
 Return the index of the most significant bit set in x.
 
int ffs_msb (unsigned long x)
 
int ffs_msb (uint64_t x)
 
int ffs_lsb (unsigned x)
 Return the index of the least significant bit set in x.
 
int ffs_lsb (unsigned long x)
 
int ffs_lsb (uint64_t x)
 
uint32_t int_sqrt (uint32_t x)
 Return the integer approximation of x's square root.
 
uint64_t int_sqrt (uint64_t x)
 
uint32_t int_divide (uint32_t a, uint32_t b)
 Return a / b.
 
int32_t int_divide (int32_t a, uint32_t b)
 
uint64_t int_divide (uint64_t a, uint32_t b)
 
int64_t int_divide (int64_t a, uint32_t b)
 
template<typename T >
void int_multiply (T a, T b, T &xlow, T &xhigh)
 Multiply a * b, placing the low-order bits of the result in xlow and the high-order bits in xhigh.
 
uint32_t int_remainder (uint32_t a, uint32_t b, uint32_t &quot)
 Divide a / b, placing quotient in quot and returning remainder.
 
int32_t int_remainder (int32_t a, uint32_t b, int32_t &quot)
 
uint32_t int_remainder (uint64_t a, uint32_t b, uint64_t &quot)
 
uint32_t int_remainder (int64_t a, uint32_t b, int64_t &quot)
 

Detailed Description

Functions for manipulating integers.

>

Function Documentation

◆ htonq()

uint64_t htonq ( uint64_t  x)
inline

Return x translated from host to network byte order.

◆ ntohq()

uint64_t ntohq ( uint64_t  x)
inline

Return x translated from network to host byte order.

◆ host_to_net_order() [1/9]

unsigned char host_to_net_order ( unsigned char  x)
inline

Translate x to network byte order.

Compare htons/htonl/htonq. host_to_net_order is particularly useful in template functions, where the type to be translated to network byte order is unknown.

◆ host_to_net_order() [2/9]

signed char host_to_net_order ( signed char  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [3/9]

char host_to_net_order ( char  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [4/9]

short host_to_net_order ( short  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [5/9]

unsigned short host_to_net_order ( unsigned short  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [6/9]

int host_to_net_order ( int  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [7/9]

unsigned host_to_net_order ( unsigned  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [8/9]

int64_t host_to_net_order ( int64_t  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ host_to_net_order() [9/9]

uint64_t host_to_net_order ( uint64_t  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [1/9]

unsigned char net_to_host_order ( unsigned char  x)
inline

Translate x to host byte order.

Compare ntohs/ntohl/ntohq. net_to_host_order is particularly useful in template functions, where the type to be translated to network byte order is unknown.

◆ net_to_host_order() [2/9]

signed char net_to_host_order ( signed char  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [3/9]

char net_to_host_order ( char  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [4/9]

short net_to_host_order ( short  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [5/9]

unsigned short net_to_host_order ( unsigned short  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [6/9]

int net_to_host_order ( int  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [7/9]

unsigned net_to_host_order ( unsigned  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [8/9]

int64_t net_to_host_order ( int64_t  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ net_to_host_order() [9/9]

uint64_t net_to_host_order ( uint64_t  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ffs_msb() [1/3]

int ffs_msb ( unsigned  x)
inline

Return the index of the most significant bit set in x.

Returns
0 if x = 0; otherwise the index of first bit set, where the most significant bit is numbered 1.

◆ ffs_msb() [2/3]

int ffs_msb ( unsigned long  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ffs_msb() [3/3]

int ffs_msb ( uint64_t  x)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ffs_lsb() [1/3]

int ffs_lsb ( unsigned  x)
inline

Return the index of the least significant bit set in x.

Returns
0 if x = 0; otherwise the index of first bit set, where the least significant bit is numbered 1.

◆ ffs_lsb() [2/3]

int ffs_lsb ( unsigned long  x)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ffs_lsb() [3/3]

int ffs_lsb ( uint64_t  x)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_sqrt() [1/2]

uint32_t int_sqrt ( uint32_t  x)

Return the integer approximation of x's square root.

Returns
The integer y where y*y <= x, but (y+1)*(y+1) > x.

◆ int_sqrt() [2/2]

uint64_t int_sqrt ( uint64_t  x)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_divide() [1/4]

uint32_t int_divide ( uint32_t  a,
uint32_t  b 
)
inline

Return a / b.

◆ int_divide() [2/4]

int32_t int_divide ( int32_t  a,
uint32_t  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_divide() [3/4]

uint64_t int_divide ( uint64_t  a,
uint32_t  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_divide() [4/4]

int64_t int_divide ( int64_t  a,
uint32_t  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_multiply()

template<typename T >
void int_multiply ( T  a,
T  b,
T &  xlow,
T &  xhigh 
)

Multiply a * b, placing the low-order bits of the result in xlow and the high-order bits in xhigh.

◆ int_remainder() [1/4]

uint32_t int_remainder ( uint32_t  a,
uint32_t  b,
uint32_t &  quot 
)
inline

Divide a / b, placing quotient in quot and returning remainder.

◆ int_remainder() [2/4]

int32_t int_remainder ( int32_t  a,
uint32_t  b,
int32_t &  quot 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_remainder() [3/4]

uint32_t int_remainder ( uint64_t  a,
uint32_t  b,
uint64_t &  quot 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ int_remainder() [4/4]

uint32_t int_remainder ( int64_t  a,
uint32_t  b,
int64_t &  quot 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.