summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2016-02-22 16:18:11 -0500
committerGravatar Benjamin Barenblat <bbaren@google.com>2016-02-22 16:18:11 -0500
commit74e86d2f4f72751a4d7db9786d1f2a7f2b99df61 (patch)
tree890121876f75fc5eecd641cc716a19b9dd2e11e8
parent8f736d5a3975a5d798700e6764216647258981b6 (diff)
Go: Also generate funct3, csr, and funct7 encodings
-rwxr-xr-xparse-opcodes19
1 files changed, 15 insertions, 4 deletions
diff --git a/parse-opcodes b/parse-opcodes
index 7d7ec2d..f336999 100755
--- a/parse-opcodes
+++ b/parse-opcodes
@@ -798,8 +798,12 @@ def make_chisel():
def print_go_insn(name):
print '\tcase A%s:' % name.upper().replace('.', '')
- # Yank bits 0-6 of the encoded instruction (i.e., the opcode) and print them.
- print '\t\treturn 0x%x' % yank(match[name], 0, 7)
+ m = match[name]
+ opcode = yank(m, 0, 7)
+ funct3 = yank(m, 12, 3)
+ csr = yank(m, 20, 12)
+ funct7 = yank(m, 25, 7)
+ print '\t\treturn &inst{0x%x, 0x%x, 0x%x, 0x%x}' % (opcode, funct3, csr, funct7)
def make_go():
print '// Automatically generated by parse-opcodes'
@@ -808,14 +812,21 @@ def make_go():
print
print 'import "log"'
print
- print 'func opcode(a int) uint32 {'
+ print 'type inst struct {'
+ print '\topcode uint32'
+ print '\tfunct3 uint32'
+ print '\tcsr uint32'
+ print '\tfunct7 uint32'
+ print '}'
+ print
+ print 'func encode(a int16) *inst {'
print '\tswitch a {'
for name in namelist:
if name not in GO_UNUSED_INSTRUCTIONS:
print_go_insn(name)
print '\t}'
print '\tlog.Fatalf("opcode: missing %v (bug in parse-opcodes)", a)'
- print '\treturn 0'
+ print '\treturn nil'
print '}'
for line in sys.stdin: