test-run-wasm-sign-extension.cc 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2017 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.

#include "test/cctest/cctest.h"
#include "test/cctest/wasm/wasm-run-utils.h"
#include "test/common/wasm/wasm-macro-gen.h"

namespace v8 {
namespace internal {
namespace wasm {

13
WASM_EXEC_TEST(I32SExtendI8) {
14
  WasmRunner<int32_t, int32_t> r(execution_tier);
15
  BUILD(r, WASM_I32_SIGN_EXT_I8(WASM_LOCAL_GET(0)));
16 17 18 19 20 21 22
  CHECK_EQ(0, r.Call(0));
  CHECK_EQ(1, r.Call(1));
  CHECK_EQ(-1, r.Call(-1));
  CHECK_EQ(0x7a, r.Call(0x7a));
  CHECK_EQ(-0x80, r.Call(0x80));
}

23
WASM_EXEC_TEST(I32SExtendI16) {
24
  WasmRunner<int32_t, int32_t> r(execution_tier);
25
  BUILD(r, WASM_I32_SIGN_EXT_I16(WASM_LOCAL_GET(0)));
26 27 28 29 30 31
  CHECK_EQ(0, r.Call(0));
  CHECK_EQ(1, r.Call(1));
  CHECK_EQ(-1, r.Call(-1));
  CHECK_EQ(0x7afa, r.Call(0x7afa));
  CHECK_EQ(-0x8000, r.Call(0x8000));
}
32

33
WASM_EXEC_TEST(I64SExtendI8) {
34
  WasmRunner<int64_t, int64_t> r(execution_tier);
35
  BUILD(r, WASM_I64_SIGN_EXT_I8(WASM_LOCAL_GET(0)));
36 37 38 39 40 41 42
  CHECK_EQ(0, r.Call(0));
  CHECK_EQ(1, r.Call(1));
  CHECK_EQ(-1, r.Call(-1));
  CHECK_EQ(0x7a, r.Call(0x7a));
  CHECK_EQ(-0x80, r.Call(0x80));
}

43
WASM_EXEC_TEST(I64SExtendI16) {
44
  WasmRunner<int64_t, int64_t> r(execution_tier);
45
  BUILD(r, WASM_I64_SIGN_EXT_I16(WASM_LOCAL_GET(0)));
46 47 48 49 50 51 52
  CHECK_EQ(0, r.Call(0));
  CHECK_EQ(1, r.Call(1));
  CHECK_EQ(-1, r.Call(-1));
  CHECK_EQ(0x7afa, r.Call(0x7afa));
  CHECK_EQ(-0x8000, r.Call(0x8000));
}

53
WASM_EXEC_TEST(I64SExtendI32) {
54
  WasmRunner<int64_t, int64_t> r(execution_tier);
55
  BUILD(r, WASM_I64_SIGN_EXT_I32(WASM_LOCAL_GET(0)));
56 57 58 59 60 61 62 63 64 65
  CHECK_EQ(0, r.Call(0));
  CHECK_EQ(1, r.Call(1));
  CHECK_EQ(-1, r.Call(-1));
  CHECK_EQ(0x7fffffff, r.Call(0x7fffffff));
  CHECK_EQ(-0x80000000LL, r.Call(0x80000000));
}

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