LSU.c File Reference
Linear Scaling Utilities for unsigned 32-bit integers.
More...
#include <PBS/INT.ih>
#include <PBS/LSU.h>
#include <LSU_pvt.ih>
|
Functions |
static __inline unsigned int | udiv_qnhid (unsigned int n1, unsigned int d) |
| Divides only the upper 32 bits of a long long.
|
static LSU_factors | lsu_calc (unsigned int numerator, unsigned int denominator) |
| Calculates the new scaling factors.
|
void | LSU_atomicCalc (LSU_factors *factors, unsigned int numerator, unsigned int denominator) |
| Calculates the scaling factors based on numerator and denominator.
|
unsigned int | LSU_atomicScale (const LSU_factors *factors, unsigned int dx) |
| Returns the scaled value of dx.
|
void | LSU_calc (LSU_factors *factors, unsigned int numerator, unsigned int denominator) |
| Calculates the scaling factors based on numerator and denominator.
|
unsigned int | LSU_scale (const LSU_factors *factors, unsigned int dx) |
| Returns the scaled value of dx.
|
Detailed Description
Linear Scaling Utilities for unsigned 32-bit integers.
- Author:
- JJRussell - russell@slac.stanford.edu
CVS $Id: LSU.c,v 1.2 2011/03/24 23:05:46 apw Exp $
Function Documentation
void LSU_atomicCalc |
( |
LSU_factors * |
factors, |
|
|
unsigned int |
numerator, |
|
|
unsigned int |
denominator | |
|
) |
| | |
Calculates the scaling factors based on numerator and denominator.
- Parameters:
-
| factors | The structure to receive the calculated scaling factors. |
| numerator | The numerator of the scale factor |
| denominator | The denominator of the scale factor |
- This routines calculates a multiply and a shift factor that can be used by LSU_scale or LSU_atomicScale to scale a variable by the ratio of numerator to denominator.
- This routine ensures atomic access to the scaling numbers. If your application does update the scale factors asynchronous to their use or your application has already arranged its own protection (perhaps be virtue of being called in interrupt code), then consider using the somewhat lighter-weight routines, LSU_calc and LSU_scale.
References INT__lock(), INT__unlock(), and lsu_calc().
LSU_atomicScale |
( |
const LSU_factors * |
factors, |
|
|
unsigned int |
dx | |
|
) |
| | |
Returns the scaled value of dx.
- Returns:
- The scaled value of dx
- Parameters:
-
| factors | The scaling factors |
| dx | The value to be scaled |
- What It Does
- This routine scales dx by the ratio of numerator and denominator values used to calculate the scaling factor. The main claim to fame here is speed on the PowerPC platforms, operating about 10 times faster than a 32 x 32 to 64 bit multiple followed by a 32-bit divide. It achieves this by precalculating factors that merely multiple and shift dx, avoiding the expensive divide operation everywhere but in the initial calculation of the multiple and shift factors.
- Atomic Operation
- On Power PC platforms only, the scaling factors are extracted in an indivisable fashion, protecting the routine from having these values recomputed out from underneath it. No such protection is offered on other platforms.
- Note:
- If your application does not update these parameters asynchonously to their use, consider using the lighter-weight routines LSU_calc and LSU_scale.
References INT__lock(), INT__unlock(), lsu__scale(), _LSU_factors::mult, and _LSU_factors::shift.
void LSU_calc |
( |
LSU_factors * |
factors, |
|
|
unsigned int |
numerator, |
|
|
unsigned int |
denominator | |
|
) |
| | |
Calculates the scaling factors based on numerator and denominator.
- Parameters:
-
| factors | The structure to receive the calculated scaling factors. |
| numerator | The numerator of the scale factor |
| denominator | The denominator of the scale factor |
- What It Does
- This routines calculates a multiply and a shift factor that can be used by LSU_scale or LSU_atomicScale to scale a variable by the ratio of numerator to denominator.
- Warning:
- If the scale factors are being update asynchronous of their use, then consider using LSU_atomicCalc and LSU_atomicScale or be sure to provide some locking/protection scheme of your own.
References lsu_calc().
static LSU_factors lsu_calc |
( |
unsigned int |
numerator, |
|
|
unsigned int |
denominator | |
|
) |
| | [static] |
LSU_scale |
( |
const LSU_factors * |
factors, |
|
|
unsigned int |
dx | |
|
) |
| | |
Returns the scaled value of dx.
- Returns:
- The scaled value of dx
- Parameters:
-
| factors | The scaling factors |
| dx | The value to be scaled |
- What It Does
- This routine scales dx by the ratio of numerator and denominator values used to calculate the scaling factor. The main claim to fame here is speed on the PowerPC platforms, operating about 10 times faster than a 32 x 32 to 64 bit multiple followed by a 32-bit divide. It achieves this by precalculating factors that merely multiple and shift dx, avoiding the expensive divide operation everywhere but in the initial calculation of the multiple and shift factors.
- Warning:
- If your application does updates these parameters asynchonously to their use, then either consider using the routines LSU_atomicCalc and LSU_atomicScale or arranging your own protection.
References lsu__scale(), _LSU_factors::mult, and _LSU_factors::shift.
unsigned int udiv_qnhid |
( |
unsigned int |
n1, |
|
|
unsigned int |
d | |
|
) |
| | [static] |
Divides only the upper 32 bits of a long long.
- Parameters:
-
| n1 | The upper 32 bits of a long long numerator |
| d | The divisor |
- This code was pilfered from the GCC source library and adopted for use in this special case. The original routine performed an extended 64 by 32 bit divide, returning a 64 bit quotient plus a remainder. In this special case one knows, aprior that, the quotient can only be 32 bits and that the remainder is irrelevant.
Referenced by lsu_calc().