SimdFloat64x2Operation.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 SIMDFloat64x2Operation::OpFloat64x2(double x, double y)
  10. {
  11. SIMDValue result;
  12. result.f64[SIMD_X] = x;
  13. result.f64[SIMD_Y] = y;
  14. return result;
  15. }
  16. SIMDValue SIMDFloat64x2Operation::OpSplat(double x)
  17. {
  18. SIMDValue result;
  19. result.f64[SIMD_X] = result.f64[SIMD_Y] = x;
  20. return result;
  21. }
  22. // Conversions
  23. SIMDValue SIMDFloat64x2Operation::OpFromFloat32x4(const SIMDValue& v)
  24. {
  25. SIMDValue result;
  26. result.f64[SIMD_X] = (double)(v.f32[SIMD_X]);
  27. result.f64[SIMD_Y] = (double)(v.f32[SIMD_Y]);
  28. return result;
  29. }
  30. SIMDValue SIMDFloat64x2Operation::OpFromInt32x4(const SIMDValue& v)
  31. {
  32. SIMDValue result;
  33. result.f64[SIMD_X] = (double)(v.i32[SIMD_X]);
  34. result.f64[SIMD_Y] = (double)(v.i32[SIMD_Y]);
  35. return result;
  36. }
  37. // Unary Ops
  38. SIMDValue SIMDFloat64x2Operation::OpAbs(const SIMDValue& value)
  39. {
  40. SIMDValue result;
  41. result.f64[SIMD_X] = (value.f64[SIMD_X] < 0) ? -1 * value.f64[SIMD_X] : value.f64[SIMD_X];
  42. result.f64[SIMD_Y] = (value.f64[SIMD_Y] < 0) ? -1 * value.f64[SIMD_Y] : value.f64[SIMD_Y];
  43. return result;
  44. }
  45. SIMDValue SIMDFloat64x2Operation::OpNeg(const SIMDValue& value)
  46. {
  47. SIMDValue result;
  48. result.f64[SIMD_X] = -1 * value.f64[SIMD_X];
  49. result.f64[SIMD_Y] = -1 * value.f64[SIMD_Y];
  50. return result;
  51. }
  52. SIMDValue SIMDFloat64x2Operation::OpNot(const SIMDValue& value)
  53. {
  54. SIMDValue result;
  55. result = SIMDInt32x4Operation::OpNot(value);
  56. return result;
  57. }
  58. SIMDValue SIMDFloat64x2Operation::OpReciprocal(const SIMDValue& value)
  59. {
  60. SIMDValue result;
  61. result.f64[SIMD_X] = 1.0/(value.f64[SIMD_X]);
  62. result.f64[SIMD_Y] = 1.0/(value.f64[SIMD_Y]);
  63. return result;
  64. }
  65. SIMDValue SIMDFloat64x2Operation::OpReciprocalSqrt(const SIMDValue& value)
  66. {
  67. SIMDValue result;
  68. result.f64[SIMD_X] = sqrt(1.0 / (value.f64[SIMD_X]));
  69. result.f64[SIMD_Y] = sqrt(1.0 / (value.f64[SIMD_Y]));
  70. return result;
  71. }
  72. SIMDValue SIMDFloat64x2Operation::OpSqrt(const SIMDValue& value)
  73. {
  74. SIMDValue result;
  75. result.f64[SIMD_X] = sqrt(value.f64[SIMD_X]);
  76. result.f64[SIMD_Y] = sqrt(value.f64[SIMD_Y]);
  77. return result;
  78. }
  79. // Binary Ops
  80. SIMDValue SIMDFloat64x2Operation::OpAdd(const SIMDValue& aValue, const SIMDValue& bValue)
  81. {
  82. SIMDValue result;
  83. result.f64[SIMD_X] = aValue.f64[SIMD_X] + bValue.f64[SIMD_X];
  84. result.f64[SIMD_Y] = aValue.f64[SIMD_Y] + bValue.f64[SIMD_Y];
  85. return result;
  86. }
  87. SIMDValue SIMDFloat64x2Operation::OpSub(const SIMDValue& aValue, const SIMDValue& bValue)
  88. {
  89. SIMDValue result;
  90. result.f64[SIMD_X] = aValue.f64[SIMD_X] - bValue.f64[SIMD_X];
  91. result.f64[SIMD_Y] = aValue.f64[SIMD_Y] - bValue.f64[SIMD_Y];
  92. return result;
  93. }
  94. SIMDValue SIMDFloat64x2Operation::OpMul(const SIMDValue& aValue, const SIMDValue& bValue)
  95. {
  96. SIMDValue result;
  97. result.f64[SIMD_X] = aValue.f64[SIMD_X] * bValue.f64[SIMD_X];
  98. result.f64[SIMD_Y] = aValue.f64[SIMD_Y] * bValue.f64[SIMD_Y];
  99. return result;
  100. }
  101. SIMDValue SIMDFloat64x2Operation::OpDiv(const SIMDValue& aValue, const SIMDValue& bValue)
  102. {
  103. SIMDValue result;
  104. result.f64[SIMD_X] = aValue.f64[SIMD_X] / bValue.f64[SIMD_X];
  105. result.f64[SIMD_Y] = aValue.f64[SIMD_Y] / bValue.f64[SIMD_Y];
  106. return result;
  107. }
  108. SIMDValue SIMDFloat64x2Operation::OpAnd(const SIMDValue& aValue, const SIMDValue& bValue)
  109. {
  110. SIMDValue result;
  111. result = SIMDInt32x4Operation::OpAnd(aValue, bValue);
  112. return result;
  113. }
  114. SIMDValue SIMDFloat64x2Operation::OpOr(const SIMDValue& aValue, const SIMDValue& bValue)
  115. {
  116. SIMDValue result;
  117. result = SIMDInt32x4Operation::OpOr(aValue, bValue);
  118. return result;
  119. }
  120. SIMDValue SIMDFloat64x2Operation::OpXor(const SIMDValue& aValue, const SIMDValue& bValue)
  121. {
  122. SIMDValue result;
  123. result = SIMDInt32x4Operation::OpXor(aValue, bValue);
  124. return result;
  125. }
  126. SIMDValue SIMDFloat64x2Operation::OpMin(const SIMDValue& aValue, const SIMDValue& bValue)
  127. {
  128. SIMDValue result;
  129. result.f64[SIMD_X] = (aValue.f64[SIMD_X] < bValue.f64[SIMD_X]) ? aValue.f64[SIMD_X] : bValue.f64[SIMD_X];
  130. result.f64[SIMD_Y] = (aValue.f64[SIMD_Y] < bValue.f64[SIMD_Y]) ? aValue.f64[SIMD_Y] : bValue.f64[SIMD_Y];
  131. return result;
  132. }
  133. SIMDValue SIMDFloat64x2Operation::OpMax(const SIMDValue& aValue, const SIMDValue& bValue)
  134. {
  135. SIMDValue result;
  136. result.f64[SIMD_X] = (aValue.f64[SIMD_X] > bValue.f64[SIMD_X]) ? aValue.f64[SIMD_X] : bValue.f64[SIMD_X];
  137. result.f64[SIMD_Y] = (aValue.f64[SIMD_Y] > bValue.f64[SIMD_Y]) ? aValue.f64[SIMD_Y] : bValue.f64[SIMD_Y];
  138. return result;
  139. }
  140. SIMDValue SIMDFloat64x2Operation::OpScale(const SIMDValue& Value, double scaleValue)
  141. {
  142. SIMDValue result;
  143. result.f64[SIMD_X] = Value.f64[SIMD_X] * scaleValue;
  144. result.f64[SIMD_Y] = Value.f64[SIMD_Y] * scaleValue;
  145. return result;
  146. }
  147. SIMDValue SIMDFloat64x2Operation::OpLessThan(const SIMDValue& aValue, const SIMDValue& bValue)
  148. {
  149. SIMDValue result;
  150. int x = aValue.f64[SIMD_X] < bValue.f64[SIMD_X];
  151. int y = aValue.f64[SIMD_Y] < bValue.f64[SIMD_Y];
  152. result = SIMDInt32x4Operation::OpBool(x, x, y, y);
  153. return result;
  154. }
  155. SIMDValue SIMDFloat64x2Operation::OpLessThanOrEqual(const SIMDValue& aValue, const SIMDValue& bValue)
  156. {
  157. SIMDValue result;
  158. int x = aValue.f64[SIMD_X] <= bValue.f64[SIMD_X];
  159. int y = aValue.f64[SIMD_Y] <= bValue.f64[SIMD_Y];
  160. result = SIMDInt32x4Operation::OpBool(x, x, y, y);
  161. return result;
  162. }
  163. SIMDValue SIMDFloat64x2Operation::OpEqual(const SIMDValue& aValue, const SIMDValue& bValue)
  164. {
  165. SIMDValue result;
  166. int x = aValue.f64[SIMD_X] == bValue.f64[SIMD_X];
  167. int y = aValue.f64[SIMD_Y] == bValue.f64[SIMD_Y];
  168. result = SIMDInt32x4Operation::OpBool(x, x, y, y);
  169. return result;
  170. }
  171. SIMDValue SIMDFloat64x2Operation::OpNotEqual(const SIMDValue& aValue, const SIMDValue& bValue)
  172. {
  173. SIMDValue result;
  174. int x = aValue.f64[SIMD_X] != bValue.f64[SIMD_X];
  175. int y = aValue.f64[SIMD_Y] != bValue.f64[SIMD_Y];
  176. result = SIMDInt32x4Operation::OpBool(x, x, y, y);
  177. return result;
  178. }
  179. SIMDValue SIMDFloat64x2Operation::OpGreaterThan(const SIMDValue& aValue, const SIMDValue& bValue)
  180. {
  181. SIMDValue result;
  182. int x = aValue.f64[SIMD_X] > bValue.f64[SIMD_X];
  183. int y = aValue.f64[SIMD_Y] > bValue.f64[SIMD_Y];
  184. result = SIMDInt32x4Operation::OpBool(x, x, y, y);
  185. return result;
  186. }
  187. SIMDValue SIMDFloat64x2Operation::OpGreaterThanOrEqual(const SIMDValue& aValue, const SIMDValue& bValue)
  188. {
  189. SIMDValue result;
  190. int x = aValue.f64[SIMD_X] >= bValue.f64[SIMD_X];
  191. int y = aValue.f64[SIMD_Y] >= bValue.f64[SIMD_Y];
  192. result = SIMDInt32x4Operation::OpBool(x, x, y, y);
  193. return result;
  194. }
  195. SIMDValue SIMDFloat64x2Operation::OpSelect(const SIMDValue& mV, const SIMDValue& tV, const SIMDValue& fV)
  196. {
  197. SIMDValue result;
  198. SIMDValue trueResult = SIMDInt32x4Operation::OpAnd(mV, tV);
  199. SIMDValue notValue = SIMDInt32x4Operation::OpNot(mV);
  200. SIMDValue falseResult = SIMDInt32x4Operation::OpAnd(notValue, fV);
  201. result = SIMDInt32x4Operation::OpOr(trueResult, falseResult);
  202. return result;
  203. }
  204. }
  205. #endif