Equivalent RISC-V asm code

That’s AVR assembly language that could probably just as easily (and more portably) written in C as:

void tunedDelay(uint16_t delay){
  do {
    delay--;
  } while (delay != 0xFFFF);
}

There are a couple of problems with using such code in other systems:

  • the compiler could optimise the whole thing away, as no result is produced
  • it will run at different speeds on different CPU cores or at different clock speeds
  • it will run at inconsistent or at least hard to calculate speeds on all but the simplest CPUs due to things such as instruction caches and branch predictors

On the Hifive1 or any RISC-V) you are much better off using the timer register which enables you to measure delays accurate to about 0.03 us (30 ns). That AVR code looks like it’s about 0.5 us per iteration at 16 MHz. See Delay function in freedom sdk