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

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: 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
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 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); 1857 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0)));
1858 1858
1859 for (int i = 0; i < kNumBytes; i += 2) { 1859 for (int i = 0; i < kNumBytes; i += 2) {
1860 int32_t expected = memory[i] | (memory[i + 1] << 8); 1860 int32_t expected = memory[i] | (memory[i + 1] << 8);
1861 CHECK_EQ(expected, r.Call(i)); 1861 CHECK_EQ(expected, r.Call(i));
1862 } 1862 }
1863 } 1863 }
1864 1864
1865 WASM_EXEC_TEST(Int32Global) { 1865 WASM_EXEC_TEST(Int32Global) {
1866 TestingModule module(execution_mode); 1866 TestingModule module(execution_mode);
1867 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); 1867 int32_t* global = module.AddGlobal<int32_t>(kAstI32);
1868 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1868 WasmRunner<int32_t> r(&module, MachineType::Int32());
1869 // global = global + p0 1869 // global = global + p0
1870 BUILD(r, WASM_STORE_GLOBAL( 1870 BUILD(r, WASM_STORE_GLOBAL(
1871 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); 1871 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0))));
1872 1872
1873 *global = 116; 1873 *global = 116;
1874 for (int i = 9; i < 444444; i += 111111) { 1874 for (int i = 9; i < 444444; i += 111111) {
1875 int32_t expected = *global + i; 1875 int32_t expected = *global + i;
1876 r.Call(i); 1876 r.Call(i);
1877 CHECK_EQ(expected, *global); 1877 CHECK_EQ(expected, *global);
1878 } 1878 }
1879 } 1879 }
1880 1880
1881 WASM_EXEC_TEST(Int32Globals_DontAlias) { 1881 WASM_EXEC_TEST(Int32Globals_DontAlias) {
1882 const int kNumGlobals = 3; 1882 const int kNumGlobals = 3;
1883 TestingModule module(execution_mode); 1883 TestingModule module(execution_mode);
1884 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), 1884 int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32),
1885 module.AddGlobal<int32_t>(MachineType::Int32()), 1885 module.AddGlobal<int32_t>(kAstI32),
1886 module.AddGlobal<int32_t>(MachineType::Int32())}; 1886 module.AddGlobal<int32_t>(kAstI32)};
1887 1887
1888 for (int g = 0; g < kNumGlobals; ++g) { 1888 for (int g = 0; g < kNumGlobals; ++g) {
1889 // global = global + p0 1889 // global = global + p0
1890 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1890 WasmRunner<int32_t> r(&module, MachineType::Int32());
1891 BUILD(r, WASM_STORE_GLOBAL( 1891 BUILD(r, WASM_STORE_GLOBAL(
1892 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); 1892 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0))));
1893 1893
1894 // Check that reading/writing global number {g} doesn't alter the others. 1894 // Check that reading/writing global number {g} doesn't alter the others.
1895 *globals[g] = 116 * g; 1895 *globals[g] = 116 * g;
1896 int32_t before[kNumGlobals]; 1896 int32_t before[kNumGlobals];
1897 for (int i = 9; i < 444444; i += 111113) { 1897 for (int i = 9; i < 444444; i += 111113) {
1898 int32_t sum = *globals[g] + i; 1898 int32_t sum = *globals[g] + i;
1899 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j]; 1899 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j];
1900 r.Call(i); 1900 r.Call(i);
1901 for (int j = 0; j < kNumGlobals; ++j) { 1901 for (int j = 0; j < kNumGlobals; ++j) {
1902 int32_t expected = j == g ? sum : before[j]; 1902 int32_t expected = j == g ? sum : before[j];
1903 CHECK_EQ(expected, *globals[j]); 1903 CHECK_EQ(expected, *globals[j]);
1904 } 1904 }
1905 } 1905 }
1906 } 1906 }
1907 } 1907 }
1908 1908
1909 WASM_EXEC_TEST(Float32Global) { 1909 WASM_EXEC_TEST(Float32Global) {
1910 TestingModule module(execution_mode); 1910 TestingModule module(execution_mode);
1911 float* global = module.AddGlobal<float>(MachineType::Float32()); 1911 float* global = module.AddGlobal<float>(kAstF32);
1912 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1912 WasmRunner<int32_t> r(&module, MachineType::Int32());
1913 // global = global + p0 1913 // global = global + p0
1914 BUILD(r, B2(WASM_STORE_GLOBAL( 1914 BUILD(r, B2(WASM_STORE_GLOBAL(
1915 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), 1915 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0),
1916 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), 1916 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))),
1917 WASM_ZERO)); 1917 WASM_ZERO));
1918 1918
1919 *global = 1.25; 1919 *global = 1.25;
1920 for (int i = 9; i < 4444; i += 1111) { 1920 for (int i = 9; i < 4444; i += 1111) {
1921 volatile float expected = *global + i; 1921 volatile float expected = *global + i;
1922 r.Call(i); 1922 r.Call(i);
1923 CHECK_EQ(expected, *global); 1923 CHECK_EQ(expected, *global);
1924 } 1924 }
1925 } 1925 }
1926 1926
1927 WASM_EXEC_TEST(Float64Global) { 1927 WASM_EXEC_TEST(Float64Global) {
1928 TestingModule module(execution_mode); 1928 TestingModule module(execution_mode);
1929 double* global = module.AddGlobal<double>(MachineType::Float64()); 1929 double* global = module.AddGlobal<double>(kAstF64);
1930 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1930 WasmRunner<int32_t> r(&module, MachineType::Int32());
1931 // global = global + p0 1931 // global = global + p0
1932 BUILD(r, B2(WASM_STORE_GLOBAL( 1932 BUILD(r, B2(WASM_STORE_GLOBAL(
1933 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0), 1933 0, WASM_F64_ADD(WASM_LOAD_GLOBAL(0),
1934 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))), 1934 WASM_F64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
1935 WASM_ZERO)); 1935 WASM_ZERO));
1936 1936
1937 *global = 1.25; 1937 *global = 1.25;
1938 for (int i = 9; i < 4444; i += 1111) { 1938 for (int i = 9; i < 4444; i += 1111) {
1939 volatile double expected = *global + i; 1939 volatile double expected = *global + i;
1940 r.Call(i); 1940 r.Call(i);
1941 CHECK_EQ(expected, *global); 1941 CHECK_EQ(expected, *global);
1942 } 1942 }
1943 } 1943 }
1944 1944
1945 WASM_EXEC_TEST(MixedGlobals) { 1945 WASM_EXEC_TEST(MixedGlobals) {
1946 TestingModule module(execution_mode); 1946 TestingModule module(execution_mode);
1947 int32_t* unused = module.AddGlobal<int32_t>(MachineType::Int32()); 1947 int32_t* unused = module.AddGlobal<int32_t>(kAstI32);
1948 byte* memory = module.AddMemory(32); 1948 byte* memory = module.AddMemory(32);
1949 1949
1950 int8_t* var_int8 = module.AddGlobal<int8_t>(MachineType::Int8()); 1950 int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32);
1951 uint8_t* var_uint8 = module.AddGlobal<uint8_t>(MachineType::Uint8()); 1951 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32);
1952 int16_t* var_int16 = module.AddGlobal<int16_t>(MachineType::Int16()); 1952 float* var_float = module.AddGlobal<float>(kAstF32);
1953 uint16_t* var_uint16 = module.AddGlobal<uint16_t>(MachineType::Uint16()); 1953 double* var_double = module.AddGlobal<double>(kAstF64);
1954 int32_t* var_int32 = module.AddGlobal<int32_t>(MachineType::Int32());
1955 uint32_t* var_uint32 = module.AddGlobal<uint32_t>(MachineType::Uint32());
1956 float* var_float = module.AddGlobal<float>(MachineType::Float32());
1957 double* var_double = module.AddGlobal<double>(MachineType::Float64());
1958 1954
1959 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1955 WasmRunner<int32_t> r(&module, MachineType::Int32());
1960 1956
1961 BUILD( 1957 BUILD(r, WASM_BLOCK(9, WASM_STORE_GLOBAL(
1962 r, 1958 1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
1963 WASM_BLOCK( 1959 WASM_STORE_GLOBAL(
1964 9, 1960 2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
1965 WASM_STORE_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int8(), WASM_ZERO)), 1961 WASM_STORE_GLOBAL(
1966 WASM_STORE_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint8(), WASM_ZERO)), 1962 3, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)),
1967 WASM_STORE_GLOBAL(3, WASM_LOAD_MEM(MachineType::Int16(), WASM_ZERO)), 1963 WASM_STORE_GLOBAL(
1968 WASM_STORE_GLOBAL(4, WASM_LOAD_MEM(MachineType::Uint16(), WASM_ZERO)), 1964 4, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)),
1969 WASM_STORE_GLOBAL(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), 1965 WASM_ZERO));
1970 WASM_STORE_GLOBAL(6, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
1971 WASM_STORE_GLOBAL(7,
1972 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)),
1973 WASM_STORE_GLOBAL(8,
1974 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)),
1975 WASM_ZERO));
1976 1966
1977 memory[0] = 0xaa; 1967 memory[0] = 0xaa;
1978 memory[1] = 0xcc; 1968 memory[1] = 0xcc;
1979 memory[2] = 0x55; 1969 memory[2] = 0x55;
1980 memory[3] = 0xee; 1970 memory[3] = 0xee;
1981 memory[4] = 0x33; 1971 memory[4] = 0x33;
1982 memory[5] = 0x22; 1972 memory[5] = 0x22;
1983 memory[6] = 0x11; 1973 memory[6] = 0x11;
1984 memory[7] = 0x99; 1974 memory[7] = 0x99;
1985 r.Call(1); 1975 r.Call(1);
1986 1976
1987 CHECK(static_cast<int8_t>(0xaa) == *var_int8);
1988 CHECK(static_cast<uint8_t>(0xaa) == *var_uint8);
1989 CHECK(static_cast<int16_t>(0xccaa) == *var_int16);
1990 CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16);
1991 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32); 1977 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32);
1992 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32); 1978 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32);
1993 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); 1979 CHECK(bit_cast<float>(0xee55ccaa) == *var_float);
1994 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); 1980 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double);
1995 1981
1996 USE(unused); 1982 USE(unused);
1997 } 1983 }
1998 1984
1999 WASM_EXEC_TEST(CallEmpty) { 1985 WASM_EXEC_TEST(CallEmpty) {
2000 const int32_t kExpected = -414444; 1986 const int32_t kExpected = -414444;
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
2860 MachineType::Int32()); 2846 MachineType::Int32());
2861 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); 2847 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO);
2862 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2848 const int32_t kMin = std::numeric_limits<int32_t>::min();
2863 CHECK_EQ(0, r.Call(133, 100)); 2849 CHECK_EQ(0, r.Call(133, 100));
2864 CHECK_EQ(0, r.Call(kMin, -1)); 2850 CHECK_EQ(0, r.Call(kMin, -1));
2865 CHECK_EQ(0, r.Call(0, 1)); 2851 CHECK_EQ(0, r.Call(0, 1));
2866 CHECK_TRAP(r.Call(100, 0)); 2852 CHECK_TRAP(r.Call(100, 0));
2867 CHECK_TRAP(r.Call(-1001, 0)); 2853 CHECK_TRAP(r.Call(-1001, 0));
2868 CHECK_TRAP(r.Call(kMin, 0)); 2854 CHECK_TRAP(r.Call(kMin, 0));
2869 } 2855 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698