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 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2769 MachineType::Int32()); | 2769 MachineType::Int32()); |
2770 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); | 2770 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); |
2771 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2771 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2772 CHECK_EQ(0, r.Call(133, 100)); | 2772 CHECK_EQ(0, r.Call(133, 100)); |
2773 CHECK_EQ(0, r.Call(kMin, -1)); | 2773 CHECK_EQ(0, r.Call(kMin, -1)); |
2774 CHECK_EQ(0, r.Call(0, 1)); | 2774 CHECK_EQ(0, r.Call(0, 1)); |
2775 CHECK_TRAP(r.Call(100, 0)); | 2775 CHECK_TRAP(r.Call(100, 0)); |
2776 CHECK_TRAP(r.Call(-1001, 0)); | 2776 CHECK_TRAP(r.Call(-1001, 0)); |
2777 CHECK_TRAP(r.Call(kMin, 0)); | 2777 CHECK_TRAP(r.Call(kMin, 0)); |
2778 } | 2778 } |
2779 | |
2780 // TODO(jpp): WASM_EXEC_TEST(TryCatch) | |
2781 | |
2782 // TODO(jpp): Move these macros to src/wasm/wasm-macro-gen.h once zero cost | |
2783 // exceptions are added to the spec. | |
2784 #define TRY_FINALLY(...) kExprTryFinally, __VA_ARGS__, kExprEnd | |
2785 #define FINALLY(...) kExprFinally, __VA_ARGS__ | |
2786 | |
2787 WASM_EXEC_TEST(TryFinally_single) { | |
2788 if (execution_mode == kExecuteInterpreted) { | |
2789 // TODO(jpp): implement eh support in the interpreter. | |
2790 return; | |
2791 } | |
2792 | |
2793 FLAG_wasm_eh_prototype = true; | |
2794 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), | |
2795 MachineType::Int32()); | |
2796 // r(i32 p, i32 q) -> i32 { | |
2797 // try { | |
2798 // if (q) { | |
2799 // break; | |
2800 // } | |
2801 // p += 0x0f0; | |
2802 // } finally { | |
2803 // p += 0x00f; | |
2804 // } | |
2805 // p += 0xf00 | |
2806 // return p; | |
2807 // } | |
2808 BUILD(r, TRY_FINALLY( | |
2809 WASM_IF(WASM_GET_LOCAL(1), WASM_BREAK(0)), | |
2810 WASM_SET_LOCAL( | |
2811 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_2(0xf0))), | |
2812 FINALLY(WASM_SET_LOCAL( | |
2813 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(0x0f))))), | |
2814 WASM_SET_LOCAL(0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0xf00))), | |
2815 WASM_GET_LOCAL(0)); | |
2816 | |
2817 CHECK_EQ(0xFFFF, r.Call(0xF000, 0)); | |
2818 CHECK_EQ(0xFF0F, r.Call(0xF000, 1)); | |
2819 } | |
2820 | |
2821 WASM_EXEC_TEST(TryFinally_double) { | |
2822 if (execution_mode == kExecuteInterpreted) { | |
2823 // TODO(jpp): implement eh support in the interpreter. | |
2824 return; | |
2825 } | |
2826 | |
2827 FLAG_wasm_eh_prototype = true; | |
2828 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), | |
2829 MachineType::Int32()); | |
2830 // r(i32 p, i32 q) -> i32 { | |
2831 // a: try { | |
2832 // b: try { | |
2833 // if (q == 40) { | |
2834 // break a; | |
2835 // } else { | |
2836 // if (q == 1) { | |
2837 // break b; | |
2838 // } | |
2839 // } | |
2840 // p += 0x00000f; | |
2841 // } finally { | |
2842 // p += 0x0000f0; | |
2843 // } | |
2844 // p += 0x000f00; | |
2845 // } finally { | |
2846 // p += 0x00f000; | |
2847 // } | |
2848 // return p; | |
2849 // } | |
2850 BUILD( | |
2851 r, | |
2852 TRY_FINALLY( | |
2853 TRY_FINALLY( | |
2854 WASM_IF_ELSE(WASM_I32_EQ(WASM_GET_LOCAL(1), WASM_I32V(40)), | |
2855 WASM_BREAK(1), | |
2856 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(1), WASM_I32V(1)), | |
2857 WASM_BREAK(1))), | |
2858 WASM_SET_LOCAL( | |
2859 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x00000f))), | |
2860 FINALLY(WASM_SET_LOCAL( | |
2861 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x0000f0))))), | |
2862 WASM_SET_LOCAL(0, | |
2863 WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x000f00))), | |
2864 FINALLY(WASM_SET_LOCAL( | |
2865 0, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V(0x00f000))))), | |
2866 WASM_GET_LOCAL(0)); | |
2867 | |
2868 CHECK_EQ(0x7000ffff, r.Call(0x70000000, 2)); | |
2869 CHECK_EQ(0x7000fff0, r.Call(0x70000000, 1)); | |
2870 CHECK_EQ(0x7000f0f0, r.Call(0x70000000, 40)); | |
2871 } | |
2872 | |
2873 WASM_EXEC_TEST(TryFinally_multiple) { | |
2874 if (execution_mode == kExecuteInterpreted) { | |
John
2016/08/22 13:36:34
Yeah, this test is complicated, but I don't see an
| |
2875 // TODO(jpp): implement eh support in the interpreter. | |
2876 return; | |
2877 } | |
2878 | |
2879 FLAG_wasm_eh_prototype = true; | |
2880 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), | |
2881 MachineType::Int32()); | |
2882 | |
2883 // Handy-dandy shortcuts for recurring patterns for this test. | |
2884 #define I32_IOR_LOCAL(local, value) \ | |
2885 WASM_SET_LOCAL(local, WASM_I32_IOR(WASM_GET_LOCAL(local), WASM_I32V(value))) | |
2886 #define IF_LOCAL_IS_BREAK_TO(local, value, depth) \ | |
2887 WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(local), WASM_I32V(value)), \ | |
2888 WASM_BREAK(depth)) | |
2889 | |
2890 // r(i32 p, i32 q) -> i32 { | |
2891 // a: try { | |
2892 // b: try { | |
2893 // c: try { | |
2894 // d: try { | |
2895 // e: try { | |
2896 // switch (q) { | |
2897 // case 1: break e; | |
2898 // case 2: break d; | |
2899 // case 3: break c; | |
2900 // case 4: break b; | |
2901 // case 5: break a; | |
2902 // } | |
2903 // p |= 0x00000001; | |
2904 // } finally { | |
2905 // p |= 0x00000002; | |
2906 // } | |
2907 // switch (q) { | |
2908 // case 6: break d; | |
2909 // case 7: break c; | |
2910 // case 8: break b; | |
2911 // case 9: break a; | |
2912 // } | |
2913 // p |= 0x00000004; | |
2914 // } finally { | |
2915 // p |= 0x00000008; | |
2916 // } | |
2917 // switch (q) { | |
2918 // case 10: break c; | |
2919 // case 11: break b; | |
2920 // case 12: break a; | |
2921 // } | |
2922 // p |= 0x00000010; | |
2923 // } finally { | |
2924 // p |= 0x00000020; | |
2925 // } | |
2926 // switch (q) { | |
2927 // case 13: break b; | |
2928 // case 14: break a; | |
2929 // } | |
2930 // p |= 0x00000040; | |
2931 // } finally { | |
2932 // p |= 0x00000080; | |
2933 // } | |
2934 // switch (q) { | |
2935 // case 15: break a; | |
2936 // } | |
2937 // p |= 0x00000100; | |
2938 // } finally { | |
2939 // p |= 0x00000200; | |
2940 // } | |
2941 // return p; | |
2942 // } | |
2943 BUILD( | |
2944 r, | |
2945 TRY_FINALLY( | |
2946 TRY_FINALLY( | |
2947 TRY_FINALLY( | |
2948 TRY_FINALLY( | |
2949 TRY_FINALLY(IF_LOCAL_IS_BREAK_TO(1, 1, 0), | |
2950 IF_LOCAL_IS_BREAK_TO(1, 2, 1), | |
2951 IF_LOCAL_IS_BREAK_TO(1, 3, 2), | |
2952 IF_LOCAL_IS_BREAK_TO(1, 4, 3), | |
2953 IF_LOCAL_IS_BREAK_TO(1, 5, 4), | |
2954 I32_IOR_LOCAL(0, 0x00000001), | |
2955 FINALLY(I32_IOR_LOCAL(0, 0x00000002))), | |
2956 IF_LOCAL_IS_BREAK_TO(1, 6, 0), | |
2957 IF_LOCAL_IS_BREAK_TO(1, 7, 1), | |
2958 IF_LOCAL_IS_BREAK_TO(1, 8, 2), | |
2959 IF_LOCAL_IS_BREAK_TO(1, 9, 3), | |
2960 I32_IOR_LOCAL(0, 0x00000004), | |
2961 FINALLY(I32_IOR_LOCAL(0, 0x00000008))), | |
2962 IF_LOCAL_IS_BREAK_TO(1, 10, 0), | |
2963 IF_LOCAL_IS_BREAK_TO(1, 11, 1), | |
2964 IF_LOCAL_IS_BREAK_TO(1, 12, 2), I32_IOR_LOCAL(0, 0x00000010), | |
2965 FINALLY(I32_IOR_LOCAL(0, 0x00000020))), | |
2966 IF_LOCAL_IS_BREAK_TO(1, 13, 0), IF_LOCAL_IS_BREAK_TO(1, 14, 1), | |
2967 I32_IOR_LOCAL(0, 0x00000040), | |
2968 FINALLY(I32_IOR_LOCAL(0, 0x00000080))), | |
2969 IF_LOCAL_IS_BREAK_TO(1, 15, 0), I32_IOR_LOCAL(0, 0x00000100), | |
2970 FINALLY(I32_IOR_LOCAL(0, 0x00000200))), | |
2971 WASM_GET_LOCAL(0)); | |
2972 #undef WASM_IF_LOCAL_IS_BREAK_TO | |
2973 #undef WASM_I32_IOR_LOCAL | |
2974 | |
2975 const struct { | |
2976 uint32_t inputs[2]; | |
2977 uint32_t expected_output; | |
2978 } kTests[] = { | |
2979 {{0x80000000u, 0}, 0x800003ffu}, {{0x80000000u, 1}, 0x800003feu}, | |
2980 {{0x80000000u, 2}, 0x800003fau}, {{0x80000000u, 3}, 0x800003eau}, | |
2981 {{0x80000000u, 4}, 0x800003aau}, {{0x80000000u, 5}, 0x800002aau}, | |
2982 {{0x80000000u, 6}, 0x800003fbu}, {{0x80000000u, 7}, 0x800003ebu}, | |
2983 {{0x80000000u, 8}, 0x800003abu}, {{0x80000000u, 9}, 0x800002abu}, | |
2984 {{0x80000000u, 10}, 0x800003efu}, {{0x80000000u, 11}, 0x800003afu}, | |
2985 {{0x80000000u, 12}, 0x800002afu}, {{0x80000000u, 13}, 0x800003bfu}, | |
2986 {{0x80000000u, 14}, 0x800002bfu}, {{0x80000000u, 15}, 0x800002ffu}, | |
2987 }; | |
2988 | |
2989 for (uint32_t ii = 0; ii < arraysize(kTests); ++ii) { | |
2990 const auto& test_instance = kTests[ii]; | |
2991 CHECK_EQ(test_instance.expected_output, | |
2992 static_cast<uint32_t>( | |
2993 r.Call(test_instance.inputs[0], test_instance.inputs[1]))); | |
2994 } | |
2995 } | |
2996 | |
2997 // TODO(jpp): WASM_EXEC_TEST(TryCatchFinally) | |
OLD | NEW |