SimdBool32x4OperationX86X64.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 _M_IX86 || _M_AMD64
  7. namespace Js
  8. {
  9. SIMDValue SIMDBool32x4Operation::OpBool32x4(bool x, bool y, bool z, bool w)
  10. {
  11. X86SIMDValue x86Result;
  12. x86Result.m128i_value = _mm_set_epi32(w?-1:0, z?-1:0, y?-1:0, x?-1:0);
  13. return X86SIMDValue::ToSIMDValue(x86Result);
  14. }
  15. SIMDValue SIMDBool32x4Operation::OpBool32x4(const SIMDValue& v)
  16. {
  17. // overload function with input parameter as SIMDValue for completeness
  18. SIMDValue result;
  19. result = v;
  20. return result;
  21. }
  22. // Unary Ops
  23. template <typename T>
  24. bool SIMDBool32x4Operation::OpAnyTrue(const SIMDValue& simd)
  25. {
  26. SIMDValue canonSimd = SIMDUtils::CanonicalizeToBools<T>(simd); //copy-by-value since we need to modify the copy
  27. X86SIMDValue x86Simd = X86SIMDValue::ToX86SIMDValue(canonSimd);
  28. int mask_8 = _mm_movemask_epi8(x86Simd.m128i_value); //latency 3, throughput 1
  29. return mask_8 != 0;
  30. }
  31. template <typename T>
  32. bool SIMDBool32x4Operation::OpAllTrue(const SIMDValue& simd)
  33. {
  34. SIMDValue canonSimd = SIMDUtils::CanonicalizeToBools<T>(simd); //copy-by-value since we need to modify the copy
  35. X86SIMDValue x86Simd = X86SIMDValue::ToX86SIMDValue(canonSimd);
  36. int mask_8 = _mm_movemask_epi8(x86Simd.m128i_value); //latency 3, throughput 1
  37. return mask_8 == 0xFFFF;
  38. }
  39. template bool SIMDBool32x4Operation::OpAllTrue<int64>(const SIMDValue& simd);
  40. template bool SIMDBool32x4Operation::OpAllTrue<int32>(const SIMDValue& simd);
  41. template bool SIMDBool32x4Operation::OpAllTrue<int16>(const SIMDValue& simd);
  42. template bool SIMDBool32x4Operation::OpAllTrue<int8>(const SIMDValue& simd);
  43. //
  44. template bool SIMDBool32x4Operation::OpAnyTrue<int64>(const SIMDValue& simd);
  45. template bool SIMDBool32x4Operation::OpAnyTrue<int32>(const SIMDValue& simd);
  46. template bool SIMDBool32x4Operation::OpAnyTrue<int16>(const SIMDValue& simd);
  47. template bool SIMDBool32x4Operation::OpAnyTrue<int8>(const SIMDValue& simd);
  48. }
  49. #endif