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/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 | 10 |
(...skipping 2449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2460 | 2460 |
2461 // Build the target function. | 2461 // Build the target function. |
2462 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2462 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2463 uint32_t index = t.CompileAndAdd(); | 2463 uint32_t index = t.CompileAndAdd(); |
2464 | 2464 |
2465 // Builder the caller function. | 2465 // Builder the caller function. |
2466 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); | 2466 WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32()); |
2467 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2467 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2468 | 2468 |
2469 FOR_FLOAT32_INPUTS(i) { | 2469 FOR_FLOAT32_INPUTS(i) { |
2470 FOR_FLOAT32_INPUTS(j) { | 2470 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); } |
2471 volatile float expected = *i - *j; | |
2472 CheckFloatEq(expected, r.Call(*i, *j)); | |
2473 } | |
2474 } | 2471 } |
2475 } | 2472 } |
2476 | 2473 |
2477 | 2474 |
2478 TEST(Run_WasmCall_Float64Sub) { | 2475 TEST(Run_WasmCall_Float64Sub) { |
2479 TestingModule module; | 2476 TestingModule module; |
2480 double* memory = module.AddMemoryElems<double>(16); | 2477 double* memory = module.AddMemoryElems<double>(16); |
2481 WasmRunner<int32_t> r(&module); | 2478 WasmRunner<int32_t> r(&module); |
2482 | 2479 |
2483 // TODO(titzer): convert to a binop test. | 2480 // TODO(titzer): convert to a binop test. |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2903 | 2900 |
2904 CHECK_TRAP(r.Call(0)); | 2901 CHECK_TRAP(r.Call(0)); |
2905 CHECK_TRAP(r.Call(1)); | 2902 CHECK_TRAP(r.Call(1)); |
2906 CHECK_TRAP(r.Call(2)); | 2903 CHECK_TRAP(r.Call(2)); |
2907 } | 2904 } |
2908 | 2905 |
2909 TEST(Run_Wasm_F32Floor) { | 2906 TEST(Run_Wasm_F32Floor) { |
2910 WasmRunner<float> r(MachineType::Float32()); | 2907 WasmRunner<float> r(MachineType::Float32()); |
2911 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); | 2908 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); |
2912 | 2909 |
2913 FOR_FLOAT32_INPUTS(i) { CheckFloatEq(floorf(*i), r.Call(*i)); } | 2910 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } |
2914 } | 2911 } |
2915 | 2912 |
2916 TEST(Run_Wasm_F32Ceil) { | 2913 TEST(Run_Wasm_F32Ceil) { |
2917 WasmRunner<float> r(MachineType::Float32()); | 2914 WasmRunner<float> r(MachineType::Float32()); |
2918 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); | 2915 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); |
2919 | 2916 |
2920 FOR_FLOAT32_INPUTS(i) { CheckFloatEq(ceilf(*i), r.Call(*i)); } | 2917 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); } |
2921 } | 2918 } |
2922 | 2919 |
2923 TEST(Run_Wasm_F32Trunc) { | 2920 TEST(Run_Wasm_F32Trunc) { |
2924 WasmRunner<float> r(MachineType::Float32()); | 2921 WasmRunner<float> r(MachineType::Float32()); |
2925 BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0))); | 2922 BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0))); |
2926 | 2923 |
2927 FOR_FLOAT32_INPUTS(i) { CheckFloatEq(truncf(*i), r.Call(*i)); } | 2924 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); } |
2928 } | 2925 } |
2929 | 2926 |
2930 TEST(Run_Wasm_F32NearestInt) { | 2927 TEST(Run_Wasm_F32NearestInt) { |
2931 WasmRunner<float> r(MachineType::Float32()); | 2928 WasmRunner<float> r(MachineType::Float32()); |
2932 BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0))); | 2929 BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0))); |
2933 | 2930 |
2934 FOR_FLOAT32_INPUTS(i) { CheckFloatEq(nearbyintf(*i), r.Call(*i)); } | 2931 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); } |
2935 } | 2932 } |
2936 | 2933 |
2937 TEST(Run_Wasm_F64Floor) { | 2934 TEST(Run_Wasm_F64Floor) { |
2938 WasmRunner<double> r(MachineType::Float64()); | 2935 WasmRunner<double> r(MachineType::Float64()); |
2939 BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0))); | 2936 BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0))); |
2940 | 2937 |
2941 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(floor(*i), r.Call(*i)); } | 2938 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); } |
2942 } | 2939 } |
2943 | 2940 |
2944 TEST(Run_Wasm_F64Ceil) { | 2941 TEST(Run_Wasm_F64Ceil) { |
2945 WasmRunner<double> r(MachineType::Float64()); | 2942 WasmRunner<double> r(MachineType::Float64()); |
2946 BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0))); | 2943 BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0))); |
2947 | 2944 |
2948 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(ceil(*i), r.Call(*i)); } | 2945 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); } |
2949 } | 2946 } |
2950 | 2947 |
2951 TEST(Run_Wasm_F64Trunc) { | 2948 TEST(Run_Wasm_F64Trunc) { |
2952 WasmRunner<double> r(MachineType::Float64()); | 2949 WasmRunner<double> r(MachineType::Float64()); |
2953 BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0))); | 2950 BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0))); |
2954 | 2951 |
2955 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(trunc(*i), r.Call(*i)); } | 2952 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); } |
2956 } | 2953 } |
2957 | 2954 |
2958 TEST(Run_Wasm_F64NearestInt) { | 2955 TEST(Run_Wasm_F64NearestInt) { |
2959 WasmRunner<double> r(MachineType::Float64()); | 2956 WasmRunner<double> r(MachineType::Float64()); |
2960 BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0))); | 2957 BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0))); |
2961 | 2958 |
2962 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(nearbyint(*i), r.Call(*i)); } | 2959 FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); } |
2963 } | 2960 } |
2964 | 2961 |
2965 TEST(Run_Wasm_F32Min) { | 2962 TEST(Run_Wasm_F32Min) { |
2966 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 2963 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); |
2967 BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2964 BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2968 | 2965 |
2969 FOR_FLOAT32_INPUTS(i) { | 2966 FOR_FLOAT32_INPUTS(i) { |
2970 FOR_FLOAT32_INPUTS(j) { | 2967 FOR_FLOAT32_INPUTS(j) { |
2971 float expected; | 2968 float expected; |
2972 if (*i < *j) { | 2969 if (*i < *j) { |
2973 expected = *i; | 2970 expected = *i; |
2974 } else if (*j < *i) { | 2971 } else if (*j < *i) { |
2975 expected = *j; | 2972 expected = *j; |
2976 } else if (*i != *i) { | 2973 } else if (*i != *i) { |
2977 // If *i or *j is NaN, then the result is NaN. | 2974 // If *i or *j is NaN, then the result is NaN. |
2978 expected = *i; | 2975 expected = *i; |
2979 } else { | 2976 } else { |
2980 expected = *j; | 2977 expected = *j; |
2981 } | 2978 } |
2982 | 2979 |
2983 CheckFloatEq(expected, r.Call(*i, *j)); | 2980 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); |
2984 } | 2981 } |
2985 } | 2982 } |
2986 } | 2983 } |
2987 | 2984 |
2988 | 2985 |
2989 TEST(Run_Wasm_F64Min) { | 2986 TEST(Run_Wasm_F64Min) { |
2990 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 2987 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); |
2991 BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 2988 BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
2992 | 2989 |
2993 FOR_FLOAT64_INPUTS(i) { | 2990 FOR_FLOAT64_INPUTS(i) { |
2994 FOR_FLOAT64_INPUTS(j) { | 2991 FOR_FLOAT64_INPUTS(j) { |
2995 double expected; | 2992 double expected; |
2996 if (*i < *j) { | 2993 if (*i < *j) { |
2997 expected = *i; | 2994 expected = *i; |
2998 } else if (*j < *i) { | 2995 } else if (*j < *i) { |
2999 expected = *j; | 2996 expected = *j; |
3000 } else if (*i != *i) { | 2997 } else if (*i != *i) { |
3001 // If *i or *j is NaN, then the result is NaN. | 2998 // If *i or *j is NaN, then the result is NaN. |
3002 expected = *i; | 2999 expected = *i; |
3003 } else { | 3000 } else { |
3004 expected = *j; | 3001 expected = *j; |
3005 } | 3002 } |
3006 | 3003 |
3007 CheckDoubleEq(expected, r.Call(*i, *j)); | 3004 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); |
3008 } | 3005 } |
3009 } | 3006 } |
3010 } | 3007 } |
3011 | 3008 |
3012 | 3009 |
3013 TEST(Run_Wasm_F32Max) { | 3010 TEST(Run_Wasm_F32Max) { |
3014 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 3011 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); |
3015 BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 3012 BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
3016 | 3013 |
3017 FOR_FLOAT32_INPUTS(i) { | 3014 FOR_FLOAT32_INPUTS(i) { |
3018 FOR_FLOAT32_INPUTS(j) { | 3015 FOR_FLOAT32_INPUTS(j) { |
3019 float expected; | 3016 float expected; |
3020 if (*i > *j) { | 3017 if (*i > *j) { |
3021 expected = *i; | 3018 expected = *i; |
3022 } else if (*j > *i) { | 3019 } else if (*j > *i) { |
3023 expected = *j; | 3020 expected = *j; |
3024 } else if (*i != *i) { | 3021 } else if (*i != *i) { |
3025 // If *i or *j is NaN, then the result is NaN. | 3022 // If *i or *j is NaN, then the result is NaN. |
3026 expected = *i; | 3023 expected = *i; |
3027 } else { | 3024 } else { |
3028 expected = *j; | 3025 expected = *j; |
3029 } | 3026 } |
3030 | 3027 |
3031 CheckFloatEq(expected, r.Call(*i, *j)); | 3028 CHECK_FLOAT_EQ(expected, r.Call(*i, *j)); |
3032 } | 3029 } |
3033 } | 3030 } |
3034 } | 3031 } |
3035 | 3032 |
3036 | 3033 |
3037 TEST(Run_Wasm_F64Max) { | 3034 TEST(Run_Wasm_F64Max) { |
3038 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 3035 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); |
3039 BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 3036 BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
3040 | 3037 |
3041 FOR_FLOAT64_INPUTS(i) { | 3038 FOR_FLOAT64_INPUTS(i) { |
3042 FOR_FLOAT64_INPUTS(j) { | 3039 FOR_FLOAT64_INPUTS(j) { |
3043 double expected; | 3040 double expected; |
3044 if (*i > *j) { | 3041 if (*i > *j) { |
3045 expected = *i; | 3042 expected = *i; |
3046 } else if (*j > *i) { | 3043 } else if (*j > *i) { |
3047 expected = *j; | 3044 expected = *j; |
3048 } else if (*i != *i) { | 3045 } else if (*i != *i) { |
3049 // If *i or *j is NaN, then the result is NaN. | 3046 // If *i or *j is NaN, then the result is NaN. |
3050 expected = *i; | 3047 expected = *i; |
3051 } else { | 3048 } else { |
3052 expected = *j; | 3049 expected = *j; |
3053 } | 3050 } |
3054 | 3051 |
3055 CheckDoubleEq(expected, r.Call(*i, *j)); | 3052 CHECK_DOUBLE_EQ(expected, r.Call(*i, *j)); |
3056 } | 3053 } |
3057 } | 3054 } |
3058 } | 3055 } |
3059 | 3056 |
3060 // TODO(ahaas): Fix on arm and mips and reenable. | 3057 // TODO(ahaas): Fix on arm and mips and reenable. |
3061 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS && \ | 3058 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS && \ |
3062 !V8_TARGET_ARCH_MIPS64 | 3059 !V8_TARGET_ARCH_MIPS64 |
3063 | 3060 |
3064 TEST(Run_Wasm_F32Min_Snan) { | 3061 TEST(Run_Wasm_F32Min_Snan) { |
3065 // Test that the instruction does not return a signalling NaN. | 3062 // Test that the instruction does not return a signalling NaN. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3280 } | 3277 } |
3281 } | 3278 } |
3282 #endif | 3279 #endif |
3283 | 3280 |
3284 | 3281 |
3285 TEST(Run_Wasm_F64CopySign) { | 3282 TEST(Run_Wasm_F64CopySign) { |
3286 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); | 3283 WasmRunner<double> r(MachineType::Float64(), MachineType::Float64()); |
3287 BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 3284 BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
3288 | 3285 |
3289 FOR_FLOAT64_INPUTS(i) { | 3286 FOR_FLOAT64_INPUTS(i) { |
3290 FOR_FLOAT64_INPUTS(j) { CheckDoubleEq(copysign(*i, *j), r.Call(*i, *j)); } | 3287 FOR_FLOAT64_INPUTS(j) { CHECK_DOUBLE_EQ(copysign(*i, *j), r.Call(*i, *j)); } |
3291 } | 3288 } |
3292 } | 3289 } |
3293 | 3290 |
3294 | 3291 |
3295 // TODO(tizer): Fix on arm and reenable. | 3292 // TODO(tizer): Fix on arm and reenable. |
3296 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64 | 3293 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64 |
3297 | 3294 |
3298 TEST(Run_Wasm_F32CopySign) { | 3295 TEST(Run_Wasm_F32CopySign) { |
3299 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); | 3296 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); |
3300 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 3297 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
3301 | 3298 |
3302 FOR_FLOAT32_INPUTS(i) { | 3299 FOR_FLOAT32_INPUTS(i) { |
3303 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); } | 3300 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysign(*i, *j), r.Call(*i, *j)); } |
3304 } | 3301 } |
3305 } | 3302 } |
3306 | 3303 |
3307 | 3304 |
3308 #endif | 3305 #endif |
3309 | 3306 |
3310 | 3307 |
3311 void CompileCallIndirectMany(LocalType param) { | 3308 void CompileCallIndirectMany(LocalType param) { |
3312 // Make sure we don't run out of registers when compiling indirect calls | 3309 // Make sure we don't run out of registers when compiling indirect calls |
3313 // with many many parameters. | 3310 // with many many parameters. |
(...skipping 28 matching lines...) Expand all Loading... |
3342 | 3339 |
3343 #if WASM_64 | 3340 #if WASM_64 |
3344 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 3341 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
3345 #endif | 3342 #endif |
3346 | 3343 |
3347 | 3344 |
3348 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 3345 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
3349 | 3346 |
3350 | 3347 |
3351 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 3348 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
OLD | NEW |