00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.accellera.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_macros.h -- Miscellaneous definitions that are needed by the headers. 00021 00022 Original Author: Stan Y. Liao, Synopsys, Inc. 00023 00024 CHANGE LOG AT THE END OF THE FILE 00025 *****************************************************************************/ 00026 00027 00028 #ifndef SC_MACROS_H 00029 #define SC_MACROS_H 00030 00031 00032 namespace sc_dt { 00033 00034 template <class T> 00035 inline 00036 const T 00037 sc_min( const T& a, const T& b ) 00038 { 00039 return ( ( a <= b ) ? a : b ); 00040 } 00041 00042 template <class T> 00043 inline 00044 const T 00045 sc_max( const T& a, const T& b ) 00046 { 00047 return ( ( a >= b ) ? a : b ); 00048 } 00049 00050 template <class T> 00051 inline 00052 const T 00053 sc_abs( const T& a ) 00054 { 00055 // return ( a >= 0 ? a : -a ); 00056 // the code below is functionaly the same as the code above; the 00057 // difference is that the code below works for all arithmetic 00058 // SystemC datatypes. 00059 T z( a ); 00060 z = 0; 00061 if( a >= z ) { 00062 return a; 00063 } else { 00064 T c( a ); 00065 c = -a; 00066 return c; 00067 } 00068 } 00069 00070 } // namespace sc_dt 00071 00072 namespace sc_core { 00073 00074 // token stringification 00075 00076 #define SC_STRINGIFY_HELPER_( Arg ) \ 00077 SC_STRINGIFY_HELPER_DEFERRED_( Arg ) 00078 #define SC_STRINGIFY_HELPER_DEFERRED_( Arg ) \ 00079 SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg ) 00080 #define SC_STRINGIFY_HELPER_MORE_DEFERRED_( Arg ) \ 00081 #Arg 00082 00083 00084 // token concatenation 00085 00086 #define SC_CONCAT_HELPER_( a, b ) \ 00087 SC_CONCAT_HELPER_DEFERRED_( a, b ) 00088 #define SC_CONCAT_HELPER_DEFERRED_( a, b ) \ 00089 SC_CONCAT_HELPER_MORE_DEFERRED_( a,b ) 00090 #define SC_CONCAT_HELPER_MORE_DEFERRED_( a, b ) \ 00091 a ## b 00092 #define SC_CONCAT_UNDERSCORE_( a, b ) \ 00093 SC_CONCAT_HELPER_( a, SC_CONCAT_HELPER_( _, b ) ) 00094 00095 /* 00096 * These help debugging -- 00097 * -- user can find out where each process is stopped at. 00098 */ 00099 00100 #define WAIT() \ 00101 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \ 00102 ::sc_core::wait() 00103 00104 #define WAITN(n) \ 00105 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \ 00106 ::sc_core::wait(n) 00107 00108 #define WAIT_UNTIL(expr) \ 00109 ::sc_core::sc_set_location( __FILE__, __LINE__ ); \ 00110 do { ::sc_core::wait(); } while( !(expr) ) 00111 00112 } // namespace sc_core 00113 00114 // $Log: sc_macros.h,v $ 00115 // Revision 1.5 2011/08/26 20:46:09 acg 00116 // Andy Goodrich: moved the modification log to the end of the file to 00117 // eliminate source line number skew when check-ins are done. 00118 // 00119 // Revision 1.4 2011/02/18 20:27:14 acg 00120 // Andy Goodrich: Updated Copyrights. 00121 // 00122 // Revision 1.3 2011/02/13 21:47:37 acg 00123 // Andy Goodrich: update copyright notice. 00124 // 00125 // Revision 1.2 2008/05/22 17:06:25 acg 00126 // Andy Goodrich: updated copyright notice to include 2008. 00127 // 00128 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00129 // SystemC 2.3 00130 // 00131 // Revision 1.3 2006/01/13 18:44:29 acg 00132 // Added $Log to record CVS changes into the source. 00133 00134 #endif