xref: /netbsd-src/sys/external/bsd/gnu-efi/dist/lib/riscv64/math.c (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /*	$NetBSD: math.c,v 1.1.1.1 2021/09/30 18:50:09 jmcneill Exp $	*/
2 
3 // SPDX-License-Identifier: BSD-2-Clause-Patent
4 /*
5  * This code is based on EDK II MdePkg/Library/BaseLib/Math64.c
6  * Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
7  */
8 
9 #include "lib.h"
10 
11 /**
12  * LShiftU64() - left shift
13  */
14 UINT64
15 LShiftU64 (
16 	IN UINT64   Operand,
17 	IN UINTN    Count
18 )
19 {
20 	return Operand << Count;
21 }
22 
23 /**
24  * RShiftU64() - right shift
25  */
26 UINT64
27 RShiftU64 (
28 	IN UINT64   Operand,
29 	IN UINTN    Count
30 )
31 {
32 	return Operand >> Count;
33 }
34 
35 /**
36  * MultU64x32() - multiply
37  */
38 UINT64
39 MultU64x32 (
40 	IN UINT64   Multiplicand,
41 	IN UINTN    Multiplier
42 )
43 {
44 	return Multiplicand * Multiplier;
45 }
46 
47 /**
48  * DivU64x32() - divide
49  */
50 UINT64
51 DivU64x32 (
52 	IN UINT64   Dividend,
53 	IN UINTN    Divisor,
54 	OUT UINTN   *Remainder OPTIONAL
55 )
56 {
57 	ASSERT(Divisor != 0);
58 
59 	if (Remainder) {
60 		*Remainder = Dividend % Divisor;
61 	}
62 
63 	return Dividend / Divisor;
64 }
65