Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 2165633006: [wasm] Remove special memory type for (internal) globals and use local type instead. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [wasm] Remove special memory type for (internal) globals and use local type instead. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); 1851 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0)));
1852 1852
1853 for (int i = 0; i < kNumBytes; i += 2) { 1853 for (int i = 0; i < kNumBytes; i += 2) {
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>(MachineType::Int32()); 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_STORE_GLOBAL(
1865 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); 1865 0, WASM_I32_ADD(WASM_LOAD_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>(MachineType::Int32()), 1878 int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32),
1879 module.AddGlobal<int32_t>(MachineType::Int32()), 1879 module.AddGlobal<int32_t>(kAstI32),
1880 module.AddGlobal<int32_t>(MachineType::Int32())}; 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_STORE_GLOBAL(
1886 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); 1886 g, WASM_I32_ADD(WASM_LOAD_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>(MachineType::Float32()); 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_STORE_GLOBAL(
1909 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), 1909 0, WASM_F32_ADD(WASM_LOAD_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>(MachineType::Float64()); 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_STORE_GLOBAL(
1927 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), 1927 0, WASM_F64_ADD(WASM_LOAD_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>(MachineType::Int32()); 1941 int32_t* unused = module.AddGlobal<int32_t>(kAstI32);
1942 byte* memory = module.AddMemory(32); 1942 byte* memory = module.AddMemory(32);
1943 1943
1944 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); 1944 int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32);
1945 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); 1945 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32);
1946 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); 1946 float* var_float = module.AddGlobal<float>(kAstF32);
1947 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); 1947 double* var_double = module.AddGlobal<double>(kAstF64);
1948 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32());
1949 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32());
1950 float* var_float = module.AddGlobal<float>(MachineType::Float32());
1951 double* var_double = module.AddGlobal<double>(MachineType::Float64());
1952 1948
1953 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1949 WasmRunner<int32_t> r(&module, MachineType::Int32());
1954 1950
1955 BUILD( 1951 BUILD(
1956 r, 1952 r,
1957 WASM_BLOCK( 1953 WASM_BLOCK(
1958 WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int8(), WASM_ZERO)), 1954 WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
1959 WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint8(), WASM_ZERO)), 1955 WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
1960 WASM_STORE_GLOBAL(3, WASM_LOAD_MEM(MachineType::Int16(), WASM_ZERO)), 1956 WASM_STORE_GLOBAL(3,
1961 WASM_STORE_GLOBAL(4, WASM_LOAD_MEM(MachineType::Uint16(), WASM_ZERO)),
1962 WASM_STORE_GLOBAL(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
1963 WASM_STORE_GLOBAL(6, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
1964 WASM_STORE_GLOBAL(7,
1965 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)), 1957 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)),
1966 WASM_STORE_GLOBAL(8, 1958 WASM_STORE_GLOBAL(4,
1967 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)), 1959 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)),
1968 WASM_ZERO)); 1960 WASM_ZERO));
1969 1961
1970 memory[0] = 0xaa; 1962 memory[0] = 0xaa;
1971 memory[1] = 0xcc; 1963 memory[1] = 0xcc;
1972 memory[2] = 0x55; 1964 memory[2] = 0x55;
1973 memory[3] = 0xee; 1965 memory[3] = 0xee;
1974 memory[4] = 0x33; 1966 memory[4] = 0x33;
1975 memory[5] = 0x22; 1967 memory[5] = 0x22;
1976 memory[6] = 0x11; 1968 memory[6] = 0x11;
1977 memory[7] = 0x99; 1969 memory[7] = 0x99;
1978 r.Call(1); 1970 r.Call(1);
1979 1971
1980 CHECK(static_cast<int8_t>(0xaa) == *var_int8);
1981 CHECK(static_cast<uint8_t>(0xaa) == *var_uint8);
1982 CHECK(static_cast<int16_t>(0xccaa) == *var_int16);
1983 CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16);
1984 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32); 1972 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32);
1985 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32); 1973 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32);
1986 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); 1974 CHECK(bit_cast<float>(0xee55ccaa) == *var_float);
1987 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); 1975 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double);
1988 1976
1989 USE(unused); 1977 USE(unused);
1990 } 1978 }
1991 1979
1992 WASM_EXEC_TEST(CallEmpty) { 1980 WASM_EXEC_TEST(CallEmpty) {
1993 const int32_t kExpected = -414444; 1981 const int32_t kExpected = -414444;
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
2850 MachineType::Int32()); 2838 MachineType::Int32());
2851 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);
2852 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2840 const int32_t kMin = std::numeric_limits<int32_t>::min();
2853 CHECK_EQ(0, r.Call(133, 100)); 2841 CHECK_EQ(0, r.Call(133, 100));
2854 CHECK_EQ(0, r.Call(kMin, -1)); 2842 CHECK_EQ(0, r.Call(kMin, -1));
2855 CHECK_EQ(0, r.Call(0, 1)); 2843 CHECK_EQ(0, r.Call(0, 1));
2856 CHECK_TRAP(r.Call(100, 0)); 2844 CHECK_TRAP(r.Call(100, 0));
2857 CHECK_TRAP(r.Call(-1001, 0)); 2845 CHECK_TRAP(r.Call(-1001, 0));
2858 CHECK_TRAP(r.Call(kMin, 0)); 2846 CHECK_TRAP(r.Call(kMin, 0));
2859 } 2847 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698