17b1019a6SJerry Jelinek /*******************************************************************************
27b1019a6SJerry Jelinek  *
37b1019a6SJerry Jelinek  * Module Name: utmath - Integer math support routines
47b1019a6SJerry Jelinek  *
57b1019a6SJerry Jelinek  ******************************************************************************/
67b1019a6SJerry Jelinek 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127b1019a6SJerry Jelinek  * All rights reserved.
137b1019a6SJerry Jelinek  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
1197b1019a6SJerry Jelinek  * Redistribution and use in source and binary forms, with or without
1207b1019a6SJerry Jelinek  * modification, are permitted provided that the following conditions
1217b1019a6SJerry Jelinek  * are met:
1227b1019a6SJerry Jelinek  * 1. Redistributions of source code must retain the above copyright
1237b1019a6SJerry Jelinek  *    notice, this list of conditions, and the following disclaimer,
1247b1019a6SJerry Jelinek  *    without modification.
1257b1019a6SJerry Jelinek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1267b1019a6SJerry Jelinek  *    substantially similar to the "NO WARRANTY" disclaimer below
1277b1019a6SJerry Jelinek  *    ("Disclaimer") and any redistribution must be conditioned upon
1287b1019a6SJerry Jelinek  *    including a substantially similar Disclaimer requirement for further
1297b1019a6SJerry Jelinek  *    binary redistribution.
1307b1019a6SJerry Jelinek  * 3. Neither the names of the above-listed copyright holders nor the names
1317b1019a6SJerry Jelinek  *    of any contributors may be used to endorse or promote products derived
1327b1019a6SJerry Jelinek  *    from this software without specific prior written permission.
1337b1019a6SJerry Jelinek  *
1347b1019a6SJerry Jelinek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1357b1019a6SJerry Jelinek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1377b1019a6SJerry Jelinek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
1517b1019a6SJerry Jelinek 
1527b1019a6SJerry Jelinek #include "acpi.h"
1537b1019a6SJerry Jelinek #include "accommon.h"
1547b1019a6SJerry Jelinek 
1557b1019a6SJerry Jelinek 
1567b1019a6SJerry Jelinek #define _COMPONENT          ACPI_UTILITIES
1577b1019a6SJerry Jelinek         ACPI_MODULE_NAME    ("utmath")
1587b1019a6SJerry Jelinek 
1597b1019a6SJerry Jelinek /* Structures used only for 64-bit divide */
1607b1019a6SJerry Jelinek 
1617b1019a6SJerry Jelinek typedef struct uint64_struct
1627b1019a6SJerry Jelinek {
1637b1019a6SJerry Jelinek     UINT32                          Lo;
1647b1019a6SJerry Jelinek     UINT32                          Hi;
1657b1019a6SJerry Jelinek 
1667b1019a6SJerry Jelinek } UINT64_STRUCT;
1677b1019a6SJerry Jelinek 
1687b1019a6SJerry Jelinek typedef union uint64_overlay
1697b1019a6SJerry Jelinek {
1707b1019a6SJerry Jelinek     UINT64                          Full;
1717b1019a6SJerry Jelinek     UINT64_STRUCT                   Part;
1727b1019a6SJerry Jelinek 
1737b1019a6SJerry Jelinek } UINT64_OVERLAY;
1747b1019a6SJerry Jelinek 
175*35786f68SRobert Mustacchi /*
176*35786f68SRobert Mustacchi  * Optional support for 64-bit double-precision integer multiply and shift.
177*35786f68SRobert Mustacchi  * This code is configurable and is implemented in order to support 32-bit
178*35786f68SRobert Mustacchi  * kernel environments where a 64-bit double-precision math library is not
179*35786f68SRobert Mustacchi  * available.
180*35786f68SRobert Mustacchi  */
181*35786f68SRobert Mustacchi #ifndef ACPI_USE_NATIVE_MATH64
182*35786f68SRobert Mustacchi 
183*35786f68SRobert Mustacchi /*******************************************************************************
184*35786f68SRobert Mustacchi  *
185*35786f68SRobert Mustacchi  * FUNCTION:    AcpiUtShortMultiply
186*35786f68SRobert Mustacchi  *
187*35786f68SRobert Mustacchi  * PARAMETERS:  Multiplicand        - 64-bit multiplicand
188*35786f68SRobert Mustacchi  *              Multiplier          - 32-bit multiplier
189*35786f68SRobert Mustacchi  *              OutProduct          - Pointer to where the product is returned
190*35786f68SRobert Mustacchi  *
191*35786f68SRobert Mustacchi  * DESCRIPTION: Perform a short multiply.
192*35786f68SRobert Mustacchi  *
193*35786f68SRobert Mustacchi  ******************************************************************************/
194*35786f68SRobert Mustacchi 
195*35786f68SRobert Mustacchi ACPI_STATUS
AcpiUtShortMultiply(UINT64 Multiplicand,UINT32 Multiplier,UINT64 * OutProduct)196*35786f68SRobert Mustacchi AcpiUtShortMultiply (
197*35786f68SRobert Mustacchi     UINT64                  Multiplicand,
198*35786f68SRobert Mustacchi     UINT32                  Multiplier,
199*35786f68SRobert Mustacchi     UINT64                  *OutProduct)
200*35786f68SRobert Mustacchi {
201*35786f68SRobert Mustacchi     UINT64_OVERLAY          MultiplicandOvl;
202*35786f68SRobert Mustacchi     UINT64_OVERLAY          Product;
203*35786f68SRobert Mustacchi     UINT32                  Carry32;
204*35786f68SRobert Mustacchi 
205*35786f68SRobert Mustacchi 
206*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (UtShortMultiply);
207*35786f68SRobert Mustacchi 
208*35786f68SRobert Mustacchi 
209*35786f68SRobert Mustacchi     MultiplicandOvl.Full = Multiplicand;
210*35786f68SRobert Mustacchi 
211*35786f68SRobert Mustacchi     /*
212*35786f68SRobert Mustacchi      * The Product is 64 bits, the carry is always 32 bits,
213*35786f68SRobert Mustacchi      * and is generated by the second multiply.
214*35786f68SRobert Mustacchi      */
215*35786f68SRobert Mustacchi     ACPI_MUL_64_BY_32 (0, MultiplicandOvl.Part.Hi, Multiplier,
216*35786f68SRobert Mustacchi         Product.Part.Hi, Carry32);
217*35786f68SRobert Mustacchi 
218*35786f68SRobert Mustacchi     ACPI_MUL_64_BY_32 (0, MultiplicandOvl.Part.Lo, Multiplier,
219*35786f68SRobert Mustacchi         Product.Part.Lo, Carry32);
220*35786f68SRobert Mustacchi 
221*35786f68SRobert Mustacchi     Product.Part.Hi += Carry32;
222*35786f68SRobert Mustacchi 
223*35786f68SRobert Mustacchi     /* Return only what was requested */
224*35786f68SRobert Mustacchi 
225*35786f68SRobert Mustacchi     if (OutProduct)
226*35786f68SRobert Mustacchi     {
227*35786f68SRobert Mustacchi         *OutProduct = Product.Full;
228*35786f68SRobert Mustacchi     }
229*35786f68SRobert Mustacchi 
230*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
231*35786f68SRobert Mustacchi }
232*35786f68SRobert Mustacchi 
233*35786f68SRobert Mustacchi 
234*35786f68SRobert Mustacchi /*******************************************************************************
235*35786f68SRobert Mustacchi  *
236*35786f68SRobert Mustacchi  * FUNCTION:    AcpiUtShortShiftLeft
237*35786f68SRobert Mustacchi  *
238*35786f68SRobert Mustacchi  * PARAMETERS:  Operand             - 64-bit shift operand
239*35786f68SRobert Mustacchi  *              Count               - 32-bit shift count
240*35786f68SRobert Mustacchi  *              OutResult           - Pointer to where the result is returned
241*35786f68SRobert Mustacchi  *
242*35786f68SRobert Mustacchi  * DESCRIPTION: Perform a short left shift.
243*35786f68SRobert Mustacchi  *
244*35786f68SRobert Mustacchi  ******************************************************************************/
245*35786f68SRobert Mustacchi 
246*35786f68SRobert Mustacchi ACPI_STATUS
AcpiUtShortShiftLeft(UINT64 Operand,UINT32 Count,UINT64 * OutResult)247*35786f68SRobert Mustacchi AcpiUtShortShiftLeft (
248*35786f68SRobert Mustacchi     UINT64                  Operand,
249*35786f68SRobert Mustacchi     UINT32                  Count,
250*35786f68SRobert Mustacchi     UINT64                  *OutResult)
251*35786f68SRobert Mustacchi {
252*35786f68SRobert Mustacchi     UINT64_OVERLAY          OperandOvl;
253*35786f68SRobert Mustacchi 
254*35786f68SRobert Mustacchi 
255*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (UtShortShiftLeft);
256*35786f68SRobert Mustacchi 
257*35786f68SRobert Mustacchi 
258*35786f68SRobert Mustacchi     OperandOvl.Full = Operand;
259*35786f68SRobert Mustacchi 
260*35786f68SRobert Mustacchi     if ((Count & 63) >= 32)
261*35786f68SRobert Mustacchi     {
262*35786f68SRobert Mustacchi         OperandOvl.Part.Hi = OperandOvl.Part.Lo;
263*35786f68SRobert Mustacchi         OperandOvl.Part.Lo = 0;
264*35786f68SRobert Mustacchi         Count = (Count & 63) - 32;
265*35786f68SRobert Mustacchi     }
266*35786f68SRobert Mustacchi     ACPI_SHIFT_LEFT_64_BY_32 (OperandOvl.Part.Hi,
267*35786f68SRobert Mustacchi         OperandOvl.Part.Lo, Count);
268*35786f68SRobert Mustacchi 
269*35786f68SRobert Mustacchi     /* Return only what was requested */
270*35786f68SRobert Mustacchi 
271*35786f68SRobert Mustacchi     if (OutResult)
272*35786f68SRobert Mustacchi     {
273*35786f68SRobert Mustacchi         *OutResult = OperandOvl.Full;
274*35786f68SRobert Mustacchi     }
275*35786f68SRobert Mustacchi 
276*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
277*35786f68SRobert Mustacchi }
278*35786f68SRobert Mustacchi 
279*35786f68SRobert Mustacchi /*******************************************************************************
280*35786f68SRobert Mustacchi  *
281*35786f68SRobert Mustacchi  * FUNCTION:    AcpiUtShortShiftRight
282*35786f68SRobert Mustacchi  *
283*35786f68SRobert Mustacchi  * PARAMETERS:  Operand             - 64-bit shift operand
284*35786f68SRobert Mustacchi  *              Count               - 32-bit shift count
285*35786f68SRobert Mustacchi  *              OutResult           - Pointer to where the result is returned
286*35786f68SRobert Mustacchi  *
287*35786f68SRobert Mustacchi  * DESCRIPTION: Perform a short right shift.
288*35786f68SRobert Mustacchi  *
289*35786f68SRobert Mustacchi  ******************************************************************************/
290*35786f68SRobert Mustacchi 
291*35786f68SRobert Mustacchi ACPI_STATUS
AcpiUtShortShiftRight(UINT64 Operand,UINT32 Count,UINT64 * OutResult)292*35786f68SRobert Mustacchi AcpiUtShortShiftRight (
293*35786f68SRobert Mustacchi     UINT64                  Operand,
294*35786f68SRobert Mustacchi     UINT32                  Count,
295*35786f68SRobert Mustacchi     UINT64                  *OutResult)
296*35786f68SRobert Mustacchi {
297*35786f68SRobert Mustacchi     UINT64_OVERLAY          OperandOvl;
298*35786f68SRobert Mustacchi 
299*35786f68SRobert Mustacchi 
300*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (UtShortShiftRight);
301*35786f68SRobert Mustacchi 
302*35786f68SRobert Mustacchi 
303*35786f68SRobert Mustacchi     OperandOvl.Full = Operand;
304*35786f68SRobert Mustacchi 
305*35786f68SRobert Mustacchi     if ((Count & 63) >= 32)
306*35786f68SRobert Mustacchi     {
307*35786f68SRobert Mustacchi         OperandOvl.Part.Lo = OperandOvl.Part.Hi;
308*35786f68SRobert Mustacchi         OperandOvl.Part.Hi = 0;
309*35786f68SRobert Mustacchi         Count = (Count & 63) - 32;
310*35786f68SRobert Mustacchi     }
311*35786f68SRobert Mustacchi     ACPI_SHIFT_RIGHT_64_BY_32 (OperandOvl.Part.Hi,
312*35786f68SRobert Mustacchi         OperandOvl.Part.Lo, Count);
313*35786f68SRobert Mustacchi 
314*35786f68SRobert Mustacchi     /* Return only what was requested */
315*35786f68SRobert Mustacchi 
316*35786f68SRobert Mustacchi     if (OutResult)
317*35786f68SRobert Mustacchi     {
318*35786f68SRobert Mustacchi         *OutResult = OperandOvl.Full;
319*35786f68SRobert Mustacchi     }
320*35786f68SRobert Mustacchi 
321*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
322*35786f68SRobert Mustacchi }
323*35786f68SRobert Mustacchi #else
324*35786f68SRobert Mustacchi 
325*35786f68SRobert Mustacchi /*******************************************************************************
326*35786f68SRobert Mustacchi  *
327*35786f68SRobert Mustacchi  * FUNCTION:    AcpiUtShortMultiply
328*35786f68SRobert Mustacchi  *
329*35786f68SRobert Mustacchi  * PARAMETERS:  See function headers above
330*35786f68SRobert Mustacchi  *
331*35786f68SRobert Mustacchi  * DESCRIPTION: Native version of the UtShortMultiply function.
332*35786f68SRobert Mustacchi  *
333*35786f68SRobert Mustacchi  ******************************************************************************/
334*35786f68SRobert Mustacchi 
335*35786f68SRobert Mustacchi ACPI_STATUS
AcpiUtShortMultiply(UINT64 Multiplicand,UINT32 Multiplier,UINT64 * OutProduct)336*35786f68SRobert Mustacchi AcpiUtShortMultiply (
337*35786f68SRobert Mustacchi     UINT64                  Multiplicand,
338*35786f68SRobert Mustacchi     UINT32                  Multiplier,
339*35786f68SRobert Mustacchi     UINT64                  *OutProduct)
340*35786f68SRobert Mustacchi {
341*35786f68SRobert Mustacchi 
342*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (UtShortMultiply);
343*35786f68SRobert Mustacchi 
344*35786f68SRobert Mustacchi 
345*35786f68SRobert Mustacchi     /* Return only what was requested */
346*35786f68SRobert Mustacchi 
347*35786f68SRobert Mustacchi     if (OutProduct)
348*35786f68SRobert Mustacchi     {
349*35786f68SRobert Mustacchi         *OutProduct = Multiplicand * Multiplier;
350*35786f68SRobert Mustacchi     }
351*35786f68SRobert Mustacchi 
352*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
353*35786f68SRobert Mustacchi }
354*35786f68SRobert Mustacchi 
355*35786f68SRobert Mustacchi /*******************************************************************************
356*35786f68SRobert Mustacchi  *
357*35786f68SRobert Mustacchi  * FUNCTION:    AcpiUtShortShiftLeft
358*35786f68SRobert Mustacchi  *
359*35786f68SRobert Mustacchi  * PARAMETERS:  See function headers above
360*35786f68SRobert Mustacchi  *
361*35786f68SRobert Mustacchi  * DESCRIPTION: Native version of the UtShortShiftLeft function.
362*35786f68SRobert Mustacchi  *
363*35786f68SRobert Mustacchi  ******************************************************************************/
364*35786f68SRobert Mustacchi 
365*35786f68SRobert Mustacchi ACPI_STATUS
AcpiUtShortShiftLeft(UINT64 Operand,UINT32 Count,UINT64 * OutResult)366*35786f68SRobert Mustacchi AcpiUtShortShiftLeft (
367*35786f68SRobert Mustacchi     UINT64                  Operand,
368*35786f68SRobert Mustacchi     UINT32                  Count,
369*35786f68SRobert Mustacchi     UINT64                  *OutResult)
370*35786f68SRobert Mustacchi {
371*35786f68SRobert Mustacchi 
372*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (UtShortShiftLeft);
373*35786f68SRobert Mustacchi 
374*35786f68SRobert Mustacchi 
375*35786f68SRobert Mustacchi     /* Return only what was requested */
376*35786f68SRobert Mustacchi 
377*35786f68SRobert Mustacchi     if (OutResult)
378*35786f68SRobert Mustacchi     {
379*35786f68SRobert Mustacchi         *OutResult = Operand << Count;
380*35786f68SRobert Mustacchi     }
381*35786f68SRobert Mustacchi 
382*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
383*35786f68SRobert Mustacchi }
384*35786f68SRobert Mustacchi 
385*35786f68SRobert Mustacchi /*******************************************************************************
386*35786f68SRobert Mustacchi  *
387*35786f68SRobert Mustacchi  * FUNCTION:    AcpiUtShortShiftRight
388*35786f68SRobert Mustacchi  *
389*35786f68SRobert Mustacchi  * PARAMETERS:  See function headers above
390*35786f68SRobert Mustacchi  *
391*35786f68SRobert Mustacchi  * DESCRIPTION: Native version of the UtShortShiftRight function.
392*35786f68SRobert Mustacchi  *
393*35786f68SRobert Mustacchi  ******************************************************************************/
394*35786f68SRobert Mustacchi 
395*35786f68SRobert Mustacchi ACPI_STATUS
AcpiUtShortShiftRight(UINT64 Operand,UINT32 Count,UINT64 * OutResult)396*35786f68SRobert Mustacchi AcpiUtShortShiftRight (
397*35786f68SRobert Mustacchi     UINT64                  Operand,
398*35786f68SRobert Mustacchi     UINT32                  Count,
399*35786f68SRobert Mustacchi     UINT64                  *OutResult)
400*35786f68SRobert Mustacchi {
401*35786f68SRobert Mustacchi 
402*35786f68SRobert Mustacchi     ACPI_FUNCTION_TRACE (UtShortShiftRight);
403*35786f68SRobert Mustacchi 
404*35786f68SRobert Mustacchi 
405*35786f68SRobert Mustacchi     /* Return only what was requested */
406*35786f68SRobert Mustacchi 
407*35786f68SRobert Mustacchi     if (OutResult)
408*35786f68SRobert Mustacchi     {
409*35786f68SRobert Mustacchi         *OutResult = Operand >> Count;
410*35786f68SRobert Mustacchi     }
411*35786f68SRobert Mustacchi 
412*35786f68SRobert Mustacchi     return_ACPI_STATUS (AE_OK);
413*35786f68SRobert Mustacchi }
414*35786f68SRobert Mustacchi #endif
415*35786f68SRobert Mustacchi 
416*35786f68SRobert Mustacchi /*
417*35786f68SRobert Mustacchi  * Optional support for 64-bit double-precision integer divide. This code
418*35786f68SRobert Mustacchi  * is configurable and is implemented in order to support 32-bit kernel
419*35786f68SRobert Mustacchi  * environments where a 64-bit double-precision math library is not available.
420*35786f68SRobert Mustacchi  *
421*35786f68SRobert Mustacchi  * Support for a more normal 64-bit divide/modulo (with check for a divide-
422*35786f68SRobert Mustacchi  * by-zero) appears after this optional section of code.
423*35786f68SRobert Mustacchi  */
424*35786f68SRobert Mustacchi #ifndef ACPI_USE_NATIVE_DIVIDE
425*35786f68SRobert Mustacchi 
4267b1019a6SJerry Jelinek 
4277b1019a6SJerry Jelinek /*******************************************************************************
4287b1019a6SJerry Jelinek  *
4297b1019a6SJerry Jelinek  * FUNCTION:    AcpiUtShortDivide
4307b1019a6SJerry Jelinek  *
4317b1019a6SJerry Jelinek  * PARAMETERS:  Dividend            - 64-bit dividend
4327b1019a6SJerry Jelinek  *              Divisor             - 32-bit divisor
4337b1019a6SJerry Jelinek  *              OutQuotient         - Pointer to where the quotient is returned
4347b1019a6SJerry Jelinek  *              OutRemainder        - Pointer to where the remainder is returned
4357b1019a6SJerry Jelinek  *
4367b1019a6SJerry Jelinek  * RETURN:      Status (Checks for divide-by-zero)
4377b1019a6SJerry Jelinek  *
4387b1019a6SJerry Jelinek  * DESCRIPTION: Perform a short (maximum 64 bits divided by 32 bits)
4397b1019a6SJerry Jelinek  *              divide and modulo. The result is a 64-bit quotient and a
4407b1019a6SJerry Jelinek  *              32-bit remainder.
4417b1019a6SJerry Jelinek  *
4427b1019a6SJerry Jelinek  ******************************************************************************/
4437b1019a6SJerry Jelinek 
4447b1019a6SJerry Jelinek ACPI_STATUS
AcpiUtShortDivide(UINT64 Dividend,UINT32 Divisor,UINT64 * OutQuotient,UINT32 * OutRemainder)4457b1019a6SJerry Jelinek AcpiUtShortDivide (
4467b1019a6SJerry Jelinek     UINT64                  Dividend,
4477b1019a6SJerry Jelinek     UINT32                  Divisor,
4487b1019a6SJerry Jelinek     UINT64                  *OutQuotient,
4497b1019a6SJerry Jelinek     UINT32                  *OutRemainder)
4507b1019a6SJerry Jelinek {
4517b1019a6SJerry Jelinek     UINT64_OVERLAY          DividendOvl;
4527b1019a6SJerry Jelinek     UINT64_OVERLAY          Quotient;
4537b1019a6SJerry Jelinek     UINT32                  Remainder32;
4547b1019a6SJerry Jelinek 
4557b1019a6SJerry Jelinek 
4567b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (UtShortDivide);
4577b1019a6SJerry Jelinek 
4587b1019a6SJerry Jelinek 
4597b1019a6SJerry Jelinek     /* Always check for a zero divisor */
4607b1019a6SJerry Jelinek 
4617b1019a6SJerry Jelinek     if (Divisor == 0)
4627b1019a6SJerry Jelinek     {
4637b1019a6SJerry Jelinek         ACPI_ERROR ((AE_INFO, "Divide by zero"));
4647b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
4657b1019a6SJerry Jelinek     }
4667b1019a6SJerry Jelinek 
4677b1019a6SJerry Jelinek     DividendOvl.Full = Dividend;
4687b1019a6SJerry Jelinek 
4697b1019a6SJerry Jelinek     /*
4707b1019a6SJerry Jelinek      * The quotient is 64 bits, the remainder is always 32 bits,
4717b1019a6SJerry Jelinek      * and is generated by the second divide.
4727b1019a6SJerry Jelinek      */
4737b1019a6SJerry Jelinek     ACPI_DIV_64_BY_32 (0, DividendOvl.Part.Hi, Divisor,
4747b1019a6SJerry Jelinek         Quotient.Part.Hi, Remainder32);
4757b1019a6SJerry Jelinek 
4767b1019a6SJerry Jelinek     ACPI_DIV_64_BY_32 (Remainder32, DividendOvl.Part.Lo, Divisor,
4777b1019a6SJerry Jelinek         Quotient.Part.Lo, Remainder32);
4787b1019a6SJerry Jelinek 
4797b1019a6SJerry Jelinek     /* Return only what was requested */
4807b1019a6SJerry Jelinek 
4817b1019a6SJerry Jelinek     if (OutQuotient)
4827b1019a6SJerry Jelinek     {
4837b1019a6SJerry Jelinek         *OutQuotient = Quotient.Full;
4847b1019a6SJerry Jelinek     }
4857b1019a6SJerry Jelinek     if (OutRemainder)
4867b1019a6SJerry Jelinek     {
4877b1019a6SJerry Jelinek         *OutRemainder = Remainder32;
4887b1019a6SJerry Jelinek     }
4897b1019a6SJerry Jelinek 
4907b1019a6SJerry Jelinek     return_ACPI_STATUS (AE_OK);
4917b1019a6SJerry Jelinek }
4927b1019a6SJerry Jelinek 
4937b1019a6SJerry Jelinek 
4947b1019a6SJerry Jelinek /*******************************************************************************
4957b1019a6SJerry Jelinek  *
4967b1019a6SJerry Jelinek  * FUNCTION:    AcpiUtDivide
4977b1019a6SJerry Jelinek  *
4987b1019a6SJerry Jelinek  * PARAMETERS:  InDividend          - Dividend
4997b1019a6SJerry Jelinek  *              InDivisor           - Divisor
5007b1019a6SJerry Jelinek  *              OutQuotient         - Pointer to where the quotient is returned
5017b1019a6SJerry Jelinek  *              OutRemainder        - Pointer to where the remainder is returned
5027b1019a6SJerry Jelinek  *
5037b1019a6SJerry Jelinek  * RETURN:      Status (Checks for divide-by-zero)
5047b1019a6SJerry Jelinek  *
5057b1019a6SJerry Jelinek  * DESCRIPTION: Perform a divide and modulo.
5067b1019a6SJerry Jelinek  *
5077b1019a6SJerry Jelinek  ******************************************************************************/
5087b1019a6SJerry Jelinek 
5097b1019a6SJerry Jelinek ACPI_STATUS
AcpiUtDivide(UINT64 InDividend,UINT64 InDivisor,UINT64 * OutQuotient,UINT64 * OutRemainder)5107b1019a6SJerry Jelinek AcpiUtDivide (
5117b1019a6SJerry Jelinek     UINT64                  InDividend,
5127b1019a6SJerry Jelinek     UINT64                  InDivisor,
5137b1019a6SJerry Jelinek     UINT64                  *OutQuotient,
5147b1019a6SJerry Jelinek     UINT64                  *OutRemainder)
5157b1019a6SJerry Jelinek {
5167b1019a6SJerry Jelinek     UINT64_OVERLAY          Dividend;
5177b1019a6SJerry Jelinek     UINT64_OVERLAY          Divisor;
5187b1019a6SJerry Jelinek     UINT64_OVERLAY          Quotient;
5197b1019a6SJerry Jelinek     UINT64_OVERLAY          Remainder;
5207b1019a6SJerry Jelinek     UINT64_OVERLAY          NormalizedDividend;
5217b1019a6SJerry Jelinek     UINT64_OVERLAY          NormalizedDivisor;
5227b1019a6SJerry Jelinek     UINT32                  Partial1;
5237b1019a6SJerry Jelinek     UINT64_OVERLAY          Partial2;
5247b1019a6SJerry Jelinek     UINT64_OVERLAY          Partial3;
5257b1019a6SJerry Jelinek 
5267b1019a6SJerry Jelinek 
5277b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (UtDivide);
5287b1019a6SJerry Jelinek 
5297b1019a6SJerry Jelinek 
5307b1019a6SJerry Jelinek     /* Always check for a zero divisor */
5317b1019a6SJerry Jelinek 
5327b1019a6SJerry Jelinek     if (InDivisor == 0)
5337b1019a6SJerry Jelinek     {
5347b1019a6SJerry Jelinek         ACPI_ERROR ((AE_INFO, "Divide by zero"));
5357b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
5367b1019a6SJerry Jelinek     }
5377b1019a6SJerry Jelinek 
5387b1019a6SJerry Jelinek     Divisor.Full  = InDivisor;
5397b1019a6SJerry Jelinek     Dividend.Full = InDividend;
5407b1019a6SJerry Jelinek     if (Divisor.Part.Hi == 0)
5417b1019a6SJerry Jelinek     {
5427b1019a6SJerry Jelinek         /*
5437b1019a6SJerry Jelinek          * 1) Simplest case is where the divisor is 32 bits, we can
5447b1019a6SJerry Jelinek          * just do two divides
5457b1019a6SJerry Jelinek          */
5467b1019a6SJerry Jelinek         Remainder.Part.Hi = 0;
5477b1019a6SJerry Jelinek 
5487b1019a6SJerry Jelinek         /*
5497b1019a6SJerry Jelinek          * The quotient is 64 bits, the remainder is always 32 bits,
5507b1019a6SJerry Jelinek          * and is generated by the second divide.
5517b1019a6SJerry Jelinek          */
5527b1019a6SJerry Jelinek         ACPI_DIV_64_BY_32 (0, Dividend.Part.Hi, Divisor.Part.Lo,
5537b1019a6SJerry Jelinek             Quotient.Part.Hi, Partial1);
5547b1019a6SJerry Jelinek 
5557b1019a6SJerry Jelinek         ACPI_DIV_64_BY_32 (Partial1, Dividend.Part.Lo, Divisor.Part.Lo,
5567b1019a6SJerry Jelinek             Quotient.Part.Lo, Remainder.Part.Lo);
5577b1019a6SJerry Jelinek     }
5587b1019a6SJerry Jelinek 
5597b1019a6SJerry Jelinek     else
5607b1019a6SJerry Jelinek     {
5617b1019a6SJerry Jelinek         /*
5627b1019a6SJerry Jelinek          * 2) The general case where the divisor is a full 64 bits
5637b1019a6SJerry Jelinek          * is more difficult
5647b1019a6SJerry Jelinek          */
5657b1019a6SJerry Jelinek         Quotient.Part.Hi   = 0;
5667b1019a6SJerry Jelinek         NormalizedDividend = Dividend;
5677b1019a6SJerry Jelinek         NormalizedDivisor  = Divisor;
5687b1019a6SJerry Jelinek 
5697b1019a6SJerry Jelinek         /* Normalize the operands (shift until the divisor is < 32 bits) */
5707b1019a6SJerry Jelinek 
5717b1019a6SJerry Jelinek         do
5727b1019a6SJerry Jelinek         {
5737b1019a6SJerry Jelinek             ACPI_SHIFT_RIGHT_64 (
5747b1019a6SJerry Jelinek                 NormalizedDivisor.Part.Hi, NormalizedDivisor.Part.Lo);
5757b1019a6SJerry Jelinek             ACPI_SHIFT_RIGHT_64 (
5767b1019a6SJerry Jelinek                 NormalizedDividend.Part.Hi, NormalizedDividend.Part.Lo);
5777b1019a6SJerry Jelinek 
5787b1019a6SJerry Jelinek         } while (NormalizedDivisor.Part.Hi != 0);
5797b1019a6SJerry Jelinek 
5807b1019a6SJerry Jelinek         /* Partial divide */
5817b1019a6SJerry Jelinek 
5827b1019a6SJerry Jelinek         ACPI_DIV_64_BY_32 (
5837b1019a6SJerry Jelinek             NormalizedDividend.Part.Hi, NormalizedDividend.Part.Lo,
5847b1019a6SJerry Jelinek             NormalizedDivisor.Part.Lo, Quotient.Part.Lo, Partial1);
5857b1019a6SJerry Jelinek 
5867b1019a6SJerry Jelinek         /*
5877b1019a6SJerry Jelinek          * The quotient is always 32 bits, and simply requires
5887b1019a6SJerry Jelinek          * adjustment. The 64-bit remainder must be generated.
5897b1019a6SJerry Jelinek          */
5907b1019a6SJerry Jelinek         Partial1 = Quotient.Part.Lo * Divisor.Part.Hi;
5917b1019a6SJerry Jelinek         Partial2.Full = (UINT64) Quotient.Part.Lo * Divisor.Part.Lo;
5927b1019a6SJerry Jelinek         Partial3.Full = (UINT64) Partial2.Part.Hi + Partial1;
5937b1019a6SJerry Jelinek 
5947b1019a6SJerry Jelinek         Remainder.Part.Hi = Partial3.Part.Lo;
5957b1019a6SJerry Jelinek         Remainder.Part.Lo = Partial2.Part.Lo;
5967b1019a6SJerry Jelinek 
5977b1019a6SJerry Jelinek         if (Partial3.Part.Hi == 0)
5987b1019a6SJerry Jelinek         {
5997b1019a6SJerry Jelinek             if (Partial3.Part.Lo >= Dividend.Part.Hi)
6007b1019a6SJerry Jelinek             {
6017b1019a6SJerry Jelinek                 if (Partial3.Part.Lo == Dividend.Part.Hi)
6027b1019a6SJerry Jelinek                 {
6037b1019a6SJerry Jelinek                     if (Partial2.Part.Lo > Dividend.Part.Lo)
6047b1019a6SJerry Jelinek                     {
6057b1019a6SJerry Jelinek                         Quotient.Part.Lo--;
6067b1019a6SJerry Jelinek                         Remainder.Full -= Divisor.Full;
6077b1019a6SJerry Jelinek                     }
6087b1019a6SJerry Jelinek                 }
6097b1019a6SJerry Jelinek                 else
6107b1019a6SJerry Jelinek                 {
6117b1019a6SJerry Jelinek                     Quotient.Part.Lo--;
6127b1019a6SJerry Jelinek                     Remainder.Full -= Divisor.Full;
6137b1019a6SJerry Jelinek                 }
6147b1019a6SJerry Jelinek             }
6157b1019a6SJerry Jelinek 
6167b1019a6SJerry Jelinek             Remainder.Full = Remainder.Full - Dividend.Full;
6177b1019a6SJerry Jelinek             Remainder.Part.Hi = (UINT32) -((INT32) Remainder.Part.Hi);
6187b1019a6SJerry Jelinek             Remainder.Part.Lo = (UINT32) -((INT32) Remainder.Part.Lo);
6197b1019a6SJerry Jelinek 
6207b1019a6SJerry Jelinek             if (Remainder.Part.Lo)
6217b1019a6SJerry Jelinek             {
6227b1019a6SJerry Jelinek                 Remainder.Part.Hi--;
6237b1019a6SJerry Jelinek             }
6247b1019a6SJerry Jelinek         }
6257b1019a6SJerry Jelinek     }
6267b1019a6SJerry Jelinek 
6277b1019a6SJerry Jelinek     /* Return only what was requested */
6287b1019a6SJerry Jelinek 
6297b1019a6SJerry Jelinek     if (OutQuotient)
6307b1019a6SJerry Jelinek     {
6317b1019a6SJerry Jelinek         *OutQuotient = Quotient.Full;
6327b1019a6SJerry Jelinek     }
6337b1019a6SJerry Jelinek     if (OutRemainder)
6347b1019a6SJerry Jelinek     {
6357b1019a6SJerry Jelinek         *OutRemainder = Remainder.Full;
6367b1019a6SJerry Jelinek     }
6377b1019a6SJerry Jelinek 
6387b1019a6SJerry Jelinek     return_ACPI_STATUS (AE_OK);
6397b1019a6SJerry Jelinek }
6407b1019a6SJerry Jelinek 
6417b1019a6SJerry Jelinek #else
6427b1019a6SJerry Jelinek 
6437b1019a6SJerry Jelinek /*******************************************************************************
6447b1019a6SJerry Jelinek  *
6457b1019a6SJerry Jelinek  * FUNCTION:    AcpiUtShortDivide, AcpiUtDivide
6467b1019a6SJerry Jelinek  *
6477b1019a6SJerry Jelinek  * PARAMETERS:  See function headers above
6487b1019a6SJerry Jelinek  *
6497b1019a6SJerry Jelinek  * DESCRIPTION: Native versions of the UtDivide functions. Use these if either
6507b1019a6SJerry Jelinek  *              1) The target is a 64-bit platform and therefore 64-bit
6517b1019a6SJerry Jelinek  *                 integer math is supported directly by the machine.
6527b1019a6SJerry Jelinek  *              2) The target is a 32-bit or 16-bit platform, and the
6537b1019a6SJerry Jelinek  *                 double-precision integer math library is available to
6547b1019a6SJerry Jelinek  *                 perform the divide.
6557b1019a6SJerry Jelinek  *
6567b1019a6SJerry Jelinek  ******************************************************************************/
6577b1019a6SJerry Jelinek 
6587b1019a6SJerry Jelinek ACPI_STATUS
AcpiUtShortDivide(UINT64 InDividend,UINT32 Divisor,UINT64 * OutQuotient,UINT32 * OutRemainder)6597b1019a6SJerry Jelinek AcpiUtShortDivide (
6607b1019a6SJerry Jelinek     UINT64                  InDividend,
6617b1019a6SJerry Jelinek     UINT32                  Divisor,
6627b1019a6SJerry Jelinek     UINT64                  *OutQuotient,
6637b1019a6SJerry Jelinek     UINT32                  *OutRemainder)
6647b1019a6SJerry Jelinek {
6657b1019a6SJerry Jelinek 
6667b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (UtShortDivide);
6677b1019a6SJerry Jelinek 
6687b1019a6SJerry Jelinek 
6697b1019a6SJerry Jelinek     /* Always check for a zero divisor */
6707b1019a6SJerry Jelinek 
6717b1019a6SJerry Jelinek     if (Divisor == 0)
6727b1019a6SJerry Jelinek     {
6737b1019a6SJerry Jelinek         ACPI_ERROR ((AE_INFO, "Divide by zero"));
6747b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
6757b1019a6SJerry Jelinek     }
6767b1019a6SJerry Jelinek 
6777b1019a6SJerry Jelinek     /* Return only what was requested */
6787b1019a6SJerry Jelinek 
6797b1019a6SJerry Jelinek     if (OutQuotient)
6807b1019a6SJerry Jelinek     {
6817b1019a6SJerry Jelinek         *OutQuotient = InDividend / Divisor;
6827b1019a6SJerry Jelinek     }
6837b1019a6SJerry Jelinek     if (OutRemainder)
6847b1019a6SJerry Jelinek     {
6857b1019a6SJerry Jelinek         *OutRemainder = (UINT32) (InDividend % Divisor);
6867b1019a6SJerry Jelinek     }
6877b1019a6SJerry Jelinek 
6887b1019a6SJerry Jelinek     return_ACPI_STATUS (AE_OK);
6897b1019a6SJerry Jelinek }
6907b1019a6SJerry Jelinek 
6917b1019a6SJerry Jelinek ACPI_STATUS
AcpiUtDivide(UINT64 InDividend,UINT64 InDivisor,UINT64 * OutQuotient,UINT64 * OutRemainder)6927b1019a6SJerry Jelinek AcpiUtDivide (
6937b1019a6SJerry Jelinek     UINT64                  InDividend,
6947b1019a6SJerry Jelinek     UINT64                  InDivisor,
6957b1019a6SJerry Jelinek     UINT64                  *OutQuotient,
6967b1019a6SJerry Jelinek     UINT64                  *OutRemainder)
6977b1019a6SJerry Jelinek {
6987b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (UtDivide);
6997b1019a6SJerry Jelinek 
7007b1019a6SJerry Jelinek 
7017b1019a6SJerry Jelinek     /* Always check for a zero divisor */
7027b1019a6SJerry Jelinek 
7037b1019a6SJerry Jelinek     if (InDivisor == 0)
7047b1019a6SJerry Jelinek     {
7057b1019a6SJerry Jelinek         ACPI_ERROR ((AE_INFO, "Divide by zero"));
7067b1019a6SJerry Jelinek         return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
7077b1019a6SJerry Jelinek     }
7087b1019a6SJerry Jelinek 
7097b1019a6SJerry Jelinek 
7107b1019a6SJerry Jelinek     /* Return only what was requested */
7117b1019a6SJerry Jelinek 
7127b1019a6SJerry Jelinek     if (OutQuotient)
7137b1019a6SJerry Jelinek     {
7147b1019a6SJerry Jelinek         *OutQuotient = InDividend / InDivisor;
7157b1019a6SJerry Jelinek     }
7167b1019a6SJerry Jelinek     if (OutRemainder)
7177b1019a6SJerry Jelinek     {
7187b1019a6SJerry Jelinek         *OutRemainder = InDividend % InDivisor;
7197b1019a6SJerry Jelinek     }
7207b1019a6SJerry Jelinek 
7217b1019a6SJerry Jelinek     return_ACPI_STATUS (AE_OK);
7227b1019a6SJerry Jelinek }
7237b1019a6SJerry Jelinek 
7247b1019a6SJerry Jelinek #endif
725