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

📄 align.memcpy.c

📁 代码优化,有效使用内存,透视优化技术,对比优化方法,如果你在追求代码效率的最大化,该资源你不能不读.
💻 C
字号:
/* ---------------------------------------------------------------------------
 * @
 *						UTILITY DEMONSTRATING THE INFLUENCE
 *		OF ADDRESS ALIGNMENT ON THE COPYING SPEED OF LARGE MEMROY BLOCKS
 *		==================================================================
 *
 * Build 0x001 06.07.2002
--------------------------------------------------------------------------- */
// configuration
#define BLOCK_SIZE		(8*M)				// size of the copied block


#include <DoCPU.h>
main()
{
	char *p1, *p2;

	// TITLE
	PRINT("= = = influence of address alignment on the memory copying speed = = =\n");
	PRINT_TITLE;

	// allocating the memory
	p1 = malloc(BLOCK_SIZE);
	p2 = malloc(BLOCK_SIZE);


	/*------------------------------------------------------------------------
	 *
	 *					copying aligned block
	 *
	----------------------------------------------------------------------- */
	VVV;
	A_BEGIN(0)
		memcpy(p2, p1, BLOCK_SIZE);
	A_END(0)

	/*------------------------------------------------------------------------
	 *
	 *				copying the block with unaligned target
	 *
	----------------------------------------------------------------------- */
	VVV;
	A_BEGIN(1)
		memcpy(p2 + 1, p1, BLOCK_SIZE);
	A_END(1)

	/*------------------------------------------------------------------------
	 *
	 *				copying the block with unaligned source
	 *
	----------------------------------------------------------------------- */
	VVV;
	A_BEGIN(2)
		memcpy(p2, p1 + 1, BLOCK_SIZE);
	A_END(2)

	/*------------------------------------------------------------------------
	 *
	 *				copying the totally unaligned block
	 *
	----------------------------------------------------------------------- */
	VVV;
	A_BEGIN(3)
		memcpy(p2 + 1, p1 + 1, BLOCK_SIZE);
	A_END(3)

	// output
	Lx_OUT("unalign dst......",Ax_GET(0),Ax_GET(1));
	Lx_OUT("unalign src......",Ax_GET(0),Ax_GET(2));
	Lx_OUT("unalign src & dst",Ax_GET(0),Ax_GET(3));
}


⌨️ 快捷键说明

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