source: trunk/libdjvu/MMX.h @ 15

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

needed libs update

File size: 7.0 KB
RevLine 
[15]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.h,v 1.9 2003/12/01 22:57:40 leonb Exp $
55// $Name: release_3_5_16 $
56
57#ifndef _MMX_H_
58#define _MMX_H_
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62#if NEED_GNUG_PRAGMAS
63# pragma interface
64#endif
65
66#include "DjVuGlobal.h"
67
68#ifdef HAVE_NAMESPACES
69namespace DJVU {
70# ifdef NOT_DEFINED // Just to fool emacs c++ mode
71}
72#endif
73#endif
74
75
76/** @name MMX.h
77    Files #"MMX.h"# and #"MMX.cpp"# implement basic routines for
78    supporting the MMX instructions on x86.  Future instruction sets
79    for other processors may be supported in this file as well.
80
81    Macro #MMX# is defined if the compiler supports the X86-MMX instructions.
82    It does not mean however that the processor supports the instruction set.
83    Variable #MMXControl::mmxflag# must be used to decide whether MMX.
84    instructions can be executed.  MMX instructions are entered in the middle
85    of C++ code using the following macros.  Examples can be found in
86    #"IWTransform.cpp"#.
87
88    \begin{description}
89    \item[MMXrr( insn, srcreg, dstreg)]
90       Encode a register to register MMX instruction
91       (e.g. #paddw# or #punpcklwd#).
92    \item[MMXar( insn, addr, dstreg )]
93       Encode a memory to register MMX instruction
94       (e.g. #moveq# from memory).
95    \item[MMXra( insn, srcreg, addr )]
96       Encode a register to memory MMX instruction
97       (e.g. #moveq# to memory).
98    \item[MMXir( insn, imm, dstreg )]
99       Encode a immediate to register MMX instruction
100       (e.g #psraw#).
101    \item[MMXemms]
102       Execute the #EMMS# instruction to reset the FPU state.
103    \end{description}
104
105    @memo
106    Essential support for MMX.
107    @version
108    #$Id: MMX.h,v 1.9 2003/12/01 22:57:40 leonb Exp $#
109    @author:
110    L\'eon Bottou <leonb@research.att.com> -- initial implementation */
111//@{
112
113
114/** MMX Control.
115    Class #MMXControl# encapsulates a few static functions for
116    globally enabling or disabling MMX support. */
117
118class MMXControl
119{
120 public:
121  // MMX DETECTION
122  /** Detects and enable MMX or similar technologies.  This function checks
123      whether the CPU supports a vectorial instruction set (such as Intel's
124      MMX) and enables them.  Returns a boolean indicating whether such an
125      instruction set is available.  Speedups factors may vary. */
126  static int enable_mmx();
127  /** Disables MMX or similar technologies.  The transforms will then be
128      performed using the baseline code. */
129  static int disable_mmx();
130  /** Contains a value greater than zero if the CPU supports vectorial
131      instructions. A negative value means that you must call \Ref{enable_mmx}
132      and test the value again. Direct access to this member should only be
133      used to transfer the instruction flow to the vectorial branch of the
134      code. Never modify the value of this variable.  Use #enable_mmx# or
135      #disable_mmx# instead. */
136  static int mmxflag;  // readonly
137};
138
139//@}
140
141
142
143
144// ----------------------------------------
145// GCC MMX MACROS
146
147#ifndef NO_MMX
148
149#if defined(__GNUC__) && defined(__i386__)
150#define MMXemms \
151  __asm__ volatile("emms" : : : "memory" )
152#define MMXrr(op,src,dst) \
153  __asm__ volatile( #op " %%" #src ",%%" #dst : : : "memory")
154#define MMXir(op,imm,dst) \
155  __asm__ volatile( #op " %0,%%" #dst : : "i" (imm) : "memory")
156#define MMXar(op,addr,dst) \
157  __asm__ volatile( #op " %0,%%" #dst : : "m" (*(int*)(addr)) : "memory")
158#define MMXra(op,src,addr) \
159  __asm__ volatile( #op " %%" #src ",%0" : : "m" (*(int*)(addr)) : "memory")
160#define MMX 1
161#endif
162
163
164// ----------------------------------------
165// MSVC MMX MACROS
166
167#if defined(_MSC_VER) && defined(_M_IX86)
168// Compiler option /GM is required
169#pragma warning( disable : 4799 )
170#define MMXemms \
171  __asm { emms }
172#define MMXrr(op,src,dst) \
173  __asm { op dst,src }
174#define MMXir(op,imm,dst) \
175  __asm { op dst,imm }
176#define MMXar(op,addr,dst) \
177  { register __int64 var=*(__int64*)(addr); __asm { op dst,var } }
178#define MMXra(op,src,addr) \
179  { register __int64 var; __asm { op [var],src };  *(__int64*)addr = var; }
180// Probably not as efficient as GCC macros
181#define MMX 1
182#endif
183
184#endif
185
186// -----------
187
188#ifdef HAVE_NAMESPACES
189}
190# ifndef NOT_USING_DJVU_NAMESPACE
191using namespace DJVU;
192# endif
193#endif
194#endif
Note: See TracBrowser for help on using the repository browser.