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

  1. /*
  2.     $Id: smult64.c,v 1.3 1996/10/24 22:51:46 aros Exp $
  3.     $Log: smult64.c,v $
  4.     Revision 1.3  1996/10/24 22:51:46  aros
  5.     Use proper Amiga datatypes (eg: ULONG not unsigned long)
  6.  
  7.     Revision 1.2  1996/10/24 15:51:38  aros
  8.     Use the official AROS macros over the __AROS versions.
  9.  
  10.     Revision 1.1  1996/08/31 12:58:13  aros
  11.     Merged in/modified for FreeBSD.
  12.  
  13.     Desc: Signed 64 bit multiplication function.
  14.     Lang: english
  15. */
  16. #include "utility_intern.h"
  17.  
  18. /*****************************************************************************
  19.  
  20.     NAME */
  21.         #include <clib/utility_protos.h>
  22.  
  23.         AROS_LH2(QUAD, SMult64,
  24.  
  25. /*  SYNOPSIS */
  26.         AROS_LHA(LONG, arg1, D0),
  27.         AROS_LHA(LONG, arg2, D1),
  28.  
  29. /*  LOCATION */
  30.         struct UtilityBase *, UtilityBase, 33, Utility)
  31.  
  32. /*  FUNCTION
  33.         Compute the signed 64-bit product of arg1 * arg2.
  34.  
  35.     INPUTS
  36.         arg1, arg2  -   32 bit signed 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/UMult64()
  51.  
  52.     INTERNALS
  53.         This is essentially SMult32(), 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 2^32 * ac term (see docs for
  57.             SMult32().
  58.  
  59.     HISTORY
  60.         29-10-95    digulla automatically created from
  61.                             utility_lib.fd and clib/utility_protos.h
  62.         18-08-96    iaint   Modified SMult32().
  63.  
  64. *****************************************************************************/
  65. {
  66.     AROS_LIBFUNC_INIT
  67.  
  68. #ifdef HAS_64BITMULS
  69.     return arg1 * arg2;
  70. #else
  71.  
  72.     QUAD product;
  73.     WORD a0, a1, b0, b1;
  74.     BOOL neg;
  75.  
  76.     /* Fix everything up so that -ve signs don't vanish */
  77.     if(arg1 < 0)
  78.     {
  79.         neg = 1; arg1 = -arg1;
  80.     }
  81.     else
  82.         neg = 0;
  83.  
  84.     if(arg2 <= 0)
  85.     {
  86.         neg ^= 1; arg2 = -arg2;
  87.     }
  88.  
  89.     a0 = arg1 & 0xFFFF;
  90.     a1 = (arg1 >> 16) & 0xFFFF;
  91.  
  92.     b0 = arg2 & 0xFFFF;
  93.     b1 = (arg2 >> 16) & 0xFFFF;
  94.  
  95.     /* In case numbers are small */
  96.     if(a1 && b1)
  97.         product = (QUAD)(a1 * b1) << 32;
  98.     else
  99.         product = 0;
  100.  
  101.     product += (((a1 * b0) + (a0 * b1)) << 16) + (a0 * b0);
  102.  
  103.     return (neg ? -product : product);
  104. #endif
  105.  
  106.     AROS_LIBFUNC_EXIT
  107. } /* SMult64 */
  108.