Data Representation and Alignment Topics Simple static allocation and alignment of basic types and data structures Policies Mechanisms.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
Pointers & Dynamic Memory Allocation Mugurel Ionu Andreica Spring 2012.
Chapter 7:: Data Types Programming Language Pragmatics
Chapter 9 Imperative and object-oriented languages 1.
University of Washington Data Structures! Arrays  One-dimensional  Multi-dimensional (nested)  Multi-level Structs  Alignment Unions 1.
Structured Data: Sept. 20, 2001 Topics Arrays Structs Unions class08.ppt “The course that gives CMU its Zip!”
Machine-Level Programming IV: Structured Data Apr. 23, 2008 Topics Arrays Structures Unions EECS213.
Structured Data I: Homogenous Data Sept. 17, 1998 Topics Arrays –Single –Nested Pointers –Multilevel Arrays Optimized Array Code class08.ppt “The.
Structured Data II Heterogenous Data Sept. 22, 1998 Topics Structure Allocation Alignment Operating on Byte Strings Unions Byte Ordering Alpha Memory Organization.
– 1 – Referencing Examples Code Does Not Do Any Bounds Checking! ReferenceAddressValueGuaranteed? mit[3]36 + 4* 3 = 483 Yes mit[5]36 + 4* 5 = 566 No mit[-1]36.
1 1 Machine-Level Programming IV: x86-64 Procedures, Data Andrew Case Slides adapted from Jinyang Li, Randy Bryant & Dave O’Hallaron.
1 Homework HW6 due class 22 K&R 6.6 K&R 5.7 – 5.9 (skipped earlier) Finishing up K&R Chapter 6.
Machine-Level Programming 6 Structured Data Topics Structs Unions.
Ithaca College 1 Machine-Level Programming VIII: Advanced Topics: alignment & Unions Comp 21000: Introduction to Computer Systems & Assembly Lang Systems.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
Machine-Level Programming IV: Structured Data Topics Arrays Structs Unions CS 105 “Tour of the Black Holes of Computing”
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Machine-Level Programming IV: Data : Introduction.
ECE 454 Computer Systems Programming Memory performance (Part II: Optimizing for caches) Ding Yuan ECE Dept., University of Toronto
Homework Finishing up K&R Chapter 6 today Also, K&R 5.7 – 5.9 (skipped earlier)
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
University of Amsterdam Computer Systems – Data in C Arnoud Visser 1 Computer Systems New to C?
Machine-level Programming IV: Data Structures Topics –Arrays –Structs –Unions.
University of Washington Today Lab 3 out  Buffer overflow! Finish-up data structures 1.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Machine-Level Programming IV: Data Topics: Arrays.
Fabián E. Bustamante, Spring 2007 Machine-Level Prog. IV - Structured Data Today Arrays Structures Unions Next time Arrays.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Machine-Level Programming IV: Data MCS284: Computer.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Data Structures - Part I CS 215 Lecture 7. Motivation  Real programs use abstractions like lists, trees, stacks, and queues.  The data associated with.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
Assembly - Arrays תרגול 7 מערכים.
Structures and Union. Review bitwise operations –you need them for performance in terms of space and time –shifts are equivalent to arithmetics enumeration.
EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – ARM Addressing Endianness, Loading, and Storing Data – Data Layout Struct Packing.
Recitation 3 Outline Recursive procedure Complex data structures –Arrays –Structs –Unions Function pointer Reminders Lab 2: Wed. 11:59PM Lab 3: start early.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Machine-Level Programming IV: Data Slides adapted.
Structs & typedef. Structs 2 Contiguously-allocated region of memory Refer to members within structure by names Members may be of different types Example:
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Java Programming Language Lecture27- An Introduction.
Lecture 9 Aggregate Data Topics Arrays Structs Unions again Lab 02 comments Vim, gedit, February 22, 2016 CSCE 212 Computer Architecture.
Machine-Level Programming IV: Data
Machine-Level Programming IV: Data
C Tutorial (part 5) CS220, Spring 2012
The Hardware/Software Interface CSE351 Winter 2013
Machine-Level Programming IV: Structured Data
Machine-Level Programming IV: Data
Heterogeneous Data Structures & Alignment
Machine-Level Programming IV: Data CSCE 312
Data Structures and Analysis (COMP 410)
Feb 2 Announcements Arrays/Structs in C Lab 2? HW2 released
Machine-Level Programming 6 Structured Data
Machine-Level Programming IV: Data
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Instructor: Phil Gibbons
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Instructors: Majd Sakr and Khaled Harras
Structured Data II Heterogenous Data Feb. 15, 2000
Machine-Level Programming IV: Data
Machine-Level Programming IV: Data /18-213/14-513/15-513: Introduction to Computer Systems 8th Lecture, September 20, 2018.
Instructors: Majd Sakr and Khaled Harras
Machine Level Representation of Programs (III)
Machine-Level Programming IV: Machine Data 9th Lecture
Machine-Level Programming VIII: Data Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017 Systems book chapter 3* * Modified slides.
Machine-Level Programming 5 Structured Data
Machine-Level Programming 5 Structured Data
Instructor: Fatma CORUT ERGİN
Data Spring, 2019 Euiseong Seo
Machine-Level Programming VIII: Data Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017 Systems book chapter 3* * Modified slides.
Machine-Level Programming IV: Data
Presentation transcript:

