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