xref: /freebsd/stand/ficl/math64.h (revision 5f4c09dd85bff675e0ca63c55ea3c517e0fddfcc)
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.
11 **
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.
16 **
17 ** Get the latest Ficl release at http://ficl.sourceforge.net
18 **
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.
29 **
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.
41 */
42 
43 
44 #if !defined (__MATH64_H__)
45 #define __MATH64_H__
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 DPINT   m64Abs(DPINT x);
52 int     m64IsNegative(DPINT x);
53 DPUNS   m64Mac(DPUNS u, FICL_UNS mul, FICL_UNS add);
54 DPINT   m64MulI(FICL_INT x, FICL_INT y);
55 DPINT   m64Negate(DPINT x);
56 INTQR   m64FlooredDivI(DPINT num, FICL_INT den);
57 void    i64Push(FICL_STACK *pStack, DPINT i64);
58 DPINT   i64Pop(FICL_STACK *pStack);
59 void    u64Push(FICL_STACK *pStack, DPUNS u64);
60 DPUNS   u64Pop(FICL_STACK *pStack);
61 INTQR   m64SymmetricDivI(DPINT num, FICL_INT den);
62 UNS16   m64UMod(DPUNS *pUD, UNS16 base);
63 
64 
65 #if PORTABLE_LONGMULDIV != 0   /* see sysdep.h */
66 DPUNS   m64Add(DPUNS x, DPUNS y);
67 DPUNS   m64ASL( DPUNS x );
68 DPUNS   m64ASR( DPUNS x );
69 int     m64Compare(DPUNS x, DPUNS y);
70 DPUNS   m64Or( DPUNS x, DPUNS y );
71 DPUNS   m64Sub(DPUNS x, DPUNS y);
72 #endif
73 
74 #define i64Extend(i64) (i64).hi = ((i64).lo < 0) ? -1L : 0
75 #define m64CastIU(i64) (*(DPUNS *)(&(i64)))
76 #define m64CastUI(u64) (*(DPINT *)(&(u64)))
77 #define m64CastQRIU(iqr) (*(UNSQR *)(&(iqr)))
78 #define m64CastQRUI(uqr) (*(INTQR *)(&(uqr)))
79 
80 #define CELL_HI_BIT (1L << (BITS_PER_CELL-1))
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif
87 
88