1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "test/cctest/cctest.h"
6 #include "test/cctest/wasm/wasm-run-utils.h"
7 #include "test/common/wasm/wasm-macro-gen.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace wasm {
12
WASM_EXEC_TEST(I32SExtendI8)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 CHECK_EQ(0, r.Call(0));
17 CHECK_EQ(1, r.Call(1));
18 CHECK_EQ(-1, r.Call(-1));
19 CHECK_EQ(0x7a, r.Call(0x7a));
20 CHECK_EQ(-0x80, r.Call(0x80));
21 }
22
WASM_EXEC_TEST(I32SExtendI16)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 CHECK_EQ(0, r.Call(0));
27 CHECK_EQ(1, r.Call(1));
28 CHECK_EQ(-1, r.Call(-1));
29 CHECK_EQ(0x7afa, r.Call(0x7afa));
30 CHECK_EQ(-0x8000, r.Call(0x8000));
31 }
32
WASM_EXEC_TEST(I64SExtendI8)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 CHECK_EQ(0, r.Call(0));
37 CHECK_EQ(1, r.Call(1));
38 CHECK_EQ(-1, r.Call(-1));
39 CHECK_EQ(0x7a, r.Call(0x7a));
40 CHECK_EQ(-0x80, r.Call(0x80));
41 }
42
WASM_EXEC_TEST(I64SExtendI16)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 CHECK_EQ(0, r.Call(0));
47 CHECK_EQ(1, r.Call(1));
48 CHECK_EQ(-1, r.Call(-1));
49 CHECK_EQ(0x7afa, r.Call(0x7afa));
50 CHECK_EQ(-0x8000, r.Call(0x8000));
51 }
52
WASM_EXEC_TEST(I64SExtendI32)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 CHECK_EQ(0, r.Call(0));
57 CHECK_EQ(1, r.Call(1));
58 CHECK_EQ(-1, r.Call(-1));
59 CHECK_EQ(0x7fffffff, r.Call(0x7fffffff));
60 CHECK_EQ(-0x80000000LL, r.Call(0x80000000));
61 }
62
63 } // namespace wasm
64 } // namespace internal
65 } // namespace v8
66