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 4664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4675 __ pop(rcx); | 4675 __ pop(rcx); |
4676 __ pop(rax); | 4676 __ pop(rax); |
4677 __ pop(rdx); | 4677 __ pop(rdx); |
4678 __ push(rcx); | 4678 __ push(rcx); |
4679 | 4679 |
4680 // Do a tail call to the rewritten stub. | 4680 // Do a tail call to the rewritten stub. |
4681 __ jmp(rdi); | 4681 __ jmp(rdi); |
4682 } | 4682 } |
4683 | 4683 |
4684 | 4684 |
4685 void GenerateFastPixelArrayLoad(MacroAssembler* masm, | |
4686 Register receiver, | |
4687 Register key, | |
4688 Register elements, | |
4689 Register untagged_key, | |
4690 Register result, | |
4691 Label* not_pixel_array, | |
4692 Label* key_not_smi, | |
4693 Label* out_of_range) { | |
4694 // Register use: | |
4695 // receiver - holds the receiver and is unchanged. | |
4696 // key - holds the key and is unchanged (must be a smi). | |
4697 // elements - is set to the the receiver's element if | |
4698 // the receiver doesn't have a pixel array or the | |
4699 // key is not a smi, otherwise it's the elements' | |
4700 // external pointer. | |
4701 // untagged_key - is set to the untagged key | |
4702 | |
4703 // Some callers already have verified that the key is a smi. key_not_smi is | |
4704 // set to NULL as a sentinel for that case. Otherwise, add an explicit check | |
4705 // to ensure the key is a smi must be added. | |
4706 if (key_not_smi != NULL) { | |
4707 __ JumpIfNotSmi(key, key_not_smi); | |
4708 } else { | |
4709 if (FLAG_debug_code) { | |
4710 __ AbortIfNotSmi(key); | |
4711 } | |
4712 } | |
4713 __ SmiToInteger32(untagged_key, key); | |
4714 | |
4715 __ movq(elements, FieldOperand(receiver, JSObject::kElementsOffset)); | |
4716 // By passing NULL as not_pixel_array, callers signal that they have already | |
4717 // verified that the receiver has pixel array elements. | |
4718 if (not_pixel_array != NULL) { | |
4719 __ CheckMap(elements, Factory::pixel_array_map(), not_pixel_array, true); | |
4720 } else { | |
4721 if (FLAG_debug_code) { | |
4722 // Map check should have already made sure that elements is a pixel array. | |
4723 __ Cmp(FieldOperand(elements, HeapObject::kMapOffset), | |
4724 Factory::pixel_array_map()); | |
4725 __ Assert(equal, "Elements isn't a pixel array"); | |
4726 } | |
4727 } | |
4728 | |
4729 // Check that the smi is in range. | |
4730 __ cmpl(untagged_key, FieldOperand(elements, PixelArray::kLengthOffset)); | |
4731 __ j(above_equal, out_of_range); // unsigned check handles negative keys. | |
4732 | |
4733 // Load and tag the element as a smi. | |
4734 __ movq(elements, FieldOperand(elements, PixelArray::kExternalPointerOffset)); | |
4735 __ movzxbq(result, Operand(elements, untagged_key, times_1, 0)); | |
4736 __ Integer32ToSmi(result, result); | |
4737 __ ret(0); | |
4738 } | |
4739 | |
4740 | |
4741 // Stores an indexed element into a pixel array, clamping the stored value. | |
4742 void GenerateFastPixelArrayStore(MacroAssembler* masm, | |
4743 Register receiver, | |
4744 Register key, | |
4745 Register value, | |
4746 Register elements, | |
4747 Register scratch1, | |
4748 bool load_elements_from_receiver, | |
4749 bool key_is_untagged, | |
4750 Label* key_not_smi, | |
4751 Label* value_not_smi, | |
4752 Label* not_pixel_array, | |
4753 Label* out_of_range) { | |
4754 // Register use: | |
4755 // receiver - holds the receiver and is unchanged. | |
4756 // key - holds the key (must be a smi) and is unchanged. | |
4757 // value - holds the value (must be a smi) and is unchanged. | |
4758 // elements - holds the element object of the receiver on entry if | |
4759 // load_elements_from_receiver is false, otherwise used | |
4760 // internally to store the pixel arrays elements and | |
4761 // external array pointer. | |
4762 // | |
4763 Register external_pointer = elements; | |
4764 Register untagged_key = scratch1; | |
4765 Register untagged_value = receiver; // Only set once success guaranteed. | |
4766 | |
4767 // Fetch the receiver's elements if the caller hasn't already done so. | |
4768 if (load_elements_from_receiver) { | |
4769 __ movq(elements, FieldOperand(receiver, JSObject::kElementsOffset)); | |
4770 } | |
4771 | |
4772 // By passing NULL as not_pixel_array, callers signal that they have already | |
4773 // verified that the receiver has pixel array elements. | |
4774 if (not_pixel_array != NULL) { | |
4775 __ CheckMap(elements, Factory::pixel_array_map(), not_pixel_array, true); | |
4776 } else { | |
4777 if (FLAG_debug_code) { | |
4778 // Map check should have already made sure that elements is a pixel array. | |
4779 __ Cmp(FieldOperand(elements, HeapObject::kMapOffset), | |
4780 Factory::pixel_array_map()); | |
4781 __ Assert(equal, "Elements isn't a pixel array"); | |
4782 } | |
4783 } | |
4784 | |
4785 // Key must be a smi and it must be in range. | |
4786 if (key_is_untagged) { | |
4787 untagged_key = key; | |
4788 } else { | |
4789 // Some callers already have verified that the key is a smi. key_not_smi is | |
4790 // set to NULL as a sentinel for that case. Otherwise, add an explicit | |
4791 // check to ensure the key is a smi. | |
4792 if (key_not_smi != NULL) { | |
4793 __ JumpIfNotSmi(key, key_not_smi); | |
4794 } else { | |
4795 if (FLAG_debug_code) { | |
4796 __ AbortIfNotSmi(key); | |
4797 } | |
4798 } | |
4799 __ SmiToInteger32(untagged_key, key); | |
4800 } | |
4801 __ cmpl(untagged_key, FieldOperand(elements, PixelArray::kLengthOffset)); | |
4802 __ j(above_equal, out_of_range); // unsigned check handles negative keys. | |
4803 | |
4804 // Value must be a smi. | |
4805 __ JumpIfNotSmi(value, value_not_smi); | |
4806 __ SmiToInteger32(untagged_value, value); | |
4807 | |
4808 { // Clamp the value to [0..255]. | |
4809 NearLabel done; | |
4810 __ testl(untagged_value, Immediate(0xFFFFFF00)); | |
4811 __ j(zero, &done); | |
4812 __ setcc(negative, untagged_value); // 1 if negative, 0 if positive. | |
4813 __ decb(untagged_value); // 0 if negative, 255 if positive. | |
4814 __ bind(&done); | |
4815 } | |
4816 | |
4817 __ movq(external_pointer, | |
4818 FieldOperand(elements, PixelArray::kExternalPointerOffset)); | |
4819 __ movb(Operand(external_pointer, untagged_key, times_1, 0), untagged_value); | |
4820 __ ret(0); // Return value in eax. | |
4821 } | |
4822 | |
4823 #undef __ | 4685 #undef __ |
4824 | 4686 |
4825 } } // namespace v8::internal | 4687 } } // namespace v8::internal |
4826 | 4688 |
4827 #endif // V8_TARGET_ARCH_X64 | 4689 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |