Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

iextensions.h

00001 // Copyright (C) 2001 InfoSpace Speech Solutions
00002 // author: Jean-Marc Valin
00003 
00004 #ifndef IEXTENSIONS_H
00005 #define IEXTENSIONS_H
00006 
00007 namespace FD {
00008 
00009 class IExtensions {
00010    static bool isse;
00011    static bool i3dnow;
00012   public:
00013    static void detect();
00014    static void detectSSE();
00015    static void detect3DNow();
00016    static inline bool haveSSE() {return isse;}
00017    static inline bool have3DNow() {return i3dnow;}
00018    
00019 };
00020 
00021 
00022 
00023 #if defined(_ENABLE_SSE) || defined(_ENABLE_3DNOW)
00024 
00025 #ifdef __GNUC__
00026 
00027 inline void prefetchnta(void *ptr)
00028 {
00029    if (IExtensions::have3DNow() || IExtensions::haveSSE())
00030       __asm__ __volatile__ ("prefetchnta (%0)" : : "r" (ptr));
00031 }
00032 
00033 inline void prefetcht0(void *ptr)
00034 {
00035    if (IExtensions::have3DNow() || IExtensions::haveSSE())
00036       __asm__ __volatile__ ("prefetcht0 (%0)" : : "r" (ptr));
00037 }
00038 
00039 inline void prefetcht1(void *ptr)
00040 {
00041    if (IExtensions::have3DNow() || IExtensions::haveSSE())
00042       __asm__ __volatile__ ("prefetcht1 (%0)" : : "r" (ptr));
00043 }
00044 
00045 inline void prefetcht2(void *ptr)
00046 {
00047    if (IExtensions::have3DNow() || IExtensions::haveSSE())
00048       __asm__ __volatile__ ("prefetcht2 (%0)" : : "r" (ptr));
00049 }
00050 
00051 
00052 inline void emms()
00053 {
00054    if (IExtensions::have3DNow())
00055    {
00056       __asm__ __volatile__ ("femms"
00057          : :
00058          : "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)");
00059    } else if (IExtensions::haveSSE())
00060    {
00061       __asm__ __volatile__ ("emms"
00062          : :
00063          : "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)");
00064    }
00065 }
00066 
00067 #endif /*__GUNC__*/
00068 
00069 #ifdef WIN32
00070 
00071 
00072 //FIXME: Until I understand how to use the prefetch* instructions under VC++
00073 inline void prefetchnta(void *ptr) {}
00074 inline void prefetcht0(void *ptr) {}
00075 inline void prefetcht1(void *ptr) {}
00076 inline void prefetcht2(void *ptr) {}
00077 inline void emms() {}
00078 
00079 
00080 #endif /*WIN32*/
00081 
00082 #else
00083 
00084 inline void prefetchnta(void *ptr) {}
00085 inline void prefetcht0(void *ptr) {}
00086 inline void prefetcht1(void *ptr) {}
00087 inline void prefetcht2(void *ptr) {}
00088 inline void emms() {}
00089 
00090 #endif /*defined(_ENABLE_SSE) || defined(_ENABLE_3DNOW)*/
00091 
00092 
00093 }//namespace FD
00094 
00095 #endif /*IEXTENSIONS_H*/

Generated on Wed Oct 5 14:28:55 2005 for FlowDesigner by  doxygen 1.4.4