| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2935 | 2935 |
| 2936 add(bitmap_reg, ecx); | 2936 add(bitmap_reg, ecx); |
| 2937 mov(ecx, addr_reg); | 2937 mov(ecx, addr_reg); |
| 2938 shr(ecx, kPointerSizeLog2); | 2938 shr(ecx, kPointerSizeLog2); |
| 2939 and_(ecx, (1 << Bitmap::kBitsPerCellLog2) - 1); | 2939 and_(ecx, (1 << Bitmap::kBitsPerCellLog2) - 1); |
| 2940 mov(mask_reg, Immediate(1)); | 2940 mov(mask_reg, Immediate(1)); |
| 2941 shl_cl(mask_reg); | 2941 shl_cl(mask_reg); |
| 2942 } | 2942 } |
| 2943 | 2943 |
| 2944 | 2944 |
| 2945 void MacroAssembler::EnsureNotWhite( | 2945 void MacroAssembler::JumpIfWhite(Register value, Register bitmap_scratch, |
| 2946 Register value, | 2946 Register mask_scratch, Label* value_is_white, |
| 2947 Register bitmap_scratch, | 2947 Label::Distance distance) { |
| 2948 Register mask_scratch, | |
| 2949 Label* value_is_white_and_not_data, | |
| 2950 Label::Distance distance) { | |
| 2951 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, ecx)); | 2948 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, ecx)); |
| 2952 GetMarkBits(value, bitmap_scratch, mask_scratch); | 2949 GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 2953 | 2950 |
| 2954 // If the value is black or grey we don't need to do anything. | 2951 // If the value is black or grey we don't need to do anything. |
| 2955 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); | 2952 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 2956 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); | 2953 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 2957 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); | 2954 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 2958 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); | 2955 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 2959 | 2956 |
| 2960 Label done; | |
| 2961 | |
| 2962 // Since both black and grey have a 1 in the first position and white does | 2957 // Since both black and grey have a 1 in the first position and white does |
| 2963 // not have a 1 there we only need to check one bit. | 2958 // not have a 1 there we only need to check one bit. |
| 2964 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | 2959 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 2965 j(not_zero, &done, Label::kNear); | 2960 j(zero, value_is_white, Label::kNear); |
| 2966 | |
| 2967 if (emit_debug_code()) { | |
| 2968 // Check for impossible bit pattern. | |
| 2969 Label ok; | |
| 2970 push(mask_scratch); | |
| 2971 // shl. May overflow making the check conservative. | |
| 2972 add(mask_scratch, mask_scratch); | |
| 2973 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | |
| 2974 j(zero, &ok, Label::kNear); | |
| 2975 int3(); | |
| 2976 bind(&ok); | |
| 2977 pop(mask_scratch); | |
| 2978 } | |
| 2979 | |
| 2980 // Value is white. We check whether it is data that doesn't need scanning. | |
| 2981 // Currently only checks for HeapNumber and non-cons strings. | |
| 2982 Register map = ecx; // Holds map while checking type. | |
| 2983 Register length = ecx; // Holds length of object after checking type. | |
| 2984 Label not_heap_number; | |
| 2985 Label is_data_object; | |
| 2986 | |
| 2987 // Check for heap-number | |
| 2988 mov(map, FieldOperand(value, HeapObject::kMapOffset)); | |
| 2989 cmp(map, isolate()->factory()->heap_number_map()); | |
| 2990 j(not_equal, ¬_heap_number, Label::kNear); | |
| 2991 mov(length, Immediate(HeapNumber::kSize)); | |
| 2992 jmp(&is_data_object, Label::kNear); | |
| 2993 | |
| 2994 bind(¬_heap_number); | |
| 2995 // Check for strings. | |
| 2996 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); | |
| 2997 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); | |
| 2998 // If it's a string and it's not a cons string then it's an object containing | |
| 2999 // no GC pointers. | |
| 3000 Register instance_type = ecx; | |
| 3001 movzx_b(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); | |
| 3002 test_b(instance_type, kIsIndirectStringMask | kIsNotStringMask); | |
| 3003 j(not_zero, value_is_white_and_not_data); | |
| 3004 // It's a non-indirect (non-cons and non-slice) string. | |
| 3005 // If it's external, the length is just ExternalString::kSize. | |
| 3006 // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). | |
| 3007 Label not_external; | |
| 3008 // External strings are the only ones with the kExternalStringTag bit | |
| 3009 // set. | |
| 3010 DCHECK_EQ(0, kSeqStringTag & kExternalStringTag); | |
| 3011 DCHECK_EQ(0, kConsStringTag & kExternalStringTag); | |
| 3012 test_b(instance_type, kExternalStringTag); | |
| 3013 j(zero, ¬_external, Label::kNear); | |
| 3014 mov(length, Immediate(ExternalString::kSize)); | |
| 3015 jmp(&is_data_object, Label::kNear); | |
| 3016 | |
| 3017 bind(¬_external); | |
| 3018 // Sequential string, either Latin1 or UC16. | |
| 3019 DCHECK(kOneByteStringTag == 0x04); | |
| 3020 and_(length, Immediate(kStringEncodingMask)); | |
| 3021 xor_(length, Immediate(kStringEncodingMask)); | |
| 3022 add(length, Immediate(0x04)); | |
| 3023 // Value now either 4 (if Latin1) or 8 (if UC16), i.e., char-size shifted | |
| 3024 // by 2. If we multiply the string length as smi by this, it still | |
| 3025 // won't overflow a 32-bit value. | |
| 3026 DCHECK_EQ(SeqOneByteString::kMaxSize, SeqTwoByteString::kMaxSize); | |
| 3027 DCHECK(SeqOneByteString::kMaxSize <= | |
| 3028 static_cast<int>(0xffffffffu >> (2 + kSmiTagSize))); | |
| 3029 imul(length, FieldOperand(value, String::kLengthOffset)); | |
| 3030 shr(length, 2 + kSmiTagSize + kSmiShiftSize); | |
| 3031 add(length, Immediate(SeqString::kHeaderSize + kObjectAlignmentMask)); | |
| 3032 and_(length, Immediate(~kObjectAlignmentMask)); | |
| 3033 | |
| 3034 bind(&is_data_object); | |
| 3035 // Value is a data object, and it is white. Mark it black. Since we know | |
| 3036 // that the object is white we can make it black by flipping one bit. | |
| 3037 or_(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); | |
| 3038 | |
| 3039 and_(bitmap_scratch, Immediate(~Page::kPageAlignmentMask)); | |
| 3040 add(Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset), | |
| 3041 length); | |
| 3042 if (emit_debug_code()) { | |
| 3043 mov(length, Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset)); | |
| 3044 cmp(length, Operand(bitmap_scratch, MemoryChunk::kSizeOffset)); | |
| 3045 Check(less_equal, kLiveBytesCountOverflowChunkSize); | |
| 3046 } | |
| 3047 | |
| 3048 bind(&done); | |
| 3049 } | 2961 } |
| 3050 | 2962 |
| 3051 | 2963 |
| 3052 void MacroAssembler::EnumLength(Register dst, Register map) { | 2964 void MacroAssembler::EnumLength(Register dst, Register map) { |
| 3053 STATIC_ASSERT(Map::EnumLengthBits::kShift == 0); | 2965 STATIC_ASSERT(Map::EnumLengthBits::kShift == 0); |
| 3054 mov(dst, FieldOperand(map, Map::kBitField3Offset)); | 2966 mov(dst, FieldOperand(map, Map::kBitField3Offset)); |
| 3055 and_(dst, Immediate(Map::EnumLengthBits::kMask)); | 2967 and_(dst, Immediate(Map::EnumLengthBits::kMask)); |
| 3056 SmiTag(dst); | 2968 SmiTag(dst); |
| 3057 } | 2969 } |
| 3058 | 2970 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3169 mov(eax, dividend); | 3081 mov(eax, dividend); |
| 3170 shr(eax, 31); | 3082 shr(eax, 31); |
| 3171 add(edx, eax); | 3083 add(edx, eax); |
| 3172 } | 3084 } |
| 3173 | 3085 |
| 3174 | 3086 |
| 3175 } // namespace internal | 3087 } // namespace internal |
| 3176 } // namespace v8 | 3088 } // namespace v8 |
| 3177 | 3089 |
| 3178 #endif // V8_TARGET_ARCH_IA32 | 3090 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |