kviewshell
MMX.cpp
Go to the documentation of this file.00001 //C- -*- C++ -*- 00002 //C- ------------------------------------------------------------------- 00003 //C- DjVuLibre-3.5 00004 //C- Copyright (c) 2002 Leon Bottou and Yann Le Cun. 00005 //C- Copyright (c) 2001 AT&T 00006 //C- 00007 //C- This software is subject to, and may be distributed under, the 00008 //C- GNU General Public License, Version 2. The license should have 00009 //C- accompanied the software or you may obtain a copy of the license 00010 //C- from the Free Software Foundation at http://www.fsf.org . 00011 //C- 00012 //C- This program is distributed in the hope that it will be useful, 00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 //C- GNU General Public License for more details. 00016 //C- 00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library 00018 //C- distributed by Lizardtech Software. On July 19th 2002, Lizardtech 00019 //C- Software authorized us to replace the original DjVu(r) Reference 00020 //C- Library notice by the following text (see doc/lizard2002.djvu): 00021 //C- 00022 //C- ------------------------------------------------------------------ 00023 //C- | DjVu (r) Reference Library (v. 3.5) 00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved. 00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No. 00026 //C- | 6,058,214 and patents pending. 00027 //C- | 00028 //C- | This software is subject to, and may be distributed under, the 00029 //C- | GNU General Public License, Version 2. The license should have 00030 //C- | accompanied the software or you may obtain a copy of the license 00031 //C- | from the Free Software Foundation at http://www.fsf.org . 00032 //C- | 00033 //C- | The computer code originally released by LizardTech under this 00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH 00035 //C- | ORIGINAL CODE." Subject to any third party intellectual property 00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 00040 //C- | General Public License. This grant only confers the right to 00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 00042 //C- | the extent such infringement is reasonably necessary to enable 00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 00045 //C- | any greater extent that may be necessary to utilize further 00046 //C- | modifications or combinations. 00047 //C- | 00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY 00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF 00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 00052 //C- +------------------------------------------------------------------ 00053 // 00054 // $Id: MMX.cpp,v 1.10 2004/05/13 16:50:10 leonb Exp $ 00055 // $Name: release_3_5_15 $ 00056 00057 #ifdef HAVE_CONFIG_H 00058 # include "config.h" 00059 #endif 00060 #if NEED_GNUG_PRAGMAS 00061 # pragma implementation 00062 #endif 00063 00064 #include "MMX.h" 00065 #include <stdio.h> 00066 #include <stdlib.h> 00067 00068 00069 #ifdef HAVE_NAMESPACES 00070 namespace DJVU { 00071 # ifdef NOT_DEFINED // Just to fool emacs c++ mode 00072 } 00073 #endif 00074 #endif 00075 00076 00077 // ---------------------------------------- 00078 // PRINTING MMX REGISTERS (Debug) 00079 00080 00081 #if defined(MMX) && defined(DEBUG) 00082 extern "C" void 00083 mmx_show() 00084 { 00085 /* This function can be called from a debugger 00086 in order to visualize the contents of the MMX registers. */ 00087 int mmregs[16]; 00088 MMXra( movq, mm0, &mmregs[0]); 00089 MMXra( movq, mm1, &mmregs[2]); 00090 MMXra( movq, mm2, &mmregs[4]); 00091 MMXra( movq, mm3, &mmregs[6]); 00092 MMXra( movq, mm4, &mmregs[8]); 00093 MMXra( movq, mm5, &mmregs[10]); 00094 MMXra( movq, mm6, &mmregs[12]); 00095 MMXra( movq, mm7, &mmregs[14]); 00096 MMXemms; 00097 for (int i=0; i<8; i++) 00098 DjVuPrintMessageUTF8("mm%d: %08x%08x\n", i, 00099 mmregs[i+i+1], mmregs[i+i]); 00100 MMXar( movq, &mmregs[0], mm0); 00101 MMXar( movq, &mmregs[2], mm1); 00102 MMXar( movq, &mmregs[4], mm2); 00103 MMXar( movq, &mmregs[6], mm3); 00104 MMXar( movq, &mmregs[8], mm4); 00105 MMXar( movq, &mmregs[10], mm5); 00106 MMXar( movq, &mmregs[12], mm6); 00107 MMXar( movq, &mmregs[14], mm7); 00108 } 00109 #endif 00110 00111 00112 00113 // ---------------------------------------- 00114 // MMX ENABLE/DISABLE 00115 00116 // Default settings autodetect MMX. 00117 // Use macro DISABLE_MMX to disable MMX by default. 00118 00119 #if defined(MMX) && !defined(DISABLE_MMX) 00120 int MMXControl::mmxflag = -1; 00121 #else 00122 int MMXControl::mmxflag = 0; 00123 #endif 00124 00125 int 00126 MMXControl::disable_mmx() 00127 { 00128 mmxflag = 0; 00129 return mmxflag; 00130 } 00131 00132 int 00133 MMXControl::enable_mmx() 00134 { 00135 int cpuflags = 0; 00136 #if defined(MMX) && defined(__GNUC__) && defined(__i386__) 00137 // Detection of MMX for GCC 00138 __asm__ volatile ("pushl %%ebx\n\t" 00139 "pushfl\n\t" 00140 "popl %%ecx\n\t" 00141 "xorl %%edx,%%edx\n\t" 00142 // Check that CPUID exists 00143 "movl %%ecx,%%eax\n\t" 00144 "xorl $0x200000,%%eax\n\t" 00145 "pushl %%eax\n\t" 00146 "popfl\n\t" 00147 "pushfl\n\t" 00148 "popl %%eax\n\t" 00149 "xorl %%ecx,%%eax\n\t" 00150 "jz 1f\n\t" 00151 "pushl %%ecx\n\t" 00152 "popfl\n\t" 00153 // Check that CR0:EM is clear 00154 "smsw %%ax\n\t" 00155 "andl $4,%%eax\n\t" 00156 "jnz 1f\n\t" 00157 // Execute CPUID 00158 "movl $1,%%eax\n\t" 00159 "cpuid\n" 00160 // EBX contains magic when -fPIC is on. 00161 "1:\tpopl %%ebx\n\t" 00162 "movl %%edx, %0" 00163 : "=m" (cpuflags) : 00164 : "eax","ecx","edx"); 00165 #endif 00166 #if defined(MMX) && defined(_MSC_VER) && defined(_M_IX86) 00167 // Detection of MMX for MSVC 00168 __asm { pushfd 00169 pop ecx 00170 xor edx,edx 00171 ;// Check that CPUID exists 00172 mov eax,ecx 00173 xor eax,0x200000 00174 push eax 00175 popfd 00176 pushfd 00177 pop eax 00178 xor eax,ecx 00179 jz fini 00180 push ecx 00181 popfd 00182 ;// Check that CR0:EM is zero 00183 smsw ax 00184 and eax,4 00185 jnz fini 00186 ;// Execute CPUID 00187 mov eax,1 00188 _emit 0xf 00189 _emit 0xa2 00190 fini: 00191 mov cpuflags,edx 00192 ;// MSVC determines clobbered registers by scanning the assembly code. 00193 ;// Since it does not know CPUID, it would not know that EBX is clobbered 00194 ;// without the dummy instruction below... 00195 xor ebx,ebx 00196 } 00197 #endif 00198 mmxflag = !!(cpuflags & 0x800000); 00199 return mmxflag; 00200 } 00201 00202 00203 00204 #ifdef HAVE_NAMESPACES 00205 } 00206 # ifndef NOT_USING_DJVU_NAMESPACE 00207 using namespace DJVU; 00208 # endif 00209 #endif