/******************************************************************************
*
* Filename:     math48.h
*
* Copyright (c) Robert Milne 2008  All rights reserved.
*
******************************************************************************/
#ifndef _MATH48_H_
#define _MATH48_H_

#include "all.h"  //typedefs

/******************************************************************************
*  E X P O R T E D    D A T A    T Y P E S
******************************************************************************/
typedef union {
  int32 l; //use for 32 bit ops with ICC12 lib
  struct {
    uint16 h;
    uint16 l;
  } w;
  struct {
    uint8 unused;
    uint8 h;
    uint8 m;
    uint8 l;
  } b;
} uint24;

typedef union {
  int32 l; //use for 32 bit ops with ICC12 lib
  struct {
    int16 h;
    int16 l;
  } w;
  struct {
    int8 sign;
    int8 h;
    int8 m;
    int8 l;
  } b;
} int24;

typedef union {
  struct {
    int32 l;
    int16 s;
  } shift16;
  struct {
    int16 s;
    int32 l;
  } noshift16;
  struct {
    int8 hh;
    int8 hl;
    int8 mh;
    int8 ml;
    int8 lh;
    int8 ll;
  } b;
  struct {
    int16 h;
    int16 m;
    int16 l;
  } w;
} uint48;

typedef union {
  struct {
    int32 h;
    int32 l;
  } l;
  struct {
    int16 hh;
    int16 hl;
    int16 lh;
    int16 ll;
  } w;
} int64;


/******************************************************************************
*  E X P O R T E D    F U N C T I O N    P R O T O T Y P E S
******************************************************************************/
//mult64(int32* n1, int32* n2, int64* n3){*n3 = *n1 * *n2;}
void mult64(int32* n1, int32* n2, int64* n3);

//mult48(int24* n1, int24* n2, uint48* n3){*n3 = *n1 * *n2;}
void mult48(uint24* n1, uint24* n2, uint48* n3);

//add48(int48* n1, int48* n2){*n1 += *n2;}
void add48(uint48* n1, uint48* n2);

//sub48(int48* n1, int48* n2){*n1 -= *n2;}
void sub48(uint48* n1, uint48* n2);

//neg24(uint24* n){*n = 0 - *n;}
void neg24(uint24* n);

//neg48(uint48* n){*n = 0 - *n;}
void neg48(uint48* n);

//rshft48(uint48* n){*n >>= 1;}
void rshft48(uint48* n);

//srshft48(int48* n){*n >>= 1;}
void srshft48(uint48* n);

//lshft48(uint48* n){*n <<= 1;}
void lshft48(uint48* n);

//sext48(uint48* n){
//  if(0 > *n.noshift16.l){*n.noshift16.s = 0xFFFF;}
//  else{*n.noshift16.s = 0;}
//}
void sext48(uint48* n);


#endif // #ifndef _MATH48_H_
