Use mask instead of modulo, since bo->backoff is always power of 2
[dfdiff.git] / sys / boot / ficl / math64.h
blob471cf321df10c4ba0a70fe906de0d69f88ae53e6
1 /*******************************************************************
2 ** m a t h 6 4 . h
3 ** Forth Inspired Command Language - 64 bit math support routines
4 ** Author: John Sadler (john_sadler@alum.mit.edu)
5 ** Created: 25 January 1998
6 ** $Id: math64.h,v 1.9 2001/12/05 07:21:34 jsadler Exp $
7 *******************************************************************/
8 /*
9 ** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
10 ** All rights reserved.
12 ** I am interested in hearing from anyone who uses ficl. If you have
13 ** a problem, a success story, a defect, an enhancement request, or
14 ** if you would like to contribute to the ficl release, please
15 ** contact me by email at the address above.
17 ** Get the latest Ficl release at http://ficl.sourceforge.net
19 ** L I C E N S E and D I S C L A I M E R
20 **
21 ** Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions
23 ** are met:
24 ** 1. Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** 2. Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in the
28 ** documentation and/or other materials provided with the distribution.
30 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 ** SUCH DAMAGE.
44 * $FreeBSD: src/sys/boot/ficl/math64.h,v 1.4 2002/04/09 17:45:11 dcs Exp $
45 * $DragonFly: src/sys/boot/ficl/math64.h,v 1.3 2003/11/10 06:08:33 dillon Exp $
48 #if !defined (__MATH64_H__)
49 #define __MATH64_H__
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
55 DPINT m64Abs(DPINT x);
56 int m64IsNegative(DPINT x);
57 DPUNS m64Mac(DPUNS u, FICL_UNS mul, FICL_UNS add);
58 DPINT m64MulI(FICL_INT x, FICL_INT y);
59 DPINT m64Negate(DPINT x);
60 INTQR m64FlooredDivI(DPINT num, FICL_INT den);
61 void i64Push(FICL_STACK *pStack, DPINT i64);
62 DPINT i64Pop(FICL_STACK *pStack);
63 void u64Push(FICL_STACK *pStack, DPUNS u64);
64 DPUNS u64Pop(FICL_STACK *pStack);
65 INTQR m64SymmetricDivI(DPINT num, FICL_INT den);
66 UNS16 m64UMod(DPUNS *pUD, UNS16 base);
69 #if PORTABLE_LONGMULDIV != 0 /* see sysdep.h */
70 DPUNS m64Add(DPUNS x, DPUNS y);
71 DPUNS m64ASL( DPUNS x );
72 DPUNS m64ASR( DPUNS x );
73 int m64Compare(DPUNS x, DPUNS y);
74 DPUNS m64Or( DPUNS x, DPUNS y );
75 DPUNS m64Sub(DPUNS x, DPUNS y);
76 #endif
78 #define i64Extend(i64) (i64).hi = ((i64).lo < 0) ? -1L : 0
79 #define m64CastIU(i64) (*(DPUNS *)(&(i64)))
80 #define m64CastUI(u64) (*(DPINT *)(&(u64)))
81 #define m64CastQRIU(iqr) (*(UNSQR *)(&(iqr)))
82 #define m64CastQRUI(uqr) (*(INTQR *)(&(uqr)))
84 #define CELL_HI_BIT (1L << (BITS_PER_CELL-1))
86 #ifdef __cplusplus
88 #endif
90 #endif