140843Smsmith/*******************************************************************
240843Smsmith** m a t h 6 4 . h
340843Smsmith** Forth Inspired Command Language - 64 bit math support routines
440843Smsmith** Author: John Sadler (john_sadler@alum.mit.edu)
540843Smsmith** Created: 25 January 1998
694290Sdcs** $Id: math64.h,v 1.9 2001/12/05 07:21:34 jsadler Exp $
740843Smsmith*******************************************************************/
840843Smsmith/*
976116Sdcs** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
1076116Sdcs** All rights reserved.
1176116Sdcs**
1294290Sdcs** I am interested in hearing from anyone who uses ficl. If you have
1394290Sdcs** a problem, a success story, a defect, an enhancement request, or
1494290Sdcs** if you would like to contribute to the ficl release, please
1594290Sdcs** contact me by email at the address above.
1694290Sdcs**
1776116Sdcs** Get the latest Ficl release at http://ficl.sourceforge.net
1876116Sdcs**
1976116Sdcs** L I C E N S E  and  D I S C L A I M E R
2040843Smsmith**
2176116Sdcs** Redistribution and use in source and binary forms, with or without
2276116Sdcs** modification, are permitted provided that the following conditions
2376116Sdcs** are met:
2476116Sdcs** 1. Redistributions of source code must retain the above copyright
2576116Sdcs**    notice, this list of conditions and the following disclaimer.
2676116Sdcs** 2. Redistributions in binary form must reproduce the above copyright
2776116Sdcs**    notice, this list of conditions and the following disclaimer in the
2876116Sdcs**    documentation and/or other materials provided with the distribution.
2976116Sdcs**
3076116Sdcs** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
3176116Sdcs** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3276116Sdcs** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3376116Sdcs** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
3476116Sdcs** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3576116Sdcs** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3676116Sdcs** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3776116Sdcs** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3876116Sdcs** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3976116Sdcs** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4076116Sdcs** SUCH DAMAGE.
4140843Smsmith*/
4240843Smsmith
4351786Sdcs/* $FreeBSD$ */
4451786Sdcs
4540843Smsmith#if !defined (__MATH64_H__)
4640843Smsmith#define __MATH64_H__
4740843Smsmith
4840843Smsmith#ifdef __cplusplus
4940843Smsmithextern "C" {
5040843Smsmith#endif
5140843Smsmith
5251786SdcsDPINT   m64Abs(DPINT x);
5351786Sdcsint     m64IsNegative(DPINT x);
5451786SdcsDPUNS   m64Mac(DPUNS u, FICL_UNS mul, FICL_UNS add);
5551786SdcsDPINT   m64MulI(FICL_INT x, FICL_INT y);
5651786SdcsDPINT   m64Negate(DPINT x);
5751786SdcsINTQR   m64FlooredDivI(DPINT num, FICL_INT den);
5851786Sdcsvoid    i64Push(FICL_STACK *pStack, DPINT i64);
5951786SdcsDPINT   i64Pop(FICL_STACK *pStack);
6051786Sdcsvoid    u64Push(FICL_STACK *pStack, DPUNS u64);
6151786SdcsDPUNS   u64Pop(FICL_STACK *pStack);
6251786SdcsINTQR   m64SymmetricDivI(DPINT num, FICL_INT den);
6351786SdcsUNS16   m64UMod(DPUNS *pUD, UNS16 base);
6440843Smsmith
6551786Sdcs
6651786Sdcs#if PORTABLE_LONGMULDIV != 0   /* see sysdep.h */
6751786SdcsDPUNS   m64Add(DPUNS x, DPUNS y);
6851786SdcsDPUNS   m64ASL( DPUNS x );
6951786SdcsDPUNS   m64ASR( DPUNS x );
7051786Sdcsint     m64Compare(DPUNS x, DPUNS y);
7151786SdcsDPUNS   m64Or( DPUNS x, DPUNS y );
7251786SdcsDPUNS   m64Sub(DPUNS x, DPUNS y);
7351786Sdcs#endif
7451786Sdcs
7540843Smsmith#define i64Extend(i64) (i64).hi = ((i64).lo < 0) ? -1L : 0
7651786Sdcs#define m64CastIU(i64) (*(DPUNS *)(&(i64)))
7751786Sdcs#define m64CastUI(u64) (*(DPINT *)(&(u64)))
7840843Smsmith#define m64CastQRIU(iqr) (*(UNSQR *)(&(iqr)))
7940843Smsmith#define m64CastQRUI(uqr) (*(INTQR *)(&(uqr)))
8040843Smsmith
8151786Sdcs#define CELL_HI_BIT (1L << (BITS_PER_CELL-1))
8251786Sdcs
8340843Smsmith#ifdef __cplusplus
8440843Smsmith}
8540843Smsmith#endif
8640843Smsmith
8740843Smsmith#endif
8840843Smsmith
89