cgul_multiply64.h File Reference

portable multiplication that can produce 64-bit products More...

#include "cgul_common.h"
#include "cgul_exception.h"
Include dependency graph for cgul_multiply64.h:
This graph shows which files directly or indirectly include this file:

Functions

CGUL_BEGIN_C CGUL_EXPORT void cgul_multiply64 (cgul_exception_t *cex, unsigned int x, unsigned int y, unsigned int *high, unsigned int *low)
 

Detailed Description

Portable multiplication that can produce 64-bit products.

Author
Paul Serice

Function Documentation

§ cgul_multiply64()

CGUL_BEGIN_C CGUL_EXPORT void cgul_multiply64 ( cgul_exception_t cex,
unsigned int  x,
unsigned int  y,
unsigned int *  high,
unsigned int *  low 
)

This function multiplies two 32-bit unsigned integers x and y to produce a 64-bit unsigned product using only 32-bit arithmetic. The high 32-bits of the 64-bit product will be stored in *high if high is not NULL, and the low 32-bits of the 64-bit product will be stored in *low if low is not NULL.

The following printf() format specification can be used to convert *high and *low into a proper hexadecimal string because it accounts for the significance of the leading zeros in *low:

    printf("%#0x%08x", *high, *low);

This function takes about 2.5 times as long to run as native 64-bit multiplication. Thus, it should only be used if your compiler does not support a 64-bit type. To conditionally use this code, include the "cgul_int.h" header and test if CGUL_UINT64 is not defined.

Parameters
[in]cexc-style exception
[in]xfirst 32-bit multiplicand
[in]ysecond 32-bit multiplicand
[out]highhigh 32-bits of the product of x and y
[out]lowlow 32-bits of the product of x and y

Referenced by cgul_multiply64_cxx::multiply64().