CSAPP:datalab

深入了解计算机系统——实验二(Data Lab)(详解) 深入了解计算机系统——实验二(Data Lab)(详解)实验内容及操作步骤bitAnd函数getByte函数logicalShift函数bitCount函数bang函数tmin函数fitsBits函数divpwr2函数negate函数isPositive函数isLessOrEqual函数ilog2函数float_neg函数float_i2f函数float_twice函数如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释 阅读详情

题目要求

/* 
 * CS:APP Data Lab 
 * 
 * <Please put your name and userid here>
 * 
 * bits.c - Source file with your solutions to the Lab.
 *          This is the file you will hand in to your instructor.
 *
 * WARNING: Do not include the <stdio.h> header; it confuses the dlc
 * compiler. You can still use printf for debugging without including
 * <stdio.h>, although you might get a compiler warning. In general,
 * it's not good practice to ignore compiler warnings, but in this
 * case it's OK.  
 */

#if 0
/*
 * Instructions to Students:
 *
 * STEP 1: Read the following instructions carefully.
 */

You will provide your solution to the Data Lab by
editing the collection of functions in this source file.

INTEGER CODING RULES:

  Replace the "return" statement in each function with one
  or more lines of C code that implements the function. Your code 
  must conform to the following style:

  int Funct(arg1, arg2, ...) {
      /* brief description of how your implementation works */
      int var1 = Expr1;
      ...
      int varM = ExprM;

      varJ = ExprJ;
      ...
      varN = ExprN;
      return ExprR;
  }

  Each "Expr" is an expression using ONLY the following:
  1. Integer constants 0 through 255 (0xFF), inclusive. You are
      not allowed to use big constants such as 0xffffffff.
  2. Function arguments and local variables (no global variables).
  3. Unary integer operations ! ~
  4. Binary integer operations & ^ | + << >>

  Some of the problems restrict the set of allowed operators even further.
  Each "Expr" may consist of multiple operators. You are not restricted to
  one operator per line.

  You are expressly forbidden to:
  1. Use any control constructs such as if, do, while, for, switch, etc.
  2. Define or use any macros.
  3. Define any additional functions in this file.
  4. Call any functions.
  5. Use any other operations, such as &&, ||, -, or ?:
  6. Use any form of casting.
  7. Use any data type other than int.  This implies that you
     cannot use arrays, structs, or unions.


  You may assume that your machine:
  1. Uses 2s complement, 32-bit representations of integers.
  2. Performs right shifts arithmetically.
  3. Has unpredictable behavior when shifting an integer by more
     than the word size.

EXAMPLES OF ACCEPTABLE CODING STYLE:
  /*
   * pow2plus1 - returns 2^x + 1, where 0 <= x <= 31
   */
  int pow2plus1(int x) {
     /* exploit ability of shifts to compute powers of 2 */
     return (1 << x) + 1;
  }

  /*
   * pow2plus4 - returns 2^x + 4, where 0 <= x <= 31
   */
  int pow2plus4(int x) {
     /* exploit ability of shifts to compute powers of 2 */
     int result = (1 << x);
     result += 4;
     return result;
  }

FLOATING POINT CODING RULES

For the problems that require you to implent floating-point operations,
the coding rules are less strict.  You are allowed to use looping and
conditional control.  You are allowed to use both ints and unsigneds.
You can use arbitrary integer and unsigned constants.

You are expressly forbidden to:
  1. Define or use any macros.
  2. Define any additional functions in this file.
  3. Call any functions.
  4. Use any form of casting.
  5. Use any data type other than int or unsigned.  This means that you
     cannot use arrays, structs, or unions.
  6. Use any floating point data types, operations, or constants.


NOTES:
  1. Use the dlc (data lab checker) compiler (described in the handout) to 
     check the legality of your solutions.
  2. Each function has a maximum number of operators (! ~ & ^ | + << >>)
     that you are allowed to use for your implementation of the function. 
     The max operator count is checked by dlc. Note that '=' is not 
     counted; you may use as many of these as you want without penalty.
  3. Use the btest test harness to check your functions for correctness.
  4. Use the BDD checker to formally verify your functions
  5. The maximum number of ops for each function is given in the
     header comment for each function. If there are any inconsistencies 
     between the maximum ops in the writeup and in this file, consider
     this file the authoritative source.

