]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ia32/DivS64x64Remainder.c
1) Sync EdkCompatibilityPkg with EDK 1.04. The changes includes:
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / BaseLib / Ia32 / DivS64x64Remainder.c
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2004 - 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name:\r
14\r
15 DivS64x64Remainder.c\r
16 \r
17Abstract: \r
18\r
19 Integer division worker functions for Ia32.\r
20\r
21--*/\r
22\r
c7f33ca4 23#include "BaseLibInternals.h"\r
3eb9473e 24\r
25/**\r
26 Worker function that Divides a 64-bit signed integer by a 64-bit signed integer and\r
27 generates a 64-bit signed result and a optional 64-bit signed remainder.\r
28\r
29 This function divides the 64-bit unsigned value Dividend by the 64-bit\r
30 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r
31 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.\r
32 This function returns the 64-bit unsigned quotient.\r
33\r
34 @param Dividend A 64-bit signed value.\r
35 @param Divisor A 64-bit signed value.\r
36 @param Remainder A pointer to a 64-bit signed value. This parameter is\r
37 optional and may be NULL.\r
38\r
39 @return Dividend / Divisor\r
40\r
41**/\r
42INT64\r
43InternalMathDivRemS64x64 (\r
44 IN INT64 Dividend,\r
45 IN INT64 Divisor,\r
46 OUT INT64 *Remainder OPTIONAL\r
47 )\r
48{\r
49 INT64 Quot;\r
50\r
51 Quot = InternalMathDivRemU64x64 (\r
52 Dividend >= 0 ? Dividend : -Dividend,\r
53 Divisor >= 0 ? Divisor : -Divisor,\r
54 (UINT64 *) Remainder\r
55 );\r
56 if (Remainder != NULL && Dividend < 0) {\r
57 *Remainder = -*Remainder;\r
58 }\r
59 return (Dividend ^ Divisor) >= 0 ? Quot : -Quot;\r
60}\r