Skip to content

Commit

Permalink
[mips][microMIPSr6] Implement CLO and CLZ instructions
Browse files Browse the repository at this point in the history
This patch implements CLO and CLZ instructions using mapping.

Differential Revision: http://reviews.llvm.org/D8553

llvm-svn: 237257
  • Loading branch information
Jozef Kolek committed May 13, 2015
1 parent 780a3b3 commit 6fec325
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
27 changes: 27 additions & 0 deletions llvm/lib/Target/Mips/MicroMips32r6InstrFormats.td
Expand Up @@ -109,3 +109,30 @@ class POOL32A_FM_MMR6<bits<10> funct> : MipsR6Inst {
let Inst{10} = 0;
let Inst{9-0} = funct;
}

class POOL32A_2R_FM_MMR6<bits<10> funct> : MipsR6Inst {
bits<5> rs;
bits<5> rt;

bits<32> Inst;

let Inst{31-26} = 0b000000;
let Inst{25-21} = rt;
let Inst{20-16} = rs;
let Inst{15-6} = funct;
let Inst{5-0} = 0b111100;
}

class SPECIAL_2R_FM_MMR6<bits<6> funct> : MipsR6Inst {
bits<5> rs;
bits<5> rt;

bits<32> Inst;

let Inst{31-26} = 0b000000;
let Inst{25-21} = rs;
let Inst{20-16} = 0b00000;
let Inst{15-11} = rt;
let Inst{10-6} = 0b00001;
let Inst{5-0} = funct;
}
14 changes: 14 additions & 0 deletions llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td
Expand Up @@ -26,6 +26,8 @@ class BALC_MMR6_ENC : BRANCH_OFF26_FM<0b101101>;
class BC_MMR6_ENC : BRANCH_OFF26_FM<0b100101>;
class BITSWAP_MMR6_ENC : POOL32A_BITSWAP_FM_MMR6<0b101100>;
class CACHE_MMR6_ENC : CACHE_PREF_FM_MMR6<0b001000, 0b0110>;
class CLO_MMR6_ENC : POOL32A_2R_FM_MMR6<0b0100101100>;
class CLZ_MMR6_ENC : SPECIAL_2R_FM_MMR6<0b010000>;
class JIALC_MMR6_ENC : JMP_IDX_COMPACT_FM<0b100000>;
class JIC_MMR6_ENC : JMP_IDX_COMPACT_FM<0b101000>;
class LWPC_MMR6_ENC : PCREL19_FM_MMR6<0b01>;
Expand Down Expand Up @@ -91,6 +93,16 @@ class CACHE_HINT_MMR6_DESC<string instr_asm, Operand MemOpnd,
class CACHE_MMR6_DESC : CACHE_HINT_MMR6_DESC<"cache", mem_mm_12, GPR32Opnd>;
class PREF_MMR6_DESC : CACHE_HINT_MMR6_DESC<"pref", mem_mm_12, GPR32Opnd>;

class CLO_CLZ_MMR6_DESC_BASE<string instr_asm, RegisterOperand GPROpnd>
: MMR6Arch<instr_asm> {
dag OutOperandList = (outs GPROpnd:$rt);
dag InOperandList = (ins GPROpnd:$rs);
string AsmString = !strconcat(instr_asm, "\t$rt, $rs");
}

class CLO_MMR6_DESC : CLO_CLZ_MMR6_DESC_BASE<"clo", GPR32Opnd>;
class CLZ_MMR6_DESC : CLO_CLZ_MMR6_DESC_BASE<"clz", GPR32Opnd>;

