Skip to contentSkip to conversation

i386: inline restore_fpu

PATCH Chuck Ebbert 2 participants 2 messages Jul 23, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 10 lines · Linus Torvalds
      /*
       * The "nop" is needed to make the instructions the same
       * length.
       */
      #define restore_fpu(tsk)                        \
              alternative_input(                      \
                      "nop ; frstor %1",              \
                      "fxrstor %1",                   \
                      X86_FEATURE_FXSR,               \
                      "m" ((tsk)->thread.i387.fsave))

Probably a very minor point, but shouldn't it be

                        "m" ((tsk)->thread.i387.fxsave))

because that's the largest possible operand that could end up being read?

Quoted 3 lines

Now, we should do the same for "fnsave ; fwait" vs "fxsave ; fnclex" too, but I was lazy. If somebody wants to try that, it would need an "alternative_output()" define but should otherwise be trivial too.

Is that function called __save_init_fpu because it saves and then
initializes the fpu? Unlike fsave, fxsave does not init the fpu after it saves the state; to make the behavior match it should be "fxsave ; fninit"

__
Chuck

#1 lore raw
Quoted 6 lines · Chuck Ebbert

Probably a very minor point, but shouldn't it be

                        "m" ((tsk)->thread.i387.fxsave))

because that's the largest possible operand that could end up being read?

Yes, I ended up fixing that already (along with handling the fxsave case too).

Quoted 3 lines

Is that function called __save_init_fpu because it saves and then
initializes the fpu? Unlike fsave, fxsave does not init the fpu after it saves the state; to make the behavior match it should be "fxsave ; fninit"

The "init" part is really just "reset_exceptions" - we don't care about the rest of the state, and the naming is historical (ie it's really called "init" because "fnsave" does the reset by re-initializing everything, ie there's an implied "fninit").

So for the fxsave path, we just use fnclex, since that's faster than a full fninit.

Linus