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