Leaked source code of windows server 2003
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.

88 lines
1.7 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains routines that emulate MMX instructions in ordinary C
  4. // for algorithm development.
  5. //
  6. // Copyright (C) Microsoft Corporation, 1997.
  7. //
  8. //-----------------------------------------------------------------------------
  9. #include "d3dtypesp.h"
  10. #include "d3ditype.h"
  11. #include "mmxemul.h"
  12. UINT16 MMX_addsw(INT16 x, INT16 y)
  13. {
  14. INT32 z = x + y;
  15. if (z > 0x7fff)
  16. z = 0x7fff;
  17. if (z < -32768)
  18. z = -32768;
  19. return (INT16)z;
  20. }
  21. INT16 MMX_addusw(UINT16 x, UINT16 y)
  22. {
  23. INT32 z = (INT32)x + (INT32)y;
  24. if (z > 0xffff)
  25. z = 0xffff;
  26. if (z < 0)
  27. z = 0;
  28. return (UINT16)z;
  29. }
  30. UINT16 MMX_cmpeqw(INT16 x, INT16 y)
  31. {
  32. if (x == y) {
  33. return 0xffff;
  34. } else {
  35. return 0x0;
  36. }
  37. }
  38. UINT16 MMX_cmpgtw(INT16 x, INT16 y)
  39. {
  40. if (x > y) {
  41. return 0xffff;
  42. } else {
  43. return 0x0;
  44. }
  45. }
  46. // Emulate 16 bit MMX style multiplies
  47. // Note that MULHW only works with signed operands, but MULLW works for
  48. // signed and unsigned operands.
  49. INT16 MMX_mulhw(INT16 x, INT16 y)
  50. {
  51. INT32 z = x*y;
  52. INT16 r = (INT16)(z>>16);
  53. return r;
  54. }
  55. INT16 MMX_mullw(INT16 x, INT16 y)
  56. {
  57. INT32 z = x*y;
  58. INT16 r = z & 0xffff;
  59. return r;
  60. }
  61. INT16 MMX_subsw(INT16 x, INT16 y)
  62. {
  63. INT32 z = x - y;
  64. if (z > 0x7fff)
  65. z = 0x7fff;
  66. if (z < -32768)
  67. z = -32768;
  68. return (INT16)z;
  69. }
  70. UINT16 MMX_subusw(UINT16 x, UINT16 y)
  71. {
  72. INT32 z = (INT32)x - (INT32)y;
  73. if (z > 0xffff)
  74. z = 0xffff;
  75. if (z < 0)
  76. z = 0;
  77. return (UINT16)z;
  78. }