class JMP_MMR6_IDX_COMPACT_DESC_BASE<string opstr, DAGOperand opnd,
RegisterOperand GPROpnd>
: MMR6Arch<opstr> {
Expand Down Expand Up @@ -166,6 +178,8 @@ def BC_MMR6 : R6MMR6Rel, BC_MMR6_ENC, BC_MMR6_DESC, ISA_MICROMIPS32R6;
def BITSWAP_MMR6 : R6MMR6Rel, BITSWAP_MMR6_ENC, BITSWAP_MMR6_DESC,
ISA_MICROMIPS32R6;
def CACHE_MMR6 : R6MMR6Rel, CACHE_MMR6_ENC, CACHE_MMR6_DESC, ISA_MICROMIPS32R6;
def CLO_MMR6 : R6MMR6Rel, CLO_MMR6_ENC, CLO_MMR6_DESC, ISA_MICROMIPS32R6;
def CLZ_MMR6 : R6MMR6Rel, CLZ_MMR6_ENC, CLZ_MMR6_DESC, ISA_MICROMIPS32R6;
def JIALC_MMR6 : R6MMR6Rel, JIALC_MMR6_ENC, JIALC_MMR6_DESC, ISA_MICROMIPS32R6;
def JIC_MMR6 : R6MMR6Rel, JIC_MMR6_ENC, JIC_MMR6_DESC, ISA_MICROMIPS32R6;
def LWPC_MMR6 : R6MMR6Rel, LWPC_MMR6_ENC, LWPC_MMR6_DESC, ISA_MICROMIPS32R6;
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Target/Mips/Mips32r6InstrInfo.td
Expand Up @@ -615,7 +615,8 @@ class SC_R6_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {

class SC_R6_DESC : SC_R6_DESC_BASE<"sc", GPR32Opnd>;

class CLO_CLZ_R6_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
class CLO_CLZ_R6_DESC_BASE<string instr_asm, RegisterOperand GPROpnd>
: MipsR6Arch<instr_asm> {
dag OutOperandList = (outs GPROpnd:$rd);
dag InOperandList = (ins GPROpnd:$rs);
string AsmString = !strconcat(instr_asm, "\t$rd, $rs");
Expand Down Expand Up @@ -683,8 +684,8 @@ def BOVC : BOVC_ENC, BOVC_DESC, ISA_MIPS32R6;
def CACHE_R6 : R6MMR6Rel, CACHE_ENC, CACHE_DESC, ISA_MIPS32R6;
def CLASS_D : CLASS_D_ENC, CLASS_D_DESC, ISA_MIPS32R6, HARDFLOAT;
def CLASS_S : CLASS_S_ENC, CLASS_S_DESC, ISA_MIPS32R6, HARDFLOAT;
def CLO_R6 : CLO_R6_ENC, CLO_R6_DESC, ISA_MIPS32R6;
def CLZ_R6 : CLZ_R6_ENC, CLZ_R6_DESC, ISA_MIPS32R6;
def CLO_R6 : R6MMR6Rel, CLO_R6_ENC, CLO_R6_DESC, ISA_MIPS32R6;
def CLZ_R6 : R6MMR6Rel, CLZ_R6_ENC, CLZ_R6_DESC, ISA_MIPS32R6;
defm S : CMP_CC_M<FIELD_CMP_FORMAT_S, "s", FGR32Opnd>;
defm D : CMP_CC_M<FIELD_CMP_FORMAT_D, "d", FGR64Opnd>;
def DIV : DIV_ENC, DIV_DESC, ISA_MIPS32R6;
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/MC/Disassembler/Mips/micromips32r6.txt
Expand Up @@ -24,6 +24,10 @@
# CHECK: cache 1, 8($5)
0x20 0x25 0x60 0x08

0x01 0x65 0x4b 0x3c # CHECK: clo $11, $5

0x03 0x80 0xe8 0x50 # CHECK: clz $sp, $gp

0x80 0x05 0x01 0x00 # CHECK: jialc $5, 256

0xa0 0x05 0x01 0x00 # CHECK: jic $5, 256
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/MC/Mips/micromips32r6/valid.s
Expand Up @@ -11,6 +11,8 @@
bc 14572256 # CHECK: bc 14572256 # encoding: [0x94,0x37,0x96,0xb8]
bitswap $4, $2 # CHECK: bitswap $4, $2 # encoding: [0x00,0x44,0x0b,0x3c]
cache 1, 8($5) # CHECK: cache 1, 8($5) # encoding: [0x20,0x25,0x60,0x08]
clo $11, $a1 # CHECK: clo $11, $5 # encoding: [0x01,0x65,0x4b,0x3c]
clz $sp, $gp # CHECK: clz $sp, $gp # encoding: [0x03,0x80,0xe8,0x50]
jialc $5, 256 # CHECK: jialc $5, 256 # encoding: [0x80,0x05,0x01,0x00]
jic $5, 256 # CHECK: jic $5, 256 # encoding: [0xa0,0x05,0x01,0x00]
lwpc $2,268 # CHECK: lwpc $2, 268 # encoding: [0x78,0x48,0x00,0x43]
Expand Down

0 comments on commit 6fec325

Please sign in to comment.