Skip to content

Commit

Permalink
logical imm meta mnemonics
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanr13 authored and kawakami-k committed Feb 1, 2025
1 parent 36fc731 commit 9db7da1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/xbyak_aarch64_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@ uint32_t genS(const VRegElem &Reg) {
return s;
}

bool CodeGenerator::isValidLogicalImm(uint64_t imm, uint32_t size) {
// check imm
if (imm == 0 || imm == ones(size)) {
return false;
}

auto ptn_size = getPtnSize(imm, size);
auto ptn = imm & ones(ptn_size);
auto rotate_num = getPtnRotateNum(ptn, ptn_size);
auto rotate_ptn = lrotate(ptn, ptn_size, rotate_num);
auto one_bit_num = countOneBit(rotate_ptn, ptn_size);
auto seq_one_bit_num = countSeqOneBit(rotate_ptn, ptn_size);

// check ptn
if (one_bit_num != seq_one_bit_num) {
return false;
}
return true;
}

uint32_t CodeGenerator::genNImmrImms(uint64_t imm, uint32_t size) {
// check imm
if (imm == 0 || imm == ones(size)) {
Expand Down
1 change: 1 addition & 0 deletions xbyak_aarch64/xbyak_aarch64_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class CodeGenerator : public CodeArray {
// ############### encoding helper function #############
// generate encoded imm
uint32_t genNImmrImms(uint64_t imm, uint32_t size);
bool isValidLogicalImm(uint64_t imm, uint32_t size);

// generate relative address for label offset
uint64_t genLabelOffset(const Label &label, const JmpLabel &jmpL) {
Expand Down
36 changes: 36 additions & 0 deletions xbyak_aarch64/xbyak_aarch64_meta_mnemonic.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,39 @@ template <typename T> void cmp_imm(const WReg &a, T imm, const WReg &b) {

return;
}

void and_imm(const WReg &dst, const WReg &src, uint32_t imm, const WReg &tmp) {
if (isValidLogicalImm(imm, 32)) {
and_(dst, src, imm);
} else {
mov(tmp, imm);
and_(dst, src, tmp);
}
}

void ands_imm(const WReg &dst, const WReg &src, uint32_t imm, const WReg &tmp) {
if (isValidLogicalImm(imm, 32)) {
ands(dst, src, imm);
} else {
mov(tmp, imm);
ands(dst, src, tmp);
}
}

void orr_imm(const WReg &dst, const WReg &src, uint32_t imm, const WReg &tmp) {
if (isValidLogicalImm(imm, 32)) {
orr(dst, src, imm);
} else {
mov(tmp, imm);
orr(dst, src, tmp);
}
}

void eor_imm(const WReg &dst, const WReg &src, uint32_t imm, const WReg &tmp) {
if (isValidLogicalImm(imm, 32)) {
eor(dst, src, imm);
} else {
mov(tmp, imm);
eor(dst, src, tmp);
}
}

0 comments on commit 9db7da1

Please sign in to comment.