Debian Codegraph @

code/asm/snapvector.asm

raw
1 ; ===========================================================================
2 ; Copyright (C) 2011 Thilo Schulz <[email protected]>
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 Quake III Arena source code; if not, write to the Free Software
18 ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 ; ===========================================================================
20
21 ; MASM version of snapvector conversion function using SSE or FPU
22 ; assume __cdecl calling convention is being used for x86, __fastcall for x64
23 ;
24 ; function prototype:
25 ; void qsnapvector(vec3_t vec)
26
27 IFNDEF idx64
28 .686p
29 .xmm
30 .model flat, c
31 ENDIF
32
33 .data
34
35 ALIGN 16
36 ssemask DWORD 0FFFFFFFFh, 0FFFFFFFFh, 0FFFFFFFFh, 00000000h
37 ssecw DWORD 00001F80h
38
39 .code
40
41 IFDEF idx64
42 ; qsnapvector using SSE
43
44 qsnapvectorsse PROC
45 movaps xmm1, ssemask ; initialize the mask register
46 movups xmm0, [rcx] ; here is stored our vector. Read 4 values in one go
47 movaps xmm2, xmm0 ; keep a copy of the original data
48 andps xmm0, xmm1 ; set the fourth value to zero in xmm0
49 andnps xmm1, xmm2 ; copy fourth value to xmm1 and set rest to zero
50 cvtps2dq xmm0, xmm0 ; convert 4 single fp to int
51 cvtdq2ps xmm0, xmm0 ; convert 4 int to single fp
52 orps xmm0, xmm1 ; combine all 4 values again
53 movups [rcx], xmm0 ; write 3 rounded and 1 unchanged values back to memory
54 ret
55 qsnapvectorsse ENDP
56
57 ELSE
58
59 qsnapvectorsse PROC
60 mov eax, dword ptr 4[esp] ; store address of vector in eax
61 movaps xmm1, ssemask ; initialize the mask register for maskmovdqu
62 movups xmm0, [eax] ; here is stored our vector. Read 4 values in one go
63 movaps xmm2, xmm0 ; keep a copy of the original data
64 andps xmm0, xmm1 ; set the fourth value to zero in xmm0
65 andnps xmm1, xmm2 ; copy fourth value to xmm1 and set rest to zero
66 cvtps2dq xmm0, xmm0 ; convert 4 single fp to int
67 cvtdq2ps xmm0, xmm0 ; convert 4 int to single fp
68 orps xmm0, xmm1 ; combine all 4 values again
69 movups [eax], xmm0 ; write 3 rounded and 1 unchanged values back to memory
70 ret
71 qsnapvectorsse ENDP
72
73 qroundx87 macro src
74 fld dword ptr src
75 fistp dword ptr src
76 fild dword ptr src
77 fstp dword ptr src
78 endm
79
80 qsnapvectorx87 PROC
81 mov eax, dword ptr 4[esp]
82 qroundx87 [eax]
83 qroundx87 4[eax]
84 qroundx87 8[eax]
85 ret
86 qsnapvectorx87 ENDP
87
88 ENDIF
89
90 end