网站大量收购闲置独家精品文档,联系QQ:2885784924

复旦大学软件学院计算机系统课件 Heterogeneous Data Structures Alignment.ppt

复旦大学软件学院计算机系统课件 Heterogeneous Data Structures Alignment.ppt

  1. 1、本文档共26页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * * * * * * * * * * * * * * * * * * * * * Compilers Autumn 2002 Compilers Autumn 2002 * Heterogeneous Data Structures Alignment * Outline Struct Union Alignment Chap 3.9, 3.10 * Structures Group objects into a single object struct rect { int llx; /* X coordinate of lower-left corner */ int lly; /* Y coordinate of lower-left corner */ int color; /* Coding of color */ int width; /* Width (in pixels) */ int height; /* Height (in pixels) */ }; * Structure Each object is referenced by name struct rect r; r.llx = r.lly = 0; r.color = 0xFF00FF; r.width = 10; r.height = 20; * Structure int area (struct rect *rp) { return (*rp).width * (*rp).height; } void rotate_left (struct rect *rp) { /* Exchange width and height */ int t = rp-height; rp-height = rp-width; rp-width = t; } * Structures Memory layout All the components are stored in a contiguous region of memory A pointer to a structure is the address of its first byte * Structure struct rec { int i; int j; int a[3]; int *p; } *r; i j a[0] a[1] a[2] p Contents Offset 0 4 8 20 * Structure References to structure elements Using offsets as displacements r-j = r-i (Copy element r-i to element r-j) r is in register %edx. 1 movl (%edx), %eax Get r-i 2 movl %eax, 4(%edx) Store in r-j i j a[0] a[1] a[2] p Contents Offset 0 4 8 20 * Structure (r-a[i]) r in %eax, i in %edx: 1 leal 8(%eax,%edx,4),%ecx Generate r-a[i] i j a[0] a[1] a[2] p Contents Offset 0 4 8 20 * Structure r-p = r-a[r-i + r-j]; r in register %edx: 1 movl 4(%edx), %eax Get r-j 2 addl (%edx), %eax Add r-i 3 leal 8(%edx,%eax,4),%eax Compute r-a[r-i + r-j] 4 movl %eax, 20(%edx) Store in r-p i j a[0] a[1] a[2] p Contents Offset 0 4 8 20 * Unions A single object can be referenced by using different data types The syntax of a union declaration is identical to that for structures, but its semantics are very different Rather than having the different fields reference different blocks of memory, they all

文档评论(0)

ormition + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档