]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DivS64x64Remainder.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DivS64x64Remainder.c
1 /** @file
2 Integer division worker functions for Ia32.
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "BaseLibInternals.h"
10
11 /**
12 Worker function that Divides a 64-bit signed integer by a 64-bit signed integer and
13 generates a 64-bit signed result and a optional 64-bit signed remainder.
14
15 This function divides the 64-bit signed value Dividend by the 64-bit
16 signed value Divisor and generates a 64-bit signed quotient. If Remainder
17 is not NULL, then the 64-bit signed remainder is returned in Remainder.
18 This function returns the 64-bit signed quotient.
19
20 @param Dividend A 64-bit signed value.
21 @param Divisor A 64-bit signed value.
22 @param Remainder A pointer to a 64-bit signed value. This parameter is
23 optional and may be NULL.
24
25 @return Dividend / Divisor
26
27 **/
28 INT64
29 EFIAPI
30 InternalMathDivRemS64x64 (
31 IN INT64 Dividend,
32 IN INT64 Divisor,
33 OUT INT64 *Remainder OPTIONAL
34 )
35 {
36 INT64 Quot;
37
38 Quot = InternalMathDivRemU64x64 (
39 (UINT64) (Dividend >= 0 ? Dividend : -Dividend),
40 (UINT64) (Divisor >= 0 ? Divisor : -Divisor),
41 (UINT64 *) Remainder
42 );
43 if (Remainder != NULL && Dividend < 0) {
44 *Remainder = -*Remainder;
45 }
46 return (Dividend ^ Divisor) >= 0 ? Quot : -Quot;
47 }