unit FastcodeFloor01; //Version : 0.1 Preliminary version //Only direct calling supported interface function FloorFastcodeP4(const X : Extended) : Extended; overload; function FloorFastcodeP3(const X : Extended) : Extended; overload; function FloorFastcodeXP(const X : Extended) : Extended; overload; function FloorFastcodeOpteron(const X : Extended) : Extended; overload; function FloorFastcodeRTL(const X : Extended) : Extended; overload; function FloorFastcodePascal(const X : Extended) : Extended; overload; function FloorFastcodeBlended(const X : Extended) : Extended; overload; function FloorFastcodeP4(const X : Double) : Double; overload; function FloorFastcodeP3(const X : Double) : Double; overload; function FloorFastcodeXP(const X : Double) : Double; overload; function FloorFastcodeOpteron(const X : Double) : Double; overload; function FloorFastcodeRTL(const X : Double) : Double; overload; function FloorFastcodePascal(const X : Double) : Double; overload; function FloorFastcodeBlended(const X : Double) : Double; overload; function FloorFastcodeP4(const X : Single) : Single; overload; function FloorFastcodeP3(const X : Single) : Single; overload; function FloorFastcodeXP(const X : Single) : Single; overload; function FloorFastcodeOpteron(const X : Single) : Single; overload; function FloorFastcodeRTL(const X : Single) : Single; overload; function FloorFastcodePascal(const X : Single) : Single; overload; function FloorFastcodeBlended(const X : Single) : Single; overload; implementation //Author: John O'Harrow //Date: N/A //Optimized for: P4 //Instructionset(s): N/A //Original Name: FloorExtendedJOH function FloorFastcodeP4(const X : Extended) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: John O'Harrow //Date: N/A //Optimized for: P3 //Instructionset(s): N/A //Original Name: FloorExtendedJOH function FloorFastcodeP3(const X : Extended) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: XP //Instructionset(s): N/A //Original Name: FloorExtendedDKC1 function FloorFastcodeXP(const X : Extended) : Int64; asm fnstcw [esp-12].Word //Get current controlword mov ax, [esp-12] //into eax or ax, 0000010000000000B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down and ax, 1111011111111111B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down mov [esp-8], ax fldcw word ptr [esp-8] fld X fistp qword ptr [esp-8] mov eax, [esp-8] mov edx, [esp-4] fldcw word ptr [esp-12] //Restore controlword end; //Author: John O'Harrow //Date: N/A //Optimized for: Opteron //Instructionset(s): N/A //Original Name: FloorExtendedJOH function FloorFastcodeOpteron(const X : Extended) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: John O'Harrow //Date: N/A //Optimized for: RTL //Instructionset(s): N/A //Original Name: FloorExtendedJOH function FloorFastcodeRTL(const X : Extended) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Pascal //Instructionset(s): N/A //Original Name: FloorExtendedDKCPas1 function FloorFastcodePascal(const X: Extended): Int64; begin Result := Trunc(X); if ((X < 0) and (X - Result <> 0)) then Dec(Result); end; //Author: John O'Harrow //Date: N/A //Optimized for: Blended //Instructionset(s): N/A //Original Name: FloorExtendedJOH function FloorFastcodeBlended(const X : Extended) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: John O'Harrow //Date: N/A //Optimized for: P4 //Instructionset(s): N/A //Original Name: FloorDoubleJOH function FloorFastcodeP4(const X : Double ) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: John O'Harrow //Date: N/A //Optimized for: P3 //Instructionset(s): N/A //Original Name: FloorDoubleJOH function FloorFastcodeP3(const X : Double ) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: John O'Harrow //Date: N/A //Optimized for: XP //Instructionset(s): N/A //Original Name: FloorDoubleJOH function FloorFastcodeXP(const X : Double ) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Opteron //Instructionset(s): N/A //Original Name: FloorDoubleDKC1 function FloorFastcodeOpteron(const X : Double) : Int64; asm fnstcw [esp-12].Word //Get current controlword mov ax, [esp-12] //into eax or ax, 0000010000000000B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down and ax, 1111011111111111B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down mov [esp-8], ax fldcw word ptr [esp-8] fld X fistp qword ptr [esp-8] mov eax, [esp-8] mov edx, [esp-4] fldcw word ptr [esp-12] //Restore controlword end; //Author: John O'Harrow //Date: N/A //Optimized for: RTL //Instructionset(s): N/A //Original Name: FloorDoubleJOH function FloorFastcodeRTL(const X : Double ) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Pascal //Instructionset(s): N/A //Original Name: FloorDoubleDKCPas1 function FloorFastcodePascal(const X: Double): Int64; begin Result := Trunc(X); if ((X < 0) and (X - Result <> 0)) then Dec(Result); end; //Author: John O'Harrow //Date: N/A //Optimized for: Blended //Instructionset(s): N/A //Original Name: FloorDoubleJOH function FloorFastcodeBlended(const X : Double ) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: P4 //Instructionset(s): N/A //Original Name: FloorSingleDKC1 function FloorFastcodeP4(const X : Single) : Int64; asm fnstcw [esp-12].Word //Get current controlword mov ax, [esp-12] //into eax or ax, 0000010000000000B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down and ax, 1111011111111111B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down mov [esp-8], ax fldcw word ptr [esp-8] fld X fistp qword ptr [esp-8] mov eax, [esp-8] mov edx, [esp-4] fldcw word ptr [esp-12] //Restore controlword end; //Author: John O'Harrow //Date: N/A //Optimized for: P3 //Instructionset(s): N/A //Original Name: FloorSingleJOH function FloorFastcodeP3(const X : Single) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: XP //Instructionset(s): N/A //Original Name: FloorSingleDKC1 function FloorFastcodeXP(const X : Single) : Int64; asm fnstcw [esp-12].Word //Get current controlword mov ax, [esp-12] //into eax or ax, 0000010000000000B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down and ax, 1111011111111111B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down mov [esp-8], ax fldcw word ptr [esp-8] fld X fistp qword ptr [esp-8] mov eax, [esp-8] mov edx, [esp-4] fldcw word ptr [esp-12] //Restore controlword end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Opteron //Instructionset(s): N/A //Original Name: FloorSingleDKC1 function FloorFastcodeOpteron(const X : Single) : Int64; asm fnstcw [esp-12].Word //Get current controlword mov ax, [esp-12] //into eax or ax, 0000010000000000B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down and ax, 1111011111111111B //Bit 10-11 is rounding and bit10 = 0 & bit11 = 1 is round down mov [esp-8], ax fldcw word ptr [esp-8] fld X fistp qword ptr [esp-8] mov eax, [esp-8] mov edx, [esp-4] fldcw word ptr [esp-12] //Restore controlword end; //Author: John O'Harrow //Date: N/A //Optimized for: RTL //Instructionset(s): N/A //Original Name: FloorSingleJOH function FloorFastcodeRTL(const X : Single) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; //Author: Dennis Kjaer Christensen //Date: N/A //Optimized for: Pascal //Instructionset(s): N/A //Original Name: FloorSingleDKCPas1 function FloorFastcodePascal(const X: Single): Int64; begin Result := Trunc(X); if ((X < 0) and (X - Result <> 0)) then Dec(Result); end; //Author: John O'Harrow //Date: N/A //Optimized for: Blended //Instructionset(s): N/A //Original Name: FloorSingleJOH function FloorFastcodeBlended(const X : Single) : Int64; var OldCW, NewCW : Word; asm fnstcw OldCW {Save Current Control Word} mov ax, OldCW and ax, $F7FF {Clear Bit 11} or ax, $0700 {Set Bits 8, 9 and 10} mov NewCW, ax {Bits 8/9 = Precision, Bits 10/11 = Rounding Mode} fldcw NewCW {Set Round to -ve Infinity Mode with 64 Bit Precision} fld X fistp Result fldcw OldCW {Restore Original Control Word} end; end.