1

I read here that a jmpl instruction must be followed by nop.

The SPARC V8 manual tells me that an rett instruction must always be preceded by a jmpl instruction.

But, I haven't been able to find a relation between jmpl and restore instructions. I am currently working on SPARC V8 architecture and one of the ELF files I encountered has a restore right after jmpl, while I expected an nop. I don't know if this is correct or the ELF (and by extension the SPARC code) is wrong.

Is having restore right after jmpl correct?

SonOfEl
  • 175
  • 1
  • 10
  • 1
    This is called a *branch delay slot.* The instruction following a jump is always executed before the jump takes action. On modern SPARC implementations, it's usually faster to leave these slots empty for CPU design reasons. I suppose they have hard-coded some common special cases like `jmpl; rett`. – fuz Sep 02 '20 at 14:23

2 Answers2

6

I read here that a jmpl instruction must be followed by nop.

... and the page you linked tells you why:

So when you program in SPARC, follow every call and jmpl instructions with a nop instruction to avoid executing an extra instruction unintentially ...

This means: The nop is not a requirement of the CPU, but it is an advise of the author of the web page for programmers to avoid errors.

On another page of the same course the author explains that a professional programmer (or a C compiler) would use the following sequence to return from a function:

jmpl %i7+8, %g0
restore

This means that it is not only allowed to use restore in the delay slot of the jmpl instruction, but it is even the normal sequence for returning from a function.

Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38
2

You don't need a nop. Just be aware that the instruction after the jumpl will be executed, because it is sill in the pipeline. So jmpl followed by rett executes the jumpl and the rett. Presumably this is an interrupt service routine or similar?

TonyK
  • 16,761
  • 4
  • 37
  • 72