/*
 * STEP 2: Modify the following functions according the coding rules.
 * 
 *   IMPORTANT. TO AVOID GRADING SURPRISES:
 *   1. Use the dlc compiler to check that your solutions conform
 *      to the coding rules.
 *   2. Use the BDD checker to formally verify that your solutions produce 
 *      the correct answers.
 */

参考答案

第一题 bitAnd

/* 
 * bitAnd - x&y using only ~ and | 
 *   Example: bitAnd(6, 5) = 4
 *   Legal ops: ~ |
 *   Max ops: 8
 *   Rating: 1
 */
int bitAnd(int x, int y) {
  return ~(~x | ~y);
}

布尔代数基本定理:a & b = ~(~a | ~b)

第二题getBytes

/* 
 * getByte - Extract byte n from word x
 *   Bytes numbered from 0 (LSB) to 3 (MSB)
 *   Examples: getByte(0x12345678,1) = 0x56
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 6
 *   Rating: 2
 */
int getByte(int x, int n) {
  return (x >> (n << 3)) & 0xFF;

}

x 右移n个字节,mask下0xFF。8bit为一个字节,n个字节表示n*8 = n << 3。

第三题logicalShift

/* 
 * logicalShift - shift x to the right by n, using a logical shift
 *   Can assume that 0 <= n <= 31
 *   Examples: logicalShift(0x87654321,4) = 0x08765432
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 20
 *   Rating: 3 
 */
int logicalShift(int x, int n) {
  int aritShift = x >> n;
  int mask = (~(1 << 31) >> n << 1) + 1;
  return aritShift & mask; 
}

先进行算术右移,将左边因为算术右移产生的1 mask掉。其中mask = 00…011…1,前面n个0,后面全为1。mask = (~(1 << 31) >> n << 1) + 1. 注意⚠️最后+1,是因为左移1位产生的0,要给它填上。

第四题bitCount

/*
 * bitCount - returns count of number of 1's in word
 *   Examples: bitCount(5) = 2, bitCount(7) = 3
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 40
 *   Rating: 4
 */
int bitCount(int x) {
  int mask1;
  int mask2;
  int mask4;
  int mask8;
  int mask16;

  mask1 = 0x55 | 0x55 << 8;
  mask1 = mask1 | mask1 << 16;
  mask2 = 0x33 | 0x33 << 8;
  mask2 = mask2 | mask2 << 16; 
  mask4 = 0x0F | 0x0F << 8;
  mask4 = mask4 | mask4 << 16;
  mask8 = 0xFF | 0xFF << 16;
  mask16 = 0xFF | 0xFF << 8;

  x = (x & mask1) + ((x >> 1) & mask1);
  x = (x & mask2) + ((x >> 2) & mask2);
  x = (x + (x >> 4)) & mask4;
  x = (x + (x >> 8)) & mask8;
  x = (x + (x >> 16)) & mask16;

  return x;
}

这题总体思路是divide and conquer。

  1. 将x的bit表示,分成两个一组,组内一位相加。
    例如:10010010111010101011101000001101,分成 10 01 00 10 11 10 10 10 10 11 10 10 00 00 11 01。
    组内相加得到x1 = 01 01 00 01 10 01 01 01 01 10 01 01 00 00 10 01. 这样表示每组分别有多少个1。
    实现这个操作只要将(x & mask1) + ((x >> 1) & mask1), 其中mask1 = 01010101…0101.
    mask1 可以经过如上代码得到。

  2. 再将x1的bit表示,分成四个一组,同样组内两位相加。
    10 01 00 10 11 10 10 10 10 11 10 10 00 00 11 01,分成1001 0010 1110 1010 1011 1010 0000 1101。
    组内相加得到x2 = 0010 0010 0101 100 0101 0100 0000 0101。同样地表示没组分别有多少个1。
    实现这个操作只要将(x & mask2) + ((x >> 2) & mask2), 其中mask2 = 00110011…0011.
    mask2 可以经过如上代码得到。

  3. 以此类推…

注意⚠️,最后三次操作没有先经过mask,而是直接相加再mask,不是因为遵守分配律,而是因为前面2次要先mask再相加是因为算术右移产生1,要先把它mask成0。 而经过第二次的四位一组,组内2位两位相加,表示bit 1的数量肯定不会超过4,即四位一组表示成0100。这样进行算术右移不会产生1,所以为了减少运算次数,可以先相加再mask。

第五题bang

/* 
 * bang - Compute !x without using !
 *   Examples: bang(3) = 0, bang(0) = 1
 *   Legal ops: ~ & ^ | + << >>
 *   Max ops: 12
 *   Rating: 4 
 */
int bang(int x) {
  return (((~x + 1) | x) >> 31) + 1;
}

这里利用了补码相反数的特性。除了0,0x80000000以外的任何数,它与其相反数的符号为一定是不同的。而0x80000000的相反数仍然为本身,所以只有0 | 0的相反数的最高位为0,其余均为1。因此 ((~x + 1) | x ) >> 31 若不是0,那么会产生0xFFFFFFFF;若为0,则为0x0。经过 + 1之后,则实现了 !x 功能。

第六题tmin

/* 
 * tmin - return minimum two's complement integer 
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 4
 *   Rating: 1
 */
int tmin(void) {
  return 0x80 << 24;
}

水题,直接利用补码定义就好了。

第七题fitsBits

/* 
 * fitsBits - return 1 if x can be represented as an 
 *  n-bit, two's complement integer.
 *   1 <= n <= 32
 *   Examples: fitsBits(5,3) = 0, fitsBits(-4,3) = 1
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 15
 *   Rating: 2
 */
int fitsBits(int x, int n) {
  int shiftNumber = 32 + ~n + 1;
  int tmp = x << shiftNumber >> shiftNumber; 
  return !(tmp ^ x);
}

x能否用更少的位数n表示,可以看成n位的数能否经过符号扩展,变成与x位数一样的数。因为符号扩展的位都是0或都是1。所以经过 x << (32 - n) >> (32 - n)之后,如果能用n位表示,则一定与原来x相同。判断一个数是否和另一个数相同用异或即可,相同则为0。最后加!,如果相同,则返回1,表示能用n位表示x。

第八题divpwr2

/* 
 * divpwr2 - Compute x/(2^n), for 0 <= n <= 30
 *  Round toward zero
 *   Examples: divpwr2(15,1) = 7, divpwr2(-33,4) = -2
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 15
 *   Rating: 2
 */
int divpwr2(int x, int n) {
    int signMask = x >> 31;
    return (x + (signMask & ((1 << n) + ~0))) >> n;
}

分类讨论,如果x >= 0, 那么 x/(2^n) = x >> n;如果 x < 0, 那么x/(2^n) = (x + (1 << n) - 1) >> n; 现在构造一个数 bias 使得在 x >= 0时,bias = 0;在 x < 0 时,bias = (1 << n) - 1; signMask = x >> 31, 表示如果x负数则,signMask = 0xFFFFFFFF;否则signMask = 0x0。所以 bias = signMask & (1 << n) + ~0) 。其中~0 = -1。

第九题negate

/* 
 * negate - return -x 
 *   Example: negate(1) = -1.
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 5
 *   Rating: 2
 */
int negate(int x) {
  return ~x + 1;
}

水题,按照补码相反数定义来就好了。

第十题isPositive

/* 
 * isPositive - return 1 if x > 0, return 0 otherwise 
 *   Example: isPositive(-1) = 0.
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 8
 *   Rating: 3
 */
int isPositive(int x) {
  return !(!x | (x >> 31)); 
}

由于正数不包括0,所以不能只看符号位来判断。所以可以进行下转换正数 = !( x为 0 或 负数)。若x为0,!x = 1;若x为负数,可以看符号为(x >> 31) = 0xFFFFFFFF。因此如果x为0或负数,那么!x | (x >> 31) != 0。再加个逻辑反,!!(!x | (x >> 31) = 0;反之,若x为正数,!!(!x | (x >> 31) = 1;

第十一题isLessOrEqual

/* 
 * isLessOrEqual - if x <= y  then return 1, else return 0 
 *   Example: isLessOrEqual(4,5) = 1.
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 24
 *   Rating: 3
 */
int isLessOrEqual(int x, int y) {
  int sx;
  int sy;
  int sdiff;

  sx = (x >> 31) & 1;
  sy = (y >> 31) & 1;
  sdiff = ((y + (~x + 1)) >> 31) & 1; 
  return (((sx ^ sy) & sx) | !sdiff & !(sx ^ sy));
}

考虑到y-x,可能存在溢出情况,分类讨论。如果x, y 异号且x为负,则返回1;如果x, y 异号且x为正,则返回0;如果x,y同号,根据y-x正负判断。

第十二题ilog2

/*
 * ilog2 - return floor(log base 2 of x), where x > 0
 *   Example: ilog2(16) = 4
 *   Legal ops: ! ~ & ^ | + << >>
 *   Max ops: 90
 *   Rating: 4
 */
int ilog2(int x) {
  int bitsNumber;

  bitsNumber = (!!(x >> 16)) << 4;
  bitsNumber = bitsNumber + ((!!(x >> (bitsNumber+8))) << 3);
  bitsNumber = bitsNumber + ((!!(x >> (bitsNumber+4))) << 2);
  bitsNumber = bitsNumber + ((!!(x >> (bitsNumber+2))) << 1);
  bitsNumber = bitsNumber + (!!(x >> (bitsNumber+1)));
  return bitsNumber;
}

这题类似用二分搜索最高位为1的位置,比如说找到为第k位,那么结果就是k。注意⚠️为什么用二分?减少运算!

第十三题float_neg


/* 
 * float_neg - Return bit-level equivalent of expression -f for
 *   floating point argument f.
 *   Both the argument and result are passed as unsigned int's, but
 *   they are to be interpreted as the bit-level representations of
 *   single-precision floating point values.
 *   When argument is NaN, return argument.
 *   Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
 *   Max ops: 10
 *   Rating: 2
 */
unsigned float_neg(unsigned uf) {
  unsigned result;
  unsigned tmp;

  result = uf ^ (0x80 << 24);
  tmp = uf & 0x7FFFFFFF;
  if( tmp > 0x7F800000) 
    return uf;
  return result;
}

在最高位置为0情况下,如果大于0x7F800000,一定是NaN,直接返回。如果不大于符号为取反,返回。

第十四题float_i2f

/* 
 * float_i2f - Return bit-level equivalent of expression (float) x
 *   Result is returned as unsigned int, but
 *   it is to be interpreted as the bit-level representation of a
 *   single-precision floating point values.
 *   Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
 *   Max ops: 30
 *   Rating: 4
 */
unsigned float_i2f(int x) {
  unsigned shiftLeft;
  unsigned afterShift, tmp;
  unsigned absX;
  unsigned sign;
  unsigned flag;

  absX = x;
  shiftLeft = 0;
  sign = 0;

  if(!x) return 0;

  if(x < 0) {
    sign = 0x80 << 24;
    absX = -x;
  }
  afterShift=absX;

  while(1)
  {
    tmp = afterShift;
    afterShift <<= 1;
    shiftLeft++;
    if(tmp & (0x80 << 24)) break;
  }
  if((afterShift & 0x01ff) > 0x0100)
    flag = 1;
  else if((afterShift & 0x03ff) == 0x0300)
    flag = 1;
  else
    flag = 0;
  return (sign | (afterShift >> 9) | ((159-shiftLeft) << 23)) + flag; 

}

IEEE754表示浮点数,以及Rounding规则的定义题,根据规则来就好了。

第十五题float_twice

/* 
 * float_twice - Return bit-level equivalent of expression 2*f for
 *   floating point argument f.
 *   Both the argument and result are passed as unsigned int's, but
 *   they are to be interpreted as the bit-level representation of
 *   single-precision floating point values.
 *   When argument is NaN, return argument
 *   Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
 *   Max ops: 30
 *   Rating: 4
 */
unsigned float_twice(unsigned uf) {
  if( (uf & 0x7F800000) == 0 )
    uf = ((uf & 0x007FFFFF) << 1) | (0x80000000 & uf);
  else if (( uf & 0x7F800000) != 0x7F800000)
    uf = uf + 0x800000;
  return uf;
}

如果阶码为0,那么就是非规格数,直接将尾数左移1位到阶码域上,其他不变即可。例如 0 00000000 1000…001 变成 0 00000001 000…0010。这样可以做的原因正是由于非规格化数的指数E = 1 - bias,而不是-bias。这样使得可以平滑地从非规格数过度到规格化数。
如果阶码不为0且不是255,那么直接阶码加1即可。
如果阶码为255,那么是NaN,∞,-∞,直接返回。

题目地址和源码

题目地址: http://csapp.cs.cmu.edu/3e/labs.html
源码:https://github.com/eadren/csapp-datalab/blob/master/bits.c

CSAPP:DataLab实验 目录前言实验内容及操作步骤操作步骤一、安装dlc二、阅读引导以及注意事项【datalab-handout下的bits.c文件中的引导以及注意事项】三、函数实现实验结果及分析 前言 学生实现简单的逻辑,二进制补码和浮点函数,但使用C的高度受限的子集。例如,可能会要求他们仅使用位级操作和直线代码来计算数字的绝对值。 本实验帮助学生了解C数据类型的位级表示和数据操作的位级行为。 实验内容及操作步骤 填... 阅读详情

相关推荐

CSAPP:Lab的Datalab中bitCount的思路

不得不说CSAPP:Lab对于我这样的小白来说的难度还是挺高的,bitCount这题是通过百度才解出来的... 原题: /* * bitCount - returns count of number of 1's in word * Examples: bitCount(5) = 2, bitCount(7) = 3 * Legal ops: ! ~ & ^ | + > *

LinJingchun的博客 6146

深入理解计算机系统——实验(二)Data Lab(附解释)

2019-6-15更新 要期末考试啦,翻了下书,发现第8个函数divpwr2中的偏置值为2^n-1的证明就在教材中,教材是华章教育的《深入理解计算机系统》(原书第2版),证明部分在P64-P66。

悲伤无声地涌出来 2万+

深入理解计算机系统(CSAPP) 实验详解:DataLab

更新历史 20200911开始做这个实验 该实验的目的 该实验的目的是提升对计算机基础信息的理解和操作,例如位,整数,浮动,补码等等。 搭建环境 环境的搭建很简单,我们遵循以下几个步骤即可 下载VM Box,并安装ubuntu 然后我们在虚拟机中更新环境,在终端中执行一下命令 //更新apt软件源 apt-get update //安装sudo apt-get install sudo //安装c/c++编译环境,build-essential软件包列表内包含libc6-dev、libc-dev、g

专业记录代码 1万+

CSAPP《深入理解计算系统》,我的学习心得

大家好,我是小林。 今天跟大家聊聊《深入理解计算系统》,这本书的英文全称叫ComputerSystem:A programer perspective 英文名翻译过来是「程序员视角下的计算机系统」,也被简称为 CSAPP。 贴心的小林,也把这本书找给大家了:计算机电子书下载 可能大家以为这本书是讲操作系统的,我最开始也以为是这样。后面当我开始啃这本书的时候,发现我大错特错,它远不止我想的那样。 这本书是从程序员的角度学习计算机系统是如何工作的,通过描述程序是如何映射到计算机系统上,程序是如何执行的,以及程

小林coding 5万+

csapp,csapp,csapp分享

csapp共享给大家一起

新手必看:四旋翼无人机PID调参实战指南(附常见问题排查)

本文为四旋翼无人机新手提供PID调参实战指南,详细解析Kp、Ki、Kd参数的实际意义及调参技巧,包含常见问题排查方法。通过系统化的调参流程和实用参考表,帮助用户快速掌握无人机飞行控制核心技能,避免常见错误,提升飞行稳定性与响应性能。

k0l1m2n3o的博客 605

深入理解计算机系统作业0

主要考察二进制的位运算处理...

m0_60284775的博客 1878

【MFiX后处理】MFiX中使用des_usr_var输出颗粒的传热量(2020-11-27更新变更输出变量名方法)

参考之前Yin的那一篇博客 https://www.cnblogs.com/Jay-CFD/p/10621274.html 输出一下颗粒传热量 使用的算例是fluid_bed_dem_2d 打开des scalar tracking 前面都和Yin那篇一样,打开enable user scalar tracking 输入2 因为第一个用来测试Y加速度了 第二个输出传热量 然后在output vtk中勾选好 更改源代码 源代码为des_thermo_newvalues.f 在mfix-GUI自带的ed

beidou111的博客 1539

CSAPP学习系列:什么是CSAPP

CSAPP全称Computer Systems A Programmer's perspective,国内通常的书名翻译是《深入理解计算机系统》

weixin_36349662的博客 2万+

【用unity实现100个游戏之15】开发一个类保卫萝卜的Unity2D塔防游戏5(附项目源码,完结)

本期是本项目的最后一篇,主要内容是配置环境、生成不同敌人、结束重开。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2584

【即插即用模块】卷积篇 | TGRS 2025 | HLKConv:小核+空洞=大核,感受野一致,但更轻更准!

本文介绍了分层大核卷积模块HLKConv,该模块通过动态大核+空洞卷积实现高效感受野扩展,将超大核卷积分解为小核+空洞卷积(如53×53核用17×17+dilation=3实现),计算量仅为普通大核的1/10。模块采用双分支设计:基础卷积分支捕捉局部细节,大核空洞分支捕捉长距离关联,通过1×1卷积融合。实验表明HLKConv在红外小目标检测中优于传统大核卷积,适用于高分辨率视觉任务。代码实现了不同核尺寸的配置,输入输出特征维度保持不变,计算效率显著提升。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 354

CSAPP实验一:DataLab

首先,判断高16位是否存在1,如果存在1的话,我们就只需要在高16位上寻找最高位;从这个函数开始,就都是涉及到浮点数表示了,如果不是很了解,建议仔细阅读一下《深入理解计算机系统》第二章后半部分的内容。是帮助我们检查我们写的代码是否合法,是否按照题目要求使用了规定的运算符并且是否超出规定的运算符的数目,通过执行命令。这个很容易实现,我们可以先生成一个奇数位都是1,偶数位都是0的掩码mask。我们可以分别进行判断,首先判断10位是否为3,我们可以利用右移运算符。因此,我们可以通过找出最高的1的位置来计算答案。

m0_51171995的博客 4338

【RT-DETR实战】117、华为昇腾CANN部署探索:从模型转换到推理踩坑实录

本文总结了RT-DETR模型在昇腾310B芯片上部署的关键挑战与解决方案。主要遇到四大问题:1)模型转换时需注意ONNX导出设置,建议先固定尺寸验证;2)内存布局差异导致推理异常,需精确匹配NHWC/NCHW格式;3)流水线并发优化中内存复用和异步处理是关键;4)调试阶段需利用专用工具逐层比对。作者提出六条实用建议,包括小尺寸验证、预处理对齐、内存池设计等,强调部署是持续适配过程,需建立完整的测试体系应对工具链迭代。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 209

CSAPP:DataLab

实验1:DataLab 要干啥? 按照要求填写bitsc.c内函数。 怎么干? bitAnd(int x, int y): 只使用~与|符号来实现x&y的效果,离散数学的知识,即 答案:~((~x)|(~y)) getByte(int x, int n): 只使用 ! ~ & ^ | + << >>符号,且最多只使用6个,来实现获取x中第n个字节信息,n从0开始。 基本思想就是让x右移f(n)个比特位,然后与0xff进行&运算,为什么是0xff呢

weixin_42559124的博客 2081

【干货分享】高通 SA8295P PCB 设计规范指南

高通SA8295P芯片是第四代骁龙汽车数字座舱平台的核心组件,采用5nm工艺,集成高性能CPU/GPU和30TOPS算力的NPU。文章详细介绍了该芯片各接口的layout设计规范,包括USB3.1/2.0、eDP/DP、MIPI CSI/DSI、PCIe Gen3等接口的阻抗、损耗、延时等关键指标要求,为新能源汽车电子设计提供重要参考。

一只豌豆象的博客 279

096、PCIE环回模式(Loopback):调试时自己和自己对话的利器

摘要: PCIE环回模式是调试利器,通过让芯片内部数据自环来定位问题层级。文章详解三种环回模式:物理层环回验证基础收发,数据链路层环回测试DLLP机制,事务层环回验证端到端协议。分享了实战中的典型问题(时钟异常、状态机卡死、计数器失真)和"从下往上"的调试流程,强调要区分调试与生产功能,建议早期验证环回模式。通过具体代码示例和调试案例,说明合理使用环回模式能显著提升排查效率,是PCIE调试必备技能。(149字)

z534437748的博客 114

lab1 CSAPP:datalab

非常简单的一个lab,位运算好的话一会就写完了。

EQUINOX1的博客 345

QuecOpen RTOS学习笔记

对计算机响应时间有要求的系统,通常称为临界系统或应用。为了满足临界系统或应用对计算机响应 时间的要求,人们开发了实时操作系统(Real Time Operation System)。 实时操作系统指所有任务均在规定时间内完成的操作系统,同时任务完成必须满足时序可预测性。需 要注意的是,实时操作系统的本质是其反应具有时序可预测性。得益于此,实时操作系统通常反应非常快。 实时操作系统的内核对象一般包括任务、信号量、互斥锁、消息队列、定时器、事件通知和软件看门 狗等。

zxm8513CSDN博客 2036

csapp实验1:Datalab

最近在学习csapp,顺便做下lab。以下都是本人所做的,有误之处,请大家多多指教。 实验简介 ​ Data LAB 目的是熟悉位运算 运行操作: 只修改bit.c ./dlc bits.c //看编译是否通过 ./dlc -e bits.c //查看使用操作符数 编译通过后,使用 btest 进行验证 make // 每次修改完之...

qq_37772475的博客 1533

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

CSAPP实验:lab1-Datalab

实验资料链接实验环境:我使用的环境是vscode + wsl,也可以使用虚拟机下载一个纯净的Linux系统,我更建议前一种做法因为更方便。安装第一种环境可以参考这篇文章。1.在提供网站内下载实验的handout文件到本地2.代开vscode的远程服务启用WSL将本地文件复制一份到Linux目录下3.使用tar xvf hand-out.tar指令解压文件4.每次完成一个函数都使用make重新编译一下5.利用 ./btest -f 函数名 测试函数是否正确。

ljttt123的博客 750

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

CSAPP实验1:datalab

前言 CSAPP上的实验还是十分有趣的,尤其是其自动评分系统。做完了实验之后自己也确实对知识的理解更加深入了。有关CSAPP的知识以后或许我会再写博客,现在则先把实验写写博客吧 百度网盘下载实验文档 提取码:kdx4 实验 题1-2 //1 /* * bitXor - x^y using only ~ and & * Example: bitXor(4, 5) = 1 * Legal ops: ~ & * Max ops: 14 * Rating: 1 */

qq_50271250的博客 1476

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CSAPP:Datalab

第一个ICS的lab 默念了两天“我要死了”之后终于写完了 不是非常满意(尤其是howManyBits…)但至少是熬出来了…???? 先记录一下思路,希望能在ddl之前优化howManyBits 初次提交结果: 是的,就是81步的蛮力算法????   Datalab的int部分是不能使用循环和条件的,只能用位运算实现 很简单的两个: bitXor&tmin /* * bitXor -...

Rachel_IS的博客 1072

CSAPP:DataLab详细解析

做题的时候看了好多博客,一点一点更深入的了解、学习。不得不说lab真的很好,学到很多。 做题准备我已经在上一个博客提到了,建议写之前看一下README。

Here is prician 5658

CSAPP:DataLab1实验

本文章是在学完csapp第二章后,做lab1所写下的一些笔记。在进行实验之前,需要做一些准备工作(虚拟机的安装(Vmware Workstation+Ubuntu),Lab环境配置),然后进入实验官网,csapp实验网站中每个实验标题后面都有四个附件,前面的三个为给教师的说明文档和实验题目版本的说明,我们只需要下载Self-Study Handout(自学手册)并阅读其中的README(给学生的说明文档)即可。

m0_74476593的博客 251
上一篇: Hash表
pppppppc
博客等级 码龄12年 6粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值