Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

Commit

Permalink
s390: fix overflowing offset in std and ld
Browse files Browse the repository at this point in the history
use StoreDouble and LoadDouble function to avoid overflowing
offset used in std and ld

R=joransiu@ca.ibm.com, michael_dawson@ca.ibm.com, bjaideep@ca.ibm.com
BUG=

Review-Url: https://codereview.chromium.org/2492913002
Cr-Commit-Position: refs/heads/master@{#40907}
  • Loading branch information
jyan authored and Commit bot committed Nov 10, 2016
1 parent f56685d commit c7ebb14
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/crankshaft/s390/lithium-codegen-s390.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void LCodeGen::SaveCallerDoubles() {
BitVector* doubles = chunk()->allocated_double_registers();
BitVector::Iterator save_iterator(doubles);
while (!save_iterator.Done()) {
__ std(DoubleRegister::from_code(save_iterator.Current()),
MemOperand(sp, count * kDoubleSize));
__ StoreDouble(DoubleRegister::from_code(save_iterator.Current()),
MemOperand(sp, count * kDoubleSize));
save_iterator.Advance();
count++;
}
Expand All @@ -81,8 +81,8 @@ void LCodeGen::RestoreCallerDoubles() {
BitVector::Iterator save_iterator(doubles);
int count = 0;
while (!save_iterator.Done()) {
__ ld(DoubleRegister::from_code(save_iterator.Current()),
MemOperand(sp, count * kDoubleSize));
__ LoadDouble(DoubleRegister::from_code(save_iterator.Current()),
MemOperand(sp, count * kDoubleSize));
save_iterator.Advance();
count++;
}
Expand Down Expand Up @@ -2089,7 +2089,8 @@ void LCodeGen::DoBranch(LBranch* instr) {
EmitBranch(instr, al);
} else if (type.IsHeapNumber()) {
DCHECK(!info()->IsStub());
__ ld(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset));
__ LoadDouble(dbl_scratch,
FieldMemOperand(reg, HeapNumber::kValueOffset));
// Test the double value. Zero and NaN are false.
__ lzdr(kDoubleRegZero);
__ cdbr(dbl_scratch, kDoubleRegZero);
Expand Down Expand Up @@ -2678,7 +2679,7 @@ void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) {
if (instr->hydrogen()->representation().IsDouble()) {
DCHECK(access.IsInobject());
DoubleRegister result = ToDoubleRegister(instr->result());
__ ld(result, FieldMemOperand(object, offset));
__ LoadDouble(result, FieldMemOperand(object, offset));
return;
}

Expand Down Expand Up @@ -2816,9 +2817,10 @@ void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) {
}
} else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS
if (!use_scratch) {
__ ld(result, MemOperand(external_pointer, base_offset));
__ LoadDouble(result, MemOperand(external_pointer, base_offset));
} else {
__ ld(result, MemOperand(scratch0(), external_pointer, base_offset));
__ LoadDouble(result,
MemOperand(scratch0(), external_pointer, base_offset));
}
}
} else {
Expand Down Expand Up @@ -2913,9 +2915,9 @@ void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) {
}

if (!use_scratch) {
__ ld(result, MemOperand(elements, base_offset));
__ LoadDouble(result, MemOperand(elements, base_offset));
} else {
__ ld(result, MemOperand(scratch, elements, base_offset));
__ LoadDouble(result, MemOperand(scratch, elements, base_offset));
}

if (instr->hydrogen()->RequiresHoleCheck()) {
Expand Down Expand Up @@ -3836,7 +3838,7 @@ void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
DCHECK(!hinstr->NeedsWriteBarrier());
DoubleRegister value = ToDoubleRegister(instr->value());
DCHECK(offset >= 0);
__ std(value, FieldMemOperand(object, offset));
__ StoreDouble(value, FieldMemOperand(object, offset));
return;
}

Expand All @@ -3861,7 +3863,7 @@ void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
if (FLAG_unbox_double_fields && representation.IsDouble()) {
DCHECK(access.IsInobject());
DoubleRegister value = ToDoubleRegister(instr->value());
__ std(value, FieldMemOperand(object, offset));
__ StoreDouble(value, FieldMemOperand(object, offset));
if (hinstr->NeedsWriteBarrier()) {
record_value = ToRegister(instr->value());
}
Expand Down Expand Up @@ -4090,14 +4092,15 @@ void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) {
__ CanonicalizeNaN(double_scratch, value);
DCHECK(address_offset >= 0);
if (use_scratch)
__ std(double_scratch, MemOperand(scratch, elements, address_offset));
__ StoreDouble(double_scratch,
MemOperand(scratch, elements, address_offset));
else
__ std(double_scratch, MemOperand(elements, address_offset));
__ StoreDouble(double_scratch, MemOperand(elements, address_offset));
} else {
if (use_scratch)
__ std(value, MemOperand(scratch, elements, address_offset));
__ StoreDouble(value, MemOperand(scratch, elements, address_offset));
else
__ std(value, MemOperand(elements, address_offset));
__ StoreDouble(value, MemOperand(elements, address_offset));
}
}

Expand Down Expand Up @@ -4677,7 +4680,8 @@ void LCodeGen::EmitNumberUntagD(LNumberUntagD* instr, Register input_reg,
DeoptimizeIf(ne, instr, DeoptimizeReason::kNotAHeapNumber);
}
// load heap number
__ ld(result_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset));
__ LoadDouble(result_reg,
FieldMemOperand(input_reg, HeapNumber::kValueOffset));
if (deoptimize_on_minus_zero) {
__ TestDoubleIsMinusZero(result_reg, scratch, ip);
DeoptimizeIf(eq, instr, DeoptimizeReason::kMinusZero);
Expand All @@ -4689,7 +4693,8 @@ void LCodeGen::EmitNumberUntagD(LNumberUntagD* instr, Register input_reg,
__ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex);
DeoptimizeIf(ne, instr, DeoptimizeReason::kNotAHeapNumberUndefined);
__ LoadRoot(scratch, Heap::kNanValueRootIndex);
__ ld(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset));
__ LoadDouble(result_reg,
FieldMemOperand(scratch, HeapNumber::kValueOffset));
__ b(&done, Label::kNear);
}
} else {
Expand Down Expand Up @@ -4731,8 +4736,8 @@ void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) {
// Deoptimize if we don't have a heap number.
DeoptimizeIf(ne, instr, DeoptimizeReason::kNotAHeapNumber);

__ ld(double_scratch2,
FieldMemOperand(input_reg, HeapNumber::kValueOffset));
__ LoadDouble(double_scratch2,
FieldMemOperand(input_reg, HeapNumber::kValueOffset));
if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
// preserve heap number pointer in scratch2 for minus zero check below
__ LoadRR(scratch2, input_reg);
Expand Down Expand Up @@ -5046,7 +5051,7 @@ void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) {

// Heap number
__ bind(&heap_number);
__ ld(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset));
__ LoadDouble(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset));
__ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0());
__ b(&done, Label::kNear);

Expand Down

0 comments on commit c7ebb14

Please sign in to comment.