flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 02 Mar 2019, 12:00
It is common for OSes to not save/restore the FPU/SSE/AVX registers upon a task switch. Usually they employ lazy save/restore when the new task starts to use the FPU. This is triggered by disabling the FPU and waiting for each task to start using it. That way if you only have a single task using the FPU then there is no time wasted to keep saving and restoring the FPU registers.
|
|||
![]() |
|
N-LG 02 Mar 2019, 12:35
in order not to save these registry unnecessarily, I thought to assign to each task a level of use of the tasks and to make the backups according to that
the level of use will also allow not to perform tasks that would not be compatible with the instruction set of the processor. (all this is not done yet) |
|||
![]() |
|
revolution 02 Mar 2019, 12:43
If you know all of your tasks and what they use then a list will work. But it can lead to inefficiency is some circumstances. For example, maybe a task doesn't use the FPU during the upcoming time-slice, and then you would save and restore the FPU state even though it wasn't needed.
|
|||
![]() |
|
N-LG 02 Mar 2019, 13:02
I did not study the FPU (I did not need it yet) and I did not know it could be disabled.
when the FPU is disabled and the proc is trying to execute a FPU instruction, does it generate an exception? it is the #NM (Device Not Available) exception? does it work the same way for the SIMD unit? |
|||
![]() |
|
revolution 02 Mar 2019, 13:45
I use the term FPU as a proxy for all the float related stuff FPU/SSE/AVX. They are disabled by setting a bit in the control register (CR0 I think?). Then you get an exception if a task attempts to execute something that needs the FPU/SEE/AVX unit.
If you have the concept of which task "owns" the FPU then you can use that to determine where to save and restore its state. |
|||
![]() |
|
N-LG 03 Mar 2019, 17:21
I think that I will use a signal emitted by the task to signal that it starts or finish using the FPU / SIMD unit, so that the system knows when to save the registers
however I do not know if there is any other way than FXSAVE / FXRSTOR to backup / restore the registry. I searched but I do not see other ways |
|||
![]() |
|
revolution 03 Mar 2019, 18:12
There is also XSAVE, XRSTOR and XSAVEOPT
|
|||
![]() |
|
N-LG 03 Mar 2019, 21:27
ok, this is the extension of FXSAVE / FXRSTOR for AVX, I note for later, already I must get to use properly SSE first before trying AVX
thank you for all these indications |
|||
![]() |
|
dunkaist 03 Mar 2019, 21:28
You have to use XSAVE family instructions to save AVX context. You can't use lazy context switching via CR0.TS with XSAVE*, by design.
|
|||
![]() |
|
Tomasz Grysztar 03 Mar 2019, 21:53
dunkaist wrote: You can't use lazy context switching via CR0.TS with XSAVE*, by design. |
|||
![]() |
|
dunkaist 06 Mar 2019, 22:41
Tomasz Grysztar wrote:
I was actually thinking about 'CR0.TS vs AVX' but wrote 'CR0.TS vs XSAVE'. And you, Tomasz, somehow felt that and replied with a link to 'CR0.TS vs AVX' patch . It turns out even AVX512 context can be lazily switched. Thank you for pointing me to this! Just for completenes, 'CR0.TS vs XSAVE' is possible though not recommended. Intel wrote: Vol 3, 13.4 DESIGNING OS FACILITIES FOR SAVING X87 FPU, SSE AND EXTENDED STATES ON TASK OR CONTEXT SWITCHES |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.