diff --git a/any_const_hides_copy_const.cpp b/any_const_hides_copy_const.cpp index a657763..925db91 100644 --- a/any_const_hides_copy_const.cpp +++ b/any_const_hides_copy_const.cpp @@ -6,14 +6,11 @@ struct a a() : m(0) {} - a( int e ) - : m(e) - {} //private: -// a( const a & _ ) -// : m( _.m+1) -// {} + a( const a & _ ) + : m( _.m+1) + {} }; struct b : public a @@ -26,10 +23,9 @@ struct b : public a int main() { - a o; - a o2 = o; - std::cout << o2.m << std::endl; -// std::cout << o2.m <<' '< + +void f( int i = 11 ) +{ + printf( "%d\n", i ); +} + + +int main( void ) +{ + f( 12 ); + + return 0; +} + diff --git a/getCurrentTime.h b/getCurrentTime.h new file mode 100644 index 0000000..63033b4 --- /dev/null +++ b/getCurrentTime.h @@ -0,0 +1,329 @@ +// toIntTest.cpp : Defines the entry point for the console application. +// + +#include +#include +#include +#include + +#undef min +#undef max + + +#if defined( WIN32 ) +//#define QUERY_PERFORMANCE_COUNTER +#define RDTSC +#else +#define GET_TIME_OF_DAY +#endif + +#ifdef RDTSC +#include + +class perf +{ + __int64 r64; + + __forceinline __int64 getCurrentTime() + { + __asm + { + // + // Serialized instruction ensure all previouse + // instructions a done befor reading the performance + // counter. + // +// cpuid + // + // Read the time stamp counter. + // + rdtsc + } + } + +public: + __forceinline perf() + { + ::Sleep( 0 ); + __asm cpuid + r64 = getCurrentTime(); + } + + __forceinline double elapsed() + { + __int64 now = getCurrentTime(); + return double(now - r64 ); + } + +}; + +__int64 nCPUFrequency; +double dblCPUFrequency; + +inline __int64 getCurrentTimeI() +{ + __asm + { + rdtsc + } +} + +inline double getCurrentTime() +{ +// return double(getCurrentTimeI()); + // + // The time stamp counter. + // + union { + __int64 r64; + __int32 r32[2]; + } tsc; + // + // Read the time stamp counter. + // + __asm + { + // + // Serialized instruction ensure all previouse + // instructions a done befor reading the performance + // counter. + // +// cpuid + // + // Read the counter. + // + rdtsc + // + // + // +// mov tsc.r32[0], eax +// mov tsc.r32[4], edx + movd xmm0,eax + movd xmm1,edx + pshufd xmm1, xmm0, 0xF7 + + } + + + + // + // Get time in seconds. + // + return double(tsc.r64);// / dblCPUFrequency; +} + +void initGetCurrentTimeLib_hlpr() +{ + // + // Use only one fixed CPU + // + BOOL b; + DWORD_PTR proc_affi; + DWORD_PTR sys_affi; + DWORD_PTR exclud_affi; + GetProcessAffinityMask( GetCurrentProcess(), &proc_affi, &sys_affi ); + exclud_affi = proc_affi & ~sys_affi; + proc_affi = ( exclud_affi ) ? proc_affi : proc_affi; + int i = 0; + while (( proc_affi >>= 1 )) ++i; + proc_affi = 1 << i; + b = SetProcessAffinityMask( GetCurrentProcess(), proc_affi ); + // + // Set the priority of thread high. + // + b = SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ); + b = SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL ); + // + // Get the frequency. + // + nCPUFrequency = 2000000000; +// QueryPerformanceFrequency( +// reinterpret_cast( &nCPUFrequency ) ); + // + // Frequency counter supported in CPUs of family x86 + // starting from Pentium 4 or Pentium 3. So for old CPUs + // this will not work. + // + // If CPU doesn't support performance counter then just return. + // + if ( !nCPUFrequency ) + puts("WARNING: This CPU doesn't support QueryPerformanceFrequency."); + // + // Convert to double. + // + dblCPUFrequency = double(nCPUFrequency); +} +#endif + + +#ifdef QUERY_PERFORMANCE_COUNTER +#include + +double dblCPUFrequency; +inline double getCurrentTime() +{ + // + // This call must be quite fast. Since, in x86 architectur + // it is one instruction. Yet WIN32 API might added some + // additional processing. + // + // \todo Vahagn: add our assembly optimised function. + // + __int64 nCPUTickCount; + QueryPerformanceCounter( + reinterpret_cast( &nCPUTickCount ) + ); + // + // Get time in seconds. + // + return double(nCPUTickCount) / dblCPUFrequency; +} + +void initGetCurrentTimeLib_hlpr() +{ + // + // Use only one fixed CPU + // + BOOL b; + DWORD_PTR proc_affi; + DWORD_PTR sys_affi; + DWORD_PTR exclud_affi; + GetProcessAffinityMask( GetCurrentProcess(), &proc_affi, &sys_affi ); + exclud_affi = proc_affi & ~sys_affi; + proc_affi = ( exclud_affi ) ? proc_affi : proc_affi; + int i = 0; + while (( proc_affi >>= 1 )) ++i; + proc_affi = 1 << i; + b = SetProcessAffinityMask( GetCurrentProcess(), proc_affi ); + // + // Set the priority of thread high. + // + b = SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ); + b = SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL ); + // + // Get the frequency. + // + __int64 nCPUFrequency; + QueryPerformanceFrequency( + reinterpret_cast( &nCPUFrequency ) + ); + // + // Frequency counter supported in CPUs of family x86 + // starting from Pentium 4 or Pentium 3. So for old CPUs + // this will not work. + // + // If CPU doesn't support performance counter then just return. + // + if ( !nCPUFrequency ) + puts("WARNING: This CPU doesn't support QueryPerformanceFrequency."); + // + // Convert to double. + // + dblCPUFrequency = double(nCPUFrequency); +} +#endif + +#ifdef GET_TIME_OF_DAY +#include + +inline double getCurrentTime() +{ + timeval t; + gettimeofday(&t,0); + return (double)t.tv_sec + ((double)t.tv_usec/1000000.0); +} + +void initGetCurrentTimeLib_hlpr() +{ +} + +#endif + +void initGetCurrentTimeLib() +{ + initGetCurrentTimeLib_hlpr(); + +#if 0 +for ( int j=0; j < 10000; ++j ) +{ + + // + // Calculate the time expectation and dispersion + // of getCurrentTime on this CPU. + // + const int nProbeCount = 100000; + double dblTimeExpect = 0.; + double dblTimeDispersia = 0.; + for ( int i = nProbeCount; i; --i ) + { + register double dblTimeBase = getCurrentTime(); + register double dblTimeCurrent = getCurrentTime(); + double dblTimeDelta = dblTimeCurrent - dblTimeBase; + dblTimeExpect += dblTimeDelta; + dblTimeDispersia += dblTimeDelta * dblTimeDelta; + } + // + // finalize. + // + dblTimeExpect /= double( nProbeCount ); + dblTimeDispersia = dblTimeDispersia / double( nProbeCount ) + - dblTimeExpect * dblTimeExpect; + printf( "Expectation: %f\n" + "Dispersion: %f\n", + dblTimeExpect, + sqrt(dblTimeDispersia) ); + puts( "----------------------------------------------------" ); + } +#endif + + +#if 0 + const int nProbeCount = 1000; + double* ddd = new double[ nProbeCount ]; + double* p = ddd; + double m = std::numeric_limits::max(); + for ( int i = nProbeCount; i; --i ) + { + register double dblTimeBase = getCurrentTime(); + register double dblTimeCurrent = getCurrentTime(); + *p++ = dblTimeCurrent - dblTimeBase; + m = std::min( m, dblTimeCurrent - dblTimeBase ); +// printf( "%10.1f\n", dblTimeCurrent - dblTimeBase ); + } + + printf( "%10.1f\n", m ); + + std::ofstream o; + o.open( "times.txt" ); + p = ddd; + for ( int i = nProbeCount; i; --i ) + { + o << *p++ << std::endl; + } + o << std::endl; + delete [] ddd; +#endif + +#if 1 + + for ( int j = 0; j < 1000; ++j ) + { + const int nProbeCount = 10000; + double m = 1e300; + for ( int i = nProbeCount; i; --i ) + { + perf pc; + __asm cpuid + __asm cpuid + __asm cpuid + __asm cpuid + double c = pc.elapsed(); + m = min( m, c ); + } + std::cout << m << std::endl; + } +#endif + +} + + diff --git a/hello.cpp b/hello.cpp new file mode 100644 index 0000000..68123e8 --- /dev/null +++ b/hello.cpp @@ -0,0 +1,9 @@ +#include + + +int main ( void ) +{ + puts( "Hello GCC!!!" ); + return 1; +} + diff --git a/std_vs_qt.sh b/std_vs_qt.sh old mode 100644 new mode 100755 diff --git a/string_size.cpp b/string_size.cpp new file mode 100644 index 0000000..a4388a0 --- /dev/null +++ b/string_size.cpp @@ -0,0 +1,10 @@ +#include + +const char str [] ="This is a [] string."; + +int main ( void ) +{ + std::cout << sizeof(str) << std::endl; + return 1; +} + diff --git a/testTransform/Makefile b/testTransform/Makefile new file mode 100644 index 0000000..7ed57fd --- /dev/null +++ b/testTransform/Makefile @@ -0,0 +1,17 @@ + +objects=main.o transform.o transfomr2.o + +all: a.out + +clean: + rm -r $(objects) + +a.out : main.o tansform.o transform2.o + g++ $(CPPFLAGS) $(objects) + +main.o : main.cpp + +transform.o : transform.cpp + +transform2.o : transform2.cpp + diff --git a/testTransform/main.cpp b/testTransform/main.cpp index a16e1f9..4580b8f 100644 --- a/testTransform/main.cpp +++ b/testTransform/main.cpp @@ -488,61 +488,46 @@ void testTransform() << "pod::rectangle<double>
" << "trans*trans
" << "trans-1


