OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 | 10 |
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 int32_t expected = memory[i] | (memory[i + 1] << 8); | 1854 int32_t expected = memory[i] | (memory[i + 1] << 8); |
1855 CHECK_EQ(expected, r.Call(i)); | 1855 CHECK_EQ(expected, r.Call(i)); |
1856 } | 1856 } |
1857 } | 1857 } |
1858 | 1858 |
1859 WASM_EXEC_TEST(Int32Global) { | 1859 WASM_EXEC_TEST(Int32Global) { |
1860 TestingModule module(execution_mode); | 1860 TestingModule module(execution_mode); |
1861 int32_t* global = module.AddGlobal<int32_t>(kAstI32); | 1861 int32_t* global = module.AddGlobal<int32_t>(kAstI32); |
1862 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1862 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1863 // global = global + p0 | 1863 // global = global + p0 |
1864 BUILD(r, WASM_STORE_GLOBAL( | 1864 BUILD(r, WASM_SET_GLOBAL( |
1865 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); | 1865 0, WASM_I32_ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0)))); |
1866 | 1866 |
1867 *global = 116; | 1867 *global = 116; |
1868 for (int i = 9; i < 444444; i += 111111) { | 1868 for (int i = 9; i < 444444; i += 111111) { |
1869 int32_t expected = *global + i; | 1869 int32_t expected = *global + i; |
1870 r.Call(i); | 1870 r.Call(i); |
1871 CHECK_EQ(expected, *global); | 1871 CHECK_EQ(expected, *global); |
1872 } | 1872 } |
1873 } | 1873 } |
1874 | 1874 |
1875 WASM_EXEC_TEST(Int32Globals_DontAlias) { | 1875 WASM_EXEC_TEST(Int32Globals_DontAlias) { |
1876 const int kNumGlobals = 3; | 1876 const int kNumGlobals = 3; |
1877 TestingModule module(execution_mode); | 1877 TestingModule module(execution_mode); |
1878 int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32), | 1878 int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32), |
1879 module.AddGlobal<int32_t>(kAstI32), | 1879 module.AddGlobal<int32_t>(kAstI32), |
1880 module.AddGlobal<int32_t>(kAstI32)}; | 1880 module.AddGlobal<int32_t>(kAstI32)}; |
1881 | 1881 |
1882 for (int g = 0; g < kNumGlobals; ++g) { | 1882 for (int g = 0; g < kNumGlobals; ++g) { |
1883 // global = global + p0 | 1883 // global = global + p0 |
1884 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1884 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1885 BUILD(r, WASM_STORE_GLOBAL( | 1885 BUILD(r, WASM_SET_GLOBAL( |
1886 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); | 1886 g, WASM_I32_ADD(WASM_GET_GLOBAL(g), WASM_GET_LOCAL(0)))); |
1887 | 1887 |
1888 // Check that reading/writing global number {g} doesn't alter the others. | 1888 // Check that reading/writing global number {g} doesn't alter the others. |
1889 *globals[g] = 116 * g; | 1889 *globals[g] = 116 * g; |
1890 int32_t before[kNumGlobals]; | 1890 int32_t before[kNumGlobals]; |
1891 for (int i = 9; i < 444444; i += 111113) { | 1891 for (int i = 9; i < 444444; i += 111113) { |
1892 int32_t sum = *globals[g] + i; | 1892 int32_t sum = *globals[g] + i; |
1893 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j]; | 1893 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j]; |
1894 r.Call(i); | 1894 r.Call(i); |
1895 for (int j = 0; j < kNumGlobals; ++j) { | 1895 for (int j = 0; j < kNumGlobals; ++j) { |
1896 int32_t expected = j == g ? sum : before[j]; | 1896 int32_t expected = j == g ? sum : before[j]; |
1897 CHECK_EQ(expected, *globals[j]); | 1897 CHECK_EQ(expected, *globals[j]); |
1898 } | 1898 } |
1899 } | 1899 } |
1900 } | 1900 } |
1901 } | 1901 } |
1902 | 1902 |
1903 WASM_EXEC_TEST(Float32Global) { | 1903 WASM_EXEC_TEST(Float32Global) { |
1904 TestingModule module(execution_mode); | 1904 TestingModule module(execution_mode); |
1905 float* global = module.AddGlobal<float>(kAstF32); | 1905 float* global = module.AddGlobal<float>(kAstF32); |
1906 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1906 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1907 // global = global + p0 | 1907 // global = global + p0 |
1908 BUILD(r, B2(WASM_STORE_GLOBAL( | 1908 BUILD(r, B2(WASM_SET_GLOBAL( |
1909 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), | 1909 0, WASM_F32_ADD(WASM_GET_GLOBAL(0), |
1910 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1910 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1911 WASM_ZERO)); | 1911 WASM_ZERO)); |
1912 | 1912 |
1913 *global = 1.25; | 1913 *global = 1.25; |
1914 for (int i = 9; i < 4444; i += 1111) { | 1914 for (int i = 9; i < 4444; i += 1111) { |
1915 volatile float expected = *global + i; | 1915 volatile float expected = *global + i; |
1916 r.Call(i); | 1916 r.Call(i); |
1917 CHECK_EQ(expected, *global); | 1917 CHECK_EQ(expected, *global); |
1918 } | 1918 } |
1919 } | 1919 } |
1920 | 1920 |
1921 WASM_EXEC_TEST(Float64Global) { | 1921 WASM_EXEC_TEST(Float64Global) { |
1922 TestingModule module(execution_mode); | 1922 TestingModule module(execution_mode); |
1923 double* global = module.AddGlobal<double>(kAstF64); | 1923 double* global = module.AddGlobal<double>(kAstF64); |
1924 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1924 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1925 // global = global + p0 | 1925 // global = global + p0 |
1926 BUILD(r, B2(WASM_STORE_GLOBAL( | 1926 BUILD(r, B2(WASM_SET_GLOBAL( |
1927 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), | 1927 0, WASM_F64_ADD(WASM_GET_GLOBAL(0), |
1928 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1928 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1929 WASM_ZERO)); | 1929 WASM_ZERO)); |
1930 | 1930 |
1931 *global = 1.25; | 1931 *global = 1.25; |
1932 for (int i = 9; i < 4444; i += 1111) { | 1932 for (int i = 9; i < 4444; i += 1111) { |
1933 volatile double expected = *global + i; | 1933 volatile double expected = *global + i; |
1934 r.Call(i); | 1934 r.Call(i); |
1935 CHECK_EQ(expected, *global); | 1935 CHECK_EQ(expected, *global); |
1936 } | 1936 } |
1937 } | 1937 } |
1938 | 1938 |
1939 WASM_EXEC_TEST(MixedGlobals) { | 1939 WASM_EXEC_TEST(MixedGlobals) { |
1940 TestingModule module(execution_mode); | 1940 TestingModule module(execution_mode); |
1941 int32_t* unused = module.AddGlobal<int32_t>(kAstI32); | 1941 int32_t* unused = module.AddGlobal<int32_t>(kAstI32); |
1942 byte* memory = module.AddMemory(32); | 1942 byte* memory = module.AddMemory(32); |
1943 | 1943 |
1944 int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32); | 1944 int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32); |
1945 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32); | 1945 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32); |
1946 float* var_float = module.AddGlobal<float>(kAstF32); | 1946 float* var_float = module.AddGlobal<float>(kAstF32); |
1947 double* var_double = module.AddGlobal<double>(kAstF64); | 1947 double* var_double = module.AddGlobal<double>(kAstF64); |
1948 | 1948 |
1949 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1949 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1950 | 1950 |
1951 BUILD( | 1951 BUILD( |
1952 r, | 1952 r, |
1953 WASM_BLOCK( | 1953 WASM_BLOCK( |
1954 WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), | 1954 WASM_SET_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
1955 WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)), | 1955 WASM_SET_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)), |
1956 WASM_STORE_GLOBAL(3, | 1956 WASM_SET_GLOBAL(3, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)), |
1957 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)), | 1957 WASM_SET_GLOBAL(4, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)), |
1958 WASM_STORE_GLOBAL(4, | |
1959 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)), | |
1960 WASM_ZERO)); | 1958 WASM_ZERO)); |
1961 | 1959 |
1962 memory[0] = 0xaa; | 1960 memory[0] = 0xaa; |
1963 memory[1] = 0xcc; | 1961 memory[1] = 0xcc; |
1964 memory[2] = 0x55; | 1962 memory[2] = 0x55; |
1965 memory[3] = 0xee; | 1963 memory[3] = 0xee; |
1966 memory[4] = 0x33; | 1964 memory[4] = 0x33; |
1967 memory[5] = 0x22; | 1965 memory[5] = 0x22; |
1968 memory[6] = 0x11; | 1966 memory[6] = 0x11; |
1969 memory[7] = 0x99; | 1967 memory[7] = 0x99; |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2840 MachineType::Int32()); | 2838 MachineType::Int32()); |
2841 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); | 2839 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); |
2842 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2840 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2843 CHECK_EQ(0, r.Call(133, 100)); | 2841 CHECK_EQ(0, r.Call(133, 100)); |
2844 CHECK_EQ(0, r.Call(kMin, -1)); | 2842 CHECK_EQ(0, r.Call(kMin, -1)); |
2845 CHECK_EQ(0, r.Call(0, 1)); | 2843 CHECK_EQ(0, r.Call(0, 1)); |
2846 CHECK_TRAP(r.Call(100, 0)); | 2844 CHECK_TRAP(r.Call(100, 0)); |
2847 CHECK_TRAP(r.Call(-1001, 0)); | 2845 CHECK_TRAP(r.Call(-1001, 0)); |
2848 CHECK_TRAP(r.Call(kMin, 0)); | 2846 CHECK_TRAP(r.Call(kMin, 0)); |
2849 } | 2847 } |
OLD | NEW |