87 lines
1.2 KiB
C
87 lines
1.2 KiB
C
/*++
|
|
|
|
Copyright (c) 1998 Intel Corporation
|
|
|
|
Module Name:
|
|
|
|
math.c
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
|
|
Revision History
|
|
|
|
--*/
|
|
|
|
#include "lib.h"
|
|
|
|
|
|
/*
|
|
* Declare runtime functions
|
|
*/
|
|
|
|
#ifdef RUNTIME_CODE
|
|
#pragma RUNTIME_CODE(LShiftU64)
|
|
#pragma RUNTIME_CODE(RShiftU64)
|
|
#pragma RUNTIME_CODE(MultU64x32)
|
|
#pragma RUNTIME_CODE(DivU64x32)
|
|
#endif
|
|
|
|
/*
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
|
|
UINT64
|
|
LShiftU64 (
|
|
IN UINT64 Operand,
|
|
IN UINTN Count
|
|
)
|
|
/* Left shift 64bit by 32bit and get a 64bit result */
|
|
{
|
|
return Operand << Count;
|
|
}
|
|
|
|
UINT64
|
|
RShiftU64 (
|
|
IN UINT64 Operand,
|
|
IN UINTN Count
|
|
)
|
|
/* Right shift 64bit by 32bit and get a 64bit result */
|
|
{
|
|
return Operand >> Count;
|
|
}
|
|
|
|
|
|
UINT64
|
|
MultU64x32 (
|
|
IN UINT64 Multiplicand,
|
|
IN UINTN Multiplier
|
|
)
|
|
/* Multiple 64bit by 32bit and get a 64bit result */
|
|
{
|
|
return Multiplicand * Multiplier;
|
|
}
|
|
|
|
UINT64
|
|
DivU64x32 (
|
|
IN UINT64 Dividend,
|
|
IN UINTN Divisor,
|
|
OUT UINTN *Remainder OPTIONAL
|
|
)
|
|
/* divide 64bit by 32bit and get a 64bit result
|
|
* N.B. only works for 31bit divisors!! */
|
|
{
|
|
ASSERT (Divisor != 0);
|
|
|
|
if (Remainder) {
|
|
*Remainder = Dividend % Divisor;
|
|
}
|
|
|
|
return Dividend / Divisor;
|
|
}
|