source: trunk/libdjvu/MMX.h @ 280

Last change on this file since 280 was 280, checked in by rbri, 11 years ago

DJVU plugin: djvulibre updated to version 3.5.22

File size: 7.1 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, either Version 2 of the license,
9//C- or (at your option) any later version. The license should have
10//C- accompanied the software or you may obtain a copy of the license
11//C- from the Free Software Foundation at http://www.fsf.org .
12//C-
13//C- This program is distributed in the hope that it will be useful,
14//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
15//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16//C- GNU General Public License for more details.
17//C-
18//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
19//C- Lizardtech Software.  Lizardtech Software has authorized us to
20//C- replace the original DjVu(r) Reference Library notice by the following
21//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
22//C-
23//C-  ------------------------------------------------------------------
24//C- | DjVu (r) Reference Library (v. 3.5)
25//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
26//C- | The DjVu Reference Library is protected by U.S. Pat. No.
27//C- | 6,058,214 and patents pending.
28//C- |
29//C- | This software is subject to, and may be distributed under, the
30//C- | GNU General Public License, either Version 2 of the license,
31//C- | or (at your option) any later version. The license should have
32//C- | accompanied the software or you may obtain a copy of the license
33//C- | from the Free Software Foundation at http://www.fsf.org .
34//C- |
35//C- | The computer code originally released by LizardTech under this
36//C- | license and unmodified by other parties is deemed "the LIZARDTECH
37//C- | ORIGINAL CODE."  Subject to any third party intellectual property
38//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
39//C- | non-exclusive license to make, use, sell, or otherwise dispose of
40//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
41//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
42//C- | General Public License.   This grant only confers the right to
43//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
44//C- | the extent such infringement is reasonably necessary to enable
45//C- | recipient to make, have made, practice, sell, or otherwise dispose
46//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
47//C- | any greater extent that may be necessary to utilize further
48//C- | modifications or combinations.
49//C- |
50//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
51//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
52//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
53//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
54//C- +------------------------------------------------------------------
55//
56// $Id: MMX.h,v 1.11 2007/05/18 19:50:41 leonb Exp $
57// $Name: release_3_5_22 $
58
59#ifndef _MMX_H_
60#define _MMX_H_
61#ifdef HAVE_CONFIG_H
62#include "config.h"
63#endif
64#if NEED_GNUG_PRAGMAS
65# pragma interface
66#endif
67
68#include "DjVuGlobal.h"
69
70#ifdef HAVE_NAMESPACES
71namespace DJVU {
72# ifdef NOT_DEFINED // Just to fool emacs c++ mode
73}
74#endif
75#endif
76
77
78/** @name MMX.h
79    Files #"MMX.h"# and #"MMX.cpp"# implement basic routines for
80    supporting the MMX instructions on x86.  Future instruction sets
81    for other processors may be supported in this file as well.
82
83    Macro #MMX# is defined if the compiler supports the X86-MMX instructions.
84    It does not mean however that the processor supports the instruction set.
85    Variable #MMXControl::mmxflag# must be used to decide whether MMX.
86    instructions can be executed.  MMX instructions are entered in the middle
87    of C++ code using the following macros.  Examples can be found in
88    #"IWTransform.cpp"#.
89
90    \begin{description}
91    \item[MMXrr( insn, srcreg, dstreg)]
92       Encode a register to register MMX instruction
93       (e.g. #paddw# or #punpcklwd#).
94    \item[MMXar( insn, addr, dstreg )]
95       Encode a memory to register MMX instruction
96       (e.g. #moveq# from memory).
97    \item[MMXra( insn, srcreg, addr )]
98       Encode a register to memory MMX instruction
99       (e.g. #moveq# to memory).
100    \item[MMXir( insn, imm, dstreg )]
101       Encode a immediate to register MMX instruction
102       (e.g #psraw#).
103    \item[MMXemms]
104       Execute the #EMMS# instruction to reset the FPU state.
105    \end{description}
106
107    @memo
108    Essential support for MMX.
109    @version
110    #$Id: MMX.h,v 1.11 2007/05/18 19:50:41 leonb Exp $#
111    @author:
112    L\'eon Bottou <leonb@research.att.com> -- initial implementation */
113//@{
114
115
116/** MMX Control.
117    Class #MMXControl# encapsulates a few static functions for
118    globally enabling or disabling MMX support. */
119
120class MMXControl
121{
122 public:
123  // MMX DETECTION
124  /** Detects and enable MMX or similar technologies.  This function checks
125      whether the CPU supports a vectorial instruction set (such as Intel's
126      MMX) and enables them.  Returns a boolean indicating whether such an
127      instruction set is available.  Speedups factors may vary. */
128  static int enable_mmx();
129  /** Disables MMX or similar technologies.  The transforms will then be
130      performed using the baseline code. */
131  static int disable_mmx();
132  /** Contains a value greater than zero if the CPU supports vectorial
133      instructions. A negative value means that you must call \Ref{enable_mmx}
134      and test the value again. Direct access to this member should only be
135      used to transfer the instruction flow to the vectorial branch of the
136      code. Never modify the value of this variable.  Use #enable_mmx# or
137      #disable_mmx# instead. */
138  static int mmxflag;  // readonly
139};
140
141//@}
142
143
144
145
146// ----------------------------------------
147// GCC MMX MACROS
148
149#ifndef NO_MMX
150
151#if defined(__GNUC__) && defined(__i386__)
152#define MMXemms \
153  __asm__ volatile("emms" : : : "memory" )
154#define MMXrr(op,src,dst) \
155  __asm__ volatile( #op " %%" #src ",%%" #dst : : : "memory")
156#define MMXir(op,imm,dst) \
157  __asm__ volatile( #op " %0,%%" #dst : : "i" (imm) : "memory")
158#define MMXar(op,addr,dst) \
159  __asm__ volatile( #op " %0,%%" #dst : : "m" (*(addr)) : "memory")
160#define MMXra(op,src,addr) \
161  __asm__ volatile( #op " %%" #src ",%0" : : "m" (*(addr)) : "memory")
162#define MMX 1
163#endif
164
165
166// ----------------------------------------
167// MSVC MMX MACROS
168
169#if defined(_MSC_VER) && defined(_M_IX86)
170// Compiler option /GM is required
171#pragma warning( disable : 4799 )
172#define MMXemms \
173  __asm { emms }
174#define MMXrr(op,src,dst) \
175  __asm { op dst,src }
176#define MMXir(op,imm,dst) \
177  __asm { op dst,imm }
178#define MMXar(op,addr,dst) \
179  { register __int64 var=*(__int64*)(addr); __asm { op dst,var } }
180#define MMXra(op,src,addr) \
181  { register __int64 var; __asm { op [var],src };  *(__int64*)addr = var; }
182// Probably not as efficient as GCC macros
183#define MMX 1
184#endif
185
186#endif
187
188// -----------
189
190#ifdef HAVE_NAMESPACES
191}
192# ifndef NOT_USING_DJVU_NAMESPACE
193using namespace DJVU;
194# endif
195#endif
196#endif
Note: See TracBrowser for help on using the repository browser.