Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions riscv64/riscv64asm/gnu.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ gnuSyntaxSwitch:

case VSETVL:
args[0], args[2] = args[2], args[0]

case FLI_S, FLI_D, FLI_H, FLI_Q:
if len(args) > 1 {
args[1] = fliConstants[inst.Args[1].(Uimm).Imm]
}

case FROUND_S, FROUND_D, FROUND_H, FROUND_Q,
FROUNDNX_S, FROUNDNX_D, FROUNDNX_H, FROUNDNX_Q:
args = append(args, frmName((inst.Enc>>12)&0x7))

case FCVTMOD_W_D:
args = append(args, "rtz")
}

if args != nil {
Expand Down Expand Up @@ -436,3 +448,62 @@ func gnuVectorOp(inst Inst, args []string) string {

return op + " " + strings.Join(args, ",")
}

// frmName returns the GNU assembler rounding mode suffix for the given
// funct3 rounding mode encoding.
func frmName(funct3 uint32) string {
switch funct3 {
case 0:
return "rne"
case 1:
return "rtz"
case 2:
return "rdn"
case 3:
return "rup"
case 4:
return "rmm"
case 7:
return "dyn"
default:
return "unknown"
}
}

// fliConstants provides the objdump-format string for each of the 32 FLI
// immediate values. The constants are the same for all precisions (S/D/H/Q)
// except for index 1 (minimum positive normal), which objdump shows as "min".
var fliConstants = [32]string{
"-0x1p+0", // -1.0
"min", // minimum positive normal
"0x1p-16", // 2^-16
"0x1p-15", // 2^-15
"0x1p-8", // 2^-8
"0x1p-7", // 2^-7
"0x1p-4", // 2^-4
"0x1p-3", // 2^-3
"0x1p-2", // 0.25
"0x1.4p-2", // 0.3125
"0x1.8p-2", // 0.375
"0x1.cp-2", // 0.4375
"0x1p-1", // 0.5
"0x1.4p-1", // 0.625
"0x1.8p-1", // 0.75
"0x1.cp-1", // 0.875
"0x1p+0", // 1.0
"0x1.4p+0", // 1.25
"0x1.8p+0", // 1.5
"0x1.cp+0", // 1.75
"0x1p+1", // 2.0
"0x1.4p+1", // 2.5
"0x1.8p+1", // 3.0
"0x1p+2", // 4.0
"0x1p+3", // 8.0
"0x1p+4", // 16.0
"0x1p+7", // 128.0
"0x1p+8", // 256.0
"0x1p+15", // 2^15
"0x1p+16", // 2^16
"inf", // +Inf
"nan", // canonical NaN
}
2 changes: 1 addition & 1 deletion riscv64/riscv64asm/objdumpext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func writeELF64(f *os.File, size int) error {
// RISC-V objdump needs the .riscv.attributes section to identify extensions.
exts := "rv64i2p0_m2p0_a2p0_f2p0_d2p0_q2p0_c2p0_v1p0_" +
"zicbom1p0_zicbop1p0_zicboz1p0_zicond1p0_zmmul1p0_" +
"zfh1p0_zfhmin1p0_zba1p0_zbb1p0_zbc1p0_zbs1p0_" +
"zfa1p0_zfh1p0_zfhmin1p0_zba1p0_zbb1p0_zbc1p0_zbs1p0_" +
"zvkg1p0_zvkned1p0_zvknha1p0_zvknhb1p0_zvksed1p0_zvksh1p0"
b := buildRISCVAttributes(exts)
sect = elf.Section64{
Expand Down
154 changes: 154 additions & 0 deletions riscv64/riscv64asm/plan9x.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,20 @@ goSyntaxSwitch:

case VSETVL:
args[0], args[2] = args[2], args[0]

case FLI_S, FLI_D, FLI_H, FLI_Q:
if len(args) > 1 {
switch inst.Op {
case FLI_S:
args[1] = fliSConstants[inst.Args[1].(Uimm).Imm]
case FLI_D:
args[1] = fliDConstants[inst.Args[1].(Uimm).Imm]
case FLI_H:
args[1] = fliHConstants[inst.Args[1].(Uimm).Imm]
case FLI_Q:
args[1] = fliQConstants[inst.Args[1].(Uimm).Imm]
}
}
}

// Reverse args, placing dest last.
Expand Down Expand Up @@ -491,3 +505,143 @@ func plan9VectorOp(inst Inst, args []string) string {
op = strings.Replace(op, ".", "", -1)
return op + " " + strings.Join(args, ", ")
}

var fliSConstants = [32]string{
"$(-1.0)",
"$(1.1754943508222875e-38)",
"$(1.52587890625e-05)",
"$(3.0517578125e-05)",
"$(0.00390625)",
"$(0.0078125)",
"$(0.0625)",
"$(0.125)",
"$(0.25)",
"$(0.3125)",
"$(0.375)",
"$(0.4375)",
"$(0.5)",
"$(0.625)",
"$(0.75)",
"$(0.875)",
"$(1.0)",
"$(1.25)",
"$(1.5)",
"$(1.75)",
"$(2.0)",
"$(2.5)",
"$(3.0)",
"$(4.0)",
"$(8.0)",
"$(16.0)",
"$(128.0)",
"$(256.0)",
"$(32768.0)",
"$(65536.0)",
"$(+Inf)",
"$(NaN)",
}

var fliDConstants = [32]string{
"$(-1.0)",
"$(2.2250738585072014e-308)",
"$(1.52587890625e-05)",
"$(3.0517578125e-05)",
"$(0.00390625)",
"$(0.0078125)",
"$(0.0625)",
"$(0.125)",
"$(0.25)",
"$(0.3125)",
"$(0.375)",
"$(0.4375)",
"$(0.5)",
"$(0.625)",
"$(0.75)",
"$(0.875)",
"$(1.0)",
"$(1.25)",
"$(1.5)",
"$(1.75)",
"$(2.0)",
"$(2.5)",
"$(3.0)",
"$(4.0)",
"$(8.0)",
"$(16.0)",
"$(128.0)",
"$(256.0)",
"$(32768.0)",
"$(65536.0)",
"$(+Inf)",
"$(NaN)",
}

var fliHConstants = [32]string{
"$(-1.0)",
"$(6.103515625e-05)",
"$(1.52587890625e-05)",
"$(3.0517578125e-05)",
"$(0.00390625)",
"$(0.0078125)",
"$(0.0625)",
"$(0.125)",
"$(0.25)",
"$(0.3125)",
"$(0.375)",
"$(0.4375)",
"$(0.5)",
"$(0.625)",
"$(0.75)",
"$(0.875)",
"$(1.0)",
"$(1.25)",
"$(1.5)",
"$(1.75)",
"$(2.0)",
"$(2.5)",
"$(3.0)",
"$(4.0)",
"$(8.0)",
"$(16.0)",
"$(128.0)",
"$(256.0)",
"$(32768.0)",
"$(65536.0)",
"$(+Inf)",
"$(NaN)",
}

var fliQConstants = [32]string{
"$(-1.0)",
"$(3.3621031431120935062626778173217526e-4932)",
"$(1.52587890625e-05)",
"$(3.0517578125e-05)",
"$(0.00390625)",
"$(0.0078125)",
"$(0.0625)",
"$(0.125)",
"$(0.25)",
"$(0.3125)",
"$(0.375)",
"$(0.4375)",
"$(0.5)",
"$(0.625)",
"$(0.75)",
"$(0.875)",
"$(1.0)",
"$(1.25)",
"$(1.5)",
"$(1.75)",
"$(2.0)",
"$(2.5)",
"$(3.0)",
"$(4.0)",
"$(8.0)",
"$(16.0)",
"$(128.0)",
"$(256.0)",
"$(32768.0)",
"$(65536.0)",
"$(+Inf)",
"$(NaN)",
}
Loading
Loading