memcpy

#include <stddef.h>   //
#include <stdint.h> //uintptr_t is quoted.
#include "string.h"
/*
* sizeof(word) MUST BE A POWER OF TWO
* SO THAT wmask BELOW IS ALL ONES
*/
typedef int word; /* "word" used for optimal copy speed */ #define wsize sizeof(word)
#define wmask (wsize - 1) /*
* Copy a block of memory, handling overlap.
* This is the routine that actually implements
* (the portable versions of) bcopy, memcpy, and memmove.
*/ __private_extern__
void * memcpy(void *dst0, const void *src0, size_t length)
{
char *dst = dst0;
const char *src = src0;
size_t t; if (length == || dst == src) /* nothing to do */
goto done; /*
* Macros: loop-t-times; and loop-t-times, t>0
*/
#define TLOOP(s) if (t) TLOOP1(s)
#define TLOOP1(s) do { s; } while (--t) if ((unsigned long)dst < (unsigned long)src) {
/*
* Copy forward.
*/
t = (uintptr_t)src; /* only need low bits */
if ((t | (uintptr_t)dst) & wmask) {
/*
* Try to align operands. This cannot be done
* unless the low bits match.
*/
if ((t ^ (uintptr_t)dst) & wmask || length < wsize)
t = length;
else
t = wsize - (t & wmask);
length -= t;
TLOOP1(*dst++ = *src++);
}
/*
* Copy whole words, then mop up any trailing bytes.
*/
t = length / wsize;
TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
t = length & wmask;
TLOOP(*dst++ = *src++);
} else {
/*
* Copy backwards. Otherwise essentially the same.
* Alignment works as before, except that it takes
* (t&wmask) bytes to align, not wsize-(t&wmask).
*/
src += length;
dst += length;
t = (uintptr_t)src;
if ((t | (uintptr_t)dst) & wmask) {
if ((t ^ (uintptr_t)dst) & wmask || length <= wsize)
t = length;
else
t &= wmask;
length -= t;
TLOOP1(*--dst = *--src);
}
t = length / wsize;
TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
t = length & wmask;
TLOOP(*--dst = *--src);
}
done:
return (dst0);
} __private_extern__ void *
memmove(void *s1, const void *s2, size_t n)
{
return memcpy(s1, s2, n);
} __private_extern__ void
bcopy(const void *s1, void *s2, size_t n)
{
memcpy(s2, s1, n);

http://www.opensource.apple.com/source/xnu/xnu-2050.18.24/libsyscall/wrappers/memcpy.c

intptr_t

http://www.cnblogs.com/aprilapril/p/4318769.html

memcpy code的更多相关文章

  1. 插头DP专题

    建议入门的人先看cd琦的<基于连通性状态压缩的动态规划问题>.事半功倍. 插头DP其实是比较久以前听说的一个东西,当初是水了几道水题,最近打算温习一下,顺便看下能否入门之类. 插头DP建议 ...

  2. LInux 安全测试 2

    Centos/CentOS 6.4 linux内核2.6.3.2本地提权exp代码 jincon 发表于 2014-05-31 08:25:00 发表在: 代码审计 最近我接手的一台centos 服务 ...

  3. LInux 安全测试

    [CVE-2013-2094]Linux PREF_EVENTS Local Root 2.6.37-3.8.10 x86_64 踩(0)http://zone.wooyun.org/content/ ...

  4. 算法系列9《MD5》

    MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息传输完整一致.是计算机广泛使用的杂凑算法之一(又译摘要算法.哈希算法),主流编程语言普遍已有MD5实现. ...

  5. 插头dp的几个模板

    /* ural1519 求经过全部可行点的哈密顿回路的个数 括号匹配法,转移有点复杂,可是时间空间比較小 */ #include<cstdio> #include<cstring&g ...

  6. ural 1519 Formula 1

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1519 题目分类:插头dp 题意:求经过所有可行点的哈密顿回路的个数  * 不可走 . 可 ...

  7. Operation not permitted引发的惊魂72小时

    0.问题及描述 在测试产品的时候,莫名其妙发现了我们的主进程VPNd会出现以下的报错: 2013-07-18 13:05:13  www.1.com/192.168.200.220:65527 wri ...

  8. 模板—插头dp(Ural 1519 Formula 1)

    括号表示法: 据说比下一个要快而且灵活. #include<iostream> #include<cstring> #include<cstdio> #define ...

  9. 使用Code::blocks在windows下写网络程序

    使用Code::blocks在windows下写网络程序 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创 ...

随机推荐

  1. windows 下的定时任务

    linux 下的定时任务是crontab 以前都是linux的定时任务,这次在windows做了定时任务,简单记录一下 windows 2008下的定时任务配置: 控制面板->管理工具-> ...

  2. applicationContext.xml和web.xml的一些配置

    applicationContext.xml <!-- test环境 --> <beans profile="test"> <context:prop ...

  3. c++ 语言细节

    #include <iostream>using namespace std;int main(){     cout << "\nHello World!\n&qu ...

  4. 11g RAC集群启动关闭、各种资源检查、配置信息查看汇总。

    简要:一:集群的启动与关闭 1. rac集群的手动启动[root@node1 bin]# ./crsctl start cluster -all2. 查看rac集群的状态[root@node1 bin ...

  5. linux cpu性能测试

    sysbench --test=cpu --cpu-max-prime=20000000 run --num-threads=4 mpstat -P ALL 1 1000000

  6. Java基础之-ExecutorService

    翻译javadoc系列文章之:ExecutorService /** * An {@link Executor} that provides methods to manage termination ...

  7. Python-基础-时间日期处理小结

    Python-基础-时间日期处理小结 涉及对象 1. datetime 2. timestamp 3. time tuple 4. string 5. date datetime基本操作 1. 获取当 ...

  8. BufferedReader需要显示关闭

    BufferedReader reader = new BufferedReader(); …… reader.close(); BufferedReader需要显示关闭 解释: 方法调用结束后,这两 ...

  9. UISwitch控件的使用

    UISwitch控件的作用是提供一个开关给用户,用户可以选择打开或者关闭. UISwitch的基本属性包括: 1.onTintColor:打开状态下的背景颜色 2.thumbTintColor:滑块的 ...

  10. LVS安装使用详解

    简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,它的官方站点是www.linuxvirtualserver.org. ...