Skip to main content Link Search Menu Expand Document (external link)

III Implement FSUBR

Table of contents

  1. Tips about Implementing FSUBR
  2. Test your implementation

At this part, you will implement a missing x87 instruction (FSUBR) in gem5.

Hint : You need to modify src/arch/x86/isa/decoder/x87.isa and src/arch/x86/isa/insts/x87/arithmetic/ to implement FSUBR

Tips about Implementing FSUBR

  • Normally, the emulator itself is very complex, so we may feel that it would be difficult to modify or add our own things in the emulator. In fact, gem5 is very extensible(OOP, Structured directory/files and assisting Python configs). And the easiest way to extend in gem5 is imitation. For example, to implement the FSUBR instruction, we can mimic the implementation of the FSUB instruction.

  • these mannuals may be useful for understanding x86 ISA

  • this tutorial introduce implementing FSUBR in detail

Test your implementation

We are providing an implementation using FSUBR.

 // ret = in2 - in1
 float subtract(float in1, float in2)
    float ret = 0.0;
    asm ("fsubr %2, %0" : "=&t" (ret) : "%0" (in1), "u" (in2));
    return ret;

You need to test your implementation by building a benchmark program and run it in gem5 to validate your implementation is right.

a. In x87.isa, you may notice that some code like Inst::FSUB1(Ed), what is the meaning of the content in parentheses? How do you know that?