Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1992-2000 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. // muldiv32.h
  13. //
  14. // Description:
  15. // math routine for 32 bit signed and unsiged numbers.
  16. //
  17. // MulDiv(a,b,c) = (a * b) / c (round down, signed)
  18. //
  19. //==========================================================================;
  20. #ifndef _INC_MULDIV32
  21. #define _INC_MULDIV32
  22. #ifndef INLINE
  23. #define INLINE __inline
  24. #endif
  25. //----------------------------------------------------------------------;
  26. //
  27. // Win 32
  28. //
  29. //----------------------------------------------------------------------;
  30. #ifdef _X86_
  31. //
  32. // Use 32-bit x86 assembly.
  33. //
  34. #pragma warning(disable:4035 4704)
  35. INLINE LONG MulDiv(LONG a,LONG b,LONG c)
  36. {
  37. _asm mov eax,dword ptr a // mov eax, a
  38. _asm mov ebx,dword ptr b // mov ebx, b
  39. _asm mov ecx,dword ptr c // mov ecx, c
  40. _asm imul ebx // imul ebx
  41. _asm idiv ecx // idiv ecx
  42. _asm shld edx, eax, 16 // shld edx, eax, 16
  43. } // MulDiv()
  44. #pragma warning(default:4035 4704)
  45. #else
  46. //
  47. // Use C9 __int64 support for Daytona RISC platforms.
  48. //
  49. INLINE LONG MulDiv( LONG a, LONG b, LONG c )
  50. {
  51. return (LONG)( Int32x32To64(a,b) / c );
  52. }
  53. #endif
  54. #endif // _INC_MULDIV32