diff options
author | Colin Schmidt <colins@eecs.berkeley.edu> | 2016-07-13 05:34:43 -0700 |
---|---|---|
committer | Colin Schmidt <colins@eecs.berkeley.edu> | 2016-07-13 05:34:43 -0700 |
commit | 6dbc75bb78d31c2faaa026d3bc588f9d3db84083 (patch) | |
tree | 2c4f26481e6cb900ead7f8c4d11aaa5c05f8fc38 | |
parent | cd97d2f441715dd31bb3fd079ab86dd957b5b4b0 (diff) | |
download | riscv-opcodes-6dbc75bb78d31c2faaa026d3bc588f9d3db84083.zip riscv-opcodes-6dbc75bb78d31c2faaa026d3bc588f9d3db84083.tar.gz riscv-opcodes-6dbc75bb78d31c2faaa026d3bc588f9d3db84083.tar.bz2 |
WIP: auto-generate llvm encoding filellvm-encodings
-rw-r--r-- | Makefile | 6 | ||||
-rwxr-xr-x | parse-opcodes | 87 |
2 files changed, 82 insertions, 11 deletions
@@ -5,10 +5,11 @@ PK_H := ../riscv-pk/pk/encoding.h FESVR_H := ../riscv-fesvr/fesvr/encoding.h ENV_H := ../riscv-tests/env/encoding.h GAS_H := ../riscv-gnu-toolchain/binutils/include/opcode/riscv-opc.h +LLVM_TD := ../riscv-llvm/lib/Target/RISCV/RISCVInstrFormatBits.td ALL_OPCODES := opcodes-pseudo opcodes opcodes-rvc opcodes-rvc-pseudo opcodes-custom -install: $(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H) $(GAS_H) inst.chisel instr-table.tex priv-instr-table.tex +install: $(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H) $(GAS_H) $(LLVM_TD) inst.chisel instr-table.tex priv-instr-table.tex $(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H): $(ALL_OPCODES) parse-opcodes encoding.h cp encoding.h $@ @@ -17,6 +18,9 @@ $(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H): $(ALL_OPCODES) parse-opcodes encoding.h $(GAS_H) $(XCC_H): $(ALL_OPCODES) parse-opcodes cat $(ALL_OPCODES) | ./parse-opcodes -c > $@ +$(LLVM_TD): $(ALL_OPCODES) parse-opcodes + cat $(ALL_OPCODES) | ./parse-opcodes -llvm > $@ + inst.chisel: $(ALL_OPCODES) parse-opcodes cat opcodes opcodes-custom opcodes-pseudo | ./parse-opcodes -chisel > $@ diff --git a/parse-opcodes b/parse-opcodes index ffc1f07..d54e36c 100755 --- a/parse-opcodes +++ b/parse-opcodes @@ -151,13 +151,21 @@ csrs32 = [ opcode_base = 0 opcode_size = 7 -funct_base = 12 -funct_size = 3 +funct3_base = 12 +funct3_size = 3 +funct7_base = 25 +funct7_size = 7 +funct2_base = 25 +funct2_size = 2 def binary(n, digits=0): rep = bin(n)[2:] return rep if digits == 0 else ('0' * (digits - len(rep))) + rep +def llvm_binary(n, digits=0): + rep = bin(n)[2:] + return '0b' + ('0' * (digits - len(rep))) + rep + def make_c(match,mask): print '/* Automatically generated by parse-opcodes */' print '#ifndef RISCV_ENCODING_H' @@ -188,6 +196,63 @@ def make_c(match,mask): print 'DECLARE_CAUSE("%s", CAUSE_%s)' % (name, name.upper().replace(' ', '_')) print '#endif' +def make_llvm(match,mask): + print '/* Automatically generated by parse-opcodes */' + for name in namelist: + name2 = name.upper().replace('.','_') + if name == 'fence' or name == 'fence.i': + #print_fence_type(n, match[n], arguments[n]) + pass + elif 'aqrl' in arguments[name]: + #print_amo_type(n, match[n], arguments[n]) + pass + elif 'shamt' in arguments[name]: + #print_ish_type(n, match[n], arguments[n]) + pass + elif 'shamtw' in arguments[name]: + #print_ishw_type(n, match[n], arguments[n]) + pass + elif 'imm20' in arguments[name]: + #print_u_type(n, match[n], arguments[n]) + pass + elif 'jimm20' in arguments[name]: + #print_uj_type(n, match[n], arguments[n]) + pass + elif 'imm12' in arguments[name]: + #print_i_type(n, match[n], arguments[n]) + pass + elif 'imm12hi' in arguments[name]: + #print_s_type(n, match[n], arguments[n]) + pass + elif 'bimm12hi' in arguments[name]: + #print_sb_type(n, match[n], arguments[n]) + pass + elif 'rs3' in arguments[name]: + for rm in [('RDY','0b111'),('RNE','0b000'),('RTZ','0b001'), + ('RDN','0b010'),('RUP','0b011'),('RMM','0b100')]: + print 'class RV_BITS_%s_%s : RV_FMT_R4<%s,%s,%s>;' % (name2, + rm[0], + llvm_binary(yank(match[name],opcode_base,opcode_size),opcode_size), + llvm_binary(yank(match[name],funct2_base,funct2_size),funct2_size), + rm[1] + ) + elif 'rm' in arguments[name]: + for rm in [('RDY','0b111'),('RNE','0b000'),('RTZ','0b001'), + ('RDN','0b010'),('RUP','0b011'),('RMM','0b100')]: + print 'class RV_BITS_%s_%s : RV_FMT_R<%s,%s,%s>;' % (name2, + rm[0], + llvm_binary(yank(match[name],opcode_base,opcode_size),opcode_size), + llvm_binary(yank(match[name],funct7_base,funct7_size),funct7_size), + rm[1] + ) + else: + print 'class RV_BITS_%s : RV_FMT_R<%s,%s,%s>;' % (name2, + llvm_binary(yank(match[name],opcode_base,opcode_size),opcode_size), + llvm_binary(yank(match[name],funct7_base,funct7_size),funct7_size), + llvm_binary(yank(match[name],funct3_base,funct3_size),funct3_size) + ) + print '/* End autogenerated by parse-opcodes */' + def yank(num,start,len): return (num >> start) & ((1 << len) - 1) @@ -299,7 +364,7 @@ def print_s_type(name,match,arguments): str_arg('imm12hi','imm[11:5]',match,arguments), \ str_arg('rs2','',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('imm12lo','imm[4:0]',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -320,7 +385,7 @@ def print_sb_type(name,match,arguments): str_arg('bimm12hi','imm[12$\\vert$10:5]',match,arguments), \ str_arg('rs2','',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('bimm12lo','imm[4:1$\\vert$11]',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -339,7 +404,7 @@ def print_i_type(name,match,arguments): ( \ str_arg('imm12','imm[11:0]',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('rd','',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -358,7 +423,7 @@ def print_csr_type(name,match,arguments): ( \ str_arg('imm12','csr',match,arguments), \ ('zimm' if name[-1] == 'i' else 'rs1'), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('rd','',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -379,7 +444,7 @@ def print_ish_type(name,match,arguments): binary(yank(match,26,6),6), \ str_arg('shamt','shamt',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('rd','',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -400,7 +465,7 @@ def print_ishw_type(name,match,arguments): binary(yank(match,25,7),7), \ str_arg('shamtw','shamt',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('rd','',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -467,7 +532,7 @@ def print_amo_type(name,match,arguments): binary(yank(match,27,5),5), \ str_arg('rs2','',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('rd','',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -490,7 +555,7 @@ def print_fence_type(name,match,arguments): str_arg('pred','pred',match,arguments), \ str_arg('succ','',match,arguments), \ str_arg('rs1','',match,arguments), \ - binary(yank(match,funct_base,funct_size),funct_size), \ + binary(yank(match,funct3_base,funct3_size),funct3_size), \ str_arg('rd','',match,arguments), \ binary(yank(match,opcode_base,opcode_size),opcode_size), \ str_inst(name,arguments) \ @@ -840,5 +905,7 @@ elif sys.argv[1] == '-chisel': make_chisel() elif sys.argv[1] == '-c': make_c(match,mask) +elif sys.argv[1] == '-llvm': + make_llvm(match,mask) else: assert 0 |