Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1756090
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类: LINUX

2008-12-03 09:57:09

/* for small memory blocks (<256 bytes) this version is faster */
#define small_memcpy(to,from,n)\
 {\
 register unsigned long int dummy;\
 __asm__ __volatile__(\
 "rep; movsb"\
 :"=&D"(to), "=&S"(from), "=&c"(dummy)\
 :"0" (to), "1" (from),"2" (n)\
 : "memory");\
 }
 
/* linux kernel __memcpy (from: /include/asm/string.h) */
 static inline void * __memcpy(void * to, const void * from, size_t n)
 {
  int d0, d1, d2;
  if( n < 4 ) {
   small_memcpy(to,from,n);
  }
  else
   __asm__ __volatile__(
   "rep ; movsl\n\t"
   "testb $2,%b4\n\t"
   "je 1f\n\t"
   "movsw\n"
   "1:\ttestb $1,%b4\n\t"
   "je 2f\n\t"
   "movsb\n"
   "2:"
   : "=&c" (d0), "=&D" (d1), "=&S" (d2)
   :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
   : "memory");
  return (to);
 }
阅读(1471) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~