From 415f7bea0bd2a5606e91077f277bb2e6d7611fe0 Mon Sep 17 00:00:00 2001
From: Yang Zhang <yang.zhang@linaro.org>
Date: Wed, 26 Jul 2017 15:54:13 +0800
Subject: [PATCH] 8184900: AArch64: Fix overflow in immediate cmp instruction

Use subs instead of cmp to compare BlockZeroingLowLimit.

Reviewed-by: aph
---
 hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp | 1 +
 hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp b/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp
index a6ce63019c9..fb6131856b7 100644
--- a/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp
+++ b/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp
@@ -169,6 +169,7 @@ class MacroAssembler: public Assembler {
 
   template<class T>
   inline void cmpw(Register Rd, T imm)  { subsw(zr, Rd, imm); }
+  // imm is limited to 12 bits.
   inline void cmp(Register Rd, unsigned imm)  { subs(zr, Rd, imm); }
 
   inline void cmnw(Register Rd, unsigned imm) { addsw(zr, Rd, imm); }
diff --git a/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp b/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp
index e64caab67eb..8542a99df7f 100644
--- a/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp
+++ b/hotspot/src/cpu/aarch64/vm/stubGenerator_aarch64.cpp
@@ -764,7 +764,7 @@ class StubGenerator: public StubCodeGenerator {
       // alignment.
       Label small;
       int low_limit = MAX2(zva_length * 2, (int)BlockZeroingLowLimit);
-      __ cmp(cnt, low_limit >> 3);
+      __ subs(rscratch1, cnt, low_limit >> 3);
       __ br(Assembler::LT, small);
       __ zero_dcache_blocks(base, cnt);
       __ bind(small);