| 1 | /* |
| 2 | =========================================================================== |
| 3 | Copyright (C) 2011 Thilo Schulz <[email protected]> |
| 4 | |
| 5 | This file is part of Quake III Arena source code. |
| 6 | |
| 7 | Quake III Arena source code is free software; you can redistribute it |
| 8 | and/or modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the License, |
| 10 | or (at your option) any later version. |
| 11 | |
| 12 | Quake III Arena source code is distributed in the hope that it will be |
| 13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with Quake III Arena source code; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | =========================================================================== |
| 21 | */ |
| 22 | |
| 23 | #include "qasm-inline.h" |
| 24 | #include "../qcommon/q_shared.h" |
| 25 | |
| 26 | #if defined (__i386__) || defined(__x86_64__) |
| 27 | |
| 28 | /* |
| 29 | * GNU inline asm version of qsnapvector |
| 30 | * See MASM snapvector.asm for commentary |
| 31 | */ |
| 32 | |
| 33 | static unsigned char ssemask[16] Q_ALIGN(16) = |
| 34 | { |
| 35 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00" |
| 36 | }; |
| 37 | |
| 38 | void qsnapvectorsse(vec3_t vec) |
| 39 | { |
| 40 | __asm__ volatile |
| 41 | ( |
| 42 | "movaps (%0), %%xmm1\n" |
| 43 | "movups (%1), %%xmm0\n" |
| 44 | "movaps %%xmm0, %%xmm2\n" |
| 45 | "andps %%xmm1, %%xmm0\n" |
| 46 | "andnps %%xmm2, %%xmm1\n" |
| 47 | "cvtps2dq %%xmm0, %%xmm0\n" |
| 48 | "cvtdq2ps %%xmm0, %%xmm0\n" |
| 49 | "orps %%xmm1, %%xmm0\n" |
| 50 | "movups %%xmm0, (%1)\n" |
| 51 | : |
| 52 | : "r" (ssemask), "r" (vec) |
| 53 | : "memory", "%xmm0", "%xmm1", "%xmm2" |
| 54 | ); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | #define QROUNDX87(src) \ |
| 59 | "flds " src "\n" \ |
| 60 | "fistpl " src "\n" \ |
| 61 | "fildl " src "\n" \ |
| 62 | "fstps " src "\n" |
| 63 | |
| 64 | void qsnapvectorx87(vec3_t vec) |
| 65 | { |
| 66 | __asm__ volatile |
| 67 | ( |
| 68 | QROUNDX87("(%0)") |
| 69 | QROUNDX87("4(%0)") |
| 70 | QROUNDX87("8(%0)") |
| 71 | : |
| 72 | : "r" (vec) |
| 73 | : "memory" |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | #endif |