Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
InterruptDemo.txt87 linesDownload Raw Back to Lectures
1 2//This is the software interrupt num3//we will use.  See Software Int's for4//picking a num.  Nums are subject to change.5 6#define I_F_UNARY_MINUS I_USER7 8asm {9 10//This changes the sign of the floating11//point val in RAX12F_UNARY_MINUS_INT::13        PUSH    RAX14        FLD     U64 [RSP]15        FCHS16        FSTP    U64 [RSP]17        POP     RAX18        IRET19 20//This does the same thing, but not as21//an interrupt.22F_UNARY_MINUS_CALL::23        PUSH    RAX24        FLD     U64 [RSP]25        FCHS26        FSTP    U64 [RSP]27        POP     RAX28        RET29 30//This invokes the interrupt version31//with a C callable function.32_F_UM_INT::33        PUSH    RBP34        MOV     RBP,RSP35        MOV     RAX,SF_ARG1[RBP]36        INT     I_F_UNARY_MINUS37        POP     RBP38        RET1    839 40//This invokes the call version41//with a C callable function.42_F_UM_CALL::43        PUSH    RBP44        MOV     RBP,RSP45        MOV     RAX,SF_ARG1[RBP]46        CALL    F_UNARY_MINUS_CALL47        POP     RBP48        RET1    849}50 51_extern _F_UM_INT F64 UnaryMinusInt(F64 d);52_extern _F_UM_CALL F64 UnaryMinusCall(F64 d);53 54#define SAMPLE_SIZE     100000055U0 TimeIns()56{57  I64 start,end;58  I64 i,old_irq;59 60  CPURep;61  old_irq=IntEntrySet(I_F_UNARY_MINUS,F_UNARY_MINUS_INT,IDTET_TRAP);62 63  //Measure interrupt time64  start=GetTSC;65  for (i=0;i<SAMPLE_SIZE;i++)66    UnaryMinusInt(pi);67  end=GetTSC;68  "Interrupt Cycles: %10.5f\n",ToF64(end-start)/SAMPLE_SIZE;69 70  //Measure call time71  start=GetTSC;72  for (i=0;i<SAMPLE_SIZE;i++)73    UnaryMinusCall(pi);74  end=GetTSC;75  "Call      Cycles: %10.5f\n",ToF64(end-start)/SAMPLE_SIZE;76 77  IntEntrySet(I_F_UNARY_MINUS,old_irq,IDTET_IRQ);78}79 80TimeIns;81 82/*  Program Output836 Cores 3.395GHz84Interrupt Cycles:  573.9854385Call      Cycles:    9.7434986*/87