OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 ASSERT(!destination().is(no_reg)); | 54 ASSERT(!destination().is(no_reg)); |
55 ASSERT(cell->IsJSGlobalPropertyCell()); | 55 ASSERT(cell->IsJSGlobalPropertyCell()); |
56 | 56 |
57 __ mov(destination(), Immediate(cell)); | 57 __ mov(destination(), Immediate(cell)); |
58 __ mov(destination(), | 58 __ mov(destination(), |
59 FieldOperand(destination(), JSGlobalPropertyCell::kValueOffset)); | 59 FieldOperand(destination(), JSGlobalPropertyCell::kValueOffset)); |
60 if (FLAG_debug_code) { | 60 if (FLAG_debug_code) { |
61 __ cmp(destination(), Factory::the_hole_value()); | 61 __ cmp(destination(), Factory::the_hole_value()); |
62 __ Check(not_equal, "DontDelete cells can't contain the hole"); | 62 __ Check(not_equal, "DontDelete cells can't contain the hole"); |
63 } | 63 } |
64 | |
65 // The loaded value is not known to be a smi. | |
66 clear_as_smi(destination()); | |
64 } | 67 } |
65 | 68 |
66 | 69 |
67 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { | 70 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { |
68 LookupResult lookup; | 71 LookupResult lookup; |
69 info()->receiver()->Lookup(*name, &lookup); | 72 info()->receiver()->Lookup(*name, &lookup); |
70 | 73 |
71 ASSERT(lookup.holder() == *info()->receiver()); | 74 ASSERT(lookup.holder() == *info()->receiver()); |
72 ASSERT(lookup.type() == FIELD); | 75 ASSERT(lookup.type() == FIELD); |
73 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); | 76 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); |
74 int index = lookup.GetFieldIndex() - map->inobject_properties(); | 77 int index = lookup.GetFieldIndex() - map->inobject_properties(); |
75 int offset = index * kPointerSize; | 78 int offset = index * kPointerSize; |
76 | 79 |
77 // Negative offsets are inobject properties. | 80 // We will emit the write barrier unless the stored value is statically |
81 // known to be a smi. | |
82 bool needs_write_barrier = !is_smi(accumulator0()); | |
83 | |
84 // Perform the store. Negative offsets are inobject properties. | |
78 if (offset < 0) { | 85 if (offset < 0) { |
79 offset += map->instance_size(); | 86 offset += map->instance_size(); |
80 __ mov(scratch0(), receiver_reg()); // Copy receiver for write barrier. | 87 __ mov(FieldOperand(receiver_reg(), offset), accumulator0()); |
88 if (needs_write_barrier) { | |
89 // Preserve receiver from write barrier. | |
90 __ mov(scratch0(), receiver_reg()); | |
91 } | |
81 } else { | 92 } else { |
82 offset += FixedArray::kHeaderSize; | 93 offset += FixedArray::kHeaderSize; |
83 __ mov(scratch0(), | 94 __ mov(scratch0(), |
84 FieldOperand(receiver_reg(), JSObject::kPropertiesOffset)); | 95 FieldOperand(receiver_reg(), JSObject::kPropertiesOffset)); |
96 __ mov(FieldOperand(scratch0(), offset), accumulator0()); | |
85 } | 97 } |
86 // Perform the store. | 98 |
87 __ mov(FieldOperand(scratch0(), offset), accumulator0()); | 99 if (needs_write_barrier) { |
88 if (destination().is(no_reg)) { | 100 if (destination().is(no_reg)) { |
89 __ RecordWrite(scratch0(), offset, accumulator0(), scratch1()); | 101 // After RecordWrite accumulator0 is only accidently a smi, but it is |
90 } else { | 102 // already marked as not known to be one. |
91 // Copy the value to the other accumulator to preserve a copy from the | 103 __ RecordWrite(scratch0(), offset, accumulator0(), scratch1()); |
92 // write barrier. One of the accumulators is available as a scratch | 104 } else { |
93 // register. | 105 // Copy the value to the other accumulator to preserve a copy from the |
106 // write barrier. One of the accumulators is available as a scratch | |
107 // register. Neither is a smi. | |
108 __ mov(accumulator1(), accumulator0()); | |
109 clear_as_smi(accumulator1()); | |
110 Register value_scratch = other_accumulator(destination()); | |
111 __ RecordWrite(scratch0(), offset, value_scratch, scratch1()); | |
112 } | |
113 } else if (destination().is(accumulator1())) { | |
94 __ mov(accumulator1(), accumulator0()); | 114 __ mov(accumulator1(), accumulator0()); |
95 Register value_scratch = other_accumulator(destination()); | 115 if (is_smi(accumulator0())) { |
fschneider
2010/02/10 15:14:33
This condition should be always true, since there
Kevin Millikin (Chromium)
2010/02/11 08:30:09
Good catch. I was trying to be too general and no
| |
96 __ RecordWrite(scratch0(), offset, value_scratch, scratch1()); | 116 set_as_smi(accumulator1()); |
117 } else { | |
118 clear_as_smi(accumulator1()); | |
119 } | |
97 } | 120 } |
98 } | 121 } |
99 | 122 |
100 | 123 |
101 void FastCodeGenerator::EmitThisPropertyLoad(Handle<String> name) { | 124 void FastCodeGenerator::EmitThisPropertyLoad(Handle<String> name) { |
102 ASSERT(!destination().is(no_reg)); | 125 ASSERT(!destination().is(no_reg)); |
103 LookupResult lookup; | 126 LookupResult lookup; |
104 info()->receiver()->Lookup(*name, &lookup); | 127 info()->receiver()->Lookup(*name, &lookup); |
105 | 128 |
106 ASSERT(lookup.holder() == *info()->receiver()); | 129 ASSERT(lookup.holder() == *info()->receiver()); |
107 ASSERT(lookup.type() == FIELD); | 130 ASSERT(lookup.type() == FIELD); |
108 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); | 131 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); |
109 int index = lookup.GetFieldIndex() - map->inobject_properties(); | 132 int index = lookup.GetFieldIndex() - map->inobject_properties(); |
110 int offset = index * kPointerSize; | 133 int offset = index * kPointerSize; |
111 | 134 |
112 // Perform the load. Negative offsets are inobject properties. | 135 // Perform the load. Negative offsets are inobject properties. |
113 if (offset < 0) { | 136 if (offset < 0) { |
114 offset += map->instance_size(); | 137 offset += map->instance_size(); |
115 __ mov(destination(), FieldOperand(receiver_reg(), offset)); | 138 __ mov(destination(), FieldOperand(receiver_reg(), offset)); |
116 } else { | 139 } else { |
117 offset += FixedArray::kHeaderSize; | 140 offset += FixedArray::kHeaderSize; |
118 __ mov(scratch0(), | 141 __ mov(scratch0(), |
119 FieldOperand(receiver_reg(), JSObject::kPropertiesOffset)); | 142 FieldOperand(receiver_reg(), JSObject::kPropertiesOffset)); |
120 __ mov(destination(), FieldOperand(scratch0(), offset)); | 143 __ mov(destination(), FieldOperand(scratch0(), offset)); |
121 } | 144 } |
145 | |
146 // The loaded value is not known to be a smi. | |
147 clear_as_smi(destination()); | |
122 } | 148 } |
123 | 149 |
124 | 150 |
125 void FastCodeGenerator::EmitBitOr() { | 151 void FastCodeGenerator::EmitBitOr() { |
126 Register copied; // One operand is copied to a scratch register. | 152 if (is_smi(accumulator0()) && is_smi(accumulator1())) { |
127 Register other; // The other is not modified by the operation. | 153 // If both operands are known to be a smi then there is no need to check |
128 Register check; // A register is used for the smi check/operation. | 154 // the operands or result. There is no need to perform the operation in |
129 if (destination().is(no_reg)) { | 155 // an effect context. |
130 copied = accumulator1(); // Arbitrary choice of operand to copy. | 156 if (!destination().is(no_reg)) { |
131 other = accumulator0(); | 157 // Leave the result in the destination register. Bitwise or is |
132 check = scratch0(); // Do not clobber either operand register. | 158 // commutative. |
133 } else { | 159 __ or_(destination(), Operand(other_accumulator(destination()))); |
134 copied = destination(); | 160 } |
135 other = other_accumulator(destination()); | 161 } else if (destination().is(no_reg)) { |
136 check = destination(); | 162 // Result is not needed but do not clobber the operands in case of |
137 } | 163 // bailout. |
138 __ mov(scratch0(), copied); | 164 __ mov(scratch0(), accumulator1()); |
139 __ or_(check, Operand(other)); | 165 __ or_(scratch0(), Operand(accumulator0())); |
140 __ test(check, Immediate(kSmiTagMask)); | 166 __ test(scratch0(), Immediate(kSmiTagMask)); |
141 | |
142 // Restore the clobbered operand if necessary. | |
143 if (destination().is(no_reg)) { | |
144 __ j(not_zero, bailout(), not_taken); | 167 __ j(not_zero, bailout(), not_taken); |
145 } else { | 168 } else { |
169 // Preserve the destination operand in a scratch register in case of | |
170 // bailout. | |
146 Label done; | 171 Label done; |
172 __ mov(scratch0(), destination()); | |
173 __ or_(destination(), Operand(other_accumulator(destination()))); | |
174 __ test(destination(), Immediate(kSmiTagMask)); | |
147 __ j(zero, &done, taken); | 175 __ j(zero, &done, taken); |
148 __ mov(copied, scratch0()); | 176 __ mov(destination(), scratch0()); |
149 __ jmp(bailout()); | 177 __ jmp(bailout()); |
150 __ bind(&done); | 178 __ bind(&done); |
151 } | 179 } |
180 | |
181 // If we didn't bailout, the result (in fact, both inputs too) is known to | |
182 // be a smi. | |
183 set_as_smi(accumulator0()); | |
184 set_as_smi(accumulator1()); | |
152 } | 185 } |
153 | 186 |
154 | 187 |
155 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { | 188 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { |
156 ASSERT(info_ == NULL); | 189 ASSERT(info_ == NULL); |
157 info_ = compilation_info; | 190 info_ = compilation_info; |
158 | 191 |
159 // Save the caller's frame pointer and set up our own. | 192 // Save the caller's frame pointer and set up our own. |
160 Comment prologue_cmnt(masm(), ";; Prologue"); | 193 Comment prologue_cmnt(masm(), ";; Prologue"); |
161 __ push(ebp); | 194 __ push(ebp); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 __ ret((scope()->num_parameters() + 1) * kPointerSize); | 236 __ ret((scope()->num_parameters() + 1) * kPointerSize); |
204 | 237 |
205 __ bind(&bailout_); | 238 __ bind(&bailout_); |
206 } | 239 } |
207 | 240 |
208 | 241 |
209 #undef __ | 242 #undef __ |
210 | 243 |
211 | 244 |
212 } } // namespace v8::internal | 245 } } // namespace v8::internal |
OLD | NEW |