[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / utilities / utmath.c
index e803f75..758b8bf 100644 (file)
 #define _COMPONENT          ACPI_UTILITIES
         ACPI_MODULE_NAME    ("utmath")
 
-/*
- * Optional support for 64-bit double-precision integer divide. This code
- * is configurable and is implemented in order to support 32-bit kernel
- * environments where a 64-bit double-precision math library is not available.
- *
- * Support for a more normal 64-bit divide/modulo (with check for a divide-
- * by-zero) appears after this optional section of code.
- */
-#ifndef ACPI_USE_NATIVE_DIVIDE
-
 /* Structures used only for 64-bit divide */
 
 typedef struct uint64_struct
@@ -74,6 +64,257 @@ typedef union uint64_overlay
 
 } UINT64_OVERLAY;
 
+/*
+ * Optional support for 64-bit double-precision integer multiply and shift.
+ * This code is configurable and is implemented in order to support 32-bit
+ * kernel environments where a 64-bit double-precision math library is not
+ * available.
+ */
+#ifndef ACPI_USE_NATIVE_MATH64
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtShortMultiply
+ *
+ * PARAMETERS:  Multiplicand        - 64-bit multiplicand
+ *              Multiplier          - 32-bit multiplier
+ *              OutProduct          - Pointer to where the product is returned
+ *
+ * DESCRIPTION: Perform a short multiply.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtShortMultiply (
+    UINT64                  Multiplicand,
+    UINT32                  Multiplier,
+    UINT64                  *OutProduct)
+{
+    UINT64_OVERLAY          MultiplicandOvl;
+    UINT64_OVERLAY          Product;
+    UINT32                  Carry32;
+
+
+    ACPI_FUNCTION_TRACE (UtShortMultiply);
+
+
+    MultiplicandOvl.Full = Multiplicand;
+
+    /*
+     * The Product is 64 bits, the carry is always 32 bits,
+     * and is generated by the second multiply.
+     */
+    ACPI_MUL_64_BY_32 (0, MultiplicandOvl.Part.Hi, Multiplier,
+        Product.Part.Hi, Carry32);
+
+    ACPI_MUL_64_BY_32 (0, MultiplicandOvl.Part.Lo, Multiplier,
+        Product.Part.Lo, Carry32);
+
+    Product.Part.Hi += Carry32;
+
+    /* Return only what was requested */
+
+    if (OutProduct)
+    {
+        *OutProduct = Product.Full;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtShortShiftLeft
+ *
+ * PARAMETERS:  Operand             - 64-bit shift operand
+ *              Count               - 32-bit shift count
+ *              OutResult           - Pointer to where the result is returned
+ *
+ * DESCRIPTION: Perform a short left shift.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtShortShiftLeft (
+    UINT64                  Operand,
+    UINT32                  Count,
+    UINT64                  *OutResult)
+{
+    UINT64_OVERLAY          OperandOvl;
+
+
+    ACPI_FUNCTION_TRACE (UtShortShiftLeft);
+
+
+    OperandOvl.Full = Operand;
+
+    if ((Count & 63) >= 32)
+    {
+        OperandOvl.Part.Hi = OperandOvl.Part.Lo;
+        OperandOvl.Part.Lo ^= OperandOvl.Part.Lo;
+        Count = (Count & 63) - 32;
+    }
+    ACPI_SHIFT_LEFT_64_BY_32 (OperandOvl.Part.Hi,
+        OperandOvl.Part.Lo, Count);
+
+    /* Return only what was requested */
+
+    if (OutResult)
+    {
+        *OutResult = OperandOvl.Full;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtShortShiftRight
+ *
+ * PARAMETERS:  Operand             - 64-bit shift operand
+ *              Count               - 32-bit shift count
+ *              OutResult           - Pointer to where the result is returned
+ *
+ * DESCRIPTION: Perform a short right shift.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtShortShiftRight (
+    UINT64                  Operand,
+    UINT32                  Count,
+    UINT64                  *OutResult)
+{
+    UINT64_OVERLAY          OperandOvl;
+
+
+    ACPI_FUNCTION_TRACE (UtShortShiftRight);
+
+
+    OperandOvl.Full = Operand;
+
+    if ((Count & 63) >= 32)
+    {
+        OperandOvl.Part.Lo = OperandOvl.Part.Hi;
+        OperandOvl.Part.Hi ^= OperandOvl.Part.Hi;
+        Count = (Count & 63) - 32;
+    }
+    ACPI_SHIFT_RIGHT_64_BY_32 (OperandOvl.Part.Hi,
+        OperandOvl.Part.Lo, Count);
+
+    /* Return only what was requested */
+
+    if (OutResult)
+    {
+        *OutResult = OperandOvl.Full;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+#else
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtShortMultiply
+ *
+ * PARAMETERS:  See function headers above
+ *
+ * DESCRIPTION: Native version of the UtShortMultiply function.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtShortMultiply (
+    UINT64                  Multiplicand,
+    UINT32                  Multiplier,
+    UINT64                  *OutProduct)
+{
+
+    ACPI_FUNCTION_TRACE (UtShortMultiply);
+
+
+    /* Return only what was requested */
+
+    if (OutProduct)
+    {
+        *OutProduct = Multiplicand * Multiplier;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtShortShiftLeft
+ *
+ * PARAMETERS:  See function headers above
+ *
+ * DESCRIPTION: Native version of the UtShortShiftLeft function.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtShortShiftLeft (
+    UINT64                  Operand,
+    UINT32                  Count,
+    UINT64                  *OutResult)
+{
+
+    ACPI_FUNCTION_TRACE (UtShortShiftLeft);
+
+
+    /* Return only what was requested */
+
+    if (OutResult)
+    {
+        *OutResult = Operand << Count;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtShortShiftRight
+ *
+ * PARAMETERS:  See function headers above
+ *
+ * DESCRIPTION: Native version of the UtShortShiftRight function.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiUtShortShiftRight (
+    UINT64                  Operand,
+    UINT32                  Count,
+    UINT64                  *OutResult)
+{
+
+    ACPI_FUNCTION_TRACE (UtShortShiftRight);
+
+
+    /* Return only what was requested */
+
+    if (OutResult)
+    {
+        *OutResult = Operand >> Count;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+#endif
+
+/*
+ * Optional support for 64-bit double-precision integer divide. This code
+ * is configurable and is implemented in order to support 32-bit kernel
+ * environments where a 64-bit double-precision math library is not available.
+ *
+ * Support for a more normal 64-bit divide/modulo (with check for a divide-
+ * by-zero) appears after this optional section of code.
+ */
+#ifndef ACPI_USE_NATIVE_DIVIDE
+
 
 /*******************************************************************************
  *