ftol.nasm (2949B)
1 ;=========================================================================== 2 ;Copyright (C) 1999-2005 Id Software, Inc. 3 ; 4 ;This file is part of Quake III Arena source code. 5 ; 6 ;Quake III Arena source code is free software; you can redistribute it 7 ;and/or modify it under the terms of the GNU General Public License as 8 ;published by the Free Software Foundation; either version 2 of the License, 9 ;or (at your option) any later version. 10 ; 11 ;Quake III Arena source code is distributed in the hope that it will be 12 ;useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 ;GNU General Public License for more details. 15 ; 16 ;You should have received a copy of the GNU General Public License 17 ;along with Foobar; if not, write to the Free Software 18 ;Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 ;=========================================================================== 20 21 ; 22 ; qftol -- fast floating point to long conversion. 23 ; 24 25 segment .data 26 27 temp dd 0.0 28 fpucw dd 0 29 30 ; Precision Control Field , 2 bits / 0x0300 31 ; PC24 0x0000 Single precision (24 bits). 32 ; PC53 0x0200 Double precision (53 bits). 33 ; PC64 0x0300 Extended precision (64 bits). 34 35 ; Rounding Control Field, 2 bits / 0x0C00 36 ; RCN 0x0000 Rounding to nearest (even). 37 ; RCD 0x0400 Rounding down (directed, minus). 38 ; RCU 0x0800 Rounding up (directed plus). 39 ; RC0 0x0C00 Rounding towards zero (chop mode). 40 41 42 ; rounding towards nearest (even) 43 cw027F dd 0x027F ; double precision 44 cw037F dd 0x037F ; extended precision 45 46 ; rounding towards zero (chop mode) 47 cw0E7F dd 0x0E7F ; double precision 48 cw0F7F dd 0x0F7F ; extended precision 49 50 51 segment .text 52 53 ; 54 ; int qftol( void ) - default control word 55 ; 56 57 global qftol 58 59 qftol: 60 fistp dword [temp] 61 mov eax, [temp] 62 ret 63 64 65 ; 66 ; int qftol027F( void ) - DirectX FPU 67 ; 68 69 global qftol027F 70 71 qftol027F: 72 fnstcw [fpucw] 73 fldcw [cw027F] 74 fistp dword [temp] 75 fldcw [fpucw] 76 mov eax, [temp] 77 ret 78 79 ; 80 ; int qftol037F( void ) - Linux FPU 81 ; 82 83 global qftol037F 84 85 qftol037F: 86 fnstcw [fpucw] 87 fldcw [cw037F] 88 fistp dword [temp] 89 fldcw [fpucw] 90 mov eax, [temp] 91 ret 92 93 94 ; 95 ; int qftol0F7F( void ) - ANSI 96 ; 97 98 global qftol0F7F 99 100 qftol0F7F: 101 fnstcw [fpucw] 102 fldcw [cw0F7F] 103 fistp dword [temp] 104 fldcw [fpucw] 105 mov eax, [temp] 106 ret 107 108 ; 109 ; int qftol0E7F( void ) 110 ; 111 112 global qftol0E7F 113 114 qftol0E7F: 115 fnstcw [fpucw] 116 fldcw [cw0E7F] 117 fistp dword [temp] 118 fldcw [fpucw] 119 mov eax, [temp] 120 ret 121 122 123 124 ; 125 ; long Q_ftol( float q ) 126 ; 127 128 global Q_ftol 129 130 Q_ftol: 131 fld dword [esp+4] 132 fistp dword [temp] 133 mov eax, [temp] 134 ret 135 136 137 ; 138 ; long qftol0F7F( float q ) - Linux FPU 139 ; 140 141 global Q_ftol0F7F 142 143 Q_ftol0F7F: 144 fnstcw [fpucw] 145 fld dword [esp+4] 146 fldcw [cw0F7F] 147 fistp dword [temp] 148 fldcw [fpucw] 149 mov eax, [temp] 150 ret 151