Detecting use of floating point

View: New views
3 Messages — Rating Filter:   Alert me  

Detecting use of floating point

by Sandro Magi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there any way to detect a change in floating point state? The
floating point state tends to be expensive to save and restore, so if
there's some sort of status flag that I can clear on context switch,
and check on the next context switch to indicate whether floating
point state has changed, it would save a significant amount of context
switch time.

Sandro


_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning

Re: Detecting use of floating point

by tim-168 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For X86, the TS bit of CR0 (X86), if on ,forces a fault if FP is used.
It is set by a hardware context switch and reset by a privileged
instruction.

The EM bit may also be useful.

The OS formally does this for you. If you are writing the OS, you woudl
have the authority to MOV into CR0.

Some CPUs have this facility and others do not.

Tim Josling

On Fri, 2008-02-22 at 17:12 -0500, Sandro Magi wrote:

> Is there any way to detect a change in floating point state? The
> floating point state tends to be expensive to save and restore, so if
> there's some sort of status flag that I can clear on context switch,
> and check on the next context switch to indicate whether floating
> point state has changed, it would save a significant amount of context
> switch time.
>
> Sandro
>
>
> _______________________________________________
> Lightning mailing list
> Lightning@...
> http://lists.gnu.org/mailman/listinfo/lightning



_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning

Re: Detecting use of floating point

by Sandro Magi-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Feb 23, 2008 at 12:35 AM, tim <tej@...> wrote:

> For X86, the TS bit of CR0 (X86), if on ,forces a fault if FP is used.
>  It is set by a hardware context switch and reset by a privileged
>  instruction.
>
>  The EM bit may also be useful.
>
>  The OS formally does this for you. If you are writing the OS, you woudl
>  have the authority to MOV into CR0.
>
>  Some CPUs have this facility and others do not.

Thanks for the pointers. I knew it could be done with ring-0
privilege, as I've studied OSes that use this optimization. I was just
wondering whether it could be done at user level. I suspect that most
operating systems don't expose an API to access this state. The C99
fenv.h header [1] exposes an interface to some floating point state,
but it's mainly limited to exceptional conditions and rounding modes.

Sandro

[1] http://www.opengroup.org/onlinepubs/009695399/basedefs/fenv.h.html


_______________________________________________
Lightning mailing list
Lightning@...
http://lists.gnu.org/mailman/listinfo/lightning