memstore.direct.c

来自「代码优化,有效使用内存,透视优化技术,对比优化方法,如果你在追求代码效率的最大化」· C语言 代码 · 共 41 行

C
41
字号
/* ---------------------------------------------------------------------------
 *
 *			MEASUREMENT OF THE MEMORY INITIALIZATION SPEED IN BOTH DIRECTIONS
 *			===========================================================
 *
 * Build 0x001 26.08.2002
--------------------------------------------------------------------------- */

#include <DoCPU.h>

#define _PAGE_SIZE (4*K)				// size of one memory page
#define BLOCK_SIZE (4*M)				// processed block size


/* ---------------------------------------------------------------------------

								INITIALIZATION /---->

--------------------------------------------------------------------------- */
l_to_r(char *p)
{
			memset(p,0x66,BLOCK_SIZE);			// initializing memory
			A_READ(p,BLOCK_SIZE);				// imitating block processing
}


/* ---------------------------------------------------------------------------

							INITIALIZATION <-------/

--------------------------------------------------------------------------- */
r_to_l(char *p)
{
	char *p2;
	p2 = p;
	__asm{								// implement reverse copying in assembler
			STD							// setting the flag of reverse direction
			MOV	EDI,[p2]				// load the pointer to the block to be initialized into EDI
			MOV	ECX,BLOCK_SIZE/4		// load the number of double words to be written into ECX
			REP	STOSD					// initialize the memory by arbitrary value that happens to be contained in EAX
			MOV	[p2],EDI				// 钺眍怆

⌨️ 快捷键说明

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