wasm-atomics-utils.h 1.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WASM_ATOMICOP_UTILS_H
#define WASM_ATOMICOP_UTILS_H

#include "test/cctest/cctest.h"
#include "test/cctest/compiler/value-helper.h"
#include "test/cctest/wasm/wasm-run-utils.h"

namespace v8 {
namespace internal {
namespace wasm {

16 17 18 19 20 21 22 23
#define OPERATION_LIST(V) \
  V(Add)                  \
  V(Sub)                  \
  V(And)                  \
  V(Or)                   \
  V(Xor)                  \
  V(Exchange)

24 25 26 27
using Uint64BinOp = uint64_t (*)(uint64_t, uint64_t);
using Uint32BinOp = uint32_t (*)(uint32_t, uint32_t);
using Uint16BinOp = uint16_t (*)(uint16_t, uint16_t);
using Uint8BinOp = uint8_t (*)(uint8_t, uint8_t);
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

template <typename T>
T Add(T a, T b) {
  return a + b;
}

template <typename T>
T Sub(T a, T b) {
  return a - b;
}

template <typename T>
T And(T a, T b) {
  return a & b;
}

template <typename T>
T Or(T a, T b) {
  return a | b;
}

template <typename T>
T Xor(T a, T b) {
  return a ^ b;
}

template <typename T>
T Exchange(T a, T b) {
  return b;
}

template <typename T>
T CompareExchange(T initial, T a, T b) {
  if (initial == a) return b;
  return a;
}

}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif