/[pcsx2_0.9.7]/trunk/common/include/Utilities/Assertions.h
ViewVC logotype

Diff of /trunk/common/include/Utilities/Assertions.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 89  extern pxDoAssertFnType* pxDoAssert; Line 89  extern pxDoAssertFnType* pxDoAssert;
89  //  //
90  // Performance: All assumption/fail  types optimize into __assume()/likely() directives in  // Performance: All assumption/fail  types optimize into __assume()/likely() directives in
91  // Release builds (non-dev varieties optimize as such in Devel builds as well).  If using  // Release builds (non-dev varieties optimize as such in Devel builds as well).  If using
92    //
93    // Having pxFail and pxFailDev translate into __assume statements is very dangerous, since
94    // it can lead to the compiler optimizing out code and leading to crashes in dev/release
95    // builds.  To have code optimized, explicitly use pxAssume(false) or pxAssumeDev(false,msg);
96    
97  #define pxDiagSpot                      DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__ )  #define pxDiagSpot                      DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__ )
98  #define pxAssertSpot(cond)      DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__, _T(#cond) )  #define pxAssertSpot(cond)      DiagnosticOrigin( __TFILE__, __LINE__, __pxFUNCTION__, _T(#cond) )
# Line 100  extern pxDoAssertFnType* pxDoAssert; Line 104  extern pxDoAssertFnType* pxDoAssert;
104    
105  #define pxAssertRel(cond, msg)          ( (likely(cond)) || (pxOnAssert(pxAssertSpot(cond), msg), false) )  #define pxAssertRel(cond, msg)          ( (likely(cond)) || (pxOnAssert(pxAssertSpot(cond), msg), false) )
106  #define pxAssumeRel(cond, msg)          ((void) ( (!likely(cond)) && (pxOnAssert(pxAssertSpot(cond), msg), false) ))  #define pxAssumeRel(cond, msg)          ((void) ( (!likely(cond)) && (pxOnAssert(pxAssertSpot(cond), msg), false) ))
107  #define pxFailRel(msg)                          pxAssumeRel(false, msg)  #define pxFailRel(msg)                          pxAssertRel(false, msg)
108    
109  #if defined(PCSX2_DEBUG)  #if defined(PCSX2_DEBUG)
110    
# Line 110  extern pxDoAssertFnType* pxDoAssert; Line 114  extern pxDoAssertFnType* pxDoAssert;
114  #       define pxAssumeMsg(cond, msg)   pxAssumeRel(cond, msg)  #       define pxAssumeMsg(cond, msg)   pxAssumeRel(cond, msg)
115  #       define pxAssumeDev(cond, msg)   pxAssumeRel(cond, msg)  #       define pxAssumeDev(cond, msg)   pxAssumeRel(cond, msg)
116    
117  #       define pxFail(msg)                              pxAssumeMsg(false, msg)  #       define pxFail(msg)                              pxAssertMsg(false, msg)
118  #       define pxFailDev(msg)                   pxAssumeDev(false, msg)  #       define pxFailDev(msg)                   pxAssertDev(false, msg)
119    
120  #elif defined(PCSX2_DEVBUILD)  #elif defined(PCSX2_DEVBUILD)
121    
# Line 122  extern pxDoAssertFnType* pxDoAssert; Line 126  extern pxDoAssertFnType* pxDoAssert;
126  #       define pxAssertDev(cond, msg)   pxAssertRel(cond, msg)  #       define pxAssertDev(cond, msg)   pxAssertRel(cond, msg)
127    
128  #       define pxAssumeMsg(cond, msg)   (__assume(cond))  #       define pxAssumeMsg(cond, msg)   (__assume(cond))
129  #       define pxAssumeDev(cond, msg)   pxAssumeMsg(cond, msg)  #       define pxAssumeDev(cond, msg)   pxAssumeRel(cond, msg)
130    
131  #       define pxFail(msg)                              (__assume(false))  #       define pxFail(msg)
132  #       define pxFailDev(msg)                   pxAssumeDev(false, msg)  #       define pxFailDev(msg)                   pxAssertDev(false, msg)
133    
134  #else  #else
135    
# Line 138  extern pxDoAssertFnType* pxDoAssert; Line 142  extern pxDoAssertFnType* pxDoAssert;
142  #       define pxAssumeMsg(cond, msg)   (__assume(cond))  #       define pxAssumeMsg(cond, msg)   (__assume(cond))
143  #       define pxAssumeDev(cond, msg)   (__assume(cond))  #       define pxAssumeDev(cond, msg)   (__assume(cond))
144    
145  #       define pxFail(msg)                              (__assume(false))  #       define pxFail(msg)
146  #       define pxFailDev(msg)                   (__assume(false))  #       define pxFailDev(msg)
147    
148  #endif  #endif
149    
# Line 158  extern pxDoAssertFnType* pxDoAssert; Line 162  extern pxDoAssertFnType* pxDoAssert;
162  #define IndexBoundsCheckDev( objname, idx, sze )        pxAssertDev( (uint)(idx) < (uint)(sze), \  #define IndexBoundsCheckDev( objname, idx, sze )        pxAssertDev( (uint)(idx) < (uint)(sze), \
163          wxsFormat( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) )          wxsFormat( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) )
164    
165    #define IndexBoundsAssume( objname, idx, sze )          pxAssumeMsg( (uint)(idx) < (uint)(sze), \
166            wxsFormat( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) )
167    
168    #define IndexBoundsAssumeDev( objname, idx, sze )       pxAssumeDev( (uint)(idx) < (uint)(sze), \
169            wxsFormat( L"Array index out of bounds accessing object '%s' (index=%d, size=%d)", objname, (idx), (sze) ) )
170    
171    
172  extern void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg=NULL );  extern void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg=NULL );
173  extern void pxOnAssert( const DiagnosticOrigin& origin, const char* msg );  extern void pxOnAssert( const DiagnosticOrigin& origin, const char* msg );
174    
175  //////////////////////////////////////////////////////////////////////////////////////////  // --------------------------------------------------------------------------------------
176  // jNO_DEFAULT -- disables the default case in a switch, which improves switch optimization  // jNO_DEFAULT -- disables the default case in a switch, which improves switch optimization
177  // under MSVC.  // under MSVC.
178  //  // --------------------------------------------------------------------------------------
179  // How it Works: jASSUME turns into an __assume(0) under msvc compilers, which when specified  // How it Works: pxAssumeDev turns into an __assume(0) under msvc compilers, which when specified
180  // in the 'default:' case of a switch tells the compiler that the case is unreachable, so  // in the 'default:' case of a switch tells the compiler that the case is unreachable, so
181  // that it will not generate any code, LUTs, or conditionals to handle it.  // that it will not generate any code, LUTs, or conditionals to handle it.
182  //  //
183  // * In debug/devel builds the default case will cause an assertion.  // * In debug/devel builds the default case will cause an assertion.
184  //  //
185  #ifndef jNO_DEFAULT  #ifndef jNO_DEFAULT
   
 #if defined(__cplusplus) && defined(PCSX2_DEVBUILD)  
186  #       define jNO_DEFAULT \  #       define jNO_DEFAULT \
187                  default: \                  default: \
188                  { \                  { \
189                          pxFailDev( "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)" ); \                          pxAssumeDev( false, "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)" ); \
190                          break; \                          break; \
191                  }                  }
 #else  
 #       define jNO_DEFAULT \  
                 default: \  
                 { \  
                         jASSUME(0); \  
                         break; \  
                 }  
 #endif  
192  #endif  #endif

Legend:
Removed from v.31  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22