1 /* 2 * Copright (C) 2014 Linaro Ltd. 3 * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org> 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice and this list of conditions, without modification. 10 * 2. The name of the author may not be used to endorse or promote products 11 * derived from this software without specific prior written permission. 12 * 13 * Alternatively, this software may be distributed under the terms of the 14 * GNU General Public License as published by the Free Software Foundation; 15 * either version 2 of the License, or (at your option) any later version. 16 */ 17 18 #include "lib.h" 19 20 UINT64 21 LShiftU64 ( 22 IN UINT64 Operand, 23 IN UINTN Count 24 ) 25 // Left shift 64bit by 32bit and get a 64bit result 26 { 27 return Operand << Count; 28 } 29 30 UINT64 31 RShiftU64 ( 32 IN UINT64 Operand, 33 IN UINTN Count 34 ) 35 // Right shift 64bit by 32bit and get a 64bit result 36 { 37 return Operand >> Count; 38 } 39 40 41 UINT64 42 MultU64x32 ( 43 IN UINT64 Multiplicand, 44 IN UINTN Multiplier 45 ) 46 // Multiply 64bit by 32bit and get a 64bit result 47 { 48 return Multiplicand * Multiplier; 49 } 50 51 UINT64 52 DivU64x32 ( 53 IN UINT64 Dividend, 54 IN UINTN Divisor, 55 OUT UINTN *Remainder OPTIONAL 56 ) 57 { 58 /* 59 * GCC turns a division into a multiplication and shift with precalculated 60 * constants if the divisor is constant and the dividend fits into a 32 bit 61 * variable. Otherwise, it will turn this into calls into the 32-bit div 62 * library functions. 63 */ 64 if (Remainder) 65 *Remainder = Dividend % Divisor; 66 return Dividend / Divisor; 67 } 68