^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: utmath - Integer math support routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define _COMPONENT ACPI_UTILITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) ACPI_MODULE_NAME("utmath")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* Structures used only for 64-bit divide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) typedef struct uint64_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) u32 lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) u32 hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) } uint64_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) typedef union uint64_overlay {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u64 full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct uint64_struct part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) } uint64_overlay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Optional support for 64-bit double-precision integer multiply and shift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * This code is configurable and is implemented in order to support 32-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * kernel environments where a 64-bit double-precision math library is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #ifndef ACPI_USE_NATIVE_MATH64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * FUNCTION: acpi_ut_short_multiply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * PARAMETERS: multiplicand - 64-bit multiplicand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * multiplier - 32-bit multiplier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * out_product - Pointer to where the product is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * DESCRIPTION: Perform a short multiply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) union uint64_overlay multiplicand_ovl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) union uint64_overlay product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 carry32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ACPI_FUNCTION_TRACE(ut_short_multiply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) multiplicand_ovl.full = multiplicand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * The Product is 64 bits, the carry is always 32 bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * and is generated by the second multiply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.hi, multiplier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) product.part.hi, carry32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.lo, multiplier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) product.part.lo, carry32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) product.part.hi += carry32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (out_product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *out_product = product.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * FUNCTION: acpi_ut_short_shift_left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * PARAMETERS: operand - 64-bit shift operand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * count - 32-bit shift count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * out_result - Pointer to where the result is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * DESCRIPTION: Perform a short left shift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) union uint64_overlay operand_ovl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ACPI_FUNCTION_TRACE(ut_short_shift_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) operand_ovl.full = operand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if ((count & 63) >= 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) operand_ovl.part.hi = operand_ovl.part.lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) operand_ovl.part.lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) count = (count & 63) - 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ACPI_SHIFT_LEFT_64_BY_32(operand_ovl.part.hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) operand_ovl.part.lo, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (out_result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) *out_result = operand_ovl.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * FUNCTION: acpi_ut_short_shift_right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * PARAMETERS: operand - 64-bit shift operand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * count - 32-bit shift count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * out_result - Pointer to where the result is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * DESCRIPTION: Perform a short right shift.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) union uint64_overlay operand_ovl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ACPI_FUNCTION_TRACE(ut_short_shift_right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) operand_ovl.full = operand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if ((count & 63) >= 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) operand_ovl.part.lo = operand_ovl.part.hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) operand_ovl.part.hi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) count = (count & 63) - 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ACPI_SHIFT_RIGHT_64_BY_32(operand_ovl.part.hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) operand_ovl.part.lo, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (out_result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *out_result = operand_ovl.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * FUNCTION: acpi_ut_short_multiply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * PARAMETERS: See function headers above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * DESCRIPTION: Native version of the ut_short_multiply function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ACPI_FUNCTION_TRACE(ut_short_multiply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (out_product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *out_product = multiplicand * multiplier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * FUNCTION: acpi_ut_short_shift_left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * PARAMETERS: See function headers above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * DESCRIPTION: Native version of the ut_short_shift_left function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ACPI_FUNCTION_TRACE(ut_short_shift_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (out_result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) *out_result = operand << count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * FUNCTION: acpi_ut_short_shift_right
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * PARAMETERS: See function headers above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * DESCRIPTION: Native version of the ut_short_shift_right function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ACPI_FUNCTION_TRACE(ut_short_shift_right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (out_result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *out_result = operand >> count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Optional support for 64-bit double-precision integer divide. This code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * is configurable and is implemented in order to support 32-bit kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * environments where a 64-bit double-precision math library is not available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * Support for a more normal 64-bit divide/modulo (with check for a divide-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * by-zero) appears after this optional section of code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #ifndef ACPI_USE_NATIVE_DIVIDE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * FUNCTION: acpi_ut_short_divide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * PARAMETERS: dividend - 64-bit dividend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * divisor - 32-bit divisor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * out_quotient - Pointer to where the quotient is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * out_remainder - Pointer to where the remainder is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * RETURN: Status (Checks for divide-by-zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * DESCRIPTION: Perform a short (maximum 64 bits divided by 32 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * divide and modulo. The result is a 64-bit quotient and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * 32-bit remainder.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) acpi_ut_short_divide(u64 dividend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) u32 divisor, u64 *out_quotient, u32 *out_remainder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) union uint64_overlay dividend_ovl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) union uint64_overlay quotient;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) u32 remainder32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ACPI_FUNCTION_TRACE(ut_short_divide);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* Always check for a zero divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (divisor == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ACPI_ERROR((AE_INFO, "Divide by zero"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return_ACPI_STATUS(AE_AML_DIVIDE_BY_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) dividend_ovl.full = dividend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * The quotient is 64 bits, the remainder is always 32 bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * and is generated by the second divide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ACPI_DIV_64_BY_32(0, dividend_ovl.part.hi, divisor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) quotient.part.hi, remainder32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ACPI_DIV_64_BY_32(remainder32, dividend_ovl.part.lo, divisor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) quotient.part.lo, remainder32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (out_quotient) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *out_quotient = quotient.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (out_remainder) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *out_remainder = remainder32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * FUNCTION: acpi_ut_divide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * PARAMETERS: in_dividend - Dividend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * in_divisor - Divisor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * out_quotient - Pointer to where the quotient is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * out_remainder - Pointer to where the remainder is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * RETURN: Status (Checks for divide-by-zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * DESCRIPTION: Perform a divide and modulo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) acpi_ut_divide(u64 in_dividend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) u64 in_divisor, u64 *out_quotient, u64 *out_remainder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) union uint64_overlay dividend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) union uint64_overlay divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) union uint64_overlay quotient;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) union uint64_overlay remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) union uint64_overlay normalized_dividend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) union uint64_overlay normalized_divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) u32 partial1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) union uint64_overlay partial2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) union uint64_overlay partial3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) ACPI_FUNCTION_TRACE(ut_divide);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* Always check for a zero divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (in_divisor == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) ACPI_ERROR((AE_INFO, "Divide by zero"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return_ACPI_STATUS(AE_AML_DIVIDE_BY_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) divisor.full = in_divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dividend.full = in_dividend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (divisor.part.hi == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * 1) Simplest case is where the divisor is 32 bits, we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * just do two divides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) remainder.part.hi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * The quotient is 64 bits, the remainder is always 32 bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * and is generated by the second divide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ACPI_DIV_64_BY_32(0, dividend.part.hi, divisor.part.lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) quotient.part.hi, partial1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ACPI_DIV_64_BY_32(partial1, dividend.part.lo, divisor.part.lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) quotient.part.lo, remainder.part.lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * 2) The general case where the divisor is a full 64 bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * is more difficult
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) quotient.part.hi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) normalized_dividend = dividend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) normalized_divisor = divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* Normalize the operands (shift until the divisor is < 32 bits) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) ACPI_SHIFT_RIGHT_64(normalized_divisor.part.hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) normalized_divisor.part.lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ACPI_SHIFT_RIGHT_64(normalized_dividend.part.hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) normalized_dividend.part.lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) } while (normalized_divisor.part.hi != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Partial divide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ACPI_DIV_64_BY_32(normalized_dividend.part.hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) normalized_dividend.part.lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) normalized_divisor.part.lo, quotient.part.lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) partial1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * The quotient is always 32 bits, and simply requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * adjustment. The 64-bit remainder must be generated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) partial1 = quotient.part.lo * divisor.part.hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) partial2.full = (u64) quotient.part.lo * divisor.part.lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) partial3.full = (u64) partial2.part.hi + partial1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) remainder.part.hi = partial3.part.lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) remainder.part.lo = partial2.part.lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (partial3.part.hi == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (partial3.part.lo >= dividend.part.hi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (partial3.part.lo == dividend.part.hi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (partial2.part.lo > dividend.part.lo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) quotient.part.lo--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) remainder.full -= divisor.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) quotient.part.lo--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) remainder.full -= divisor.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) remainder.full = remainder.full - dividend.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) remainder.part.hi = (u32)-((s32)remainder.part.hi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) remainder.part.lo = (u32)-((s32)remainder.part.lo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (remainder.part.lo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) remainder.part.hi--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (out_quotient) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) *out_quotient = quotient.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (out_remainder) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) *out_remainder = remainder.full;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * FUNCTION: acpi_ut_short_divide, acpi_ut_divide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * PARAMETERS: See function headers above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * DESCRIPTION: Native versions of the ut_divide functions. Use these if either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * 1) The target is a 64-bit platform and therefore 64-bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * integer math is supported directly by the machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * 2) The target is a 32-bit or 16-bit platform, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * double-precision integer math library is available to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * perform the divide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) acpi_ut_short_divide(u64 in_dividend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) u32 divisor, u64 *out_quotient, u32 *out_remainder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ACPI_FUNCTION_TRACE(ut_short_divide);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* Always check for a zero divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (divisor == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ACPI_ERROR((AE_INFO, "Divide by zero"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return_ACPI_STATUS(AE_AML_DIVIDE_BY_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (out_quotient) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) *out_quotient = in_dividend / divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (out_remainder) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) *out_remainder = (u32) (in_dividend % divisor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) acpi_ut_divide(u64 in_dividend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) u64 in_divisor, u64 *out_quotient, u64 *out_remainder)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ACPI_FUNCTION_TRACE(ut_divide);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /* Always check for a zero divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (in_divisor == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) ACPI_ERROR((AE_INFO, "Divide by zero"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return_ACPI_STATUS(AE_AML_DIVIDE_BY_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* Return only what was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (out_quotient) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) *out_quotient = in_dividend / in_divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (out_remainder) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) *out_remainder = in_dividend % in_divisor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return_ACPI_STATUS(AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #endif