summaryrefslogtreecommitdiff
path: root/src/asm/ftola.asm
blob: eea9d0e3dde2813e52fa50d9ef34164bb3e9b392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
; ===========================================================================
; Copyright (C) 2011 Thilo Schulz <thilo@tjps.eu>
; 
; This file is part of Quake III Arena source code.
; 
; Quake III Arena source code is free software; you can redistribute it
; and/or modify it under the terms of the GNU General Public License as
; published by the Free Software Foundation; either version 2 of the License,
; or (at your option) any later version.
; 
; Quake III Arena source code is distributed in the hope that it will be
; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
; You should have received a copy of the GNU General Public License
; along with Quake III Arena source code; if not, write to the Free Software
; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
; ===========================================================================

; MASM ftol conversion functions using SSE or FPU
; assume __cdecl calling convention is being used for x86, __fastcall for x64

IFNDEF idx64
.model flat, c
ENDIF

.data

ifndef idx64
  fpucw WORD 0F7Fh
endif

.code

IFDEF idx64
; qftol using SSE

  qftolsse PROC
    cvttss2si eax, xmm0
	ret
  qftolsse ENDP

  qvmftolsse PROC
    movss xmm0, dword ptr [rdi + rbx * 4]
	cvttss2si eax, xmm0
	ret
  qvmftolsse ENDP

ELSE
; qftol using FPU

  qftolx87m macro src
    sub esp, 2
    fnstcw word ptr [esp]
    fldcw fpucw
    fld dword ptr src
	fistp dword ptr src
	fldcw [esp]
	mov eax, src
	add esp, 2
	ret
  endm
  
  qftolx87 PROC
    qftolx87m [esp + 6]
  qftolx87 ENDP

  qvmftolx87 PROC
    qftolx87m [edi + ebx * 4]
  qvmftolx87 ENDP

; qftol using SSE
  qftolsse PROC
    movss xmm0, dword ptr [esp + 4]
    cvttss2si eax, xmm0
	ret
  qftolsse ENDP

  qvmftolsse PROC
    movss xmm0, dword ptr [edi + ebx * 4]
	cvttss2si eax, xmm0
	ret
  qvmftolsse ENDP
ENDIF

end