summaryrefslogtreecommitdiff
path: root/lib/riscv64/math.c
blob: 3653e4203b9231a170e885a4ce297e7c2c3355b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: BSD-2-Clause-Patent
/*
 * This code is based on EDK II MdePkg/Library/BaseLib/Math64.c
 * Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
 */

#include "lib.h"

/**
 * LShiftU64() - left shift
 */
UINT64
LShiftU64 (
	IN UINT64   Operand,
	IN UINTN    Count
)
{
	return Operand << Count;
}

/**
 * RShiftU64() - right shift
 */
UINT64
RShiftU64 (
	IN UINT64   Operand,
	IN UINTN    Count
)
{
	return Operand >> Count;
}

/**
 * MultU64x32() - multiply
 */
UINT64
MultU64x32 (
	IN UINT64   Multiplicand,
	IN UINTN    Multiplier
)
{
	return Multiplicand * Multiplier;
}

/**
 * DivU64x32() - divide
 */
UINT64
DivU64x32 (
	IN UINT64   Dividend,
	IN UINTN    Divisor,
	OUT UINTN   *Remainder OPTIONAL
)
{
	ASSERT(Divisor != 0);

	if (Remainder) {
		*Remainder = Dividend % Divisor;
	}

	return Dividend / Divisor;
}