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