X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseLib%2FMath64.c;h=5756d0fe9263ab861362b4a59636b6be16436cd4;hb=HEAD;hp=0001124f0637335f1826fa035f34939d83613344;hpb=2fc60b703842994beb1d78f9221deca7d81d9159;p=mirror_edk2.git diff --git a/MdePkg/Library/BaseLib/Math64.c b/MdePkg/Library/BaseLib/Math64.c index 0001124f06..5756d0fe92 100644 --- a/MdePkg/Library/BaseLib/Math64.c +++ b/MdePkg/Library/BaseLib/Math64.c @@ -2,14 +2,8 @@ Leaf math worker functions that require 64-bit arithmetic support from the compiler. - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -25,14 +19,14 @@ @param Operand The 64-bit operand to shift left. @param Count The number of bits to shift left. - @return Operand << Count + @return Operand << Count. **/ UINT64 EFIAPI InternalMathLShiftU64 ( - IN UINT64 Operand, - IN UINTN Count + IN UINT64 Operand, + IN UINTN Count ) { return Operand << Count; @@ -48,14 +42,14 @@ InternalMathLShiftU64 ( @param Operand The 64-bit operand to shift right. @param Count The number of bits to shift right. - @return Operand >> Count + @return Operand >> Count. **/ UINT64 EFIAPI InternalMathRShiftU64 ( - IN UINT64 Operand, - IN UINTN Count + IN UINT64 Operand, + IN UINTN Count ) { return Operand >> Count; @@ -71,14 +65,14 @@ InternalMathRShiftU64 ( @param Operand The 64-bit operand to shift right. @param Count The number of bits to shift right. - @return Operand arithmetically shifted right by Count + @return Operand arithmetically shifted right by Count. **/ UINT64 EFIAPI InternalMathARShiftU64 ( - IN UINT64 Operand, - IN UINTN Count + IN UINT64 Operand, + IN UINTN Count ) { INTN TestValue; @@ -86,7 +80,7 @@ InternalMathARShiftU64 ( // // Test if this compiler supports arithmetic shift // - TestValue = (((-1) << (sizeof (-1) * 8 - 1)) >> (sizeof (-1) * 8 - 1)); + TestValue = (INTN)((INT64)(1ULL << 63) >> 63); if (TestValue == -1) { // // Arithmetic shift is supported @@ -101,7 +95,6 @@ InternalMathARShiftU64 ( ((INTN)Operand < 0 ? ~((UINTN)-1 >> Count) : 0); } - /** Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits with the high bits that were rotated. @@ -113,14 +106,14 @@ InternalMathARShiftU64 ( @param Operand The 64-bit operand to rotate left. @param Count The number of bits to rotate left. - @return Operand <<< Count + @return Operand <<< Count. **/ UINT64 EFIAPI InternalMathLRotU64 ( - IN UINT64 Operand, - IN UINTN Count + IN UINT64 Operand, + IN UINTN Count ) { return (Operand << Count) | (Operand >> (64 - Count)); @@ -137,14 +130,14 @@ InternalMathLRotU64 ( @param Operand The 64-bit operand to rotate right. @param Count The number of bits to rotate right. - @return Operand >>> Count + @return Operand >>> Count. **/ UINT64 EFIAPI InternalMathRRotU64 ( - IN UINT64 Operand, - IN UINTN Count + IN UINT64 Operand, + IN UINTN Count ) { return (Operand >> Count) | (Operand << (64 - Count)); @@ -165,23 +158,23 @@ InternalMathRRotU64 ( UINT64 EFIAPI InternalMathSwapBytes64 ( - IN UINT64 Operand + IN UINT64 Operand ) { UINT64 LowerBytes; UINT64 HigherBytes; - LowerBytes = (UINT64) SwapBytes32 ((UINT32) Operand); - HigherBytes = (UINT64) SwapBytes32 ((UINT32) (Operand >> 32)); + LowerBytes = (UINT64)SwapBytes32 ((UINT32)Operand); + HigherBytes = (UINT64)SwapBytes32 ((UINT32)(Operand >> 32)); return (LowerBytes << 32 | HigherBytes); } /** - Multiples a 64-bit unsigned integer by a 32-bit unsigned integer + Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer and generates a 64-bit unsigned result. - This function multiples the 64-bit unsigned value Multiplicand by the 32-bit + This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit unsigned value Multiplier and generates a 64-bit unsigned result. This 64- bit unsigned result is returned. @@ -194,33 +187,32 @@ InternalMathSwapBytes64 ( UINT64 EFIAPI InternalMathMultU64x32 ( - IN UINT64 Multiplicand, - IN UINT32 Multiplier + IN UINT64 Multiplicand, + IN UINT32 Multiplier ) { return Multiplicand * Multiplier; } - /** - Multiples a 64-bit unsigned integer by a 64-bit unsigned integer + Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer and generates a 64-bit unsigned result. - This function multiples the 64-bit unsigned value Multiplicand by the 64-bit + This function multiplies the 64-bit unsigned value Multiplicand by the 64-bit unsigned value Multiplier and generates a 64-bit unsigned result. This 64- bit unsigned result is returned. @param Multiplicand A 64-bit unsigned value. @param Multiplier A 64-bit unsigned value. - @return Multiplicand * Multiplier + @return Multiplicand * Multiplier. **/ UINT64 EFIAPI InternalMathMultU64x64 ( - IN UINT64 Multiplicand, - IN UINT64 Multiplier + IN UINT64 Multiplicand, + IN UINT64 Multiplier ) { return Multiplicand * Multiplier; @@ -237,14 +229,14 @@ InternalMathMultU64x64 ( @param Dividend A 64-bit unsigned value. @param Divisor A 32-bit unsigned value. - @return Dividend / Divisor + @return Dividend / Divisor. **/ UINT64 EFIAPI InternalMathDivU64x32 ( - IN UINT64 Dividend, - IN UINT32 Divisor + IN UINT64 Dividend, + IN UINT32 Divisor ) { return Dividend / Divisor; @@ -261,14 +253,14 @@ InternalMathDivU64x32 ( @param Dividend A 64-bit unsigned value. @param Divisor A 32-bit unsigned value. - @return Dividend % Divisor + @return Dividend % Divisor. **/ UINT32 EFIAPI InternalMathModU64x32 ( - IN UINT64 Dividend, - IN UINT32 Divisor + IN UINT64 Dividend, + IN UINT32 Divisor ) { return (UINT32)(Dividend % Divisor); @@ -288,20 +280,21 @@ InternalMathModU64x32 ( @param Remainder A pointer to a 32-bit unsigned value. This parameter is optional and may be NULL. - @return Dividend / Divisor + @return Dividend / Divisor. **/ UINT64 EFIAPI InternalMathDivRemU64x32 ( - IN UINT64 Dividend, - IN UINT32 Divisor, - OUT UINT32 *Remainder OPTIONAL + IN UINT64 Dividend, + IN UINT32 Divisor, + OUT UINT32 *Remainder OPTIONAL ) { if (Remainder != NULL) { *Remainder = (UINT32)(Dividend % Divisor); } + return Dividend / Divisor; } @@ -325,14 +318,15 @@ InternalMathDivRemU64x32 ( UINT64 EFIAPI InternalMathDivRemU64x64 ( - IN UINT64 Dividend, - IN UINT64 Divisor, - OUT UINT64 *Remainder OPTIONAL + IN UINT64 Dividend, + IN UINT64 Divisor, + OUT UINT64 *Remainder OPTIONAL ) { if (Remainder != NULL) { *Remainder = Dividend % Divisor; } + return Dividend / Divisor; } @@ -350,19 +344,20 @@ InternalMathDivRemU64x64 ( @param Remainder A pointer to a 64-bit signed value. This parameter is optional and may be NULL. - @return Dividend / Divisor + @return Dividend / Divisor. **/ INT64 EFIAPI InternalMathDivRemS64x64 ( - IN INT64 Dividend, - IN INT64 Divisor, - OUT INT64 *Remainder OPTIONAL + IN INT64 Dividend, + IN INT64 Divisor, + OUT INT64 *Remainder OPTIONAL ) { if (Remainder != NULL) { *Remainder = Dividend % Divisor; } + return Dividend / Divisor; }