xref: /netbsd-src/sys/external/bsd/gnu-efi/dist/lib/ia64/math.c (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1 /*	$NetBSD: math.c,v 1.1.1.1 2014/04/01 16:16:07 jakllsch Exp $	*/
2 
3 /*++
4 
5 Copyright (c) 1998  Intel Corporation
6 
7 Module Name:
8 
9     math.c
10 
11 Abstract:
12 
13 
14 
15 
16 Revision 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 
43 UINT64
44 LShiftU64 (
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 
53 UINT64
54 RShiftU64 (
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 
64 UINT64
65 MultU64x32 (
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 
74 UINT64
75 DivU64x32 (
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