home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / utility / umult64.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.2 KB  |  90 lines

  1. /*
  2.     $Id: umult64.c,v 1.3 1996/10/24 22:51:47 aros Exp $
  3.     $Log: umult64.c,v $
  4.     Revision 1.3  1996/10/24 22:51:47  aros
  5.     Use proper Amiga datatypes (eg: ULONG not unsigned long)
  6.  
  7.     Revision 1.2  1996/10/24 15:51:39  aros
  8.     Use the official AROS macros over the __AROS versions.
  9.  
  10.     Revision 1.1  1996/08/31 12:58:14  aros
  11.     Merged in/modified for FreeBSD.
  12.  
  13.     Desc: Unsigned 64-bit product of two 32-bit numbers.
  14.     Lang: english
  15. */
  16. #include "utility_intern.h"
  17.  
  18. /*****************************************************************************
  19.  
  20.     NAME */
  21.         #include <clib/utility_protos.h>
  22.  
  23.         AROS_LH2(UQUAD, UMult64,
  24.  
  25. /*  SYNOPSIS */
  26.         AROS_LHA(ULONG        , arg1, D0),
  27.         AROS_LHA(ULONG        , arg2, D1),
  28.  
  29. /*  LOCATION */
  30.         struct UtilityBase *, UtilityBase, 34, Utility)
  31.  
  32. /*  FUNCTION
  33.         Compute the unsigned 64-bit product of arg1 * arg2.
  34.  
  35.     INPUTS
  36.         arg1, arg2  -   32 bit unsigned numbers.
  37.  
  38.     RESULT
  39.         arg1 * arg2
  40.  
  41.     NOTES
  42.  
  43.     EXAMPLE
  44.  
  45.     BUGS
  46.         There is a problem under the current system in that it is very
  47.         hard to return a 64-bit value.
  48.  
  49.     SEE ALSO
  50.         utility/SMult32(), utility/UMult32(), utility/SMult64()
  51.  
  52.     INTERNALS
  53.         This is essentially UMult32(), but without the code to calculate
  54.         the product of the high 32 bits of the multiplicands.
  55.  
  56.         In fact all that is added is the code to calculate 2^32 * ac.
  57.  
  58.     HISTORY
  59.         29-10-95    digulla automatically created from
  60.                             utility_lib.fd and clib/utility_protos.h
  61.         18-08-96    iaint   Modified UMult32().
  62.  
  63. *****************************************************************************/
  64. {
  65.     AROS_LIBFUNC_INIT
  66.  
  67. #ifdef HAS_64BITMULU
  68.     return arg1 * arg2;
  69. #else
  70.  
  71.     UQUAD product;
  72.     UWORD a0, a1, b0, b1;
  73.  
  74.     a1 = (arg1 >> 16) & 0xffff;
  75.     a0 = arg1 & 0xffff;
  76.     b1 = (arg2 >> 16) & 0xffff;
  77.     b0 = arg2 & 0xffff;
  78.  
  79.     /* In case number is quite small an optimization */
  80.     if(a1 && b1)
  81.         product = (UQUAD)(a1 * b1) << 32;
  82.     else
  83.         product = 0;
  84.  
  85.     product += (((a1 * b0) + (a0 * b1)) << 16) + (a0 * b0);
  86.     return product;
  87. #endif
  88.     AROS_LIBFUNC_EXIT
  89. } /* UMult64 */
  90.