Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/include/executor/engine/unary_numeric.ipp
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
#include "common/roundeven.h"
5
#include "executor/executor.h"
6
7
#include <cmath>
8
9
namespace WasmEdge {
10
namespace Executor {
11
12
0
template <typename T> TypeU<T> Executor::runClzOp(ValVariant &Val) const {
13
0
  T I = Val.get<T>();
14
  // Return the count of leading zero bits in i.
15
0
  if (I != 0U) {
16
0
    T Cnt = 0;
17
0
    T Mask = static_cast<T>(0x1U) << (sizeof(T) * 8 - 1);
18
0
    while ((I & Mask) == 0U) {
19
0
      Cnt++;
20
0
      I <<= 1;
21
0
    }
22
0
    Val.get<T>() = Cnt;
23
0
  } else {
24
0
    Val.get<T>() = static_cast<T>(sizeof(T) * 8);
25
0
  }
26
0
  return {};
27
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmUnsignV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runClzOp<unsigned int>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmUnsignV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runClzOp<unsigned long>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
28
29
0
template <typename T> TypeU<T> Executor::runCtzOp(ValVariant &Val) const {
30
0
  T I = Val.get<T>();
31
  // Return the count of trailing zero bits in i.
32
0
  if (I != 0U) {
33
0
    T Cnt = 0;
34
0
    T Mask = static_cast<T>(0x1U);
35
0
    while ((I & Mask) == 0U) {
36
0
      Cnt++;
37
0
      I >>= 1;
38
0
    }
39
0
    Val.get<T>() = Cnt;
40
0
  } else {
41
0
    Val.get<T>() = static_cast<T>(sizeof(T) * 8);
42
0
  }
43
0
  return {};
44
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmUnsignV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runCtzOp<unsigned int>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmUnsignV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runCtzOp<unsigned long>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
45
46
0
template <typename T> TypeU<T> Executor::runPopcntOp(ValVariant &Val) const {
47
0
  T I = Val.get<T>();
48
  // Return the count of non-zero bits in i.
49
0
  if (I != 0U) {
50
0
    T Cnt = 0;
51
0
    T Mask = static_cast<T>(0x1U);
52
0
    while (I != 0U) {
53
0
      if (I & Mask) {
54
0
        Cnt++;
55
0
      }
56
0
      I >>= 1;
57
0
    }
58
0
    Val.get<T>() = Cnt;
59
0
  }
60
0
  return {};
61
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmUnsignV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runPopcntOp<unsigned int>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmUnsignV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runPopcntOp<unsigned long>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
62
63
0
template <typename T> TypeF<T> Executor::runAbsOp(ValVariant &Val) const {
64
#if defined(_MSC_VER) && !defined(__clang__) // MSVC
65
  // In MSVC, std::fabs cannot be used. If input is NAN, std::fabs will set the
66
  // highest bit of fraction.
67
  T &Fp = Val.get<T>();
68
  static_assert(std::is_floating_point_v<T>);
69
  if constexpr (sizeof(T) == 4) {
70
    uint32_t Tmp = reinterpret_cast<uint32_t &>(Fp) & UINT32_C(0x7fffffff);
71
    Val.get<T>() = reinterpret_cast<T &>(Tmp);
72
  } else {
73
    uint64_t Tmp =
74
        reinterpret_cast<uint64_t &>(Fp) & UINT64_C(0x7fffffffffffffff);
75
    Val.get<T>() = reinterpret_cast<T &>(Tmp);
76
  }
77
#else
78
0
  Val.get<T>() = std::fabs(Val.get<T>());
79
0
#endif
80
0
  return {};
81
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runAbsOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runAbsOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
82
83
0
template <typename T> TypeF<T> Executor::runNegOp(ValVariant &Val) const {
84
0
  Val.get<T>() = -Val.get<T>();
85
0
  return {};
86
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runNegOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runNegOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
87
88
0
template <typename T> TypeF<T> Executor::runCeilOp(ValVariant &Val) const {
89
0
  Val.get<T>() = std::ceil(Val.get<T>());
90
0
  return {};
91
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runCeilOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runCeilOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
92
93
0
template <typename T> TypeF<T> Executor::runFloorOp(ValVariant &Val) const {
94
0
  Val.get<T>() = std::floor(Val.get<T>());
95
0
  return {};
96
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runFloorOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runFloorOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
97
98
0
template <typename T> TypeF<T> Executor::runTruncOp(ValVariant &Val) const {
99
0
  Val.get<T>() = std::trunc(Val.get<T>());
100
0
  return {};
101
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runTruncOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runTruncOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
102
103
0
template <typename T> TypeF<T> Executor::runNearestOp(ValVariant &Val) const {
104
0
  Val.get<T>() = WasmEdge::roundeven(Val.get<T>());
105
0
  return {};
106
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runNearestOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runNearestOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
107
108
0
template <typename T> TypeF<T> Executor::runSqrtOp(ValVariant &Val) const {
109
0
  Val.get<T>() = std::sqrt(Val.get<T>());
110
0
  return {};
111
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runSqrtOp<float>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
Unexecuted instantiation: std::__1::enable_if<IsWasmFloatV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runSqrtOp<double>(WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>&) const
112
113
} // namespace Executor
114
} // namespace WasmEdge
115
116
#if defined(_MSC_VER) && !defined(__clang__) // MSVC
117
#include "executor/engine/unary_numeric_vector_msvc.ipp"
118
#else
119
#include "executor/engine/unary_numeric_vector.ipp"
120
#endif // MSVC