| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 4986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4997 __ pop(rcx); | 4997 __ pop(rcx); |
| 4998 __ pop(rax); | 4998 __ pop(rax); |
| 4999 __ pop(rdx); | 4999 __ pop(rdx); |
| 5000 __ push(rcx); | 5000 __ push(rcx); |
| 5001 | 5001 |
| 5002 // Do a tail call to the rewritten stub. | 5002 // Do a tail call to the rewritten stub. |
| 5003 __ jmp(rdi); | 5003 __ jmp(rdi); |
| 5004 } | 5004 } |
| 5005 | 5005 |
| 5006 | 5006 |
| 5007 void GenerateFastPixelArrayLoad(MacroAssembler* masm, | |
| 5008 Register receiver, | |
| 5009 Register key, | |
| 5010 Register elements, | |
| 5011 Register untagged_key, | |
| 5012 Register result, | |
| 5013 Label* not_pixel_array, | |
| 5014 Label* key_not_smi, | |
| 5015 Label* out_of_range) { | |
| 5016 // Register use: | |
| 5017 // receiver - holds the receiver and is unchanged. | |
| 5018 // key - holds the key and is unchanged (must be a smi). | |
| 5019 // elements - is set to the the receiver's element if | |
| 5020 // the receiver doesn't have a pixel array or the | |
| 5021 // key is not a smi, otherwise it's the elements' | |
| 5022 // external pointer. | |
| 5023 // untagged_key - is set to the untagged key | |
| 5024 | |
| 5025 // Some callers already have verified that the key is a smi. key_not_smi is | |
| 5026 // set to NULL as a sentinel for that case. Otherwise, add an explicit check | |
| 5027 // to ensure the key is a smi must be added. | |
| 5028 if (key_not_smi != NULL) { | |
| 5029 __ JumpIfNotSmi(key, key_not_smi); | |
| 5030 } else { | |
| 5031 if (FLAG_debug_code) { | |
| 5032 __ AbortIfNotSmi(key); | |
| 5033 } | |
| 5034 } | |
| 5035 __ SmiToInteger32(untagged_key, key); | |
| 5036 | |
| 5037 __ movq(elements, FieldOperand(receiver, JSObject::kElementsOffset)); | |
| 5038 // By passing NULL as not_pixel_array, callers signal that they have already | |
| 5039 // verified that the receiver has pixel array elements. | |
| 5040 if (not_pixel_array != NULL) { | |
| 5041 __ CheckMap(elements, Factory::pixel_array_map(), not_pixel_array, true); | |
| 5042 } else { | |
| 5043 if (FLAG_debug_code) { | |
| 5044 // Map check should have already made sure that elements is a pixel array. | |
| 5045 __ Cmp(FieldOperand(elements, HeapObject::kMapOffset), | |
| 5046 Factory::pixel_array_map()); | |
| 5047 __ Assert(equal, "Elements isn't a pixel array"); | |
| 5048 } | |
| 5049 } | |
| 5050 | |
| 5051 // Check that the smi is in range. | |
| 5052 __ cmpl(untagged_key, FieldOperand(elements, PixelArray::kLengthOffset)); | |
| 5053 __ j(above_equal, out_of_range); // unsigned check handles negative keys. | |
| 5054 | |
| 5055 // Load and tag the element as a smi. | |
| 5056 __ movq(elements, FieldOperand(elements, PixelArray::kExternalPointerOffset)); | |
| 5057 __ movzxbq(result, Operand(elements, untagged_key, times_1, 0)); | |
| 5058 __ Integer32ToSmi(result, result); | |
| 5059 __ ret(0); | |
| 5060 } | |
| 5061 | |
| 5062 | |
| 5063 // Stores an indexed element into a pixel array, clamping the stored value. | |
| 5064 void GenerateFastPixelArrayStore(MacroAssembler* masm, | |
| 5065 Register receiver, | |
| 5066 Register key, | |
| 5067 Register value, | |
| 5068 Register elements, | |
| 5069 Register scratch1, | |
| 5070 bool load_elements_from_receiver, | |
| 5071 bool key_is_untagged, | |
| 5072 Label* key_not_smi, | |
| 5073 Label* value_not_smi, | |
| 5074 Label* not_pixel_array, | |
| 5075 Label* out_of_range) { | |
| 5076 // Register use: | |
| 5077 // receiver - holds the receiver and is unchanged. | |
| 5078 // key - holds the key (must be a smi) and is unchanged. | |
| 5079 // value - holds the value (must be a smi) and is unchanged. | |
| 5080 // elements - holds the element object of the receiver on entry if | |
| 5081 // load_elements_from_receiver is false, otherwise used | |
| 5082 // internally to store the pixel arrays elements and | |
| 5083 // external array pointer. | |
| 5084 // | |
| 5085 Register external_pointer = elements; | |
| 5086 Register untagged_key = scratch1; | |
| 5087 Register untagged_value = receiver; // Only set once success guaranteed. | |
| 5088 | |
| 5089 // Fetch the receiver's elements if the caller hasn't already done so. | |
| 5090 if (load_elements_from_receiver) { | |
| 5091 __ movq(elements, FieldOperand(receiver, JSObject::kElementsOffset)); | |
| 5092 } | |
| 5093 | |
| 5094 // By passing NULL as not_pixel_array, callers signal that they have already | |
| 5095 // verified that the receiver has pixel array elements. | |
| 5096 if (not_pixel_array != NULL) { | |
| 5097 __ CheckMap(elements, Factory::pixel_array_map(), not_pixel_array, true); | |
| 5098 } else { | |
| 5099 if (FLAG_debug_code) { | |
| 5100 // Map check should have already made sure that elements is a pixel array. | |
| 5101 __ Cmp(FieldOperand(elements, HeapObject::kMapOffset), | |
| 5102 Factory::pixel_array_map()); | |
| 5103 __ Assert(equal, "Elements isn't a pixel array"); | |
| 5104 } | |
| 5105 } | |
| 5106 | |
| 5107 // Key must be a smi and it must be in range. | |
| 5108 if (key_is_untagged) { | |
| 5109 untagged_key = key; | |
| 5110 } else { | |
| 5111 // Some callers already have verified that the key is a smi. key_not_smi is | |
| 5112 // set to NULL as a sentinel for that case. Otherwise, add an explicit | |
| 5113 // check to ensure the key is a smi. | |
| 5114 if (key_not_smi != NULL) { | |
| 5115 __ JumpIfNotSmi(key, key_not_smi); | |
| 5116 } else { | |
| 5117 if (FLAG_debug_code) { | |
| 5118 __ AbortIfNotSmi(key); | |
| 5119 } | |
| 5120 } | |
| 5121 __ SmiToInteger32(untagged_key, key); | |
| 5122 } | |
| 5123 __ cmpl(untagged_key, FieldOperand(elements, PixelArray::kLengthOffset)); | |
| 5124 __ j(above_equal, out_of_range); // unsigned check handles negative keys. | |
| 5125 | |
| 5126 // Value must be a smi. | |
| 5127 __ JumpIfNotSmi(value, value_not_smi); | |
| 5128 __ SmiToInteger32(untagged_value, value); | |
| 5129 | |
| 5130 { // Clamp the value to [0..255]. | |
| 5131 NearLabel done; | |
| 5132 __ testl(untagged_value, Immediate(0xFFFFFF00)); | |
| 5133 __ j(zero, &done); | |
| 5134 __ setcc(negative, untagged_value); // 1 if negative, 0 if positive. | |
| 5135 __ decb(untagged_value); // 0 if negative, 255 if positive. | |
| 5136 __ bind(&done); | |
| 5137 } | |
| 5138 | |
| 5139 __ movq(external_pointer, | |
| 5140 FieldOperand(elements, PixelArray::kExternalPointerOffset)); | |
| 5141 __ movb(Operand(external_pointer, untagged_key, times_1, 0), untagged_value); | |
| 5142 __ ret(0); // Return value in eax. | |
| 5143 } | |
| 5144 | |
| 5145 #undef __ | 5007 #undef __ |
| 5146 | 5008 |
| 5147 } } // namespace v8::internal | 5009 } } // namespace v8::internal |
| 5148 | 5010 |
| 5149 #endif // V8_TARGET_ARCH_X64 | 5011 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |