资源简介
《深入理解计算机系统》一书的配套lab之malloc lab。学生用来实现自己的malloc, realloc和free函数。
Students implement their own versions of malloc, free, and realloc. This lab gives students a clear understanding of data layout and organization, and requires them to evaluate different trade-offs between space and time efficiency. One of our favorite labs. When students finish this one, they really understand pointers!
代码片段和文件信息
/*
* clock.c - Routines for using the cycle counters on x86
* Alpha and Sparc boxes.
*
* Copyright (c) 2002 R. Bryant and D. O‘Hallaron All rights reserved.
* May not be used modified or copied without permission.
*/
#include
#include
#include
#include
#include “clock.h“
/*******************************************************
* Machine dependent functions
*
* Note: the constants __i386__ and __alpha
* are set by GCC when it calls the C preprocessor
* You can verify this for yourself using gcc -v.
*******************************************************/
#if defined(__i386__)
/*******************************************************
* Pentium versions of start_counter() and get_counter()
*******************************************************/
/* $begin x86cyclecounter */
/* Initialize the cycle counter */
static unsigned cyc_hi = 0;
static unsigned cyc_lo = 0;
/* Set *hi and *lo to the high and low order bits of the cycle counter.
Implementation requires assembly code to use the rdtsc instruction. */
void access_counter(unsigned *hi unsigned *lo)
{
asm(“rdtsc; movl %%edx%0; movl %%eax%1“ /* Read cycle counter */
: “=r“ (*hi) “=r“ (*lo) /* and move results to */
: /* No input */ /* the two outputs */
: “%edx“ “%eax“);
}
/* Record the current value of the cycle counter. */
void start_counter()
{
access_counter(&cyc_hi &cyc_lo);
}
/* Return the number of cycles since the last call to start_counter. */
double get_counter()
{
unsigned ncyc_hi ncyc_lo;
unsigned hi lo borrow;
double result;
/* Get cycle counter */
access_counter(&ncyc_hi &ncyc_lo);
/* Do double precision subtraction */
lo = ncyc_lo - cyc_lo;
borrow = lo > ncyc_lo;
hi = ncyc_hi - cyc_hi - borrow;
result = (double) hi * (1 << 30) * 4 + lo;
if (result < 0) {
fprintf(stderr “Error: counter returns neg value: %.0f\n“ result);
}
return result;
}
/* $end x86cyclecounter */
#elif defined(__alpha)
/****************************************************
* Alpha versions of start_counter() and get_counter()
***************************************************/
/* Initialize the cycle counter */
static unsigned cyc_hi = 0;
static unsigned cyc_lo = 0;
/* Use Alpha cycle timer to compute cycles. Then use
measured clock speed to compute seconds
*/
/*
* counterRoutine is an array of Alpha instructions to access
* the Alpha‘s processor cycle counter. It uses the rpcc
* instruction to access the counter. This 64 bit register is
* divided into two parts. The lower 32 bits are the cycles
* used by the current process. The upper 32 bits are wall
* clock cycles. These instructions read the counter and
* convert the lower 32 bits into an unsigned int - this is the
* user space counter value.
* NOTE: The counter has a very limited time span. With a
* 450MhZ clock the c
- 上一篇:自主移动机器人导论高清PDF
- 下一篇:pdz格式转换pdf工具
相关资源
- 基于MTALAB模糊滑膜PID论文+仿真.zip
- 小草手把手教你labview仪器控制
- labview实用工程
- 陈天奇论文及翻译+演讲PPT+论文讲解陈
- labview学习资料
- labview生成一维码
- 胡广书现代信号处理课后代码.rar
- LABVIEW应用55个
- 小草手把手教你LabVIEW仪器控制.pdf
- LabVIEW(虚拟仪器LabVIEW)) 外文翻译
- LABVIEW最实用的技巧合集.pdf
- SaDE差分进化算法的程序
- LMS官方 声学分析软件 结果处理 展示
- DBN源码,深度学习领域的适合初学者
- GitLab在windows用户端的安装使用详细教
- labview小游戏-汉诺塔
- CSAPP_buflab 解答详细过程(内含源程序
- NI Labview CLAD官方模拟题
- labview边干边学数据库应用
- 有关逻辑门限值控制的ABS算法的毕业
- PLC课程设计(五层电梯).pdf
- Labview在线离线混合地图
- FPGA数字信号处理实现原理及方法-清华
- 数学建模算法与应用第2版习题解答的
- 三相异步电动机运行仿真及GUI设计
- 4QAM 方式OFDM labview
- 小波特征提取与支持向量机识别
- 《LabVIEW入门与实战开发100例》源程序
- MPLAB_X_IDE用户指南(中文版)
- 轨迹优化软件gpops5.2
评论
共有 条评论