diff --git a/src/cmd/asm/internal/asm/testdata/riscv64.s b/src/cmd/asm/internal/asm/testdata/riscv64.s index 702b82223b36af..9184f5741ac6d6 100644 --- a/src/cmd/asm/internal/asm/testdata/riscv64.s +++ b/src/cmd/asm/internal/asm/testdata/riscv64.s @@ -195,6 +195,9 @@ start: RDTIME X5 // f32210c0 RDINSTRET X5 // f32220c0 + // 10.1: Zihintpause Extension for Pause Hint + PAUSE // 0f000001 + // 12.3: Integer Conditional Operations (Zicond) CZEROEQZ X5, X6, X7 // b353530e CZEROEQZ X5, X7 // b3d3530e diff --git a/src/cmd/internal/obj/riscv/anames.go b/src/cmd/internal/obj/riscv/anames.go index 6c48e2f7de4799..181d37de3d9515 100644 --- a/src/cmd/internal/obj/riscv/anames.go +++ b/src/cmd/internal/obj/riscv/anames.go @@ -936,6 +936,7 @@ var Anames = []string{ "NEG", "NEGW", "NOT", + "PAUSE", "RDCYCLE", "RDINSTRET", "RDTIME", diff --git a/src/cmd/internal/obj/riscv/cpu.go b/src/cmd/internal/obj/riscv/cpu.go index 60174a0b3a245f..6338ed0f77de33 100644 --- a/src/cmd/internal/obj/riscv/cpu.go +++ b/src/cmd/internal/obj/riscv/cpu.go @@ -1500,6 +1500,7 @@ const ( ANEG ANEGW ANOT + APAUSE ARDCYCLE ARDINSTRET ARDTIME diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index e55c206a98e434..ef8560d74b4388 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -3674,6 +3674,10 @@ func instructionsForProg(p *obj.Prog) []*instruction { ins.rd, ins.rs1, ins.rs2 = REG_ZERO, REG_ZERO, obj.REG_NONE ins.imm = 0x0ff + case APAUSE: + ins.as, ins.rd, ins.rs1, ins.rs2 = AFENCE, REG_ZERO, REG_ZERO, obj.REG_NONE + ins.imm = 0x010 + case AFCVTWS, AFCVTLS, AFCVTWUS, AFCVTLUS, AFCVTWD, AFCVTLD, AFCVTWUD, AFCVTLUD: // Set the default rounding mode in funct3 to round to zero. if p.Scond&rmSuffixBit == 0 { diff --git a/src/runtime/asm_riscv64.h b/src/runtime/asm_riscv64.h index 2414b9f067675a..745125ebce4aa1 100644 --- a/src/runtime/asm_riscv64.h +++ b/src/runtime/asm_riscv64.h @@ -18,4 +18,5 @@ #define hasZbs #define hasZfa #define hasZicond +#define hasZihintpause #endif diff --git a/src/runtime/asm_riscv64.s b/src/runtime/asm_riscv64.s index 5bd16181ee2b87..6f87456af6ab4a 100644 --- a/src/runtime/asm_riscv64.s +++ b/src/runtime/asm_riscv64.s @@ -5,7 +5,7 @@ #include "go_asm.h" #include "funcdata.h" #include "textflag.h" - +#include "asm_riscv64.h" // When building with -buildmode=c-shared, this symbol is called when the shared // library is loaded. @@ -367,8 +367,16 @@ TEXT gogo<>(SB), NOSPLIT|NOFRAME, $0 MOV gobuf_pc(T0), T0 JALR ZERO, T0 + // func procyieldAsm(cycles uint32) -TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0 +TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0 +#ifdef hasZihintpause + MOVWU X10, T0 +yieldloop: + PAUSE + SUBW $1, T0 + BNEZ T0, yieldloop +#endif RET // Switch to m->g0's stack, call fn(g).