From 5a85e81685300e2299dabfeb25d513b99df471be Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 6 Sep 2013 22:40:51 +0200 Subject: Initial commit --- src/asm/ftola.s | 160 +++++++++++++++++++++++++++++++++++++ src/asm/matha.s | 54 +++++++++++++ src/asm/qasm.h | 38 +++++++++ src/asm/snapvectora.s | 103 ++++++++++++++++++++++++ src/asm/snd_mixa.s | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 572 insertions(+) create mode 100644 src/asm/ftola.s create mode 100644 src/asm/matha.s create mode 100644 src/asm/qasm.h create mode 100644 src/asm/snapvectora.s create mode 100644 src/asm/snd_mixa.s (limited to 'src/asm') diff --git a/src/asm/ftola.s b/src/asm/ftola.s new file mode 100644 index 0000000..7e9c523 --- /dev/null +++ b/src/asm/ftola.s @@ -0,0 +1,160 @@ +/* +=========================================================================== +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 +// + +#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 diff --git a/src/asm/matha.s b/src/asm/matha.s new file mode 100644 index 0000000..e4770d3 --- /dev/null +++ b/src/asm/matha.s @@ -0,0 +1,54 @@ +/* +=========================================================================== +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 + + .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 + +#endif // id386 diff --git a/src/asm/qasm.h b/src/asm/qasm.h new file mode 100644 index 0000000..d4b1674 --- /dev/null +++ b/src/asm/qasm.h @@ -0,0 +1,38 @@ +/* +=========================================================================== +Copyright (C) 1999-2005 Id Software, Inc. +Copyright (C) 2000-2009 Darklegion Development + +This file is part of Tremulous. + +Tremulous 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. + +Tremulous 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 Tremulous; 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 + +#endif diff --git a/src/asm/snapvectora.s b/src/asm/snapvectora.s new file mode 100644 index 0000000..11294a0 --- /dev/null +++ b/src/asm/snapvectora.s @@ -0,0 +1,103 @@ +/* +=========================================================================== +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 +// + +#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 diff --git a/src/asm/snd_mixa.s b/src/asm/snd_mixa.s new file mode 100644 index 0000000..4c6be5b --- /dev/null +++ b/src/asm/snd_mixa.s @@ -0,0 +1,217 @@ +/* +=========================================================================== +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>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 + -- cgit