Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67489
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-20 19:05
文章分类
文章存档

2016年(3)

2015年(15)

我的朋友

分类: C/C++

2015-05-24 22:26:00

glibc 2.20版本memcpy源码:
以i386为例 OP_T_THRES   值为8

点击(此处)折叠或打开

  1. memcpy (dstpp, srcpp, len)
  2.      void *dstpp;
  3.      const void *srcpp;
  4.      size_t len;
  5. {
  6.   unsigned long int dstp = (long int) dstpp;
  7.   unsigned long int srcp = (long int) srcpp;

  8.   /* Copy from the beginning to the end. */

  9.   /* If there not too few bytes to copy, use word copy. */
  10.   if (len >= OP_T_THRES)                   //判断是否大于8字节
  11.     {
  12.       /* Copy just a few bytes to make DSTP aligned. */
  13.       len -= (-dstp) % OPSIZ;                        //4字节对齐
  14.       BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);   //头部4字节不对齐部分使用movsb拷贝    

  15.       /* Copy whole pages from SRCP to DSTP by virtual address manipulation,
  16.      as much as possible. */

  17.       PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);   //i386 不支持,空的

  18.       /* Copy from SRCP to DSTP taking advantage of the known alignment of
  19.      DSTP. Number of bytes remaining is put in the third argument,
  20.      i.e. in LEN. This number may vary from machine to machine. */

  21.       WORD_COPY_FWD (dstp, srcp, len, len);    //使用movl 四字节拷贝,一个循环拷贝32字节,多余的最后用BYTE_COPY_FWD拷贝

  22.       /* Fall out and copy the tail. */
  23.     }

  24.   /* There are just a few bytes to copy. Use byte memory operations. */
  25.   BYTE_COPY_FWD (dstp, srcp, len); //movsb拷贝

  26.   return dstpp;
  27. }

阅读(2668) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~