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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1416623003: [Interpreter] Add support for for count operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix gcc error Created 5 years, 2 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/interpreter/interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 2898 matching lines...) Expand 10 before | Expand all | Expand 10 after
2909 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, 2909 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
2910 }; 2910 };
2911 2911
2912 for (size_t i = 0; i < arraysize(snippets); i++) { 2912 for (size_t i = 0; i < arraysize(snippets); i++) {
2913 Handle<BytecodeArray> bytecode_array = 2913 Handle<BytecodeArray> bytecode_array =
2914 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 2914 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
2915 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2915 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2916 } 2916 }
2917 } 2917 }
2918 2918
2919
2920 TEST(CountOperators) {
2921 InitializedHandleScope handle_scope;
2922 BytecodeGeneratorHelper helper;
2923 Zone zone;
2924
2925 FeedbackVectorSpec feedback_spec(&zone);
2926 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
2927 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
2928
2929 Handle<i::TypeFeedbackVector> vector =
2930 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
2931
2932 int closure = Register::function_closure().index();
2933 int first_context_slot = Context::MIN_CONTEXT_SLOTS;
2934
2935 int object_literal_flags =
2936 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
2937
2938 ExpectedSnippet<InstanceType> snippets[] = {
2939 {"var a = 1; return ++a;",
2940 1 * kPointerSize,
2941 1,
2942 11,
2943 {
2944 B(LdaSmi8), U8(1), //
2945 B(Star), R(0), //
2946 B(Ldar), R(0), //
2947 B(ToNumber), //
2948 B(Inc), //
2949 B(Star), R(0), //
2950 B(Return), //
2951 }},
2952 {"var a = 1; return a++;",
2953 2 * kPointerSize,
2954 1,
2955 15,
2956 {
2957 B(LdaSmi8), U8(1), //
2958 B(Star), R(0), //
2959 B(Ldar), R(0), //
2960 B(ToNumber), //
2961 B(Star), R(1), //
2962 B(Inc), //
2963 B(Star), R(0), //
2964 B(Ldar), R(1), //
2965 B(Return), //
2966 }},
2967 {"var a = 1; return --a;",
2968 1 * kPointerSize,
2969 1,
2970 11,
2971 {
2972 B(LdaSmi8), U8(1), //
2973 B(Star), R(0), //
2974 B(Ldar), R(0), //
2975 B(ToNumber), //
2976 B(Dec), //
2977 B(Star), R(0), //
2978 B(Return), //
2979 }},
2980 {"var a = 1; return a--;",
2981 2 * kPointerSize,
2982 1,
2983 15,
2984 {
2985 B(LdaSmi8), U8(1), //
2986 B(Star), R(0), //
2987 B(Ldar), R(0), //
2988 B(ToNumber), //
2989 B(Star), R(1), //
2990 B(Dec), //
2991 B(Star), R(0), //
2992 B(Ldar), R(1), //
2993 B(Return), //
2994 }},
2995 {"var a = { val: 1 }; return a.val++;",
2996 2 * kPointerSize,
2997 1,
2998 22,
2999 {
3000 B(LdaConstant), U8(0), //
3001 B(CreateObjectLiteral), U8(0), U8(object_literal_flags), //
3002 B(Star), R(0), //
3003 B(LoadICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), //
3004 B(ToNumber), //
3005 B(Star), R(1), //
3006 B(Inc), //
3007 B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot2)), //
3008 B(Ldar), R(1), //
3009 B(Return), //
3010 },
3011 2,
3012 {InstanceType::FIXED_ARRAY_TYPE,
3013 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3014 {"var a = { val: 1 }; return --a.val;",
3015 1 * kPointerSize,
3016 1,
3017 18,
3018 {
3019 B(LdaConstant), U8(0), //
3020 B(CreateObjectLiteral), U8(0), U8(object_literal_flags), //
3021 B(Star), R(0), //
3022 B(LoadICSloppy), R(0), U8(1), U8(vector->GetIndex(slot1)), //
3023 B(ToNumber), //
3024 B(Dec), //
3025 B(StoreICSloppy), R(0), U8(1), U8(vector->GetIndex(slot2)), //
3026 B(Return), //
3027 },
3028 2,
3029 {InstanceType::FIXED_ARRAY_TYPE,
3030 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
3031 {"var name = 'var'; var a = { val: 1 }; return a[name]--;",
3032 4 * kPointerSize,
3033 1,
3034 29,
3035 {
3036 B(LdaConstant), U8(0), //
3037 B(Star), R(0), //
3038 B(LdaConstant), U8(1), //
3039 B(CreateObjectLiteral), U8(0), U8(object_literal_flags), //
3040 B(Star), R(1), //
3041 B(Ldar), R(0), //
3042 B(Star), R(2), //
3043 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), //
3044 B(ToNumber), //
3045 B(Star), R(3), //
3046 B(Dec), //
3047 B(KeyedStoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), //
3048 B(Ldar), R(3), //
3049 B(Return), //
3050 },
3051 2,
3052 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
3053 InstanceType::FIXED_ARRAY_TYPE}},
3054 {"var name = 'var'; var a = { val: 1 }; return ++a[name];",
3055 3 * kPointerSize,
3056 1,
3057 25,
3058 {
3059 B(LdaConstant), U8(0), //
3060 B(Star), R(0), //
3061 B(LdaConstant), U8(1), //
3062 B(CreateObjectLiteral), U8(0), U8(object_literal_flags), //
3063 B(Star), R(1), //
3064 B(Ldar), R(0), //
3065 B(Star), R(2), //
3066 B(KeyedLoadICSloppy), R(1), U8(vector->GetIndex(slot1)), //
3067 B(ToNumber), //
3068 B(Inc), //
3069 B(KeyedStoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), //
3070 B(Return), //
3071 },
3072 2,
3073 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
3074 InstanceType::FIXED_ARRAY_TYPE}},
3075 {"var a = 1; var b = function() { return a }; return ++a;",
3076 2 * kPointerSize,
3077 1,
3078 27,
3079 {
3080 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
3081 U8(1), //
3082 B(PushContext), R(1), //
3083 B(LdaSmi8), U8(1), //
3084 B(StaContextSlot), R(1), U8(first_context_slot), //
3085 B(LdaConstant), U8(0), //
3086 B(CreateClosure), U8(0), //
3087 B(Star), R(0), //
3088 B(LdaContextSlot), R(1), U8(first_context_slot), //
3089 B(ToNumber), //
3090 B(Inc), //
3091 B(StaContextSlot), R(1), U8(first_context_slot), //
3092 B(Return), //
3093 },
3094 1,
3095 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
3096 {"var a = 1; var b = function() { return a }; return a--;",
3097 3 * kPointerSize,
3098 1,
3099 31,
3100 {
3101 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), //
3102 U8(1), //
3103 B(PushContext), R(1), //
3104 B(LdaSmi8), U8(1), //
3105 B(StaContextSlot), R(1), U8(first_context_slot), //
3106 B(LdaConstant), U8(0), //
3107 B(CreateClosure), U8(0), //
3108 B(Star), R(0), //
3109 B(LdaContextSlot), R(1), U8(first_context_slot), //
3110 B(ToNumber), //
3111 B(Star), R(2), //
3112 B(Dec), //
3113 B(StaContextSlot), R(1), U8(first_context_slot), //
3114 B(Ldar), R(2), //
3115 B(Return), //
3116 },
3117 1,
3118 {InstanceType::SHARED_FUNCTION_INFO_TYPE}},
3119 };
3120
3121 for (size_t i = 0; i < arraysize(snippets); i++) {
3122 Handle<BytecodeArray> bytecode_array =
3123 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
3124 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3125 }
3126 }
3127
3128
3129 TEST(GlobalCountOperators) {
3130 InitializedHandleScope handle_scope;
3131 BytecodeGeneratorHelper helper;
3132 Zone zone;
3133
3134 FeedbackVectorSpec feedback_spec(&zone);
3135 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot();
3136 FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot();
3137
3138 Handle<i::TypeFeedbackVector> vector =
3139 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec);
3140
3141 ExpectedSnippet<const char*> snippets[] = {
3142 {"var global = 1;\nfunction f() { return ++global; }\nf()",
3143 0,
3144 1,
3145 9,
3146 {
3147 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
3148 B(ToNumber), //
3149 B(Inc), //
3150 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
3151 B(Return), //
3152 },
3153 1,
3154 {"global"}},
3155 {"var global = 1;\nfunction f() { return global--; }\nf()",
3156 1 * kPointerSize,
3157 1,
3158 13,
3159 {
3160 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
3161 B(ToNumber), //
3162 B(Star), R(0), //
3163 B(Dec), //
3164 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
3165 B(Ldar), R(0), //
3166 B(Return),
3167 },
3168 1,
3169 {"global"}},
3170 {"unallocated = 1;\nfunction f() { 'use strict'; return --unallocated; }"
3171 "f()",
3172 0,
3173 1,
3174 9,
3175 {
3176 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot1)), //
3177 B(ToNumber), //
3178 B(Dec), //
3179 B(StaGlobalStrict), U8(0), U8(vector->GetIndex(slot2)), //
3180 B(Return), //
3181 },
3182 1,
3183 {"unallocated"}},
3184 {"unallocated = 1;\nfunction f() { return unallocated++; }\nf()",
3185 1 * kPointerSize,
3186 1,
3187 13,
3188 {
3189 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot1)), //
3190 B(ToNumber), //
3191 B(Star), R(0), //
3192 B(Inc), //
3193 B(StaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), //
3194 B(Ldar), R(0), //
3195 B(Return),
3196 },
3197 1,
3198 {"unallocated"}},
3199 };
3200
3201 for (size_t i = 0; i < arraysize(snippets); i++) {
3202 Handle<BytecodeArray> bytecode_array =
3203 helper.MakeBytecode(snippets[i].code_snippet, "f");
3204 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true);
3205 }
3206 }
3207
2919 } // namespace interpreter 3208 } // namespace interpreter
2920 } // namespace internal 3209 } // namespace internal
2921 } // namespace v8 3210 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/cctest/interpreter/test-interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698