source: trunk/libdjvu/MMX.cpp @ 17

Last change on this file since 17 was 17, checked in by Eugene Romanenko, 15 years ago

update makefiles, remove absolute paths, update djvulibre to version 3.5.17

File size: 6.9 KB
Line 
1//C-  -*- C++ -*-
2//C- -------------------------------------------------------------------
3//C- DjVuLibre-3.5
4//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5//C- Copyright (c) 2001  AT&T
6//C-
7//C- This software is subject to, and may be distributed under, the
8//C- GNU General Public License, Version 2. The license should have
9//C- accompanied the software or you may obtain a copy of the license
10//C- from the Free Software Foundation at http://www.fsf.org .
11//C-
12//C- This program is distributed in the hope that it will be useful,
13//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//C- GNU General Public License for more details.
16//C-
17//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
18//C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech
19//C- Software authorized us to replace the original DjVu(r) Reference
20//C- Library notice by the following text (see doc/lizard2002.djvu):
21//C-
22//C-  ------------------------------------------------------------------
23//C- | DjVu (r) Reference Library (v. 3.5)
24//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
25//C- | The DjVu Reference Library is protected by U.S. Pat. No.
26//C- | 6,058,214 and patents pending.
27//C- |
28//C- | This software is subject to, and may be distributed under, the
29//C- | GNU General Public License, Version 2. The license should have
30//C- | accompanied the software or you may obtain a copy of the license
31//C- | from the Free Software Foundation at http://www.fsf.org .
32//C- |
33//C- | The computer code originally released by LizardTech under this
34//C- | license and unmodified by other parties is deemed "the LIZARDTECH
35//C- | ORIGINAL CODE."  Subject to any third party intellectual property
36//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
37//C- | non-exclusive license to make, use, sell, or otherwise dispose of
38//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
39//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
40//C- | General Public License.   This grant only confers the right to
41//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
42//C- | the extent such infringement is reasonably necessary to enable
43//C- | recipient to make, have made, practice, sell, or otherwise dispose
44//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
45//C- | any greater extent that may be necessary to utilize further
46//C- | modifications or combinations.
47//C- |
48//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
49//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
50//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
51//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52//C- +------------------------------------------------------------------
53//
54// $Id: MMX.cpp,v 1.10 2004/05/13 16:50:10 leonb Exp $
55// $Name:  $
56
57#ifdef HAVE_CONFIG_H
58# include "config.h"
59#endif
60#if NEED_GNUG_PRAGMAS
61# pragma implementation
62#endif
63
64#include "MMX.h"
65#include <stdio.h>
66#include <stdlib.h>
67
68
69#ifdef HAVE_NAMESPACES
70namespace DJVU {
71# ifdef NOT_DEFINED // Just to fool emacs c++ mode
72}
73#endif
74#endif
75
76
77// ----------------------------------------
78// PRINTING MMX REGISTERS (Debug)
79
80
81#if defined(MMX) && defined(DEBUG)
82extern "C" void
83mmx_show()
84{
85  /* This function can be called from a debugger
86     in order to visualize the contents of the MMX registers. */
87  int mmregs[16];
88  MMXra( movq,  mm0, &mmregs[0]);
89  MMXra( movq,  mm1, &mmregs[2]);
90  MMXra( movq,  mm2, &mmregs[4]);
91  MMXra( movq,  mm3, &mmregs[6]);
92  MMXra( movq,  mm4, &mmregs[8]);
93  MMXra( movq,  mm5, &mmregs[10]);
94  MMXra( movq,  mm6, &mmregs[12]);
95  MMXra( movq,  mm7, &mmregs[14]);
96  MMXemms;
97  for (int i=0; i<8; i++)
98    DjVuPrintMessageUTF8("mm%d: %08x%08x\n", i, 
99           mmregs[i+i+1], mmregs[i+i]);
100  MMXar( movq,  &mmregs[0], mm0);
101  MMXar( movq,  &mmregs[2], mm1);
102  MMXar( movq,  &mmregs[4], mm2);
103  MMXar( movq,  &mmregs[6], mm3);
104  MMXar( movq,  &mmregs[8], mm4);
105  MMXar( movq,  &mmregs[10], mm5);
106  MMXar( movq,  &mmregs[12], mm6);
107  MMXar( movq,  &mmregs[14], mm7);
108}
109#endif
110
111
112
113// ----------------------------------------
114// MMX ENABLE/DISABLE
115
116// Default settings autodetect MMX.
117// Use macro DISABLE_MMX to disable MMX by default.
118
119#if defined(MMX) && !defined(DISABLE_MMX)
120int MMXControl::mmxflag = -1;
121#else
122int MMXControl::mmxflag = 0;
123#endif
124
125int 
126MMXControl::disable_mmx()
127{
128  mmxflag = 0;
129  return mmxflag;
130}
131
132int 
133MMXControl::enable_mmx()
134{
135  int cpuflags = 0;
136#if defined(MMX) && defined(__GNUC__) && defined(__i386__)
137  // Detection of MMX for GCC
138  __asm__ volatile ("pushl %%ebx\n\t"
139                    "pushfl\n\t"   
140                    "popl %%ecx\n\t"
141                    "xorl %%edx,%%edx\n\t"
142                    // Check that CPUID exists
143                    "movl %%ecx,%%eax\n\t"
144                    "xorl $0x200000,%%eax\n\t"
145                    "pushl %%eax\n\t"
146                    "popfl\n\t"
147                    "pushfl\n\t"
148                    "popl %%eax\n\t"
149                    "xorl %%ecx,%%eax\n\t"
150                    "jz 1f\n\t"
151                    "pushl %%ecx\n\t"
152                    "popfl\n\t"
153                    // Check that CR0:EM is clear
154                    "smsw %%ax\n\t"
155                    "andl $4,%%eax\n\t"
156                    "jnz 1f\n\t"
157                    // Execute CPUID
158                    "movl $1,%%eax\n\t"
159                    "cpuid\n"
160                    // EBX contains magic when -fPIC is on.
161                    "1:\tpopl %%ebx\n\t"
162                    "movl %%edx, %0"
163                    : "=m" (cpuflags) :
164                    : "eax","ecx","edx");
165#endif
166#if defined(MMX) && defined(_MSC_VER) && defined(_M_IX86)
167  // Detection of MMX for MSVC
168  __asm {  pushfd
169           pop     ecx
170           xor     edx,edx
171             ;// Check that CPUID exists
172           mov     eax,ecx       
173           xor     eax,0x200000
174           push    eax
175           popfd
176           pushfd
177           pop     eax
178           xor     eax,ecx
179           jz      fini
180           push    ecx
181           popfd
182             ;// Check that CR0:EM is zero
183           smsw    ax
184           and     eax,4
185           jnz     fini
186             ;// Execute CPUID
187           mov     eax,1
188           _emit   0xf
189           _emit   0xa2
190         fini:
191           mov     cpuflags,edx
192             ;// MSVC determines clobbered registers by scanning the assembly code.
193             ;// Since it does not know CPUID, it would not know that EBX is clobbered
194             ;// without the dummy instruction below...
195           xor     ebx,ebx
196         }
197#endif
198  mmxflag = !!(cpuflags & 0x800000);
199  return mmxflag;
200}
201
202
203
204#ifdef HAVE_NAMESPACES
205}
206# ifndef NOT_USING_DJVU_NAMESPACE
207using namespace DJVU;
208# endif
209#endif
Note: See TracBrowser for help on using the repository browser.