Index: src/arm64/full-codegen-arm64.cc |
diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc |
index 97e80676f28725377f436ce1fca13a5364975773..2099fde186898ae49305d47dfaa83667b7fbbeca 100644 |
--- a/src/arm64/full-codegen-arm64.cc |
+++ b/src/arm64/full-codegen-arm64.cc |
@@ -391,7 +391,12 @@ void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
Label ok; |
ASSERT(back_edge_target->is_bound()); |
- int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
+ // We want to do a round rather than a floor of distance/kCodeSizeMultiplier |
+ // to reduce the absolute error due to the integer division. To do that, |
+ // we add kCodeSizeMultiplier/2 to the distance (equivalent to adding 0.5 to |
+ // the result). |
+ int distance = |
+ masm_->SizeOfCodeGeneratedSince(back_edge_target) + kCodeSizeMultiplier / 2; |
int weight = Min(kMaxBackEdgeWeight, |
Max(1, distance / kCodeSizeMultiplier)); |
EmitProfilingCounterDecrement(weight); |
@@ -434,7 +439,7 @@ void FullCodeGenerator::EmitReturnSequence() { |
if (info_->ShouldSelfOptimize()) { |
weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
} else { |
- int distance = masm_->pc_offset(); |
+ int distance = masm_->pc_offset() + kCodeSizeMultiplier / 2; |
weight = Min(kMaxBackEdgeWeight, |
Max(1, distance / kCodeSizeMultiplier)); |
} |