⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clockcyclecounter.hpp

📁 Real Value FFT Algorithm
💻 HPP
字号:
/*****************************************************************************        ClockCycleCounter.hpp        Copyright (c) 2003 Laurent de SorasPlease complete the definitions according to your compiler/architecture.It's not a big deal if it's not possible to get the clock count...--- Legal stuff ---This library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*Tab=3***********************************************************************/#if defined (stopwatch_ClockCycleCounter_CURRENT_CODEHEADER)	#error Recursive inclusion of ClockCycleCounter code header.#endif#define	stopwatch_ClockCycleCounter_CURRENT_CODEHEADER#if ! defined (stopwatch_ClockCycleCounter_CODEHEADER_INCLUDED)#define	stopwatch_ClockCycleCounter_CODEHEADER_INCLUDED/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/#include	"fnc.h"

#include	<climits>namespace stopwatch{/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

/*
==============================================================================
Name: start
Description:
	Starts the counter.
Throws: Nothing
==============================================================================
*/

void	ClockCycleCounter::start (){
	_best_score = (static_cast <Int64> (1) << (sizeof (Int64) * CHAR_BIT - 2));
	const Int64		start_clock = read_clock_counter ();
	_start_time = start_clock;
	_state = start_clock - _best_score;
}/*
==============================================================================
Name: stop_lap
Description:
	Captures the current time and updates the smallest duration between two
	consecutive calls to stop_lap() or the latest start().
	start() must have been called at least once before calling this function.
Throws: Nothing
==============================================================================
*/

void	ClockCycleCounter::stop_lap (){	const Int64		end_clock = read_clock_counter ();
	_best_score = min (end_clock - _state, _best_score);
	_state = end_clock;
}/*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*//*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/Int64	ClockCycleCounter::read_clock_counter ()
{
	register Int64		clock_cnt;

#if defined (_MSC_VER)

	__asm
	{
		lea				edi, clock_cnt
		rdtsc
		mov				[edi    ], eax
		mov				[edi + 4], edx
	}

#elif defined (__GNUC__) && defined (__i386__)

	__asm__ __volatile__ ("rdtsc" : "=A" (clock_cnt));

#elif (__MWERKS__) && defined (__POWERPC__) 
	
	asm
	{
	loop:
		mftbu			clock_cnt@hiword
		mftb			clock_cnt@loword
		mftbu			r5
		cmpw			clock_cnt@hiword,r5
		bne loop
	}
	
#endif

	return (clock_cnt);
}



}	// namespace stopwatch#endif	// stopwatch_ClockCycleCounter_CODEHEADER_INCLUDED#undef stopwatch_ClockCycleCounter_CURRENT_CODEHEADER/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -