Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3355,7 +3355,7 @@ void MacroAssembler::kernel_crc32_using_crc32(Register crc, Register buf,
crc32x(crc, crc, tmp2);
crc32x(crc, crc, tmp3);
br(Assembler::GE, CRC_by32_loop);
cmn(len, 32);
cmn(len, (u1)32);
br(Assembler::NE, CRC_less32);
b(L_exit);

Expand Down Expand Up @@ -3418,7 +3418,7 @@ void MacroAssembler::kernel_crc32_using_crc32(Register crc, Register buf,

sub(len, len, 64);
add(buf, buf, 8);
cmn(len, 128);
cmn(len, (u1)128);
br(Assembler::NE, CRC_less64);
BIND(L_exit);
mvnw(crc, crc);
Expand Down Expand Up @@ -3652,7 +3652,7 @@ void MacroAssembler::kernel_crc32c_using_crc32c(Register crc, Register buf,
crc32cx(crc, crc, tmp2);
crc32cx(crc, crc, tmp3);
br(Assembler::GE, CRC_by32_loop);
cmn(len, 32);
cmn(len, (u1)32);
br(Assembler::NE, CRC_less32);
b(L_exit);

Expand Down Expand Up @@ -3715,7 +3715,7 @@ void MacroAssembler::kernel_crc32c_using_crc32c(Register crc, Register buf,

sub(len, len, 64);
add(buf, buf, 8);
cmn(len, 128);
cmn(len, (u1)128);
br(Assembler::NE, CRC_less64);
BIND(L_exit);
}
Expand Down
7 changes: 5 additions & 2 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ class MacroAssembler: public Assembler {
inline void cmp(Register Rd, unsigned char imm8) { subs(zr, Rd, imm8); }
inline void cmp(Register Rd, unsigned imm) = delete;

inline void cmnw(Register Rd, unsigned imm) { addsw(zr, Rd, imm); }
inline void cmn(Register Rd, unsigned imm) { adds(zr, Rd, imm); }
template<class T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it to be a template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we made it unsigned int, we'd risk a 64-bit signed value (from C2, for example) being truncated before being passed to addsw(Register Rd, Register Rn, uint64_t imm). As we now have a 64-bit-clean path through all this code, that would be a Bad Thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation. I reread the code and found why I got confused.
MacroAssembler::cmnw call addsw which is defined by WRAP(addsw, true).
The macro expends to

void addsw(Register Rd, Register Rn, uint64_t imm) {
    wrap_adds_subs_imm_insn(Rd, Rn, imm, &Assembler::addsw, &Assembler::addsw, true);
}

void addsw(Register Rd, Register Rn, Register Rm, enum shift_kind kind, unsigned shift = 0) {
   Assembler::addsw(Rd, Rn, Rm, kind, shift);
}

void addsw(Register Rd, Register Rn, Register Rm) {
   Assembler::addsw(Rd, Rn, Rm);
}

void addsw(Register Rd, Register Rn, Register Rm, ext::operation option, int amount = 0) {
  Assembler::addsw(Rd, Rn, Rm, option, amount);
}

I've mixed it up with Assembler::addsw(Register Rd, Register Rn, unsigned imm):

#define INSN(NAME, decode, negated)                                     \
  void NAME(Register Rd, Register Rn, unsigned imm, unsigned shift) {   \
    starti;                                                             \
    f(decode, 31, 29), f(0b10001, 28, 24), f(shift, 23, 22), f(imm, 21, 10); \
    zrf(Rd, 0), srf(Rn, 5);                                             \
  }                                                                     \
                                                                        \
  void NAME(Register Rd, Register Rn, unsigned imm) {                   \
    starti;                                                             \
    add_sub_immediate(current_insn, Rd, Rn, imm, decode, negated);      \
  }

  INSN(addsw, 0b001, 0b011);

inline void cmnw(Register Rd, T imm) { addsw(zr, Rd, imm); }

inline void cmn(Register Rd, unsigned char imm8) { adds(zr, Rd, imm8); }
inline void cmn(Register Rd, unsigned imm) = delete;

void cset(Register Rd, Assembler::Condition cond) {
csinc(Rd, zr, zr, ~cond);
Expand Down