math.c revision 1.1 1 /* $NetBSD: math.c,v 1.1 2018/08/16 18:17:47 jmcneill Exp $ */
2
3 /*
4 * Copright (C) 2014 Linaro Ltd.
5 * Author: Ard Biesheuvel <ard.biesheuvel (at) linaro.org>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice and this list of conditions, without modification.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * Alternatively, this software may be distributed under the terms of the
16 * GNU General Public License as published by the Free Software Foundation;
17 * either version 2 of the License, or (at your option) any later version.
18 */
19
20 #include "lib.h"
21
22 UINT64
23 LShiftU64 (
24 IN UINT64 Operand,
25 IN UINTN Count
26 )
27 // Left shift 64bit by 32bit and get a 64bit result
28 {
29 return Operand << Count;
30 }
31
32 UINT64
33 RShiftU64 (
34 IN UINT64 Operand,
35 IN UINTN Count
36 )
37 // Right shift 64bit by 32bit and get a 64bit result
38 {
39 return Operand >> Count;
40 }
41
42
43 UINT64
44 MultU64x32 (
45 IN UINT64 Multiplicand,
46 IN UINTN Multiplier
47 )
48 // Multiple 64bit by 32bit and get a 64bit result
49 {
50 return Multiplicand * Multiplier;
51 }
52
53 UINT64
54 DivU64x32 (
55 IN UINT64 Dividend,
56 IN UINTN Divisor,
57 OUT UINTN *Remainder OPTIONAL
58 )
59 // divide 64bit by 32bit and get a 64bit result
60 // N.B. only works for 31bit divisors!!
61 {
62 if (Remainder)
63 *Remainder = Dividend % Divisor;
64 return Dividend / Divisor;
65 }
66