SimdUint16x8Operation.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeLanguagePch.h"
  6. #if defined(_M_ARM32_OR_ARM64)
  7. namespace Js
  8. {
  9. SIMDValue SIMDUint16x8Operation::OpUint16x8(uint16 values[])
  10. {
  11. SIMDValue result;
  12. for (uint i = 0; i < 8; i++)
  13. {
  14. result.u16[i] = values[i];
  15. }
  16. return result;
  17. }
  18. SIMDValue SIMDUint16x8Operation::OpMin(const SIMDValue& aValue, const SIMDValue& bValue)
  19. {
  20. SIMDValue result;
  21. for (uint idx = 0; idx < 8; ++idx)
  22. {
  23. result.u16[idx] = (aValue.u16[idx] < bValue.u16[idx]) ? aValue.u16[idx] : bValue.u16[idx];
  24. }
  25. return result;
  26. }
  27. SIMDValue SIMDUint16x8Operation::OpMax(const SIMDValue& aValue, const SIMDValue& bValue)
  28. {
  29. SIMDValue result;
  30. for (uint idx = 0; idx < 8; ++idx)
  31. {
  32. result.u16[idx] = (aValue.u16[idx] > bValue.u16[idx]) ? aValue.u16[idx] : bValue.u16[idx];
  33. }
  34. return result;
  35. }
  36. SIMDValue SIMDUint16x8Operation::OpLessThan(const SIMDValue& aValue, const SIMDValue& bValue) //arun::ToDo return bool types
  37. {
  38. SIMDValue result;
  39. for(uint idx = 0; idx < 8; ++idx)
  40. {
  41. result.u16[idx] = (aValue.u16[idx] < bValue.u16[idx]) ? 0xff : 0x0;
  42. }
  43. return result;
  44. }
  45. SIMDValue SIMDUint16x8Operation::OpLessThanOrEqual(const SIMDValue& aValue, const SIMDValue& bValue) //arun::ToDo return bool types
  46. {
  47. SIMDValue result;
  48. for (uint idx = 0; idx < 8; ++idx)
  49. {
  50. result.u16[idx] = (aValue.u16[idx] <= bValue.u16[idx]) ? 0xff : 0x0;
  51. }
  52. return result;
  53. }
  54. SIMDValue SIMDUint16x8Operation::OpGreaterThanOrEqual(const SIMDValue& aValue, const SIMDValue& bValue)
  55. {
  56. SIMDValue result;
  57. result = SIMDUint16x8Operation::OpLessThan(aValue, bValue);
  58. result = SIMDInt32x4Operation::OpNot(result);
  59. return result;
  60. }
  61. SIMDValue SIMDUint16x8Operation::OpGreaterThan(const SIMDValue& aValue, const SIMDValue& bValue)
  62. {
  63. SIMDValue result;
  64. result = SIMDUint16x8Operation::OpLessThanOrEqual(aValue, bValue);
  65. result = SIMDInt32x4Operation::OpNot(result);
  66. return result;
  67. }
  68. SIMDValue SIMDUint16x8Operation::OpShiftRightByScalar(const SIMDValue& value, int count)
  69. {
  70. SIMDValue result;
  71. count = count & SIMDUtils::SIMDGetShiftAmountMask(2);
  72. for (uint idx = 0; idx < 8; ++idx)
  73. {
  74. result.u16[idx] = (value.u16[idx] >> count);
  75. }
  76. return result;
  77. }
  78. SIMDValue SIMDUint16x8Operation::OpAddSaturate(const SIMDValue& aValue, const SIMDValue& bValue)
  79. {
  80. SIMDValue result;
  81. for (uint idx = 0; idx < 8; ++idx)
  82. {
  83. uint32 a = (uint32)aValue.u16[idx];
  84. uint32 b = (uint32)bValue.u16[idx];
  85. result.u16[idx] = ((a + b) > MAXUINT16) ? MAXUINT16 : (uint16)(a + b);
  86. }
  87. return result;
  88. }
  89. SIMDValue SIMDUint16x8Operation::OpSubSaturate(const SIMDValue& aValue, const SIMDValue& bValue)
  90. {
  91. SIMDValue result;
  92. for (uint idx = 0; idx < 8; ++idx)
  93. {
  94. int a = (int)aValue.u16[idx];
  95. int b = (int)bValue.u16[idx];
  96. result.u16[idx] = ((a - b) < 0) ? 0 : (uint16)(a - b);
  97. }
  98. return result;
  99. }
  100. }
  101. #endif