memcpy code
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的更多相关文章
- 插头DP专题
建议入门的人先看cd琦的<基于连通性状态压缩的动态规划问题>.事半功倍. 插头DP其实是比较久以前听说的一个东西,当初是水了几道水题,最近打算温习一下,顺便看下能否入门之类. 插头DP建议 ...
- LInux 安全测试 2
Centos/CentOS 6.4 linux内核2.6.3.2本地提权exp代码 jincon 发表于 2014-05-31 08:25:00 发表在: 代码审计 最近我接手的一台centos 服务 ...
- LInux 安全测试
[CVE-2013-2094]Linux PREF_EVENTS Local Root 2.6.37-3.8.10 x86_64 踩(0)http://zone.wooyun.org/content/ ...
- 算法系列9《MD5》
MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息传输完整一致.是计算机广泛使用的杂凑算法之一(又译摘要算法.哈希算法),主流编程语言普遍已有MD5实现. ...
- 插头dp的几个模板
/* ural1519 求经过全部可行点的哈密顿回路的个数 括号匹配法,转移有点复杂,可是时间空间比較小 */ #include<cstdio> #include<cstring&g ...
- ural 1519 Formula 1
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1519 题目分类:插头dp 题意:求经过所有可行点的哈密顿回路的个数 * 不可走 . 可 ...
- Operation not permitted引发的惊魂72小时
0.问题及描述 在测试产品的时候,莫名其妙发现了我们的主进程VPNd会出现以下的报错: 2013-07-18 13:05:13 www.1.com/192.168.200.220:65527 wri ...
- 模板—插头dp(Ural 1519 Formula 1)
括号表示法: 据说比下一个要快而且灵活. #include<iostream> #include<cstring> #include<cstdio> #define ...
- 使用Code::blocks在windows下写网络程序
使用Code::blocks在windows下写网络程序 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创 ...
随机推荐
- maven 基本常识以及命令
Maven库: http://repo2.maven.org/maven2/ Maven依赖查询: http://mvnrepository.com/ Maven常用命令: 1. 创建Maven的普通 ...
- 摘要评注The Cathedral & The Bazaar
2013年暑期买到这本书,距离其第一版已经有14年之久,而最早发布在互联网上的文章更是早在1997年.在我阅读的时候,很多事迹已经沉积为历史,很多预言已经成为现实.而这本书的意义却丝毫没有因此淡化,反 ...
- 如何成为一名优秀的前端工程师 (share)
发现一篇不错的博文,和大家分享一下,为有志成为一名优秀前端工程师的童鞋们提供一个参考. :)~ 本文来源:http://www.biaodianfu.com/what-makes-a-good-fro ...
- Spark 个人实战系列(2)--Spark 服务脚本分析
前言: spark最近非常的火热, 本文不讲spark原理, 而是研究spark集群搭建和服务的脚本是如何编写的, 管中窥豹, 希望从运行脚本的角度去理解spark集群. 研究的spark为1.0.1 ...
- 设置Android studio黑色主题
设置: 如上图,点击[Theme]下拉选项,选中[Darcula]主题,点击[Apply]应用修改,弹出重启Android Studio生效修改.如图:
- my Js
1. __doPostBack是.net自动生成的(当页面中有LinkButton.DropDownList(AutoPostBack)等时:Button和ImageButton不会生成它,也不会调用 ...
- Servlet基本模式
一.首先用Myeclipse2015创建一个web项目,然后修改index.jsp. <%@ page language="java" import="java.u ...
- HSDB
select t from java.lang.Thread t $JAVA_HOME/bin/java -classpath $JAVA_HOME/lib/sa-jdi.jar sun.jvm.ho ...
- [Freemarker] - 使用struts的component调用freemarker的ftl模板方法
struts中的component标签,可以用来调用freemarker的ftl模板文件,使用component标签传参可以这样写: 使用property方式写法: <s:component t ...
- Java 大数运算
import java.util.*; import java.math.*; public class Main{ public static void main(String args[]){ S ...