"; -#if 0 + std::cout << "pod::point" << std::endl; out << "

pod::point<int32>

" << std::endl; testAllPt(); out << "

"; -#endif -#if 0 std::cout << "pod::point" << std::endl; out << "

pod::point<int64>

" << std::endl; testAllPt(); out << "

"; -#endif -#if 0 std::cout << "pod::point" << std::endl; out << "

pod::point<double>

" << std::endl; testAllPt(); out << "

"; -#endif -#if 1 std::cout << "pod::rectangle" << std::endl; out << "

pod::rectangle<int32>

" << std::endl; testAllRect(); out << "

"; -#endif -#if 0 std::cout << "pod::rectangle" << std::endl; out << "

pod::rectangle<int64>

" << std::endl; testAllRect(); out << "

"; -#endif -#if 0 std::cout << "pod::rectangle" << std::endl; out << "

pod::rectangle<double>

" << std::endl; testAllRect(); out << "

"; -#endif -#if 0 std::cout << "trans*trans" << std::endl; out << "

trans*trans

" << std::endl; testAllTrans1x1(); out << "

"; -#endif -#if 0 std::cout << "inverse trans" << std::endl; out << "

trans-1

" << std::endl; testAllTransInverse(); out << "

"; -#endif } void main ( ) diff --git a/testTransform/testTransform.vcproj b/testTransform/testTransform.vcproj index 77fbfd8..039cb82 100644 --- a/testTransform/testTransform.vcproj +++ b/testTransform/testTransform.vcproj @@ -117,7 +117,7 @@ /> + + + + + + diff --git a/testTransform/transform.cpp b/testTransform/transform.cpp index 27ff3ec..210b6ab 100644 --- a/testTransform/transform.cpp +++ b/testTransform/transform.cpp @@ -5,11 +5,11 @@ * contained herein except pursuant to a valid written license from Synopsys. */ -#include "base/type-traits2.h" -//#include "ssetypes.h" +#include "type-traits2.h" +#include "ssetypes.h" #include "transform.h" -#include "base/constants.h" +#include "constants.h" namespace base { @@ -109,8 +109,6 @@ namespace base pModifyFunLongToInt modifyLongToIntFunTbl[transformTypeMAX]; pModifyFunIntToInt modifyIntToIntFunTbl[transformTypeMAX]; pModifyFunLongToLong modifyLongToLongFunTbl[transformTypeMAX]; - pModifyFunLongLongToLongLong modifyLongLongToLongLongFunTbl[transformTypeMAX]; - pModifyRectFunLongToLong modifyRectLongToLongFunTbl[transformTypeMAX]; pModifyRectFunDblToDbl modifyRectDblToDblFunTbl[transformTypeMAX]; pModifyRectFunIntToInt modifyRectIntToIntFunTbl[transformTypeMAX]; @@ -136,7 +134,7 @@ namespace base return std::tr1::is_floating_point::value ? pod::point((oC)tmp.X(),(oC)tmp.Y()) : - pod::point((oC)base::setSaturated(tmp.X()),(oC)base::setSaturated(tmp.Y())); + pod::point((oC)base::round(tmp.X()),(oC)base::round(tmp.Y())); } // /// Modify a point using scale and offset transform. @@ -149,7 +147,7 @@ namespace base return std::tr1::is_floating_point::value ? pod::point((oC)tmp.X(),(oC)tmp.Y()) : - pod::point((oC)base::setSaturated(tmp.X()),(oC)base::setSaturated(tmp.Y())); + pod::point((oC)base::round(tmp.X()),(oC)base::round(tmp.Y())); } // /// Modify a point using a general transform. @@ -162,7 +160,7 @@ namespace base return std::tr1::is_floating_point::value ? pod::point((oC)tmp.X(),(oC)tmp.Y()) : - pod::point((oC)base::setSaturated(tmp.X()),(oC)base::setSaturated(tmp.Y())); + pod::point((oC)base::round(tmp.X()),(oC)base::round(tmp.Y())); } template @@ -178,7 +176,7 @@ namespace base return std::tr1::is_floating_point::value ? pod::point( (oC)(d.getX()), (oC)(d.getY())) : - pod::point( (oC)base::setSaturated(d.getX()), (oC)base::setSaturated(d.getY())); + pod::point( (oC)base::round(d.getX()), (oC)base::round(d.getY())); } // /// Modify a point using standard transform with magnification @@ -196,7 +194,7 @@ namespace base return std::tr1::is_floating_point::value ? pod::point( (oC)(d.getX()), (oC)(d.getY())) : - pod::point( (oC)base::setSaturated(d.getX()), (oC)base::setSaturated(d.getY())); + pod::point( (oC)base::round(d.getX()), (oC)base::round(d.getY())); } // /// Modify a point using resolution transform. @@ -205,38 +203,29 @@ namespace base pod::point GXX_HIDDEN modifyResolution( const transform &T, pod::point xy ) { pod::point tmp = xy % T.getDiagonal(); - if (T.getNext()) - { - if ( std::tr1::is_double::value ) - { - pod::point tmp2((double)tmp.X(), - (double)tmp.Y()); + if (T.getNext()) { + if (std::tr1::is_double::value) { + pod::point tmp2 = pod::point((double)tmp.X(), + (double)tmp.Y()); return T.getNext()->modifyDblToDbl(tmp2); - } - else if ( std::tr1::is_i64::value ) - { - pod::point tmp2((i64)base::setSaturated(tmp.X()), - (i64)base::setSaturated(tmp.Y())); + } else if (std::tr1::is_long::value) { + pod::point tmp2 = pod::point((long)base::round(tmp.X()), + (long)base::round(tmp.Y())); return T.getNext()->modifyLongToLong(tmp2); - } - else if ( std::tr1::is_int::value ) - { - pod::point tmp2((i64)base::setSaturated(tmp.X()), - (i64)base::setSaturated(tmp.Y())); + } else if (std::tr1::is_int::value) { + pod::point tmp2 = pod::point((long)base::round(tmp.X()), + (long)base::round(tmp.Y())); return T.getNext()->modifyLongToInt(tmp2); - } - else if ( std::tr1::is_short::value ) - { - pod::point tmp2((i64)base::setSaturated(tmp.X()), - (i64)base::setSaturated(tmp.Y())); + } else if (std::tr1::is_short::value) { + pod::point tmp2 = pod::point((long)base::round(tmp.X()), + (long)base::round(tmp.Y())); return T.getNext()->modifyLongToShort(tmp2); } - } - else + } else return std::tr1::is_floating_point::value ? pod::point((oC)tmp.X(),(oC)tmp.Y()) : - pod::point((oC)base::setSaturated(tmp.X()), - (oC)base::setSaturated(tmp.Y())); + pod::point((oC)base::round(tmp.X()), + (oC)base::round(tmp.Y())); // Should not get here or something is missing. throw except::programError(); return pod::point((oC)0, (oC)0); @@ -344,14 +333,14 @@ namespace base modifyDblToShortFunTbl[ScaleTransformType] = &modifyScale; modifyDblToShortFunTbl[ResolutionTransformType] = &modifyResolution; // - // i64 to short + // long to short // - modifyLongToShortFunTbl[ScaleOffsetTransformType] = &modifyScaleOffset; - modifyLongToShortFunTbl[GeneralTransformType] = &modifyGeneral; - modifyLongToShortFunTbl[StdTransformType] = &modifyStd; - modifyLongToShortFunTbl[StdTransformWithMagType] = &modifyStdMag; - modifyLongToShortFunTbl[ScaleTransformType] = &modifyScale; - modifyLongToShortFunTbl[ResolutionTransformType] = &modifyResolution; + modifyLongToShortFunTbl[ScaleOffsetTransformType] = &modifyScaleOffset; + modifyLongToShortFunTbl[GeneralTransformType] = &modifyGeneral; + modifyLongToShortFunTbl[StdTransformType] = &modifyStd; + modifyLongToShortFunTbl[StdTransformWithMagType] = &modifyStdMag; + modifyLongToShortFunTbl[ScaleTransformType] = &modifyScale; + modifyLongToShortFunTbl[ResolutionTransformType] = &modifyResolution; // // int to short // @@ -380,14 +369,14 @@ namespace base modifyDblToDblFunTbl[ScaleTransformType] = &modifyScale; modifyDblToDblFunTbl[ResolutionTransformType] = &modifyResolution; // - // i64 to int + // long to int // - modifyLongToIntFunTbl[ScaleOffsetTransformType] = &modifyScaleOffset; - modifyLongToIntFunTbl[GeneralTransformType] = &modifyGeneral; - modifyLongToIntFunTbl[StdTransformType] = &modifyStd; - modifyLongToIntFunTbl[StdTransformWithMagType] = &modifyStdMag; - modifyLongToIntFunTbl[ScaleTransformType] = &modifyScale; - modifyLongToIntFunTbl[ResolutionTransformType] = &modifyResolution; + modifyLongToIntFunTbl[ScaleOffsetTransformType] = &modifyScaleOffset; + modifyLongToIntFunTbl[GeneralTransformType] = &modifyGeneral; + modifyLongToIntFunTbl[StdTransformType] = &modifyStd; + modifyLongToIntFunTbl[StdTransformWithMagType] = &modifyStdMag; + modifyLongToIntFunTbl[ScaleTransformType] = &modifyScale; + modifyLongToIntFunTbl[ResolutionTransformType] = &modifyResolution; // // int to int // @@ -398,14 +387,14 @@ namespace base modifyIntToIntFunTbl[ScaleTransformType] = &modifyScale; modifyIntToIntFunTbl[ResolutionTransformType] = &modifyResolution; // - // i64 to i64 + // long to long // - modifyLongToLongFunTbl[ScaleOffsetTransformType] = &modifyScaleOffset; - modifyLongToLongFunTbl[GeneralTransformType] = &modifyGeneral; - modifyLongToLongFunTbl[StdTransformType] = &modifyStd; - modifyLongToLongFunTbl[StdTransformWithMagType] = &modifyStdMag; - modifyLongToLongFunTbl[ScaleTransformType] = &modifyScale; - modifyLongToLongFunTbl[ResolutionTransformType] = &modifyResolution; + modifyLongToLongFunTbl[ScaleOffsetTransformType] = &modifyScaleOffset; + modifyLongToLongFunTbl[GeneralTransformType] = &modifyGeneral; + modifyLongToLongFunTbl[StdTransformType] = &modifyStd; + modifyLongToLongFunTbl[StdTransformWithMagType] = &modifyStdMag; + modifyLongToLongFunTbl[ScaleTransformType] = &modifyScale; + modifyLongToLongFunTbl[ResolutionTransformType] = &modifyResolution; // /// Init get inverse func table. // @@ -457,12 +446,12 @@ namespace base // // Initialize the rectangle modification function tables. // - modifyRectLongToLongFunTbl[ScaleOffsetTransformType] = modifyScaleOffsetRect; - modifyRectLongToLongFunTbl[GeneralTransformType] = modifyGeneralRect; - modifyRectLongToLongFunTbl[StdTransformType] = modifyStdRect; - modifyRectLongToLongFunTbl[StdTransformWithMagType] = modifyStdMagRect; - modifyRectLongToLongFunTbl[ScaleTransformType] = modifyScaleRect; - modifyRectLongToLongFunTbl[ResolutionTransformType] = modifyResolutionRect; + modifyRectLongToLongFunTbl[ScaleOffsetTransformType] = modifyScaleOffsetRect; + modifyRectLongToLongFunTbl[GeneralTransformType] = modifyGeneralRect; + modifyRectLongToLongFunTbl[StdTransformType] = modifyStdRect; + modifyRectLongToLongFunTbl[StdTransformWithMagType] = modifyStdMagRect; + modifyRectLongToLongFunTbl[ScaleTransformType] = modifyScaleRect; + modifyRectLongToLongFunTbl[ResolutionTransformType] = modifyResolutionRect; modifyRectDblToDblFunTbl[ScaleOffsetTransformType] = modifyScaleOffsetRect; modifyRectDblToDblFunTbl[GeneralTransformType] = modifyGeneralRect; @@ -1404,80 +1393,80 @@ std::ostream & operator << (std::ostream & os, const transform & t) /***************************************************************************** * Instantiate template with some arguments. */ -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -#if 0 -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::point&, pod::point& ) const; +#if defined( _MSC_VER ) +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; +template void transform::modify( const pod::point&, pod::point& ) const; template void transform::modify( const pod::point&, pod::point& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; template void transform::modify( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; -template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; +template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; template void transform::modifyBBox( const pod::rectangle&, pod::rectangle& ) const; #endif diff --git a/testTransform/transform.h b/testTransform/transform.h index a216dd4..1aeacb1 100644 --- a/testTransform/transform.h +++ b/testTransform/transform.h @@ -19,7 +19,6 @@ #include #include "base/port.h" -#include "base/types.h" #include "base/constants.h" #include "base/except.h" #include "base/rectangle.h" @@ -149,29 +148,23 @@ namespace base extern pMultFun multFnTbl[transformTypeMAX*transformTypeMAX]; typedef pod::point (*pModifyFunDblToShort)(const transform &, pod::point); - typedef pod::point (*pModifyFunLongToShort)(const transform &, pod::point); + typedef pod::point (*pModifyFunLongToShort)(const transform &, pod::point); typedef pod::point (*pModifyFunIntToShort)(const transform &, pod::point); - - typedef pod::point (*pModifyFunDblToDbl)(const transform &, pod::point); - typedef pod::point (*pModifyFunDblToInt)(const transform &, pod::point); - typedef pod::point (*pModifyFunLongToInt)(const transform &, pod::point); + typedef pod::point (*pModifyFunDblToDbl)(const transform &, pod::point); + typedef pod::point (*pModifyFunLongToInt)(const transform &, pod::point); typedef pod::point (*pModifyFunIntToInt)(const transform &, pod::point); - - typedef pod::point (*pModifyFunLongToLong)(const transform &, pod::point); - typedef pod::point (*pModifyFunLongLongToLongLong)(const transform &, pod::point); - + typedef pod::point (*pModifyFunLongToLong)(const transform &, pod::point); // /// Type definition for for transforming a rectangle of type double to /// another rectangle of type double. // typedef pod::rectangle (*pModifyRectFunDblToDbl)(const transform &, const pod::rectangle &); // - /// Type definition for for transforming a rectangle of type i64 to - /// another rectangle of type i64. + /// Type definition for for transforming a rectangle of type long to + /// another rectangle of type long. // - typedef pod::rectangle (*pModifyRectFunLongToLong)(const transform &, const pod::rectangle &); - typedef pod::rectangle (*pModifyRectFunLongLongToLongLong)(const transform &, const pod::rectangle &); + typedef pod::rectangle (*pModifyRectFunLongToLong)(const transform &, const pod::rectangle &); // /// Type definition for for transforming a rectangle of type int to /// another rectangle of type int. @@ -186,9 +179,7 @@ namespace base extern pModifyFunLongToInt modifyLongToIntFunTbl[transformTypeMAX]; extern pModifyFunIntToInt modifyIntToIntFunTbl[transformTypeMAX]; extern pModifyFunLongToLong modifyLongToLongFunTbl[transformTypeMAX]; - extern pModifyFunLongLongToLongLong modifyLongLongToLongLongFunTbl[transformTypeMAX]; extern pModifyRectFunLongToLong modifyRectLongToLongFunTbl[transformTypeMAX]; - extern pModifyRectFunLongLongToLongLong modifyRectLongLongToLongLongFunTbl[transformTypeMAX]; extern pModifyRectFunDblToDbl modifyRectDblToDblFunTbl[transformTypeMAX]; extern pModifyRectFunIntToInt modifyRectIntToIntFunTbl[transformTypeMAX]; @@ -243,7 +234,7 @@ namespace base typedef pod::point (*pModifyFunLongToShort)( const transform &T, - pod::point xy ); + pod::point xy ); typedef pod::point (*pModifyFunDblToInt)( const transform &T, @@ -255,23 +246,19 @@ namespace base typedef pod::point (*pModifyFunLongToInt)( const transform &T, - pod::point xy ); + pod::point xy ); - typedef pod::point (*pModifyFunDblToLong)( + typedef pod::point (*pModifyFunDblToLong)( const transform &T, pod::point xy ); - typedef pod::point (*pModifyFunIntToLong)( + typedef pod::point (*pModifyFunIntToLong)( const transform &T, pod::point xy ); - typedef pod::point (*pModifyFunLongToLong)( + typedef pod::point (*pModifyFunLongToLong)( const transform &T, - pod::point xy ); - - typedef pod::point (*pModifyFunLongLongToLongLong)( - const transform &T, - pod::point xy ); + pod::point xy ); typedef pod::point (*pModifyFunDblToDbl)( const transform &T, @@ -283,7 +270,7 @@ namespace base typedef pod::point (*pModifyFunLongToDbl)( const transform &T, - pod::point xy ); + pod::point xy ); private: @@ -445,13 +432,6 @@ namespace base // /// Initialize the function tables. // - /*! - Attention please: Since base is (currently) linked statically all - the global variables in transform.h get instantiated multiple times - in Windows (Linux is smarter here), hence all the shared libraries - (that intend to be running on Windows) should consider calling - initFnTables() in their initialization code. - */ static void initFnTables(); // @@ -1004,21 +984,21 @@ public: // pod::point modifyDblToInt(pod::point) const { return pod::point(); } - pod::point modifyDblToInt(pod::point) const + pod::point modifyDblToInt(pod::point) const { return pod::point(); } pod::point modifyDblToShort(pod::point) const { return pod::point(); } - pod::point modifyDblToShort(pod::point) const + pod::point modifyDblToShort(pod::point) const { return pod::point(); } pod::point modifyDblToDbl(pod::point) const { return pod::point(); } pod::point modifyIntToInt(pod::point) const { return pod::point(); } - pod::point modifyIntToInt(pod::point) const + pod::point modifyIntToInt(pod::point) const { return pod::point(); } pod::point modifyIntToShort(pod::point) const { return pod::point(); } - pod::point modifyIntToShort(pod::point) const + pod::point modifyIntToShort(pod::point) const { return pod::point(); } pod::point modifyLongToShort(pod::point) const { return pod::point(); } @@ -1055,6 +1035,12 @@ public: { return (*(modifyDblToDblFunTbl[type]))(*this, p); } +#ifdef WIN32 + pod::point modify(pod::point p) const + { + return (*(modifyLongToLongFunTbl[type]))(*this, p); + } +#endif template pod::rectangle modify(pod::rectangle p) const @@ -1076,7 +1062,7 @@ public: return (*(modifyIntToShortFunTbl[type]))(*this, p); } - pod::point modifyLongToShort(pod::point p) const + pod::point modifyLongToShort(pod::point p) const { return (*(modifyLongToShortFunTbl[type]))(*this, p); } @@ -1084,7 +1070,7 @@ public: // /// Transform longs to ints. // - pod::point modifyLongToInt(pod::point p) const + pod::point modifyLongToInt(pod::point p) const { return (*(modifyLongToIntFunTbl[type]))(*this, p); } @@ -1092,20 +1078,12 @@ public: // /// Transform longs to longs. // - pod::point modifyLongToLong(pod::point p) const + pod::point modifyLongToLong(pod::point p) const { return (*(modifyLongToLongFunTbl[type]))(*this, p); } - // - /// Transform longs to longs. - // - pod::point modifyLongLongToLongLong(pod::point p) const - { - return (*(modifyLongLongToLongLongFunTbl[type]))(*this, p); - } - - pod::point modify(pod::point p) const + pod::point modify(pod::point p) const { return (*(modifyLongToLongFunTbl[type]))(*this, p); } @@ -1120,11 +1098,11 @@ public: return (*(modifyRectDblToDblFunTbl[type]))(*this, r); } - pod::rectangle operator()(const pod::rectangle & r) const + pod::rectangle operator()(const pod::rectangle & r) const { return (*(modifyRectLongToLongFunTbl[type]))(*this, r); } - + pod::rectangle operator()(const pod::rectangle & r) const { return (*(modifyRectIntToIntFunTbl[type]))(*this, r); @@ -1135,7 +1113,7 @@ public: return (*(modifyDblToDblFunTbl[type]))(*this, p); } - pod::point operator()(const pod::point & p) const + pod::point operator()(const pod::point & p) const { return (*(modifyLongToLongFunTbl[type]))(*this, p); } @@ -1192,10 +1170,6 @@ public: /// Print a transform, mainly for debug purpose. // void print(FILE *outStream, const char *linePrefix) const; - // - /// Dump transform. - // - void dump( std::ostream& ) const; }; // class transform @@ -1314,32 +1288,6 @@ namespace transformTest } return r; } - // - /// Apply the chain to the rectangle r. Round after each - /// resolution change if needed. - // - pod::rectangle apply(const pod::rectangle &r, bool round = true) const - { - pod::point ll = r.getLowerLeft(); - pod::point ur = r.getUpperRight(); - for (int i = 0; i < chainSize; i++) - { - ll = ll % chain[i]; - ur = ur % chain[i]; - if (round) - { - ll = pod::point(::round(ll.getX()), - ::round(ll.getY())); - ur = pod::point(::round(ur.getX()), - ::round(ur.getY())); - } - } - return pod::rectangle(ll, ur); - } - // - /// Dump transform. - // - void dump( std::ostream& ) const; }; /*! @@ -1453,39 +1401,6 @@ namespace transformTest { return pod::point(p * col1, p * col2) + offset; } - // - /// Apply the transformation to a double precision rectangle. - /// The result is the bounding rectangle of the transformed corners. - // - pod::rectangle apply(const pod::rectangle &r) const - { - using std::min; - using std::max; - - pod::point ll = pod::point(r.getLowerLeft() * col1, - r.getLowerLeft() * col2); - pod::point lr = pod::point(r.getLowerRight() * col1, - r.getLowerRight() * col2); - pod::point ul = pod::point(r.getUpperLeft() * col1, - r.getUpperLeft() * col2); - pod::point ur = pod::point(r.getUpperRight() * col1, - r.getUpperRight() * col2); - double x1 = min(min(ll.getX(), lr.getX()), - min(ul.getX(), ur.getX())); - double y1 = min(min(ll.getY(), lr.getY()), - min(ul.getY(), ur.getY())); - double x2 = max(max(ll.getX(), lr.getX()), - max(ul.getX(), ur.getX())); - double y2 = max(max(ll.getY(), lr.getY()), - max(ul.getY(), ur.getY())); - - return pod::rectangle(x1 + offset.getX(), y1 + offset.getY(), - x2 + offset.getX(), y2 + offset.getY()); - } - // - /// Dump transform. - // - void dump( std::ostream& os ) const; }; } // namespace base diff --git a/testTransform/transform2.cpp b/testTransform/transform2.cpp index 95fbb89..60bce8d 100644 --- a/testTransform/transform2.cpp +++ b/testTransform/transform2.cpp @@ -5,11 +5,11 @@ * contained herein except pursuant to a valid written license from Synopsys. */ -#include "base/type-traits2.h" +#include "type-traits2.h" #include "ssetypes.h" #include "transform2.h" -#include "base/constants.h" +#include "constants.h" namespace base2 { diff --git a/test_double_precision.cpp b/test_double_precision.cpp new file mode 100644 index 0000000..6403276 --- /dev/null +++ b/test_double_precision.cpp @@ -0,0 +1,20 @@ +#include +#include + +int main ( void ) +{ + volatile double d = 0.00000001; + volatile double a = 90; + volatile double b = a + d; + volatile double c = b - a; + + std::cout << std::setprecision(15) << "a = " << a << std::endl; + std::cout << std::setprecision(15) << "b = " << b << std::endl; + std::cout << std::setprecision(15) << "c = " << c << std::endl; + std::cout << std::setprecision(15) << "d = " << d << std::endl; + std::cout << "b == d -> " << (b == d) << std::endl; + + + return 0; +} + diff --git a/test_empty_struct.cpp b/test_empty_struct.cpp new file mode 100644 index 0000000..68addc4 --- /dev/null +++ b/test_empty_struct.cpp @@ -0,0 +1,10 @@ +class A +{ +}; + +int main( ) +{ + A* p = new A; + p->operator delete(); +} + diff --git a/test_i32_overflow.cpp b/test_i32_overflow.cpp new file mode 100644 index 0000000..43c86d6 --- /dev/null +++ b/test_i32_overflow.cpp @@ -0,0 +1,126 @@ +#include +#include +#include + +inline void throw_overflow () +{ + throw std::runtime_error( "Overflow!!!" ); +} + +#define E void (*err)() + +//template +inline int add( int op1, int op2, E ) +{ + asm ( "add %1, %0" + : "=r"(op1) + : "r"(op2),"0"(op1) ); + asm goto( "jo %l[throw_exception]" + : : : "memory" + : throw_exception ); + return op1; + +throw_exception: + err(); +} + +//template +inline long add( long op1, long op2, E) +{ + asm ( "add %1, %0" + : "=r"(op1) + : "r"(op2),"0"(op1) ); + asm goto( "jo %l[throw_exception]" + : : : "memory" + : throw_exception ); + return op1; + +throw_exception: + err(); +} + +// Just test a possible implementation for 386 +//template +inline long long add( long long op1, long long op2, E ) +{ + unsigned int op1l = (unsigned int)op1; + unsigned int op1h = (unsigned int)((unsigned long long)op1 >> 32); + unsigned int op2l = (unsigned int)op2; + unsigned int op2h = (unsigned int)((unsigned long long)op2 >> 32); + asm ( "add %2, %0\n" + "adc %3, %1" + : "=a"(op1l),"=d"(op1h) + : "g"(op2l),"g"(op2h),"0"(op1l),"1"(op1h) ); + asm goto( "jo %l[throw_exception]" + : : : "memory" + : throw_exception ); + return (long long)((unsigned long long)op1l | ((unsigned long long)op1h << 32)); + +throw_exception: + err(); +} + +#if 0 +// +//GCC 4.5.2 crashes on this template. +//I filed a bug against GCC. #55528 +// +template +inline C add2( C op1, C op2 ) +{ + asm ( "add %1, %0" + : "=r"(op1) + : "r"(op2),"0"(op1) ); + asm goto( "jo %l[throw_exception]" + : : : "memory" + : throw_exception ); + return op1; + +throw_exception: + return throw_overflow(); +} +#endif + +template +inline void test_add( C op1, C op2 ) +{try +{ + std::cout << op1 << " + " << op2 << " = "; + std::cout.flush(); + C r = add( op1, op2, &throw_overflow ); + std::cout << r << std::endl; +} +catch ( const std::exception& e ) +{ + std::cout << e.what() << std::endl; +} +catch ( ... ) +{ + std::cout << "unknown exception" << std::endl; +} +} + +int main( void ) +{ + test_add( 10, 20); + test_add( 100, 200); + test_add( 1000, 2000); + test_add( 1000000000, 2000000000); + test_add( 1000000000, -2000000000); + test_add( -1000000000, 2000000000); + test_add( -1000000000, -2000000000); + test_add( 1000000000L, 2000000000L); + test_add( 1000000000L,-2000000000L); + test_add( -1000000000L, 2000000000L); + test_add( -1000000000L,-2000000000L); + test_add( 7000000000000000000L, 8000000000000000000L); + test_add( 7000000000000000000L, -8000000000000000000L); + test_add( -7000000000000000000L, 8000000000000000000L); + test_add( -7000000000000000000L, -8000000000000000000L); + test_add( (long long)7000000000000000000L, (long long)8000000000000000000L); + test_add( (long long)7000000000000000000L, (long long)-8000000000000000000L); + test_add( (long long)-7000000000000000000L, (long long)8000000000000000000L); + test_add( (long long)-7000000000000000000L, (long long)-8000000000000000000L); + return 0; +} + diff --git a/test_namespace_rename.cpp b/test_namespace_rename.cpp new file mode 100644 index 0000000..3a547eb --- /dev/null +++ b/test_namespace_rename.cpp @@ -0,0 +1,39 @@ +//#include +#include + +namespace std +{ +namespace tr1 +{ + template + class A + { + public: + void f() + { + std::cout << "I am std::tr1::A::f()" << std::endl; + } + }; + + template <> + void A::f() + { + std::wcout << L"I am std::tr1::A::f()" << std::endl; + } + +} +} + +namespace std +{ + using std::tr1::A; +} + +int main( void ) +{ + std::A a; + a.f(); + + return 0; +} +