Ziel Nutzung der FPU


  • Mod

    Bisher haben wir:

    void set_fpu_control_word(const uint16_t cw)
    {
        // FLDCW = Load FPU Control Word
        __asm__ volatile("fldcw %0;"::"m"(cw)); // sets the FPU control word to "cw"
    
    }
    
    // 9th bit (OSFXSR) in the CR4 tells the CPU
    // that we intend on using the FXSAVE, FXRSTOR, and SSEx instructions.
    void setup_x87_fpu()
    {
        size_t cr4; // backup of CR4
    
        // place CR4 into our variable
        __asm__ volatile("mov %%cr4, %0;" : "=r" (cr4));
    
        // set the OSFXSR bit
        cr4 |= 0x200;
    
        // reload CR4 and INIT the FPU (FINIT)
        __asm__ volatile("mov %0, %%cr4; finit;" : : "r"(cr4));
    
        // set the FPU Control Word
        set_fpu_control_word(0x37F);
    }
    

    Beim Taskwechsel müssen nun noch weitere Sicherungsmaßnahmen vorgenommen werden. Da bisher niemand weiß, wie das exakt geht, hier eine Sammlung von Infos zu dem Thema:

    Links:
    http://lowlevel.brainsware.org/forum/index.php?topic=1711.msg19685

    Bei jedem Taskswitch setzt du das Bit.
    Wenn das Bit gesetzt ist, wird immer wenn du einen FPU Befehl nutzt die Exception (Nummer 7) ausgelöst.
    Wenn diese Exception ausgelöst wird, löschst du das Bit wieder.
    Falls ein anderer Task/Thread als der aktuelle die FPU Register zuletzt benutzt hat, musst du jetzt die FPU Register speichern und die FPU Register des aktuellen Tasks wieder laden.

    Also:
    Bei jedem Taskwechsel: Bit setzen
    Wenn die Exception 7 ausgelöst wird: Bit löschen.
    -> Wenn FPU_REGISTER_TASK != AKTUELLER_TASK
    ----> Aktueller Inhalt der FPU gehört zu nem anderen Task ergo: Register für den anderen Task speichern, Register für den aktuellen Task laden
    ----> FPU_REGISTER_TASK = AKTUELLER_TASK

    Intel® 64 and IA-32 Architectures Software Developer’s Manual
    Volume 3A: System Programming Guide, Part 1, December 2009

    13.5 DESIGNING OS FACILITIES FOR AUTOMATICALLY SAVING X87 FPU, MMX, AND SSE/SSE2/SSE3/SSSE3/SSE4 STATE ON TASK OR CONTEXT SWITCHES

    The TS flag in control register CR0 is provided to allow the operating system to delay saving the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state until an instruction that actually accesses this state is encountered in a new task. When the TS flag is set, the processor monitors the instruction stream for an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction. When the processor detects
    one of these instructions, it raises a device-not-available exception (#NM) prior to executing the instruction. The device-not-available exception handler can then be used to save the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state for the previous task (using an FXSAVE instruction) and load the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state for the current task (using an FXRSTOR instruction). If the task never encounters an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction, the device-not-available exception will not be raised and a task state will not be saved unnecessarily.


  • Mod

    Die Nutzung der FPU wurde nun ab Rev. 313 umgesetzt. #NM wird nur gesetzt, wenn es wirklich notwendig ist. Multitasking mit parallelen FPU-Anwendern ist nun kein Problem mehr. 🙂

    Dank an Tobiking für die Unterstützung!


  • Mod

    Bit9 OSFXSR in cr4 muss für den K6-2 auf 0 gesetzt sein:
    http://www.c-plusplus.net/forum/viewtopic-var-p-is-1942700.html#1942700


  • Mod

    FPU und vbe spielen nun auch zusammen.


Anmelden zum Antworten