Data Representation and Alignment Topics Simple static allocation and alignment of basic types and data structures Policies Mechanisms

– 2 – Data Representations Sizes of C Objects (in Bytes) C Data Type Intel IA32 int 4 (1 word) long int4 char1 short2 float4 double 8 (2 words) char *4 »Or any other pointer A word is 4 bytes

– 3 – Alignment Aligned Data Primitive data type requires K bytes Address must be multiple of K Required on some machines; advised on Intel Motivation for Aligning Data Memory accessed by aligned double words (or quad-words) Inefficient to load or store datum that spans quad word boundariesCompiler Inserts gaps in structure to ensure correct alignment of fields

– 4 – struct rec { int i; int a[3]; int *p; }; Structures Concept Contiguously-allocated region of memory Refer to members within structure by names Members may be of different types Memory Layout iap

– 5 – Specific Cases of Alignment Size of Primitive Data Type: 1 byte (e.g., char) no restrictions on address 2 bytes (e.g., short ) lowest 1 bit of address is 0 (2) 4 bytes (e.g., int, float, char *, etc.) lowest 2 bits of address - 00 (2) 8 bytes (e.g., double ) lowest 3 bits of address 000 (2)

– 6 – Satisfying Alignment with Structures Offsets Within Structure Must satisfy element’s alignment requirement Overall Structure Placement Each structure has alignment requirement K Largest alignment of any element Initial address & structure length must be multiples of K

– 7 – Example (under Linux) K = 4, due to int element K = 4, due to int element struct S1 { char c; int i[2]; } *p; ci[0]i[1] p+0p+4p+8 Multiple of 4 p+12

– 8 – Overall Alignment Requirement struct S2{ float x[2]; int i[2]; char c; } *p; ci[0]i[1] p+0p+12p+8p+16p+20 x[0]x[1] p+4 p must be multiple of 4

– 9 – Arrays of Structures Principle Allocated by repeating allocation for array type a[0] a+0 a[1]a[2] a+12a+24a+36 a+12a+20a+16a+24 struct S3 { short i; float v; short j; } a[10]; a[1].ia[1].ja[1].v

– 10 – Satisfying Alignment within Structure Achieving Alignment Starting address of structure array must be multiple of worst-case alignment for any element a must be multiple of 4 Offset of element within structure must be multiple of element’s alignment requirement v ’s offset of 4 is a multiple of 4 Overall size of structure must be multiple of worst-case alignment for any element Structure padded with unused space to be 12 bytes struct S3 { short i; float v; short j; } a[10]; a[0] a+0 a[i] a+12i a+12ia+12i+4 a[1].ia[1].ja[1].v Multiple of 4

Array Allocation Basic Principle T A[ L ]; Array of data type T and length L Contiguously allocated region of L * sizeof( T ) bytes char string[12]; xx + 12 int val[5]; x x + 4x + 8x + 12x + 16x + 20 double a[3]; x + 24 x x + 8x + 16 char *p[3]; x x + 4x + 8x + 12

Multidimensional (Nested) Arrays Declaration T A[ R ][ C ]; 2D array of data type T R rows, C columns T element requires K bytes Array Size R * C * K bytesArrangement Row-Major Ordering (C code) A[0][0]A[0][C-1] A[R-1][0] A[R-1][C-1] int A[R][C]; A [0] A [0] [C-1] A [1] [0] A [1] [C-1] A [R-1] [0] A [R-1] [C-1] 4*R*C Bytes

– 13 – Summary Arrays in C Contiguous allocation of memory Pointer to first element No bounds checkingStructures Allocate bytes in order declared Pad in middle and at end to satisfy alignment

– 14 – Misc: Boolean (“Bitwise”) Operators Operate on numbers as Bit Vectors Operations applied bitwise & | ^ ~