diff options
author | Benjamin Barenblat <bbaren@google.com> | 2016-02-26 13:22:22 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2016-02-26 13:22:22 -0500 |
commit | 0f4ae756c1af09883d930c04368f9e1c3aa1de6d (patch) | |
tree | f6648794df32679f13605d67de9233ff71f3fc77 /parse-opcodes | |
parent | 039497169da8a9495e10d3765ea73ed157650926 (diff) |
Go: Print CSRs as signed values
Diffstat (limited to 'parse-opcodes')
-rwxr-xr-x | parse-opcodes | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/parse-opcodes b/parse-opcodes index a6e0c87..0f7d449 100755 --- a/parse-opcodes +++ b/parse-opcodes @@ -767,6 +767,12 @@ def make_chisel(): print ' }' print '}' +def signed(value, width): + if 0 <= value < (1<<(width-1)): + return value + else: + return value - (1<<width) + def print_go_insn(name): print '\tcase A%s:' % name.upper().replace('.', '') m = match[name] @@ -774,7 +780,7 @@ def print_go_insn(name): 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) + print '\t\treturn &inst{0x%x, 0x%x, %d, 0x%x}' % (opcode, funct3, signed(csr, 12), funct7) def make_go(): print '// Automatically generated by parse-opcodes' @@ -786,7 +792,7 @@ def make_go(): print 'type inst struct {' print '\topcode uint32' print '\tfunct3 uint32' - print '\tcsr uint32' + print '\tcsr int64' print '\tfunct7 uint32' print '}' print |