SimdInt64x2Operation.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. namespace Js
  7. {
  8. SIMDValue SIMDInt64x2Operation::OpSplat(int64 val)
  9. {
  10. SIMDValue result;
  11. result.i64[0] = val;
  12. result.i64[1] = val;
  13. return result;
  14. }
  15. SIMDValue SIMDInt64x2Operation::OpAdd(const SIMDValue& a, const SIMDValue& b)
  16. {
  17. SIMDValue result;
  18. result.i64[0] = a.i64[0] + b.i64[0];
  19. result.i64[1] = a.i64[1] + b.i64[1];
  20. return result;
  21. }
  22. SIMDValue SIMDInt64x2Operation::OpSub(const SIMDValue& a, const SIMDValue& b)
  23. {
  24. SIMDValue result;
  25. result.i64[0] = a.i64[0] - b.i64[0];
  26. result.i64[1] = a.i64[1] - b.i64[1];
  27. return result;
  28. }
  29. SIMDValue SIMDInt64x2Operation::OpNeg(const SIMDValue& a)
  30. {
  31. SIMDValue result;
  32. result.i64[0] = -a.i64[0];
  33. result.i64[1] = -a.i64[1];
  34. return result;
  35. }
  36. static bool IsInRange(double val, uint64& out)
  37. {
  38. if (val != val || val <= (double)0)
  39. {
  40. out = 0;
  41. return false;
  42. }
  43. if (val >= (double)ULLONG_MAX)
  44. {
  45. out = ULLONG_MAX;
  46. return false;
  47. }
  48. return true;
  49. }
  50. static bool IsInRange(double val, int64& out)
  51. {
  52. if (val != val)
  53. {
  54. out = 0;
  55. return false;
  56. }
  57. if (val <= (double)LLONG_MIN)
  58. {
  59. out = LLONG_MIN;
  60. return false;
  61. }
  62. if (val >= (double)LLONG_MAX)
  63. {
  64. out = LLONG_MAX;
  65. return false;
  66. }
  67. return true;
  68. }
  69. template<typename T>
  70. void SIMDInt64x2Operation::OpTrunc(SIMDValue* dst, SIMDValue* src)
  71. {
  72. T convertedVal;
  73. dst->i64[0] = IsInRange(src->f64[0], convertedVal) ? (T)src->f64[0] : convertedVal;
  74. dst->i64[1] = IsInRange(src->f64[1], convertedVal) ? (T)src->f64[1] : convertedVal;
  75. }
  76. template void SIMDInt64x2Operation::OpTrunc<int64>(SIMDValue* dst, SIMDValue* src);
  77. template void SIMDInt64x2Operation::OpTrunc<uint64>(SIMDValue* dst, SIMDValue* src);
  78. void SIMDInt64x2Operation::OpShiftLeftByScalar(SIMDValue* dst, SIMDValue* src, int count)
  79. {
  80. count = count & SIMDUtils::SIMDGetShiftAmountMask(8);
  81. dst->i64[0] = src->i64[0] << count;
  82. dst->i64[1] = src->i64[1] << count;
  83. }
  84. void SIMDInt64x2Operation::OpShiftRightByScalar(SIMDValue* dst, SIMDValue* src, int count)
  85. {
  86. count = count & SIMDUtils::SIMDGetShiftAmountMask(8);
  87. dst->i64[0] = src->i64[0] >> count;
  88. dst->i64[1] = src->i64[1] >> count;
  89. }
  90. void SIMDInt64x2Operation::OpShiftRightByScalarU(SIMDValue* dst, SIMDValue* src, int count)
  91. {
  92. count = count & SIMDUtils::SIMDGetShiftAmountMask(8);
  93. dst->i64[0] = (uint64)src->i64[0] >> count;
  94. dst->i64[1] = (uint64)src->i64[1] >> count;
  95. }
  96. void SIMDInt64x2Operation::OpReplaceLane(SIMDValue* dst, SIMDValue* src, int64 val, uint index)
  97. {
  98. dst->SetValue(*src);
  99. dst->i64[index] = val;
  100. }
  101. }