mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
ioquake3 porting
This commit is contained in:
parent
2704b798e2
commit
ca3340b158
449 changed files with 104109 additions and 77701 deletions
89
code/asm/ftola.asm
Normal file
89
code/asm/ftola.asm
Normal file
|
@ -0,0 +1,89 @@
|
|||
; ===========================================================================
|
||||
; 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
|
||||
.686p
|
||||
.xmm
|
||||
.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
|
101
code/asm/ftola.c
Normal file
101
code/asm/ftola.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
===========================================================================
|
||||
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
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "qasm-inline.h"
|
||||
|
||||
#if defined (__i386__) || defined(__x86_64__)
|
||||
static const unsigned short fpucw = 0x0C7F;
|
||||
|
||||
/*
|
||||
* GNU inline asm ftol conversion functions using SSE or FPU
|
||||
*/
|
||||
|
||||
long qftolsse(float f)
|
||||
{
|
||||
long retval;
|
||||
|
||||
__asm__ volatile
|
||||
(
|
||||
"cvttss2si %1, %0\n"
|
||||
: "=r" (retval)
|
||||
: "x" (f)
|
||||
);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int qvmftolsse(void)
|
||||
{
|
||||
int retval;
|
||||
|
||||
__asm__ volatile
|
||||
(
|
||||
"movss (" EDI ", " EBX ", 4), %%xmm0\n"
|
||||
"cvttss2si %%xmm0, %0\n"
|
||||
: "=r" (retval)
|
||||
:
|
||||
: "%xmm0"
|
||||
);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long qftolx87(float f)
|
||||
{
|
||||
long retval;
|
||||
unsigned short oldcw = 0;
|
||||
|
||||
__asm__ volatile
|
||||
(
|
||||
"fnstcw %2\n"
|
||||
"fldcw %3\n"
|
||||
"flds %1\n"
|
||||
"fistpl %1\n"
|
||||
"fldcw %2\n"
|
||||
"mov %1, %0\n"
|
||||
: "=r" (retval)
|
||||
: "m" (f), "m" (oldcw), "m" (fpucw)
|
||||
);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int qvmftolx87(void)
|
||||
{
|
||||
int retval;
|
||||
unsigned short oldcw = 0;
|
||||
|
||||
__asm__ volatile
|
||||
(
|
||||
"fnstcw %1\n"
|
||||
"fldcw %2\n"
|
||||
"flds (" EDI ", " EBX ", 4)\n"
|
||||
"fistpl (" EDI ", " EBX ", 4)\n"
|
||||
"fldcw %1\n"
|
||||
"mov (" EDI ", " EBX ", 4), %0\n"
|
||||
: "=r" (retval)
|
||||
: "m" (oldcw), "m" (fpucw)
|
||||
);
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
160
code/asm/ftola.s
160
code/asm/ftola.s
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
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 Foobar; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
//
|
||||
// qftol -- fast floating point to long conversion.
|
||||
//
|
||||
|
||||
// 23/09/05 Ported to gas by intel2gas, best supporting actor Tim Angus
|
||||
// <tim@ngus.net>
|
||||
|
||||
#include "qasm.h"
|
||||
|
||||
#if id386
|
||||
|
||||
.data
|
||||
|
||||
temp: .single 0.0
|
||||
fpucw: .long 0
|
||||
|
||||
// Precision Control Field , 2 bits / 0x0300
|
||||
// PC24 0x0000 Single precision (24 bits).
|
||||
// PC53 0x0200 Double precision (53 bits).
|
||||
// PC64 0x0300 Extended precision (64 bits).
|
||||
|
||||
// Rounding Control Field, 2 bits / 0x0C00
|
||||
// RCN 0x0000 Rounding to nearest (even).
|
||||
// RCD 0x0400 Rounding down (directed, minus).
|
||||
// RCU 0x0800 Rounding up (directed plus).
|
||||
// RC0 0x0C00 Rounding towards zero (chop mode).
|
||||
|
||||
|
||||
// rounding towards nearest (even)
|
||||
cw027F: .long 0x027F
|
||||
cw037F: .long 0x037F
|
||||
|
||||
// rounding towards zero (chop mode)
|
||||
cw0E7F: .long 0x0E7F
|
||||
cw0F7F: .long 0x0F7F
|
||||
|
||||
|
||||
.text
|
||||
|
||||
//
|
||||
// int qftol( void ) - default control word
|
||||
//
|
||||
|
||||
.globl C(qftol)
|
||||
|
||||
C(qftol):
|
||||
fistpl temp
|
||||
movl temp,%eax
|
||||
ret
|
||||
|
||||
|
||||
//
|
||||
// int qftol027F( void ) - DirectX FPU
|
||||
//
|
||||
|
||||
.globl C(qftol027F)
|
||||
|
||||
C(qftol027F):
|
||||
fnstcw fpucw
|
||||
fldcw cw027F
|
||||
fistpl temp
|
||||
fldcw fpucw
|
||||
movl temp,%eax
|
||||
ret
|
||||
|
||||
//
|
||||
// int qftol037F( void ) - Linux FPU
|
||||
//
|
||||
|
||||
.globl C(qftol037F)
|
||||
|
||||
C(qftol037F):
|
||||
fnstcw fpucw
|
||||
fldcw cw037F
|
||||
fistpl temp
|
||||
fldcw fpucw
|
||||
movl temp,%eax
|
||||
ret
|
||||
|
||||
|
||||
//
|
||||
// int qftol0F7F( void ) - ANSI
|
||||
//
|
||||
|
||||
.globl C(qftol0F7F)
|
||||
|
||||
C(qftol0F7F):
|
||||
fnstcw fpucw
|
||||
fldcw cw0F7F
|
||||
fistpl temp
|
||||
fldcw fpucw
|
||||
movl temp,%eax
|
||||
ret
|
||||
|
||||
//
|
||||
// int qftol0E7F( void )
|
||||
//
|
||||
|
||||
.globl C(qftol0E7F)
|
||||
|
||||
C(qftol0E7F):
|
||||
fnstcw fpucw
|
||||
fldcw cw0E7F
|
||||
fistpl temp
|
||||
fldcw fpucw
|
||||
movl temp,%eax
|
||||
ret
|
||||
|
||||
|
||||
|
||||
//
|
||||
// long Q_ftol( float q )
|
||||
//
|
||||
|
||||
.globl C(Q_ftol)
|
||||
|
||||
C(Q_ftol):
|
||||
flds 4(%esp)
|
||||
fistpl temp
|
||||
movl temp,%eax
|
||||
ret
|
||||
|
||||
|
||||
//
|
||||
// long qftol0F7F( float q ) - Linux FPU
|
||||
//
|
||||
|
||||
.globl C(Q_ftol0F7F)
|
||||
|
||||
C(Q_ftol0F7F):
|
||||
fnstcw fpucw
|
||||
flds 4(%esp)
|
||||
fldcw cw0F7F
|
||||
fistpl temp
|
||||
fldcw fpucw
|
||||
movl temp,%eax
|
||||
ret
|
||||
#endif
|
424
code/asm/matha.s
424
code/asm/matha.s
|
@ -1,424 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
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 Foobar; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
===========================================================================
|
||||
*/
|
||||
//
|
||||
// math.s
|
||||
// x86 assembly-language math routines.
|
||||
|
||||
#include "qasm.h"
|
||||
|
||||
|
||||
#if id386
|
||||
|
||||
.data
|
||||
|
||||
.align 4
|
||||
Ljmptab: .long Lcase0, Lcase1, Lcase2, Lcase3
|
||||
.long Lcase4, Lcase5, Lcase6, Lcase7
|
||||
|
||||
.text
|
||||
|
||||
// TODO: rounding needed?
|
||||
// stack parameter offset
|
||||
#define val 4
|
||||
|
||||
.globl C(Invert24To16)
|
||||
C(Invert24To16):
|
||||
|
||||
movl val(%esp),%ecx
|
||||
movl $0x100,%edx // 0x10000000000 as dividend
|
||||
cmpl %edx,%ecx
|
||||
jle LOutOfRange
|
||||
|
||||
subl %eax,%eax
|
||||
divl %ecx
|
||||
|
||||
ret
|
||||
|
||||
LOutOfRange:
|
||||
movl $0xFFFFFFFF,%eax
|
||||
ret
|
||||
|
||||
#if 0
|
||||
|
||||
#define in 4
|
||||
#define out 8
|
||||
|
||||
.align 2
|
||||
.globl C(TransformVector)
|
||||
C(TransformVector):
|
||||
movl in(%esp),%eax
|
||||
movl out(%esp),%edx
|
||||
|
||||
flds (%eax) // in[0]
|
||||
fmuls C(vright) // in[0]*vright[0]
|
||||
flds (%eax) // in[0] | in[0]*vright[0]
|
||||
fmuls C(vup) // in[0]*vup[0] | in[0]*vright[0]
|
||||
flds (%eax) // in[0] | in[0]*vup[0] | in[0]*vright[0]
|
||||
fmuls C(vpn) // in[0]*vpn[0] | in[0]*vup[0] | in[0]*vright[0]
|
||||
|
||||
flds 4(%eax) // in[1] | ...
|
||||
fmuls C(vright)+4 // in[1]*vright[1] | ...
|
||||
flds 4(%eax) // in[1] | in[1]*vright[1] | ...
|
||||
fmuls C(vup)+4 // in[1]*vup[1] | in[1]*vright[1] | ...
|
||||
flds 4(%eax) // in[1] | in[1]*vup[1] | in[1]*vright[1] | ...
|
||||
fmuls C(vpn)+4 // in[1]*vpn[1] | in[1]*vup[1] | in[1]*vright[1] | ...
|
||||
fxch %st(2) // in[1]*vright[1] | in[1]*vup[1] | in[1]*vpn[1] | ...
|
||||
|
||||
faddp %st(0),%st(5) // in[1]*vup[1] | in[1]*vpn[1] | ...
|
||||
faddp %st(0),%st(3) // in[1]*vpn[1] | ...
|
||||
faddp %st(0),%st(1) // vpn_accum | vup_accum | vright_accum
|
||||
|
||||
flds 8(%eax) // in[2] | ...
|
||||
fmuls C(vright)+8 // in[2]*vright[2] | ...
|
||||
flds 8(%eax) // in[2] | in[2]*vright[2] | ...
|
||||
fmuls C(vup)+8 // in[2]*vup[2] | in[2]*vright[2] | ...
|
||||
flds 8(%eax) // in[2] | in[2]*vup[2] | in[2]*vright[2] | ...
|
||||
fmuls C(vpn)+8 // in[2]*vpn[2] | in[2]*vup[2] | in[2]*vright[2] | ...
|
||||
fxch %st(2) // in[2]*vright[2] | in[2]*vup[2] | in[2]*vpn[2] | ...
|
||||
|
||||
faddp %st(0),%st(5) // in[2]*vup[2] | in[2]*vpn[2] | ...
|
||||
faddp %st(0),%st(3) // in[2]*vpn[2] | ...
|
||||
faddp %st(0),%st(1) // vpn_accum | vup_accum | vright_accum
|
||||
|
||||
fstps 8(%edx) // out[2]
|
||||
fstps 4(%edx) // out[1]
|
||||
fstps (%edx) // out[0]
|
||||
|
||||
ret
|
||||
|
||||
#endif
|
||||
|
||||
#define EMINS 4+4
|
||||
#define EMAXS 4+8
|
||||
#define P 4+12
|
||||
|
||||
.align 2
|
||||
.globl C(BoxOnPlaneSide)
|
||||
C(BoxOnPlaneSide):
|
||||
pushl %ebx
|
||||
|
||||
movl P(%esp),%edx
|
||||
movl EMINS(%esp),%ecx
|
||||
xorl %eax,%eax
|
||||
movl EMAXS(%esp),%ebx
|
||||
movb pl_signbits(%edx),%al
|
||||
cmpb $8,%al
|
||||
jge Lerror
|
||||
flds pl_normal(%edx) // p->normal[0]
|
||||
fld %st(0) // p->normal[0] | p->normal[0]
|
||||
// bk000422 - warning: missing prefix `*' in absolute indirect address, maybe misassembled!
|
||||
// bk001129 - fix from Andrew Henderson, was: Ljmptab(,%eax,4)
|
||||
jmp *Ljmptab(,%eax,4)
|
||||
|
||||
|
||||
//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
||||
//dist2= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
||||
Lcase0:
|
||||
fmuls (%ebx) // p->normal[0]*emaxs[0] | p->normal[0]
|
||||
flds pl_normal+4(%edx) // p->normal[1] | p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]
|
||||
fxch %st(2) // p->normal[0] | p->normal[0]*emaxs[0] |
|
||||
// p->normal[1]
|
||||
fmuls (%ecx) // p->normal[0]*emins[0] |
|
||||
// p->normal[0]*emaxs[0] | p->normal[1]
|
||||
fxch %st(2) // p->normal[1] | p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fld %st(0) // p->normal[1] | p->normal[1] |
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fmuls 4(%ebx) // p->normal[1]*emaxs[1] | p->normal[1] |
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
flds pl_normal+8(%edx) // p->normal[2] | p->normal[1]*emaxs[1] |
|
||||
// p->normal[1] | p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fxch %st(2) // p->normal[1] | p->normal[1]*emaxs[1] |
|
||||
// p->normal[2] | p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fmuls 4(%ecx) // p->normal[1]*emins[1] |
|
||||
// p->normal[1]*emaxs[1] |
|
||||
// p->normal[2] | p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fxch %st(2) // p->normal[2] | p->normal[1]*emaxs[1] |
|
||||
// p->normal[1]*emins[1] |
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fld %st(0) // p->normal[2] | p->normal[2] |
|
||||
// p->normal[1]*emaxs[1] |
|
||||
// p->normal[1]*emins[1] |
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fmuls 8(%ebx) // p->normal[2]*emaxs[2] |
|
||||
// p->normal[2] |
|
||||
// p->normal[1]*emaxs[1] |
|
||||
// p->normal[1]*emins[1] |
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[0]*emins[0]
|
||||
fxch %st(5) // p->normal[0]*emins[0] |
|
||||
// p->normal[2] |
|
||||
// p->normal[1]*emaxs[1] |
|
||||
// p->normal[1]*emins[1] |
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[2]*emaxs[2]
|
||||
faddp %st(0),%st(3) //p->normal[2] |
|
||||
// p->normal[1]*emaxs[1] |
|
||||
// p->normal[1]*emins[1]+p->normal[0]*emins[0]|
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[2]*emaxs[2]
|
||||
fmuls 8(%ecx) //p->normal[2]*emins[2] |
|
||||
// p->normal[1]*emaxs[1] |
|
||||
// p->normal[1]*emins[1]+p->normal[0]*emins[0]|
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[2]*emaxs[2]
|
||||
fxch %st(1) //p->normal[1]*emaxs[1] |
|
||||
// p->normal[2]*emins[2] |
|
||||
// p->normal[1]*emins[1]+p->normal[0]*emins[0]|
|
||||
// p->normal[0]*emaxs[0] |
|
||||
// p->normal[2]*emaxs[2]
|
||||
faddp %st(0),%st(3) //p->normal[2]*emins[2] |
|
||||
// p->normal[1]*emins[1]+p->normal[0]*emins[0]|
|
||||
// p->normal[0]*emaxs[0]+p->normal[1]*emaxs[1]|
|
||||
// p->normal[2]*emaxs[2]
|
||||
fxch %st(3) //p->normal[2]*emaxs[2] +
|
||||
// p->normal[1]*emins[1]+p->normal[0]*emins[0]|
|
||||
// p->normal[0]*emaxs[0]+p->normal[1]*emaxs[1]|
|
||||
// p->normal[2]*emins[2]
|
||||
faddp %st(0),%st(2) //p->normal[1]*emins[1]+p->normal[0]*emins[0]|
|
||||
// dist1 | p->normal[2]*emins[2]
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
||||
//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
||||
Lcase1:
|
||||
fmuls (%ecx) // emins[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
||||
//dist2= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
||||
Lcase2:
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ecx) // emins[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
||||
//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
||||
Lcase3:
|
||||
fmuls (%ecx) // emins[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
||||
//dist2= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
||||
Lcase4:
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ecx) // emins[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
|
||||
//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
|
||||
Lcase5:
|
||||
fmuls (%ecx) // emins[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
||||
//dist2= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
||||
Lcase6:
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ecx) // emins[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
jmp LSetSides
|
||||
|
||||
//dist1= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
|
||||
//dist2= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
|
||||
Lcase7:
|
||||
fmuls (%ecx) // emins[0]
|
||||
flds pl_normal+4(%edx)
|
||||
fxch %st(2)
|
||||
fmuls (%ebx) // emaxs[0]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 4(%ecx) // emins[1]
|
||||
flds pl_normal+8(%edx)
|
||||
fxch %st(2)
|
||||
fmuls 4(%ebx) // emaxs[1]
|
||||
fxch %st(2)
|
||||
fld %st(0)
|
||||
fmuls 8(%ecx) // emins[2]
|
||||
fxch %st(5)
|
||||
faddp %st(0),%st(3)
|
||||
fmuls 8(%ebx) // emaxs[2]
|
||||
fxch %st(1)
|
||||
faddp %st(0),%st(3)
|
||||
fxch %st(3)
|
||||
faddp %st(0),%st(2)
|
||||
|
||||
LSetSides:
|
||||
|
||||
// sides = 0;
|
||||
// if (dist1 >= p->dist)
|
||||
// sides = 1;
|
||||
// if (dist2 < p->dist)
|
||||
// sides |= 2;
|
||||
|
||||
faddp %st(0),%st(2) // dist1 | dist2
|
||||
fcomps pl_dist(%edx)
|
||||
xorl %ecx,%ecx
|
||||
fnstsw %ax
|
||||
fcomps pl_dist(%edx)
|
||||
andb $1,%ah
|
||||
xorb $1,%ah
|
||||
addb %ah,%cl
|
||||
|
||||
fnstsw %ax
|
||||
andb $1,%ah
|
||||
addb %ah,%ah
|
||||
addb %ah,%cl
|
||||
|
||||
// return sides;
|
||||
|
||||
popl %ebx
|
||||
movl %ecx,%eax // return status
|
||||
|
||||
ret
|
||||
|
||||
|
||||
Lerror:
|
||||
movl 1, %eax
|
||||
ret
|
||||
|
||||
#endif // id386
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
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
|
||||
===========================================================================
|
||||
*/
|
||||
#ifndef __ASM_I386__
|
||||
#define __ASM_I386__
|
||||
|
||||
#include "../qcommon/q_platform.h"
|
||||
|
||||
#ifdef __ELF__
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
#endif
|
||||
|
||||
#ifdef __ELF__
|
||||
#define C(label) label
|
||||
#else
|
||||
#define C(label) _##label
|
||||
#endif
|
||||
|
||||
// plane_t structure
|
||||
// !!! if this is changed, it must be changed in q_shared.h too !!!
|
||||
#define pl_normal 0
|
||||
#define pl_dist 12
|
||||
#define pl_type 16
|
||||
#define pl_signbits 17
|
||||
#define pl_pad 18
|
||||
#define pl_size 20
|
||||
|
||||
#endif
|
90
code/asm/snapvector.asm
Normal file
90
code/asm/snapvector.asm
Normal file
|
@ -0,0 +1,90 @@
|
|||
; ===========================================================================
|
||||
; 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 version of snapvector conversion function using SSE or FPU
|
||||
; assume __cdecl calling convention is being used for x86, __fastcall for x64
|
||||
;
|
||||
; function prototype:
|
||||
; void qsnapvector(vec3_t vec)
|
||||
|
||||
IFNDEF idx64
|
||||
.686p
|
||||
.xmm
|
||||
.model flat, c
|
||||
ENDIF
|
||||
|
||||
.data
|
||||
|
||||
ALIGN 16
|
||||
ssemask DWORD 0FFFFFFFFh, 0FFFFFFFFh, 0FFFFFFFFh, 00000000h
|
||||
ssecw DWORD 00001F80h
|
||||
|
||||
.code
|
||||
|
||||
IFDEF idx64
|
||||
; qsnapvector using SSE
|
||||
|
||||
qsnapvectorsse PROC
|
||||
movaps xmm1, ssemask ; initialize the mask register
|
||||
movups xmm0, [rcx] ; here is stored our vector. Read 4 values in one go
|
||||
movaps xmm2, xmm0 ; keep a copy of the original data
|
||||
andps xmm0, xmm1 ; set the fourth value to zero in xmm0
|
||||
andnps xmm1, xmm2 ; copy fourth value to xmm1 and set rest to zero
|
||||
cvtps2dq xmm0, xmm0 ; convert 4 single fp to int
|
||||
cvtdq2ps xmm0, xmm0 ; convert 4 int to single fp
|
||||
orps xmm0, xmm1 ; combine all 4 values again
|
||||
movups [rcx], xmm0 ; write 3 rounded and 1 unchanged values back to memory
|
||||
ret
|
||||
qsnapvectorsse ENDP
|
||||
|
||||
ELSE
|
||||
|
||||
qsnapvectorsse PROC
|
||||
mov eax, dword ptr 4[esp] ; store address of vector in eax
|
||||
movaps xmm1, ssemask ; initialize the mask register for maskmovdqu
|
||||
movups xmm0, [eax] ; here is stored our vector. Read 4 values in one go
|
||||
movaps xmm2, xmm0 ; keep a copy of the original data
|
||||
andps xmm0, xmm1 ; set the fourth value to zero in xmm0
|
||||
andnps xmm1, xmm2 ; copy fourth value to xmm1 and set rest to zero
|
||||
cvtps2dq xmm0, xmm0 ; convert 4 single fp to int
|
||||
cvtdq2ps xmm0, xmm0 ; convert 4 int to single fp
|
||||
orps xmm0, xmm1 ; combine all 4 values again
|
||||
movups [eax], xmm0 ; write 3 rounded and 1 unchanged values back to memory
|
||||
ret
|
||||
qsnapvectorsse ENDP
|
||||
|
||||
qroundx87 macro src
|
||||
fld dword ptr src
|
||||
fistp dword ptr src
|
||||
fild dword ptr src
|
||||
fstp dword ptr src
|
||||
endm
|
||||
|
||||
qsnapvectorx87 PROC
|
||||
mov eax, dword ptr 4[esp]
|
||||
qroundx87 [eax]
|
||||
qroundx87 4[eax]
|
||||
qroundx87 8[eax]
|
||||
ret
|
||||
qsnapvectorx87 ENDP
|
||||
|
||||
ENDIF
|
||||
|
||||
end
|
77
code/asm/snapvector.c
Normal file
77
code/asm/snapvector.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
===========================================================================
|
||||
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
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "qasm-inline.h"
|
||||
#include "../qcommon/q_shared.h"
|
||||
|
||||
#if defined (__i386__) || defined(__x86_64__)
|
||||
|
||||
/*
|
||||
* GNU inline asm version of qsnapvector
|
||||
* See MASM snapvector.asm for commentary
|
||||
*/
|
||||
|
||||
static unsigned char ssemask[16] __attribute__((aligned(16))) =
|
||||
{
|
||||
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00"
|
||||
};
|
||||
|
||||
void qsnapvectorsse(vec3_t vec)
|
||||
{
|
||||
__asm__ volatile
|
||||
(
|
||||
"movaps (%0), %%xmm1\n"
|
||||
"movups (%1), %%xmm0\n"
|
||||
"movaps %%xmm0, %%xmm2\n"
|
||||
"andps %%xmm1, %%xmm0\n"
|
||||
"andnps %%xmm2, %%xmm1\n"
|
||||
"cvtps2dq %%xmm0, %%xmm0\n"
|
||||
"cvtdq2ps %%xmm0, %%xmm0\n"
|
||||
"orps %%xmm1, %%xmm0\n"
|
||||
"movups %%xmm0, (%1)\n"
|
||||
:
|
||||
: "r" (ssemask), "r" (vec)
|
||||
: "memory", "%xmm0", "%xmm1", "%xmm2"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
#define QROUNDX87(src) \
|
||||
"flds " src "\n" \
|
||||
"fistpl " src "\n" \
|
||||
"fildl " src "\n" \
|
||||
"fstps " src "\n"
|
||||
|
||||
void qsnapvectorx87(vec3_t vec)
|
||||
{
|
||||
__asm__ volatile
|
||||
(
|
||||
QROUNDX87("(%0)")
|
||||
QROUNDX87("4(%0)")
|
||||
QROUNDX87("8(%0)")
|
||||
:
|
||||
: "r" (vec)
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
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 Foobar; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
//
|
||||
// Sys_SnapVector NASM code (Andrew Henderson)
|
||||
// See win32/win_shared.c for the Win32 equivalent
|
||||
// This code is provided to ensure that the
|
||||
// rounding behavior (and, if necessary, the
|
||||
// precision) of DLL and QVM code are identical
|
||||
// e.g. for network-visible operations.
|
||||
// See ftol.nasm for operations on a single float,
|
||||
// as used in compiled VM and DLL code that does
|
||||
// not use this system trap.
|
||||
//
|
||||
|
||||
// 23/09/05 Ported to gas by intel2gas, best supporting actor Tim Angus
|
||||
// <tim@ngus.net>
|
||||
|
||||
#include "qasm.h"
|
||||
|
||||
#if id386
|
||||
.data
|
||||
|
||||
fpucw: .long 0
|
||||
cw037F: .long 0x037F
|
||||
|
||||
.text
|
||||
|
||||
// void Sys_SnapVector( float *v )
|
||||
.globl C(Sys_SnapVector)
|
||||
C(Sys_SnapVector):
|
||||
pushl %eax
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
|
||||
fnstcw fpucw
|
||||
movl 12(%ebp),%eax
|
||||
fldcw cw037F
|
||||
flds (%eax)
|
||||
fistpl (%eax)
|
||||
fildl (%eax)
|
||||
fstps (%eax)
|
||||
flds 4(%eax)
|
||||
fistpl 4(%eax)
|
||||
fildl 4(%eax)
|
||||
fstps 4(%eax)
|
||||
flds 8(%eax)
|
||||
fistpl 8(%eax)
|
||||
fildl 8(%eax)
|
||||
fstps 8(%eax)
|
||||
fldcw fpucw
|
||||
|
||||
popl %ebp
|
||||
popl %eax
|
||||
ret
|
||||
|
||||
// void Sys_SnapVectorCW( float *v, unsigned short int cw )
|
||||
.globl C(Sys_SnapVectorCW)
|
||||
C(Sys_SnapVectorCW):
|
||||
pushl %eax
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
|
||||
fnstcw fpucw
|
||||
movl 12(%ebp),%eax
|
||||
fldcw 16(%ebp)
|
||||
flds (%eax)
|
||||
fistpl (%eax)
|
||||
fildl (%eax)
|
||||
fstps (%eax)
|
||||
flds 4(%eax)
|
||||
fistpl 4(%eax)
|
||||
fildl 4(%eax)
|
||||
fstps 4(%eax)
|
||||
flds 8(%eax)
|
||||
fistpl 8(%eax)
|
||||
fildl 8(%eax)
|
||||
fstps 8(%eax)
|
||||
fldcw fpucw
|
||||
|
||||
popl %ebp
|
||||
popl %eax
|
||||
ret
|
||||
#endif
|
|
@ -1,217 +0,0 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 1999-2005 Id Software, Inc.
|
||||
|
||||
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 Foobar; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
===========================================================================
|
||||
*/
|
||||
//
|
||||
// snd_mixa.s
|
||||
// x86 assembly-language sound code
|
||||
//
|
||||
|
||||
#include "qasm.h"
|
||||
|
||||
#if id386
|
||||
|
||||
.text
|
||||
|
||||
#if 0
|
||||
//----------------------------------------------------------------------
|
||||
// 8-bit sound-mixing code
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define ch 4+16
|
||||
#define sc 8+16
|
||||
#define count 12+16
|
||||
|
||||
.globl C(S_PaintChannelFrom8)
|
||||
C(S_PaintChannelFrom8):
|
||||
pushl %esi // preserve register variables
|
||||
pushl %edi
|
||||
pushl %ebx
|
||||
pushl %ebp
|
||||
|
||||
// int data;
|
||||
// short *lscale, *rscale;
|
||||
// unsigned char *sfx;
|
||||
// int i;
|
||||
|
||||
movl ch(%esp),%ebx
|
||||
movl sc(%esp),%esi
|
||||
|
||||
// if (ch->leftvol > 255)
|
||||
// ch->leftvol = 255;
|
||||
// if (ch->rightvol > 255)
|
||||
// ch->rightvol = 255;
|
||||
movl ch_leftvol(%ebx),%eax
|
||||
movl ch_rightvol(%ebx),%edx
|
||||
cmpl $255,%eax
|
||||
jna LLeftSet
|
||||
movl $255,%eax
|
||||
LLeftSet:
|
||||
cmpl $255,%edx
|
||||
jna LRightSet
|
||||
movl $255,%edx
|
||||
LRightSet:
|
||||
|
||||
// lscale = snd_scaletable[ch->leftvol >> 3];
|
||||
// rscale = snd_scaletable[ch->rightvol >> 3];
|
||||
// sfx = (signed char *)sc->data + ch->pos;
|
||||
// ch->pos += count;
|
||||
andl $0xF8,%eax
|
||||
addl $20,%esi
|
||||
movl (%esi),%esi
|
||||
andl $0xF8,%edx
|
||||
movl ch_pos(%ebx),%edi
|
||||
movl count(%esp),%ecx
|
||||
addl %edi,%esi
|
||||
shll $7,%eax
|
||||
addl %ecx,%edi
|
||||
shll $7,%edx
|
||||
movl %edi,ch_pos(%ebx)
|
||||
addl $(C(snd_scaletable)),%eax
|
||||
addl $(C(snd_scaletable)),%edx
|
||||
subl %ebx,%ebx
|
||||
movb -1(%esi,%ecx,1),%bl
|
||||
|
||||
testl $1,%ecx
|
||||
jz LMix8Loop
|
||||
|
||||
movl (%eax,%ebx,4),%edi
|
||||
movl (%edx,%ebx,4),%ebp
|
||||
addl C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size),%edi
|
||||
addl C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size),%ebp
|
||||
movl %edi,C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size)
|
||||
movl %ebp,C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size)
|
||||
movb -2(%esi,%ecx,1),%bl
|
||||
|
||||
decl %ecx
|
||||
jz LDone
|
||||
|
||||
// for (i=0 ; i<count ; i++)
|
||||
// {
|
||||
LMix8Loop:
|
||||
|
||||
// data = sfx[i];
|
||||
// paintbuffer[i].left += lscale[data];
|
||||
// paintbuffer[i].right += rscale[data];
|
||||
movl (%eax,%ebx,4),%edi
|
||||
movl (%edx,%ebx,4),%ebp
|
||||
addl C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size),%edi
|
||||
addl C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size),%ebp
|
||||
movb -2(%esi,%ecx,1),%bl
|
||||
movl %edi,C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size)
|
||||
movl %ebp,C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size)
|
||||
|
||||
movl (%eax,%ebx,4),%edi
|
||||
movl (%edx,%ebx,4),%ebp
|
||||
movb -3(%esi,%ecx,1),%bl
|
||||
addl C(paintbuffer)+psp_left-psp_size*2(,%ecx,psp_size),%edi
|
||||
addl C(paintbuffer)+psp_right-psp_size*2(,%ecx,psp_size),%ebp
|
||||
movl %edi,C(paintbuffer)+psp_left-psp_size*2(,%ecx,psp_size)
|
||||
movl %ebp,C(paintbuffer)+psp_right-psp_size*2(,%ecx,psp_size)
|
||||
|
||||
// }
|
||||
subl $2,%ecx
|
||||
jnz LMix8Loop
|
||||
|
||||
LDone:
|
||||
popl %ebp
|
||||
popl %ebx
|
||||
popl %edi
|
||||
popl %esi
|
||||
|
||||
ret
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Transfer of stereo buffer to 16-bit DMA buffer code
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
.globl C(S_WriteLinearBlastStereo16)
|
||||
C(S_WriteLinearBlastStereo16):
|
||||
pushl %edi
|
||||
pushl %ebx
|
||||
|
||||
// int i;
|
||||
// int val;
|
||||
movl C(snd_linear_count),%ecx
|
||||
movl C(snd_p),%ebx
|
||||
movl C(snd_out),%edi
|
||||
|
||||
// for (i=0 ; i<snd_linear_count ; i+=2)
|
||||
// {
|
||||
LWLBLoopTop:
|
||||
|
||||
// val = (snd_p[i]*snd_vol)>>8;
|
||||
// if (val > 0x7fff)
|
||||
// snd_out[i] = 0x7fff;
|
||||
// else if (val < (short)0x8000)
|
||||
// snd_out[i] = (short)0x8000;
|
||||
// else
|
||||
// snd_out[i] = val;
|
||||
movl -8(%ebx,%ecx,4),%eax
|
||||
sarl $8,%eax
|
||||
cmpl $0x7FFF,%eax
|
||||
jg LClampHigh
|
||||
cmpl $0xFFFF8000,%eax
|
||||
jnl LClampDone
|
||||
movl $0xFFFF8000,%eax
|
||||
jmp LClampDone
|
||||
LClampHigh:
|
||||
movl $0x7FFF,%eax
|
||||
LClampDone:
|
||||
|
||||
// val = (snd_p[i+1]*snd_vol)>>8;
|
||||
// if (val > 0x7fff)
|
||||
// snd_out[i+1] = 0x7fff;
|
||||
// else if (val < (short)0x8000)
|
||||
// snd_out[i+1] = (short)0x8000;
|
||||
// else
|
||||
// snd_out[i+1] = val;
|
||||
movl -4(%ebx,%ecx,4),%edx
|
||||
sarl $8,%edx
|
||||
cmpl $0x7FFF,%edx
|
||||
jg LClampHigh2
|
||||
cmpl $0xFFFF8000,%edx
|
||||
jnl LClampDone2
|
||||
movl $0xFFFF8000,%edx
|
||||
jmp LClampDone2
|
||||
LClampHigh2:
|
||||
movl $0x7FFF,%edx
|
||||
LClampDone2:
|
||||
shll $16,%edx
|
||||
andl $0xFFFF,%eax
|
||||
orl %eax,%edx
|
||||
movl %edx,-4(%edi,%ecx,2)
|
||||
|
||||
// }
|
||||
subl $2,%ecx
|
||||
jnz LWLBLoopTop
|
||||
|
||||
// snd_p += snd_linear_count;
|
||||
|
||||
popl %ebx
|
||||
popl %edi
|
||||
|
||||
ret
|
||||
|
||||
#endif // id386
|
||||
|
85
code/asm/vm_x86_64.asm
Normal file
85
code/asm/vm_x86_64.asm
Normal file
|
@ -0,0 +1,85 @@
|
|||
; ===========================================================================
|
||||
; 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
|
||||
; ===========================================================================
|
||||
|
||||
; Call wrapper for vm_x86 when built with MSVC in 64 bit mode,
|
||||
; since MSVC does not support inline x64 assembler code anymore.
|
||||
;
|
||||
; assumes __fastcall calling convention
|
||||
|
||||
.code
|
||||
|
||||
; Call to compiled code after setting up the register environment for the VM
|
||||
; prototype:
|
||||
; uint8_t qvmcall64(int *programStack, int *opStack, intptr_t *instructionPointers, byte *dataBase);
|
||||
;
|
||||
; This call-stub has its own custom calling convention due to pushing all non-volatile registers
|
||||
; to the stack. The game uses set/longjmp which on Windows uses "RtlUnwindEx" to unwind the callstack.
|
||||
; This function cannot be unwound by default due to the custom calling convention.
|
||||
; To allow unwinding, we need to add custom SEH unwind data to the function.
|
||||
|
||||
qvmcall64 PROC FRAME
|
||||
push r12 ; push all non-volatile registers to stack
|
||||
.pushreg r12
|
||||
push r13
|
||||
.pushreg r13
|
||||
push r14
|
||||
.pushreg r14
|
||||
push r15
|
||||
.pushreg r15
|
||||
push rdi
|
||||
.pushreg rdi
|
||||
push rsi
|
||||
.pushreg rsi
|
||||
push rbx
|
||||
.pushreg rbx
|
||||
push rbp
|
||||
.pushreg rbp
|
||||
|
||||
; need to save pointer in rcx so we can write back the programData value to caller
|
||||
push rcx
|
||||
.pushreg rcx
|
||||
|
||||
.endprolog ; custom unwind data ends here
|
||||
|
||||
; registers r8 and r9 have correct value already thanx to __fastcall
|
||||
xor rbx, rbx ; opStackOfs starts out being 0
|
||||
mov rdi, rdx ; opStack
|
||||
mov esi, dword ptr [rcx] ; programStack
|
||||
|
||||
call qword ptr [r8] ; instructionPointers[0] is also the entry point
|
||||
|
||||
pop rcx
|
||||
|
||||
mov dword ptr [rcx], esi ; write back the programStack value
|
||||
mov al, bl ; return opStack offset
|
||||
|
||||
pop rbp ; restore all non-volatile registers after the call
|
||||
pop rbx
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
|
||||
ret
|
||||
qvmcall64 ENDP
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue