1/* $NetBSD$ */ 2 3/*++ 4 5Copyright (c) 1998 Intel Corporation 6 7Module Name: 8 9 math.c 10 11Abstract: 12 13 14 15 16Revision History 17 18--*/ 19 20#include "lib.h" 21 22 23// 24// Declare runtime functions 25// 26 27#ifdef RUNTIME_CODE 28#ifndef __GNUC__ 29#pragma RUNTIME_CODE(LShiftU64) 30#pragma RUNTIME_CODE(RShiftU64) 31#pragma RUNTIME_CODE(MultU64x32) 32#pragma RUNTIME_CODE(DivU64x32) 33#endif 34#endif 35 36// 37// 38// 39 40 41 42 43UINT64 44LShiftU64 ( 45 IN UINT64 Operand, 46 IN UINTN Count 47 ) 48// Left shift 64bit by 32bit and get a 64bit result 49{ 50 return Operand << Count; 51} 52 53UINT64 54RShiftU64 ( 55 IN UINT64 Operand, 56 IN UINTN Count 57 ) 58// Right shift 64bit by 32bit and get a 64bit result 59{ 60 return Operand >> Count; 61} 62 63 64UINT64 65MultU64x32 ( 66 IN UINT64 Multiplicand, 67 IN UINTN Multiplier 68 ) 69// Multiple 64bit by 32bit and get a 64bit result 70{ 71 return Multiplicand * Multiplier; 72} 73 74UINT64 75DivU64x32 ( 76 IN UINT64 Dividend, 77 IN UINTN Divisor, 78 OUT UINTN *Remainder OPTIONAL 79 ) 80// divide 64bit by 32bit and get a 64bit result 81// N.B. only works for 31bit divisors!! 82{ 83 ASSERT (Divisor != 0); 84 85 if (Remainder) { 86 *Remainder = Dividend % Divisor; 87 } 88 89 return Dividend / Divisor; 90} 91