Cse.m-ii-Advances in Computer Architecture (12scs23) - Notes
This document provides an overview of the course "Advanced Computer Architecture". It discusses trends in computer technology and performance. The course covers topics like pipelining, instruction-level parallelism, memory hierarchy design, storage systems, hardware and software for VLIW/EPIC architectures, large-scale multiprocessors, and computer arithmetic. It lists 6 units that will be covered in the course along with textbook and reference book details.
Cse.m-ii-Advances in Computer Architecture (12scs23) - Notes
This document provides an overview of the course "Advanced Computer Architecture". It discusses trends in computer technology and performance. The course covers topics like pipelining, instruction-level parallelism, memory hierarchy design, storage systems, hardware and software for VLIW/EPIC architectures, large-scale multiprocessors, and computer arithmetic. It lists 6 units that will be covered in the course along with textbook and reference book details.
Subject Code : 12SCS23 IA Marks : 50 No of Lecture Hrs/Week : 4 Exam hours : 3 Total No of Lecture Hours : 52 Exam Marks : 100
1. Introduction and Review of Fundamentals of Computer Design: Introduction; Classes computers; Defining computer architecture; Trends in Technology; Trends in power in Integrated Circuits; Trends in cost; Dependability, Measuring, reporting and summarizing Performance; Quantitative Principles of computer design; Performance and Price-Performance; Fallacies and pitfalls; Case studies.
2. Some topics in Pipelining, Instruction Level Parallelism, Its Exploitation and Limits on ILP: Introduction to pipelining, ILP; Crosscutting issues, fallacies, and pitfalls with respect to pipelining; Basic concepts and challenges of ILP; Case study of Pentium 4, Fallacies and pitfalls. Introduction to limits in ILP; Performance and efficiency in advanced multiple-issue processors.
3. Memory Hierarchy Design, Storage Systems: Review of basic concepts; Crosscutting issues in the design of memory hierarchies; Case study of AMD Opteron memory hierarchy; Fallacies and pitfalls in the design of memory hierarchies. Introduction to Storage Systems; Advanced topics in disk storage; Definition and examples of real faults and failures; I/O performance, reliability measures, and benchmarks; Queuing theory; Crosscutting issues; Designing and evaluating an I/O system The Internet archive cluster; Case study of NetAA FAS6000 filer; Fallacies and pitfalls.
4. Hardware and Software for VLIW and EPIC Introduction: Exploiting Instruction-Level Parallelism Statically, Detecting and Enhancing Loop-Level Parallelism, Scheduling and Structuring Code for Parallelism, Hardware Support for Exposing Parallelism: Predicated Instructions, Hardware Support for Compiler Speculation, The Intel IA-64 Architecture and Itanium Processor, Concluding Remarks.
5. Large-Scale Multiprocessors and Scientific Applications: Introduction, Interprocessor Communication: The Critical Performance Issue, Characteristics of Scientific Applications, Synchronization: Scaling Up, Performance of Scientific Applications on Shared-Memory Multiprocessors, Performance Measurement of Parallel Processors with Scientific Applications, Implementing Cache Coherence, The Custom Cluster Approach: Blue Gene/L, Concluding Remarks. 6. Computer Arithmetic Introduction, Basic Techniques of Integer Arithmetic, Floating Point, Floating-Point Multiplication, Floating-Point Addition, Division and Remainder, More on ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 2
Floating-Point Arithmetic, Speeding Up Integer Addition, Speeding Up Integer Multiplication and Division, Fallacies and Pitfalls.
Text Book: 1. Hennessey and Patterson: Computer Architecture A Quantitative Approach, 4th Edition, Elsevier, 2007.
Reference Books: 1. Kai Hwang: Advanced Computer Architecture - Parallelism, Scalability, Programmability, 2nd Edition, Tata McGraw Hill, 2010.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 3
CONTENTS UNITS PAGE NO. 1 Fundamentals of computer design 4 2 Pipelining, Instruction level parallelism and Limitations 39 3 Multiprocessors and thread level parallelism 80 4 Hardware and software for VLIW and EPIC 144 5 Large scale multiprocessors and scientific application 168 6 Computer Arithmetic 189
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 4
UNIT I FUNDAMENTALS OF COMPUTER DESIGN Introduction Today s desktop computers (less than $500 cost) ar e having more performance, larger memory and storage than a computer bought in 1085 for 1 million dollar. Highest performance microprocessors of today outperform Supercomputers of less than 10 years ago. The rapid improvement has come both from advances in the technology used to build computers and innovations made in the computer design or in other words, the improvement made in the computers can be attributed to innovations of technology and architecture design. During the first 25 years of electronic computers, both forces made a major contribution, delivering performance improvement of about 25% per year. Microprocessors were evolved during late 1970s and their ability along with improvements made in the Integrated Circuit (IC) technology y contributed to 35% performance growth per year. The virtual elimination of assembly language programming reduced the n eed for object-code compatibility. The creation of standardized vendor-independent operating system lowered the cost and risk of bringing out a new architecture. In the yearly 1980s, the Reduced Instruction Set Computer (RISC) based machines focused the attention of designers on two critical performance techniques, the exploitation Instruction Level Parallelism (ILP) and the use of caches. The figu re 1.1 shows the growth in processor performance since the mid 1980s. The graph plots performance relative to the VAX-11/780 as measured b y the SPECint benchmarks. From the figure it is clear that architectural and organizational enhancements led to 16 years of sustained growth in performance at an annual rate of over 50%. Since 2002, processor performance improvement has dropped to about 20% per year due to the following hurdles: Maximum power dissipation of air-cooled chips Little ILP left to exploit efficiently Limitations laid by memory latency The hurdles signals historic switch from relying solely on ILP to Thread Level ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 5
Parallelism (TLP) and Data Level Parallelism (DLP).
Figure 1.1 The evolution of various classes of computers: Classes of Computers 1960: Large Main frames (Millions of $ ) (Applications: Business Data processing, large Scientific computin g) 1970: Minicomputers (Scientific laboratories, Time sharing concepts) 1980: Desktop Computers (Ps) in the form of Personal computers and workstations. (Larger Memory, more computing power, Replaced Time sharing g systems) 1990: Emergence of Internet and WWW, PDAs, emergence of high performance digital consumer electronics 2000: Cell phones These changes in computer use have led to three different computing classes each characterized by different applications, requirements and computing technologies.owth in processor performance since 1980s
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 6
Desktop computing The first and still the largest market in dollar terms is desktop computing. Desktop computing system cost range from $ 500 (low end) to $ 5000 (high-end configuration). Throughout this range in price, the desktop market tends to drive to optimize price- performance. The perf ormance concerned is compute performance and graphics performance. The combination of performance and price are the driving factors to the customers and the computer designer. Hence, the newest, high performance and cost effective processor often appears first in desktop computers. Servers: Servers provide large-scale and reliable computing and file services and are mainly used in the large-scale en terprise computing and web based services. The three important Characteristics of servers are: Dependability: Severs must operate 24x7 hours a week. Failure of server system is far more catastrophic than a failure of desktop. Enterprise will lose revenue if the server is unavailable. Scalability: as the business grows, the server may have to provide more functionality/ services. Thus ability to scale up the computin g capacity, memory, storage and I/O bandwidth is crucial. Throughput: transactions completed per minute or web pages served per second are crucial for servers. Embedded Computers Simple embedded microprocessors are seen in washing machines, printers, network switches, handheld devices such as cell phones, smart cards video game devices etc. embedded computers have the widest spread of processing power and cost. The primary goal is often meeting the performance need at a minimum price rather than achieving higher performance at a higher price. The other two characteristic requirements are to minimize the memory and power. In many embedded applications, the memory can be substantial portion of the systems cost and it is very important to optimize the memory size in such cases. The application is expected to fit totally in the memory on the p rocessor ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 7
chip or off chip memory. The importance of memory size translates to an emphasis on code size which is dictated by the application. Larger memory consumes more power. All these aspects are considered while choosing or designing processor for the embedded applications. Defining Computer Arch itecture: The computer designer has to ascertain the attributes that are important for a new computer and design the system to maximize the performance while staying within cost, power and availability constraints. The task has few important aspects such as Instruction Set design, Functional organization, Logic design and implementation. Instruction Set Architecture (ISA) ISA refers to the actual programmer visible Instruction set. The ISA serves as boundary between the software and hardware. Th e seven dimensions of the ISA are: i) Class of ISA: Nearly all ISAs today ar e classified as General-Purpose- Register architectures. The operands are either Registers or Memory locations. The two popular versions of this class are: Register-Memory ISAs : ISA of 80x86, can access memory as part of many instructions. Load -Store ISA Eg. ISA of MIPS, can access memory only with Load or Store instructions. ii) Memory addressing: Byte addressing scheme is most widely used in all desktop and server computers. Both 80x86 and MIPS use byte addressing. Incase of MIPS the object must be aligned. An access to an object of s byte at byte address A is aligned if A mod s =0. 80x86 does not require alignment. Accesses are faster if operands are aligned.
iii) Addressing modes:Specify the address of a M object apart from register and constant operands. MIPS Addressing modes: Register mode addressing Immediate mode addressing Displacement mode addressing 80x86 in addition to the above addressing modes supports the additional modes of addressing: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 8
i. Register Indirect ii. Indexed iii,Based with Scaled index iv) Types and sizes of operands: MIPS and x86 support: 8 bit (ASCII character), 16 bit(Unicode character) 32 bit (Integer/word ) 64 bit (long integer/ Double word) 32 bit (IEEE-754 floating point) 64 bit (Double precision floating point) 80x86 also supports 80 bit floating point operand.(extended double Precision) v)Operations:The general category o f operations are: Data Transfer Arithmetic operations Logic operations Control operations MIPS ISA: simple & easy to implement x86 ISA: richer & larger set of operations vi) Control flow instructions:All ISAs support: Conditional & Unconditional Branches Procedure C alls & Returns MIPS 80x86 Conditional Branches tests content of Register Condition code bits Procedure C all JAL CALLF Return Address in a R Stack in M vii) Encoding an ISA Fixed Length ISA Variable Length ISA MIPS 32 Bit long 80x86 (1-18 bytes) Simplifies decoding Takes less space
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 9
Number of Registers and number of Addressing modes have significant impact on the length of instruction as the register field and addressing mode field can appear many times in a single instruction. Trends in Technology The designer must be aware of the following rapid changes in implementation technology. Integrated C ircuit (IC) Logic technology Memory technology (semiconductor DRAM technology) Storage o r magnetic disk technology Network technology
IC Logic technology: Transistor density increases by about 35%per year. Increase in die size corresponds to about 10 % to 20% per year. The combined effect is a growth rate in transistor count on a chip of about 40% to 55% per year. Semiconductor DRAM technology:cap acity increases by about 40% per year. Storage Technology: Before 1990: the storage density increased by about 30% per year. After 1990: the storage density increased by about 60 % per year. Disks are still 50 to 100 times cheaper per bit than DRAM.
Network Technology: Network performance depends both on the performance of the switches and on the performance of the transmission system. Although the technology improves continuously, the impact of these improvements can be in discrete leaps.
Performance trends: Bandwidth or throughput is the total amount of work done in given time. Latency or response time is the time between the start and the completion of an event. (for eg. Millisecond for disk access)
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 10
A simple rule of thumb is that bandwidth gro ws by at least the square of the improvement in latency. Computer designers should make plans accordingly. IC Processes are characterizes by the f ature sizes. Feature sizes decreased from 10 microns(1971) to 0.09 microns(2006) Feature sizes shrink, devices shrink quadr atically. Shrink in vertical direction makes the operating v oltage of the transistor to reduce. Transistor performance improves linearly with decreasing feature size . Transistor count improves quadratically with a linear improvement in Transistor performance. !!! Wire delay scales poorly compared to Transistor performance. Feature sizes shrink, wires get shorter. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 11
Signal delay fo r a wire increases in proportion to the product of Resistance and Capacitance.
Trends in Power in Integrated Circuits For CMOS chips, the dominant source of energy consumption is due to switching transistor, also called as Dynamic power and is given b y the following equation. Power = (1/2)*Capacitive load* Voltage
* Frequency switched dynamic For mobile devices, energy is the better metric
Energy dynamic = Capacitive load x Voltage 2 For a fix ed task, slowing clock rate (frequency switched) reduces power, but not energy Capacitive load a function of number of transistors connected to output and technology, which determines capacitance of wires and transistors Dropping voltage helps both, so went from 5V down to 1V To save energy & dynamic power, most CPUs now turn off clock of inactive modules Distributing the power, removing the heat and preventing hot spots have become increasingly difficult challenges. The leakage current flows even when a transistor is off. Therefore static power is equally important.
Power static= Current static * Voltage
Leakage current increases in processors with smaller transistor sizes Increasing the number of transistors increases power even if they are turned off In 2006, goal for leakage is 25% of total power consumption; high performance designs at 40% Very low power systems even gate voltage to inactive modules to control loss due to leakage
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 12
Trends in Cost The underlying principle that drives the cost down is the learning curve manufacturing costs decrease over time. Volume is a second key factor in determining cost. Volume decreases cost since it increases purchasing manufacturing efficiency. As a rule of thumb, the cost decreases about 10% for each doubling of volume. Cost of an Integrated Circuit Although the cost of ICs have dropped exponentially, the basic process of silicon manufacture is unchanged. A wafer is still tested and chopped into dies that are packaged.
Cost of IC = Cost of [die+ testing die+ Packaging and final test] / (Final test yoeld) Cost of die = Cost of wafer/ (Die per wafer x Die yield)
The number of dies per wafer is approximately the area of the wafer divided by the area of the die. Die per wafer = [_ * (Wafer Dia/2)2/Die area]-[_* wafer dia/_(2*Die area)]
The first term is the ratio of wafer area to die area and the second term compensates for the rectangular dies near the periphery of round wafers(as shown in figure).
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 13
Dependability: The Infrastructure providers offer Service Level Agreement (SLA) or Service Level Objectives (SLO) to guarantee that their networking or power services would be dependable. Systems alternate between 2 states of service with respect to an SLA: 1. Service accomplishment, where the service is delivered as specified in SLA 2. Service interruption, where the delivered service is different from the SLA Failure = transition from state 1 to state 2 Restoration = transition from state 2 to state 1
The two main measures of Dependability are Module Reliability and Module Availability. Module reliability is a measure of continuous service accomplishment (or time to failure) from a reference initial instant. 1. Mean Time To Failure (MTTF) measures Reliability 2. Failures In Time (FIT) = 1/MTTF, the rate of failures ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 14
Traditionally reported as failures per billion hours of operation Mean Time To Repair (MTTR) measures Service Interruption Mean Time Between Failures (MTBF) = MTTF+MTTR Module availability measures service as alternate between the 2 states of accomplishment and interruption (number between 0 and 1, e.g. 0.9) Module availability = MTTF / ( MTTF + MTTR)
Performance: The Execution time or Response time is defined as the time between the start and completion of an event. The total amount of work done in a given time is defined as the Throughput.
The Administrator of a data center may be interested in increasing the Throughput. The computer user may be interested in reducing the Response time. Computer user says that computer is faster when a program runs in less time.
The routinely executed programs are the best candidates for evaluating the performance of the new computers. To evaluate new system the user would simply compare the execution time of their workloads.
Benchmarks The real applications are the best choice of benchmarks to evaluate the performance. However, for many of the cases, the workloads will not be known at the ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 15
time of evaluation. Hence, the benchmark program which resemble the real applications are chosen. The three types of benchmarks are: KERNELS, which are small, key pieces of real applications; Toy Programs: which are 100 line programs from beginning programming assignments, such Quicksort etc., Synthetic Benchmarks: Fake programs invented to try to match the profile and behavior of real applications such as Dhrystone. To make the process of evaluation a fair justice, the following points are to be followed. Source code modifications are not allowed. Source code modifications are allowed, but are essentially impossible. Source code modifications are allowed, as long as the modified version produces the same output. To increase predictability, collections of benchmark applications, called benchmark suites, are popular SPECCPU: popular desktop benchmark suite given by Standard Performance Evaluation committee (SPEC) CPU only, split between integer and floating point programs SPECint2000 has 12 integer, SPECfp2000 has 14 integer programs SPECCPU2006 announced in Spring 2006. SPECSFS (NFS file server) and SPECWeb (WebServer) added as server benchmarks Transaction Processing Council measures server performance and costperformance for databases TPC-C Complex query for Online Transaction Processing TPC-H models ad hoc decision support TPC-W a transactional web benchmark TPC-App application server and web services benchmark
SPEC Ratio: Normalize execution times to reference computer, yielding a ratio proportional to performance = time on reference computer/time on computer being rated
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 16
If program SPECRatio on Computer A is 1.25 times bigger than Computer B, then
Note : when comparing 2 computers as a ratio, execution times on the reference computer drop out, so choice of reference computer is irrelevant.
Quantitative Principles of Computer Design While designing the computer, the advantage of the following points can be exploited to enhance the performance. * Parallelism: is one of most important methods for improving performance. - One of the simplest ways to do this is through pipelining ie, to overlap the instruction Execution to reduce the total time to complete an instruction sequence. - Parallelism can also be exploited at the level of detailed digital design. - Set- associative caches use multiple banks of memory that are typically searched n parallel. Carry look ahead which uses parallelism to speed the process of computing.
* Principle of locality: program tends to reuse data and instructions they have used recently. The rule of thumb is that program spends 90 % of its execution time in only 10% of the code. With reasonable good accuracy, prediction can be made to find what instruction and data the program will use in the near future based on its accesses in the recent past. * Focus on the common case while making a design trade off, favor the frequent case over the infrequent case. This principle applies when determining how to spend resources, since the impact of the improvement is higher if the occurrence is frequent. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 17
Amdahls Law: Amdahls law is used to find the performance gain that can be obtained by improving some portion or a functional unit of a computer Amdahls law defines the speedup that can be gained by using a particular feature. Speedup is the ratio of performance for entire task without using the enhancement when possible to the performance for entire task without using the enhancement. Execution time is the reciprocal of performance. Alternatively, speedup is defined as thee ratio of execution time for entire task without using the enhancement to the execution time for entair task using the enhancement when possible. Speedup from some enhancement depends an two factors: i. The fraction of the computation time in the original computer that can be converted to take advantage of the enhancement. Fraction enhanced is always less than or equal to. Example: If 15 seconds of the execution time of a program that takes 50 seconds in total can use an enhancement, the fraction is 15/50 or 0.3 ii. The improvement gained by the enhanced execution mode; ie how much faster the task would run if the enhanced mode were used for the entire program. Speedup enhanced is the time of the original mode over the time of the enhanced mode and is always greater then 1.
The Processor performance Equation: Processor is connected with a clock running at constant rate. These discrete time events are called clock ticks or clock cycle. CPU time for a program can be evaluated: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 18
Example: A System contains Floating point (FP) and Floating Point Square Root (FPSQR) unit. FPSQR is responsible for 20% of the execution time. One proposal is to enhance the FPSQR hardware and speedup this operation by a factor of 15 second alternate is just to try to make all FP instructions run faster by a factor of 1.6 times faster with the same effort as required for the fast FPSQR, compare the two design alternative
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 19
Pipelining: Basic and Intermediate concepts Pipeline is an implementation technique that exploits parallelism among the instructions in a sequential instruction stream. Pipeline allows to overlapping the execution of multiple instructions. A Pipeline is like an assembly line each step or pipeline stage completes a part of an instructions. Each stage of the pipeline will be operating an a separate instruction. Instructions enter at one end progress through the stage and exit at the other end. If the stages are perfectly balance. (assuming ideal conditions), then the time per instruction on the pipeline processor is given by the ratio: Time per instruction on unpipelined machine/ Number of Pipeline stages Under these conditions, the speedup from pipelining is equal to the number of stage pipeline. In practice, the pipeline stages are not perfectly balanced and pipeline does involve some overhead. Therefore, the speedup will be always then practically less than the number of stages of the pipeline. Pipeline yields a reduction in the average execution time per instruction. If the processor is assumed to take one (long) clock cycle per instruction, then pipelining decrease the clock cycle time. If the processor is assumed to take multiple CPI, then pipelining will aid to reduce the CPI.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 20
A Simple implementation of a RISC instruction set Instruction set of implementation in RISC takes at most 5 cycles without pipelining. The 5 clock cycles are: 1. Instruction fetch (IF) cycle: Send the content of program count (PC) to memory and fetch the current instruction from memory to update the PC.
2. Instruction decode / Register fetch cycle (ID): Decode the instruction and access the register file. Decoding is done in parallel with reading registers, which is possible because the register specifies are at a fixed location in a RISC architecture. This corresponds to fixed field decoding. In addition it involves: - Perform equality test on the register as they are read for a possible branch. - Sign-extend the offset field of the instruction in case it is needed. - Compute the possible branch target address. 3. Execution / Effective address Cycle (EXE) The ALU operates on the operands prepared in the previous cycle and performs one of the following function defending on the instruction type.
* Register- Register ALU instruction: ALU performs the operation specified in the instruction using the values read from the register file. * Register- Immediate ALU instruction: ALU performs the operation specified in the instruction using the first value read from the register file and that sign extended immediate. 4. Memory access (MEM) For a load instruction, using effective address the memory is read. For a store instruction memory writes the data from the 2nd register read using effective address. 5. Write back cycle (WB) ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 21
Write the result in to the register file, whether it comes from memory system (for a LOAD instruction) or from the ALU.
Five stage Pipeline for a RISC processor Each instruction taken at most 5 clock cycles for the execution * Instruction fetch cycle (IF) * Instruction decode / register fetch cycle (ID) * Execution / Effective address cycle (EX) * Memory access (MEM) * Write back cycle (WB)
The execution of the instruction comprising of the above subtask can be pipelined. Each of the clock cycles from the previous section becomes a pipe stage a cycle in the pipeline. A new instruction can be started on each clock cycle which results in the execution pattern shown figure 2.1. Though each instruction takes 5 clock cycles to complete, during each clock cycle the hardware will initiate a new instruction and will be executing some part of the five different instructions as illustrated in figure 2.1.
Each stage of the pipeline must be independent of the other stages. Also, two different operations cant be performed with the same data path resource on the same clock. For example, a single ALU cannot be used to compute the effective address and perform a subtract operation during the same clock cycle. An adder is to be provided in the stage 1 to compute new PC value and an ALU in the stage 3 to perform the arithmetic indicatedin ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 22
the instruction (See figure 2.2). Conflict should not arise out of overlap of instructions using pipeline. In other words, functional unit of each stage need to be independent of other functional unit. There are three observations due to which the risk of conflict is reduced. Separate Instruction and data memories at the level of L1 cache eliminates a conflict for a single memory that would arise between instruction fetch and data access. Register file is accessed during two stages namely ID stage WB. Hardware should allow to perform maximum two reads one write every clock cycle. To start a new instruction every cycle, it is necessary to increment and store the PC every cycle.
Buffers or registers are introduced between successive stages of the pipeline so that at the end of a clock cycle the results from one stage are stored into a register (see figure 2.3). During the next clock cycle, the next stage will use the content of these buffers as input. Figure 2.4 visualizes the pipeline activity.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 23
Basic Performance issues in Pipelining
Pipelining increases the CPU instruction throughput but, it does not reduce the executiontime of an individual instruction. In fact, the pipelining increases the execution time of each instruction due to overhead in the control of the pipeline. Pipeline overhead arises from the combination of register delays and clock skew. Imbalance among the pipe stages reduces the performance since the clock can run no faster than the time needed for the slowest pipeline stage.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 24
Pipeline Hazards
Hazards may cause the pipeline to stall. When an instruction is stalled, all the instructions issued later than the stalled instructions are also stalled. Instructions issued earlier than the stalled instructions will continue in a normal way. No new instructions are fetched during the stall. Hazard is situation that prevents the next instruction in the instruction stream from k executing during its designated clock cycle. Hazards will reduce the pipeline performance.
Performance with Pipeline stall
A stall causes the pipeline performance to degrade from ideal performance. Performance improvement from pipelining is obtained from:
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 25
Assume that, i) cycle time overhead of pipeline is ignored ii) stages are balanced With theses assumptions
If all the instructions take the same number of cycles and is equal to the number of pipeline stages or depth of the pipeline, then,
If there are no pipeline stalls, Pipeline stall cycles per instruction = zero Therefore, Speedup = Depth of the pipeline.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 26
Types of hazard Three types hazards are: 1. Structural hazard 2. Data Hazard 3. Control Hazard
Structural hazard Structural hazard arise from resource conflicts, when the hardware cannot support all possible combination of instructions simultaneously in overlapped execution. If some combination of instructions cannot be accommodated because of resource conflicts, the processor is said to have structural hazard. Structural hazard will arise when some functional unit is not fully pipelined or when some resource has not been duplicated enough to allow all combination of instructions in the pipeline to execute. For example, if memory is shared for data and instruction as a result, when an instruction contains data memory reference, it will conflict with the instruction reference for a later instruction (as shown in figure 2.5a). This will cause hazard and pipeline stalls for 1 clock cycle.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 27
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 28
Pipeline stall is commonly called Pipeline bubble or just simply bubble
Data Hazard
Consider the pipelined execution of the following instruction sequence (Timing diagram shown in figure 2.6)
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 29
DADD instruction produces the value of R1 in WB stage (Clock cycle 5) but the DSUB instruction reads the value during its ID stage (clock cycle 3). This problem is called Data Hazard. DSUB may read the wrong value if precautions are not taken. AND instruction will read the register during clock cycle 4 and will receive the wrong results. The XOR instruction operates properly, because its register read occurs in clock cycle 6 after DADD writes in clock cycle 5. The OR instruction also operates without incurring a hazard because the register file reads are performed in the second half of the cycle whereas the writes are performed in the first half of the cycle.
Minimizing data hazard by Forwarding The DADD instruction will produce the value of R! at the end of clock cycle 3. DSUB instruction requires this value only during the clock cycle 4. If the result can be moved from the pipeline register where the DADD store it to the point (input of LAU) where DSUB needs it, then the need for a stall can be avoided. Using a simple hardware technique called Data Forwarding or Bypassing or short circuiting, data can be made available from the output of the ALU to the point where it is required (input of LAU) at the beginning of immediate next clock cycle. Forwarding works as follows: i) The output of ALU from EX/MEM and MEM/WB pipeline register is always feedback to the ALU inputs. ii) If the Forwarding hardware detects that the previous ALU output serves as the source for the current ALU operations, control logic selects the forwarded result as the input rather than the value read from the register file. Forwarded results are required not only from the immediate previous instruction, but also from an instruction that started 2 cycles earlier. The result of ith instruction Is required to be forwarded to (i+2)th ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 30
instruction also. Forwarding can be generalized to include passing a result directly to the functional unit that requires it.
Data Hazard requiring stalls
LD R1, 0(R2) DADD R3, R1, R4 AND R5, R1, R6 OR R7, R1, R8 The pipelined data path for these instructions is shown in the timing diagram (figure 2.7)
The LD instruction gets the data from the memory at the end of cycle 4. even with forwarding technique, the data from LD instruction can be made available earliest during clock cycle 5. DADD instruction requires the result of LD instruction at the beginning of clock cycle 5. DADD instruction requires the result of LD instruction at the beginning of clock cycle 4. This demands data forwarding of clock cycle 4. This demands data forwarding in negative time which is not possible. Hence, the situation calls for a pipeline stall.Result from the LD instruction can be forwarded from the pipeline register to the and instruction which begins at 2 clock cycles later after the LD instruction. The load ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 31
instruction has a delay or latency that cannot be eliminated by forwarding alone. It is necessary to stall pipeline by 1 clock cycle. A hardware called Pipeline interlock detects a hazard and stalls the pipeline until the hazard is cleared. The pipeline interlock helps to preserve the correct execution pattern by introducing a stall or bubble. The CPI for the stalled instruction increases by the length of the stall. Figure 2.7 shows the pipeline before and after the stall. Stall causes the DADD to move 1 clock cycle later in time. Forwarding to the AND instruction now goes through the register file or forwarding is not required for the OR instruction. No instruction is started during the clock cycle 4.
Control Hazard
When a branch is executed, it may or may not change the content of PC. If a branch is taken, the content of PC is changed to target address. If a branch is taken, the content of PC is not changed
The simple way of dealing with the branches is to redo the fetch of the instruction following a branch. The first IF cycle is essentially a stall, because, it never performs useful work. One stall cycle for every branch will yield a performance loss 10% to 30% depending on the branch frequency
Reducing the Brach Penalties There are many methods for dealing with the pipeline stalls caused by branch delay 1. Freeze or Flush the pipeline, holding or deleting any instructions after the ranch until the branch destination is known. It is a simple scheme and branch penalty is fixed and cannot be reduced by software 2. Treat every branch as not taken, simply allowing the hardware to continue as if the branch were not to executed. Care must be taken not to change the processor state until the branch outcome is known. Instructions were fetched as if the branch were a normal instruction. If the branch is taken, it is necessary to turn the fetched instruction in to a no-of instruction and restart the fetch at the target address. Figure 2.8 shows the timing diagram of both the situations. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 32
3. Treat every branch as taken: As soon as the branch is decoded and target Address is computed, begin fetching and executing at the target if the branch target is known before branch outcome, then this scheme gets advantage. For both predicated taken or predicated not taken scheme, the compiler can improve performance by organizing the code so that the most frequent path matches the hardware choice. 4. Delayed branch technique is commonly used in early RISC processors. In a delayed branch, the execution cycle with a branch delay of one is Branch instruction Sequential successor-1 Branch target if taken
The sequential successor is in the branch delay slot and it is executed irrespective of whether or not the branch is taken. The pipeline behavior with a branch delay is shown in Figure 2.9. Processor with delayed branch, normally have a single instruction delay. Compiler has to make the successor instructions valid and useful there are three ways in which the to delay slot can be filled by the compiler.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 33
The limitations on delayed branch arise from i) Restrictions on the instructions that are scheduled in to delay slots. ii) Ability to predict at compiler time whether a branch is likely to be taken or not taken. The delay slot can be filled from choosing an instruction a) From before the branch instruction b) From the target address c) From fall- through path. The principle of scheduling the branch delay is shown in fig 2.10
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 34
What makes pipelining hard to implements?
Dealing with exceptions: Overlapping of instructions makes it more difficult to know whether an instruction can safely change the state of the CPU. In a pipelined CPU, an instruction execution extends over several clock cycles. When this instruction is in execution, the other instruction may raise exception that may force the CPU to abort the instruction in the pipeline before they complete
Types of exceptions:
The term exception is used to cover the terms interrupt, fault and exception. I/O device request, page fault, Invoking an OS service from a user program, Integer arithmetic overflow, memory protection overflow, Hardware malfunctions, Power failure etc. are the different classes of exception. Individual events have important characteristics that determine what action is needed corresponding to that exception. i) Synchronous versus Asynchronous
If the event occurs at the same place every time the program is executed with the same data and memory allocation, the event is asynchronous. Asynchronous events are ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 35
caused by devices external to the CPU and memory such events are handled after the completion of the current instruction. ii) User requested versus coerced: User requested exceptions are predictable and can always be handled after the current instruction has completed. Coerced exceptions are caused by some hardware event that is not under the control of the user program. Coerced exceptions are harder to implement because they are not predictable iii) User maskable versus user non maskable :
If an event can be masked by a user task, it is user maskable. Otherwise it is user non maskable. iv) Within versus between instructions: Exception that occur within instruction are usually synchronous, since the instruction triggers the exception. It is harder to implement exceptions that occur withininstructions than those between instructions, since the instruction must be stopped and restarted. Asynchronous exceptions that occurs within instructions arise from catastrophic situations and always causes program termination. v) Resume versus terminate: If the programs execution continues after the interrupt, it is a resuming event otherwise if is terminating event. It is easier implement exceptions that terminate execution. 29
Stopping and restarting execution: The most difficult exception have 2 properties: 1. Exception that occur within instructions 2. They must be restartable For example, a page fault must be restartable and requires the intervention of OS. Thus pipeline must be safely shutdown, so that the instruction can be restarted in the correct state. If the restarted instruction is not a branch, then we will continue to fetch the sequential successors and begin their execution in the normal fashion. 11) Restarting is ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 36
usually implemented by saving the PC of the instruction at which to restart. Pipeline control can take the following steps to save the pipeline state safely. i) Force a trap instruction in to the pipeline on the next IF ii) Until the trap is taken, turn off all writes for the faulting instruction and for all instructions that follow in pipeline. This prevents any state changes for instructions that will not be completed before the exception is handled. iii) After the exception handling routine receives control, it immediately saves the PC of the faulting instruction. This value will be used to return from the exception later.
NOTE: 1. with pipelining multiple exceptions may occur in the same clock cycle because there are multiple instructions in execution. 2 Handling the exception becomes still more complicated when the instructions are allowed to execute in out of order fashion.
Operation: send out the [PC] and fetch the instruction from memory in to the Instruction Register (IR). Increment PC by 4 to address the next sequential instruction.
2. Instruction decode / Register fetch cycle (ID)
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 37
Operation: decode the instruction and access that register file to read the registers ( rs and rt). File to read the register (rs and rt). A & B are the temporary registers. Operands are kept ready for use in the next cycle. Decoding is done in concurrent with reading register. MIPS ISA has fixed length Instructions. Hence, these fields are at fixed locations.
3. Execution/ Effective address cycle (EX)
One of the following operations are performed depending on the instruction type. * Memory reference:
:
Operation: ALU adds the operands to compute the effective address and places the result in to the register ALU output. Register Register ALU instruction:
Operation: The ALU performs the operation specified by the function code on the value taken from content of register A and register B. *. Register- Immediate ALU instruction:
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 38
Operation: the content of register A and register Imm are operated (function Op) and result is placed in temporary register ALU output. *. Branch:
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 39
UNIT II INSTRUCTION LEVEL PARALLELISM
The potential overlap among instruction execution is called Instruction Level Parallelism (ILP) since instructions can be executed in parallel. There are mainly two approaches to exploit ILP.
i) Hardware based approach: An approach that relies on hardware to help discover and exploit the parallelism dynamically. Intel Pentium series which has dominated in the market) uses this approach.
ii) Software based approach: An approach that relies on software technology to find parallelism statically at compile time. This approach has limited use in scientific or application specific environment. Static approach of exploiting ILP is found in Intel Itanium.
Factors of both programs and processors limit the amount of parallelism that can be exploited among instructions and these limit the performance achievable. The performance of the pipelined processors is given by:
Pipeline CPI= Ideal Pipeline CPI + Structural stalls + Data hazard stalls + Control stalls
By reducing each of the terms on the right hand side, it is possible to minimize the overall pipeline CPI.
To exploit the ILP, the primary focus is on Basic Block (BB). The BB is a straight line code sequence with no branches in except the entry and no branches out except at the exit. The average size of the BB is very small i.e., about 4 to 6 instructions. The flow diagram segment of a program is shown below (Figure 3.1). BB1 , BB2 and BB3 are the Basic Blocks.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 40
Figure 3.1 Flow diagram segment
The amount of overlap that can be exploited within a Basic Block is likely to be less than the average size of BB. To further enhance ILP, it is possible to look at ILP across multiple BB. The simplest and most common way to increase the ILP is to exploit the parallelism among iterations of a loop (Loop level parallelism). Each iteration of a loop can overlap with any other iteration.
Data Dependency and Hazard If two instructions are parallel, they can execute simultaneously in a pipeline of arbitrary length without causing any stalls, assuming the pipeline has sufficient resources. If two instructions are dependent, they are not parallel and must be executed in sequential order. There are three different types dependences.
Data Dependences (True Data Dependency) Name Dependences Control Dependences
Data Dependences An instruction j is data dependant on instruction i if either of the following holds: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 41
i) Instruction i produces a result that may be used by instruction j Eg1: i: L.D F0, 0(R1) j: ADD.D F4, F0, F2 ith instruction is loading the data into the F0 and jth instruction use F0 as one the operand. Hence, jth instruction is data dependant on ith instruction. Eg2: DADD R1, R2, R3 DSUB R4, R1, R5
ii) Instruction j is data dependant on instruction k and instruction k data dependant on instruction i Eg: L.D F4, 0(R1) MUL.D F0, F4, F6 ADD.D F5, F0, F7
Dependences are the property of the programs. A Data value may flow between instructions either through registers or through memory locations. Detecting the data flow and dependence that occurs through registers is quite straight forward. Dependences that flow through the memory locations are more difficult to detect. A data dependence convey three things.
a) The possibility of the Hazard. b) The order in which results must be calculated and c) An upper bound on how much parallelism can possibly exploited.
Name Dependences
A Name Dependence occurs when two instructions use the same Register or Memory location, but there is no flow of data between the instructions associated with that name.
Two types of Name dependences: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 42
i) Antidependence: between instruction i and instruction j occurs when instruction j writes a register or memory location that instruction i reads. he original ordering must be preserved to ensure that i reads the correct value. Eg: L.D F0, 0(R1) DADDUI R1, R1, R3
ii) Output dependence: Output Dependence occurs when instructions i and j write to the same register or memory location. Ex: ADD.D F4, F0, F2 SUB.D F4, F3, F5
The ordering between the instructions must be preserved to ensure that the value finally written corresponds to instruction j.The above instruction can be reordered or can be executed simultaneously if the name of the register is changed. The renaming can be easily done either statically by a compiler or dynamically by the hardware.
Data hazard: Hazards are named by the ordering in the program that must be preserved by the pipeline
RAW (Read After Write): j tries to read a source before i writes it, so j in correctly gets old value, this hazard is due to true data dependence.
WAW (Write After Write): j tries to write an operand before it is written by i. WAW hazard arises from output dependence.
WAR (Write After Read): j tries to write a destination before it is read by i, so that I incorrectly gets the new value. WAR hazard arises from an antidependence and normally cannot occur in static issue pipeline.
CONTROL DEPENDENCE: A control dependence determines the ordering of an instruction i with respect to a branch ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 43
instruction, Ex: if P1 { S1; } if P2 { S2; } S1 is Control dependent on P1 and S2 is control dependent on P2 but not on P1. a) An instruction that is control dependent on a branch cannot be moved before the branch ,so that its execution is no longer controlled by the branch. b) An instruction that is not control dependent on a branch cannot be moved after the branch so that its execution is controlled by the branch.
BASIC PIPELINE SCHEDULE AND LOOP UNROLLING
To keep a pipe line full, parallelism among instructions must be exploited by finding sequence of unrelated instructions that can be overlapped in the pipeline. To avoid a pipeline stall,a dependent instruction must be separated from the source instruction by the distance in clock cycles equal to the pipeline latency of that source instruction. A compilers ability to perform this scheduling depends both on the amount of ILP available in the program and on the latencies of the functional units in the pipeline.
The compiler can increase the amount of available ILP by transferring loops. for(i=1000; i>0 ;i=i-1) X[i] = X[i] + s; We see that this loop is parallel by the noticing that body of the each iteration is independent.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 44
The first step is to translate the above segment to MIPS assembly language Loop: L.D F0, 0(R1) : F0=array element ADD.D F4, F0, F2 : add scalar in F2 S.D F4, 0(R1) : store result DADDUI R1, R1, #-8 : decrement pointer : 8 Bytes (per DW) BNE R1, R2, Loop : branch R1! = R2
Without any Scheduling the loop will execute as follows and takes 9 cycles for each iteration. 1 Loop: L.D F0, 0(R1) ;F0=vector element 2 stall 3 ADD.D F4, F0, F2 ;add scalar in F2 4 stall 5 stall 6 S.D F4, 0(R1) ;store result 7 DADDUI R1, R1,# -8 ;decrement pointer 8B (DW) 8 stall ;assumes cant forward to branch 9 BNEZ R1, Loop ;branch R1!=zero
We can schedule the loop to obtain only two stalls and reduce the time to 7 cycles: L.D F0, 0(R1)
Loop Unrolling can be used to minimize the number of stalls. Unrolling the body of the loop by our times, the execution of four iteration can be done in 27 clock cycles or 6.75 clock cycles per iteration.
Summary of Loop unrolling and scheduling The loop unrolling requires understanding how one instruction depends on another and how the instructions can be changed or reordered given the dependences:
1. Determine loop unrolling useful by finding that loop iterations were independent (except for maintenance code) 2. Use different registers to avoid unnecessary constraints forced by using same registers for different computations 3. Eliminate the extra test and branch instructions and adjust the loop termination and iteration code 4. Determine that loads and stores in unrolled loop can be interchanged by observing that loads and stores from different iterations are independent Transformation requires analyzing memory addresses and finding that they do not refer to the same address 5. Schedule the code, preserving any dependences needed to yield the same result as the original code To reduce the Branch cost, prediction of the outcome of the branch may be done. The prediction may be done statically at compile time using compiler support or dynamically using hardware support. Schemes to reduce the impact of control hazard are discussed below:
Static Branch Prediction
Assume that the branch will not be taken and continue execution down the sequential instruction stream. If the branch is taken, the instruction that are being fetched ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 47
and decoded must be discarded. Execution continues at the branch target. Discarding instructions means we must be able to flush instructions in the IF, ID and EXE stages. Alternately, it is possible that the branch can be predicted as taken. As soon as the instruction decoded is found as branch, at the earliest, start fetching the instruction from the target address.
Average misprediction = untaken branch frequency = 34% for SPEC pgms.
The graph shows the misprediction rate for set of SPEC benchmark programs
Dynamic Branch Prediction With deeper pipelines the branch penalty increases when measured in clock cycles. Similarly, with multiple issue, the branch penalty increases in terms of instructions lost. Hence, a simple static prediction scheme is inefficient or may not be efficient in most of the situations. One approach is to look up the address of the instruction to see if a branch was taken the last time this instruction was executed, and if so, to begin fetching new instruction from the target address. This technique is called Dynamic branch prediction. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 48
Why does prediction work?
Underlying algorithm has regularities Data that is being operated on has regularities Instruction sequence has redundancies that are artifacts of way that humans/compilers think about problems. There are a small number of important branches in programs which have dynamic behavior for which dynamic branch prediction performance will be definitely better compared to static branch prediction.
Performance = (accuracy, cost of misprediction) Branch History Table (BHT) is used to dynamically predict the outcome of the current branch instruction. Lower bits of PC address index table of 1-bit values Says whether or not branch taken last time o - No address check
Problem: in a loop, 1-bit BHT will cause two mispredictions (average is 9 iterations before exit): End of loop case, when it exits instead of looping as before First time through loop on next time through code, when it predicts exit instead of looping
Simple two bit history table will give better performance. The four different states of 2 bit predictor is shown in the state transition diagram.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 49
Correlating Branch Predictor It may be possible to improve the prediction accuracy by considering the recent behavior of other branches rather than just the branch under consideration. Correlating predictors are two-level predictors. Existing correlating predictors add information about the behavior of the most recent branches to decide how to predict a given branch. Idea: record m most recently executed branches as taken or not taken, and use that pattern to select the proper n-bit branch history table (BHT) In general, (m,n) predictor means record last m branches to select between 2m history tables, each with n-bit counters Thus, old 2-bit BHT is a (0,2) predictor Global Branch History: m-bit shift register keeping T/NT status of last m branches. Each entry in table has m n-bit predictors. In case of (2,2) predictor, behavior of recent branches selects between four predictions of next branch, updating just that prediction. The scheme of the table is shown: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 50
Comparisons of different schemes are shown in the graph.
Tournament predictor is a multi level branch predictor and uses n bit saturating counter to chose between predictors. The predictors used are global predictor and local predictor. Advantage of tournament predictor is ability to select the right predictor for a particular branch which is particularly crucial for integer benchmarks. A typical tournament predictor will select the global predictor almost 40% of the time for the SPEC integer benchmarks and less than 15% of the time for the SPEC FP benchmarks ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 51
Existing tournament predictors use a 2-bit saturating counter per branch to choose among two different predictors based on which predictor was most effective oin recent prediction.
Dynamic Branch Prediction Summary Prediction is becoming important part of execution as it improves the performance of the pipeline. Branch History Table: 2 bits for loop accuracy Correlation: Recently executed branches correlated with next branch Either different branches (GA) Or different executions of same branches (PA) Tournament predictors take insight to next level, by using multiple predictors usually one based on global information and one based on local information, and combining them with a selector In 2006, tournament predictors using 30K bits are in processors like the Power and Pentium 4 Tomasulu algorithm and Reorder Buffer Tomasulu idea: 1. Have reservation stations where register renaming is possible ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 52
2. Results are directly forwarded to the reservation station along with the final registers. This is also called short circuiting or bypassing.
ROB: 1.The instructions are stored sequentially but we have indicators to say if it is speculative or completed execution. 2. If completed execution and not speculative and reached head of the queue then we commit it.
Speculating on Branch Outcomes To optimally exploit ILP (instruction-level parallelism) e.g. with pipelining, Tomasulo,etc. it is critical to efficiently maintain control dependencies (=branch dependencies) Key idea: Speculate on the outcome of branches(=predict) and execute instructions as if the predictions are correct ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 53
of course, we must proceed in such a manner as to be able to recover if our speculation turns out wrong
Three components of hardware-based speculation 1. dynamic branch prediction to pick branch outcome 2. speculation to allow instructions to execute before control dependencies are resolved, i.e., before branch outcomes become known with ability to undo in case of incorrect speculation 3. dynamic scheduling
Speculating with Tomasulo Key ideas: 1. separate execution from completion: instructions to execute speculatively but no instructions update registers or memory until no more speculative 2. therefore, add a final step after an instruction is no longer speculative, called instruction commit when it is allowed to make register and memory updates 3. allow instructions to execute and complete out of order but force them to commit in order 4. Add hardware called the reorder buffer (ROB), with registers to hold the result of an instruction between completion and commit
Tomasulos Algorithm with Speculation: Four Stages 1. Issue: get instruction from Instruction Queue _ if reservation station and ROB slot free (no structural hazard), control issues instruction to reservation station and ROB, and sends to reservation station operand values (or reservation station source for values) as well as allocated ROB slot number 2. Execution: operate on operands (EX) _ when both operands ready then execute;if not ready, watch CDB for result ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 54
3. Write result: finish execution (WB) _ write on CDB to all awaiting units and ROB; mark reservation station available 4. Commit: update register or memory with ROB result _ when instruction reaches head of ROB and results present, update register with result or store to memory and remove instruction from ROB _ if an incorrectly predicted branch reaches the head of ROB, flush the ROB, and restart at correct successor of branch
ROB Data Structure ROB entry fields Instruction type: branch, store, register operation (i.e., ALU or load) State: indicates if instruction has completed and value is ready Destination: where result is to be written register number for register operation (i.e. ALU or load), memory address for store branch has no destination result
Value: holds the value of instruction result till time to commit Additional reservation station field Destination: Corresponding ROB entry number Example 1. L.D F6, 34(R2) 2. L.D F2, 45(R3 3. MUL.D F0, F2, F4 4. SUB.D F8, F2, F6 5. DIV.D F10, F0, F6 6. ADD.D F6, F8, F2
The position of Reservation stations, ROB and FP registers are indicated below:
Show data structures just before MUL.D goes to commit
Reservation Stations
At the time MUL.D is ready to commit only the two L.D instructions have already committed,though others have completed execution Actually, the MUL.D is at the head of the ROB the L.D instructions are shown only for understanding purposes #X represents value field of ROB entry number X Floating point registers
Assume instructions in the loop have been issued twice Assume L.D and MUL.D from the first iteration have committed and all other instructions have completed Assume effective address for store is computed prior to its issue Show data structures
Notes If a branch is mispredicted, recovery is done by flushing the ROB of all entries that appear after the mispredicted branch entries before the branch are allowed to continue restart the fetch at the correct branch successor When an instruction commits or is flushed from the ROB then the corresponding slots become available for subsequent instructions
Advantages of hardware-based speculation:
-able to disambiguate memory references; -better when hardware-based branch prediction is better than software-based branch prediction done at compile time; - maintains a completely precise exception model even for speculated instructions; does not require compensation or bookkeeping code; main disadvantage: complex and requires substantial hardware resources; ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 58
INSTRUCTION LEVEL PARALLELISM 2 What is ILP? Instruction Level Parallelism Number of operations (instructions) that can be performed in parallel Formally, two instructions are parallel if they can execute simultaneously in a pipeline of arbitrary depth without causing any stalls assuming that the pipeline has sufficient resources Primary techniques used to exploit ILP Deep pipelines Multiple issue machines Basic program blocks tend to have 4-8 instructions between branches Little ILP within these blocks Must find ILP between groups of blocks Example Instruction Sequences Independent instruction sequence: lw $10, 12($1) sub $11, $2, $3 and $12, $4, $5 or $13, $6, $7 add $14, $8, $9 Dependent instruction sequence:
lw $10, 12($1) sub $11, $2, $10 and $12, $11, $10 or $13, $6, $7 add $14, $8, $13
Finding ILP: Must deal with groups of basic code blocks ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 59
Common approach: loop-level parallelism Example: In MIPS (assume $s0 initialized properly):
for (i=1000; i > 0; i--) x[i] = x[i] + s; Loop: lw $t0, 0($s1) # t0 = array element addu $t0, $t0, $s2 # add scalar in $s2 sw $t0, 0($s1) # store result addi $s1, $s1, -4 # decrement pointer bne $s1, $0, Loop # branch $s1 != 0
Loop Unrolling: Technique used to help scheduling (and performance) Copy the loop body and schedule instructions from different iterations of the loop gether MIPS example (from prev. slide):
Note the new register & counter adjustment! Previous example, we unrolled the loop once This gave us a second copy Why introduce a new register ($t1)? ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 60
Antidependence (name dependence) Loop iterations would reuse register $t0 No data overlap between loop iterations! Compiler RENAMED the register to prevent a dependence Allows for better instruction scheduling and identification of true dependencies In general, you can unroll the loop as much as you want A factor of the loop counter is generally used Limited advantages to unrolling more than a few times
Loop Unrolling: Performance: Performance (dis)advantage of unrolling Assume basic 5-stage pipeline Recall lw requires a bubble if value used immediately after For original loop 10 cycles to execute first iteration 16 cycles to execute two iterations Assuming perfect prediction For unrolled loop 14 cycles to execute first iteration -- without reordering Gain from skipping addi, bne 12 cycles to execute first iteration -- with reordering Put lw together, avoid bubbles after ea
Loop Unrolling: Limitations Overhead amortization decreases as loop is unrolled more Increase in code size Could be bad if ICache miss rate increases Register pressure Run out of registers that can be used in renaming process
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 61
Exploiting ILP: Deep Pipelines Deep Pipelines Increase pipeline depth beyond 5 stages Generally allows for higher clock rates UltraSparc III -- 14 stages Pentium III -- 12 stages Pentium IV -- 22 stages Some versions have almost 30 stages Core 2 Duo -- 14 stages AMD Athlon -- 9 stages AMD Opteron -- 12 stages Motorola G4e -- 7 stages IBM PowerPC 970 (G5) -- 14 stages Increases the number of instructions executing at the same time Most of the CPUs listed above also issue multiple instructions per cycle Issues with Deep Pipelines Branch (Mis-)prediction Speculation: Guess the outcome of an instruction to remove it as a dependence to other instructions Tens to hundreds of instructions in flight Have to flush some/all if a branch is mispredicted Memory latencies/configurations To keep latencies reasonable at high clock rates, need fast caches Generally smaller caches are faster Smaller caches have lower hit rates Techniques like way prediction and prefetching can help lower latencies
Optimal Pipelining Depths Several papers published on this topic ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 62
Esp. the 29th International Symposium on Computer Architecture (ISCA) Intel had one pushing the depth to 50 stages Others have shown ranges between 15 and 40 Most of the variation is due to the intended workload Exploiting ILP: Multiple Issue Computers Multiple Issue Computers Benefit CPIs go below one, use IPC instead (instructions/cycle) Example: Issue width = 3 instructions, Clock = 3GHz Peak rate: 9 billion instructions/second, IPC = 3 For our 5 stage pipeline, 15 instructions in flight at any given time Multiple Issue types Static Most instruction scheduling is done by the compiler Dynamic (superscalar) CPU makes most of the scheduling decisions Challenge: overcoming instruction dependencies Increased latency for loads Control hazards become worse Requires a more ambitious design Compiler techniques for scheduling Complex instruction decoding logic
Exploiting ILP:Multiple Issue Computers Static Scheduling Instruction Issuing Have to decide which instruction types can issue in a cycle Issue packet: instructions issued in a single clock cycle Issue slot: portion of an issue packet Compiler assumes a large responsibility for hazard checking, scheduling, etc. Static Multiple Issue For now, assume a souped-up 5-stage MIPS pipeline that can issue a packet with: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 63
One slot is an ALU or branch instruction One slot is a load/store instruction
Exploiting ILP:Multiple Issue Computers Dynamic Scheduling Dynamic Multiple Issue Computers Superscalar computers CPU generally manages instruction issuing and ordering Compiler helps, but CPU dominates Process Instructions issue in-order Instructions can execute out-of-order Execute once all operands are ready Instructions commit in-order Commit refers to when the architectural register file is updated (current completed state of program Aside: Data Hazard Refresher Two instructions (i and j), j follows i in program order Read after Read (RAR) Read after Write (RAW) Type: Problem: Write after Read (WAR) ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 66
Type: Problem: Write after Write (WAW) Type: Problem: Superscalar Processors Register Renaming Use more registers than are defined by the architecture Architectural registers: defined by ISA Physical registers: total registers Help with name dependencies Antidependence Write after Read hazard Output dependence Write after Write hazard
Tomasulos Superscalar Computers R. M. Tomasulo, An Efficient Algorithm for Exploiting Multiple Arithmetic Units, IBM J. of Research and Development, Jan. 1967 See also: D. W. Anderson, F. J. Sparacio, and R. M. Tomasulo, The IBM System/360 model 91: Machine philosophy and instruction-handling, IBM J. of Research and evelopment, Jan. 1967 Allows out-of-order execution Tracks when operands are available Minimizes RAW hazards Introduced renaming for WAW and WAR hazards Tomasulos Superscalar Computers
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 67
Instruction Execution Process Three parts, arbitrary number of cycles/part Above does not allow for speculative execution Issue (aka Dispatch) If empty reservation station (RS) that matches instruction, send to RS with operands rom register file and/or know which functional unit will send operand If no empty RS, stall until one is available
Rename registers as appropriate Instruction Execution Process Execute All branches before instruction must be resolved Preserves exception behavior When all operands available for an instruction, send it to functional unit Monitor common data bus (CDB) to see if result is needed by RS entry For non-load/store reservation stations ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 68
If multiple instructions ready, have to pick one to send to functional unit For load/store Compute address, then place in buffer Loads can execute once memory is free Stores must wait for value to be stored, then execute
Write Back Functional unit places on CDB Goes to both register file and reservation stations Use of CDB enables forwarding for RAW hazards Also introduces a latency between result and use of a value
Reservation Stations Require 7 fields Operation to perform on operands (2 operands) Tags showing which RS/Func. Unit will be producing operand (or zero if operand available/unnecessary) Two source operand values A field for holding memory address calculation data Initially, immediate field of instruction Later, effective address Busy Indicates that RS and its functional unit are busy Register file support Each entry contains a field that identifies which RS/func. unit will be writing into this entry (or blank/zero if noone will be writing to it) Limitation of Current Machine
Instruction execution requires branches to be resolved For wide-issue machines, may issue one branch per clock cycle! Desire: Predict branch direction to get more ILP ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 69
Eliminate control dependencies Approach: Predict branches, utilize speculative instruction execution Requires mechanisms for fixing machine when speculation is incorrect Tomasulos w/Hardware Speculation
Tomasulos w/HW Speculation Key aspects of this design Separate forwarding (result bypassing) from actual instruction completion Assuming instructions are executing speculatively Can pass results to later instructions, but prevents instruction from performing updates that cant be undone Once instruction is no longer speculative it can update register file/memory New step in execution sequence: instruction commit ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 70
Requires instructions to wait until they can commit Commits still happen in order Reorder Buffer (ROB)
Instructions hang out here before committing Provides extra registers for RS/RegFile Is a source for operands Four fields/entry Instruction type Branch, store, or register operation (ALU & load) Destination field Register number or store address Value field Holds value to write to register or data for store Ready field Has instruction finished executing? Note: store buffers from previous version now in ROB Instruction Execution Sequence Issue Issue instruction if opening in RS & ROB Send operands to RS from RegFile and/or ROB Execute Essentially the same as before Write Result Similar to before, but put result into ROB Commit (next slide) Committing Instructions Look at head of ROB Three types of instructions Incorrectly predicted branch Indicates speculation was wrong Flush ROB ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 71
Execution restarts at proper location Store Update memory Remove store from ROB Everything else Update registers Remove instruction from ROB
RUU Superscalar Computers
Modeling tool SimpleScalar implements an RUU style processor You will be using this tool after Spring Break Architecture similar to speculative Tomasulos Register Update Unit (RUU) Controls instructions scheduling and dispatching to functional units Stores intermediate source values for instructions Ensures instruction commit occurs in order! ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 72
Needs to be of appropriate size Minimum of issue width * number of pipeline stages Too small of an RUU can be a structural hazard! Result bus could be a structural hazard
A Real Computer:Intel Pentium 4 Pentium 4 Die Photo
Overview of P4 ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 73
Pentium 4 Pipeline See handout for overview of major steps Prescott (90nm version of P4) had 31 pipeline stages Not sure how pipeline is divided up
P4: Trace Cache Non-traditional instruction cache Recall x86 ISA CISC/VLIW: ugly assembly instructions of varying lengths ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 74
Hard for HW to decode Ended up translating code into RISC-like microoperations to execute Trace Cache holds sequences of RISC-like micro-ops Less time decoding, more time executing Sequence storage similar to normal instruction cache P4: Branch Handling BTBs (Branch Target Buffers) Keep both branch history and branch target addresses Target address is instruction immediately after branch Predict if no entry in BTB for branch Static prediction If a backwards branch, see how far target is from current; if within a threshold, predict taken, else predict not taken If a forward branch, predict not taken Also some other rules Front-end BTB is L2 (like) for the trace cache BTB (L1 like)
P4: Execution Core Tomasulos algorithm-like Can have up to 126 instructions in-flight Max of 3 micro-ops sent to core/cycle Max of 48 loads, 32 stores Send up to 6 instructions to functional units per cycle via 4 ports Port 0: Shared between first fast ALU and FP/Media move scheduler Port 1: Shared between second fast ALU and Complex integer and FP/Media scheduler Port 2: Load Port 3: Store P4: Rapid Execution Engine Execute 6 micro-ops/cycle Simple ALUs run at 2x machine clock rate Can generate 4 simple ALU results/cycle ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 75
Do one load and one store per cycle Loads involve data speculation Assume that most loads hit L1 and Data Translation Look-aside Buffer (DTLB) Get data into execution, while doing address check Fix if L1 miss occurred
P4: Memory Tricks Store-to-Load Forwarding Stores must wait to write until non-speculative Loads occasionally want data from store location Check both cache and Store Forwarding Buffer SFB is where stores are waiting to be written If hit when comparing load address to SFB address, use SFB data, not cache data Done on a partial address Memory Ordering Buffer Ensures that store-to-load forwarding was correct If not, must re-execute load Force forwarding Mechanism for forwarding in case addresses are misaligned MOB can tell SFB to forward or not False forwarding Fixes partial address match between load and SFB
P4: Specs for Rest of Slides For one running at 3.2 GHz From grad arch book L1 Cache Int: Load to use - 4 cycles FP: Load to use - 12 cycles Can handle up to 8 outstanding load misses L2 Cache (2 MB) ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 76
18 cycle access time
P4: Branch Prediction
P4: Misspeculation Percentages
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 77
P4: Data Cache Miss Rates
P4: CPI ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 78
P4 vs. AMD Opteron
P4 vs. Opteron: Real Performance
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 79
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 80
UNIT III
MULTIPROCESSORS AND THREAD-LEVEL PARALLELISM
We have seen the renewed interest in developing multiprocessors in early 2000: - The slowdown in uniprocessor performance due to the diminishing returns in exploring instruction-level parallelism. - Difficulty to dissipate the heat generated by uniprocessors with high clock rates. - Demand for high-performance servers where thread-level parallelism is natural. For all these reasons multiprocessor architectures has become increasingly attractive.
Taxonomy of Parallel Architectures The idea of using multiple processors both to increase performance and to improve availability dates back to the earliest electronic computers. About 30 years ago, Flynn proposed a simple model of categorizing all computers that is still useful today. He looked at the parallelism in the instruction and data streams called for by the instructions at the most constrained component of the multiprocessor, and placed all computers in one of four categories:
1. Single instruction stream, single data stream (SISD)This category is the uniprocessor.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 81
2. Single instruction stream, multiple data streams (SIMD)The same instruction is executed by multiple processors using different data streams. Each processor has its own data memory (hence multiple data), but there is a single instruction memory and control processor, which fetches and dispatches instructions. Vector architectures are the largest class of processors of this type.
3.Multiple instruction streams, single data stream (MISD)No commercial multiprocessor of this type has been built to date, but may be in the future. Some special purpose stream processors approximate a limited form of this (there is only a single data stream that is operated on by successive functional units). ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 82
4. Multiple instruction streams, multiple data streams (MIMD)Each processor fetches its own instructions and operates on its own data. The processors are often off- the-shelf microprocessors. This is a coarse model, as some multiprocessors are hybrids of these categories. Nonetheless, it is useful to put a framework on the design space.
1. MIMDs offer flexibility. With the correct hardware and software support, MIMDs can function as single-user multiprocessors focusing on high performance for one application, as multiprogrammed multiprocessors running many tasks simultaneously, or as some combination of these functions. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 83
2. MIMDs can build on the cost/performance advantages of off-the-shelf microprocessors. In fact, nearly all multiprocessors built today use the same microprocessors found in workstations and single-processor servers.
With an MIMD, each processor is executing its own instruction stream. In many cases, each processor executes a different process. Recall from the last chapter, that a process is an segment of code that may be run independently, and that the state of the process contains all the information necessary to execute that program on a processor. In a multiprogrammed environment, where the processors may be running independent tasks, each process is typically independent of the processes on other processors. It is also useful to be able to have multiple processors executing a single program and sharing the code and most of their address space. When multiple processes share code and data in this way, they are often called threads
. Today, the term thread is often used in a casual way to refer to multiple loci of execution that may run on different processors, even when they do not share an address space. To take advantage of an MIMD multiprocessor with n processors, we must usually have at least n threads or processes to execute. The independent threads are typically identified by the programmer or created by the compiler. Since the parallelism in this situation is contained in the threads, it is called thread-level parallelism. Threads may vary from large-scale, independent processesfor example, independent programs running in a multiprogrammed fashion on different processors to parallel iterations of a loop, automatically generated by a compiler and each executing for perhaps less than a thousand instructions. Although the size of a thread is important in considering how to exploit thread-level parallelism efficiently, the important qualitative distinction is that such parallelism is identified at a high-level by the software system and that the threads consist of hundreds to millions of instructions that may be executed in parallel. In contrast, instruction level parallelism is identified by primarily by the hardware, though with software help in some cases, and is found and exploited one instruction at a time.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 84
Existing MIMD multiprocessors fall into two classes, depending on the number of processors involved, which in turn dictate a memory organization and interconnect strategy. We refer to the multiprocessors by their memory organization, because what constitutes a small or large number of processors is likely to change over time. The first group, which we call
Centralized shared memory architectures have at most a few dozen processors in 2000. For multiprocessors with small processor counts, it is possible for the processors to share a single centralized memory and to interconnect the processors and memory by a bus. With large caches, the bus and the single memory, possibly with multiple banks, can satisfy the memory demands of a small number of processors. By replacing a single bus with multiple buses, or even a switch, a centralized shared memory design can be scaled to a few dozen processors. Although scaling beyond that is technically conceivable, sharing a centralized memory, even organized as multiple banks, becomes less attractive as the number of processors sharing it increases.
Because there is a single main memory that has a symmetric relationship to all processos and a uniform access time from any processor, these multiprocessors are often called symmetric (shared-memory) multiprocessors ( SMPs), and this style of architecture ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 85
is sometimes called UMA for uniform memory access. This type of centralized sharedmemory architecture is currently by far the most popular organization. The second group consists of multiprocessors with physically distributed memory. To support larger processor counts, memory must be distributed among the processors rather than centralized; otherwise the memory system would not be able to support the bandwidth demands of a larger number of processors without incurring excessively long access latency. With the rapid increase in processor performance and the associated increase in a processors memory bandwidth requirements, the scale of multiprocessor for which distributed memory is preferred over a single, centralized memory continues to decrease in number (which is another reason not to use small and large scale). Of course, the larger number of processors raises the need for a high bandwidth interconnect.
Distributing the memory among the nodes has two major benefits. First, it is a costeffective way to scale the memory bandwidth, if most of the accesses are to the local memory in the node. Second, it reduces the latency for accesses to the local memory. These two advantages make distributed memory attractive at smaller processor counts as processors get ever faster and require more memory bandwidth and lower memory ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 86
latency. The key disadvantage for a distributed memory architecture is that communicating data between processors becomes somewhat more complex and has higher latency, at least when there is no contention, because the processors no longer share a single centralized memory. As we will see shortly, the use of distributed memory leads to two different paradigms for interprocessor communication. Typically, I/O as well as memory is distributed among the nodes of the multiprocessor, and the nodes may be small SMPs (28 processors). Although the use of multiple processors in a node together with a memory and a network interface is quite useful from the cost-efficiency viewpoint.
Challenges for Parallel Processing Limited parallelism available in programs Need new algorithms that can have better parallel performance Suppose you want to achieve a speedup of 80 with 100 processors. What fraction of the original computation can be sequential?
Data Communication Models for Multiprocessors shared memory: access shared address space implicitly via load and store operations. message-passing: done by explicitly passing messages among the processors can invoke software with Remote Procedure Call (RPC) often via library, such as MPI: Message Passing Interface ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 87
also called "Synchronous communication" since communication causes synchronization between 2 processes
Message-Passing Multiprocessor - The address space can consist of multiple private address spaces that are logically disjoint and cannot be addressed by a remote processor - The same physical address on two different processors refers to two different locations in two different memories.
Multicomputer (cluster): - can even consist of completely separate computers connected on a LAN. - cost-effective for applications that require little or no communication
Symmetric Shared-Memory Architectures
Multilevel caches can substantially reduce the memory bandwidth demands of a processor. This is extremely - Cost-effective - This can work as plug in play by placing the processor and cache sub- system on a board into the bus backplane. Developed by IBM One chip multiprocessor AMD and INTEL- Two Processor SUN 8 processor multi core Symmetric shared memory support caching of Shared Data ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 88
Private Data
Private data: used by a single processor When a private item is cached, its location is migrated to the cache Since no other processor uses the data, the program behavior is identical to that in a uniprocessor. Shared data: used by multiple processor When shared data are cached, the shared value may be replicated in multiple caches advantages: reduce access latency and memory contention induces a new problem: cache coherence.
Cache Coherence Unfortunately, caching shared data introduces a new problem because the view of memory held by two different processors is through their individual caches, which, without any additional precautions, could end up seeing two different values. I.e, If two different processors have two different values for the same location, this difficulty is generally referred to as cache coherence problem
Informally: Any read must return the most recent write Too strict and too difficult to implement Better: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 89
Any write must eventually be seen by a read All writes are seen in proper order (serialization) Two rules to ensure this: If P writes x and then P1 reads it, Ps write will be seen by P1 if the read and write are sufficiently far apart Writes to a single location are serialized: seen in one order Latest write will be seen Otherwise could see writes in illogical order (could see older value after a newer value) The definition contains two different aspects of memory system: Coherence Consistency A memory system is coherent if, Program order is preserved. Processor should not continuously read the old data value. Write to the same location are serialized. The above three properties are sufficient to ensure coherence,When a written value will be seen is also important. This issue is defined by memory consistency model. Coherence and consistency are complementary. Basic schemes for enforcing coherence Coherence cache provides: migration: a data item can be moved to a local cache and used there in a transparent fashion. replication for shared data that are being simultaneously read. both are critical to performance in accessing shared data. To over come these problems, adopt a hardware solution by introducing a protocol tomaintain coherent caches named as Cache Coherence Protocols These protocols are implemented for tracking the state of any sharing of a data block. Two classes of Protocols Directory based Snooping based ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 90
Directory based Sharing status of a block of physical memory is kept in one location called the directory. Directory-based coherence has slightly higher implementation overhead than snooping. It can scale to larger processor count.
Snooping Every cache that has a copy of data also has a copy of the sharing status of the block. No centralized state is kept. Caches are also accessible via some broadcast medium (bus or switch) Cache controller monitor or snoop on the medium to determine whether or not they have a copy of a block that is represented on a bus or switch access.
Snooping protocols are popular with multiprocessor and caches attached to single shared memory as they can use the existing physical connection- bus to memory, to interrogate the status of the caches. Snoop based cache coherence scheme is implemented on a shared bus. Any communication medium that broadcasts cache misses to all the processors.
Basic Snoopy Protocols Write strategies Write-through: memory is always up-to-date Write-back: snoop in caches to find most recent copy Write Invalidate Protocol Multiple readers, single writer Write to shared data: an invalidate is sent to all caches which snoop and invalidate any copies Read miss: further read will miss in the cache and fetch a new ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 91
copy of the data. Write Broadcast/Update Protocol (typically write through) Write to shared data: broadcast on bus, processors snoop, and update any copies Read miss: memory/cache is always up-to-date. Write serialization: bus serializes requests! Bus is single point of arbitration
Assume neither cache initially holds X and the value of X in memory is 0
Example Protocol Snooping coherence protocol is usually implemented by incorporating a finitestate controller in each node Logically, think of a separate controller associated with each cache block That is, snooping operations or cache requests for different blocks can proceed independently In implementations, a single controller allows multiple operations to distinct blocks to proceed in interleaved fashion that is, one operation may be initiated before another is completed, even through only one cache access or one bus access is allowed at time
Example Write Back Snoopy Protocol Invalidation protocol, write-back cache Snoops every address on bus If it has a dirty copy of requested block, provides that block in response to the read request and aborts the memory access Each memory block is in one state: Clean in all caches and up-to-date in memory (Shared) ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 93
OR Dirty in exactly one cache (Exclusive) OR Not in any caches Each cache block is in one state (track these): Shared : block can be read OR Exclusive : cache has only copy, its writeable, and dirty OR Invalid : block contains no data (in uniprocessor cache too) Read misses: cause all caches to snoop bus Writes to clean blocks are treated as misses Write-Back State Machine CPU State Transitions for Each Cache Block is as shown below
CPU may read/write hit/miss to the block May place write/read miss on bus May receive read/write miss from bus
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 94
Conclusion End of uniprocessors speedup => Multiprocessors Parallelism challenges: % parallalizable, long latency to remote memory Centralized vs. distributed memory Small MP vs. lower latency, larger BW for Larger MP Message Passing vs. Shared Address Uniform access time vs. Non-uniform access time Snooping cache over shared medium for smaller MP by invalidating other cached copies on write Sharing cached data _ Coherence (values returned by a read), Consistency (when a written value will be returned by a read) Shared medium serializes writes _ Write consistency
Implementation Complications Write Races: Cannot update cache until bus is obtained ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 95
Otherwise, another processor may get bus first, and then write the same cache block! Two step process: Arbitrate for bus Place miss on bus and complete operation If miss occurs to block while waiting for bus, handle miss (invalidate may be needed) and then restart. Split transaction bus: Bus transaction is not atomic: can have multiple outstanding transactions for a block Multiple misses can interleave, allowing two caches to grab block in the Exclusive state Must track and prevent multiple misses for one block Must support interventions and invalidations
Performance Measurement Overall cache performance is a combination of Uniprocessor cache miss traffic Traffic caused by communication invalidation and subsequent cache misses Changing the processor count, cache size, and block size can affect these two components of miss rate Uniprocessor miss rate: compulsory, capacity, conflict Communication miss rate: coherence misses True sharing misses + false sharing misses
True and False Sharing Miss True sharing miss The first write by a PE to a shared cache block causes an invalidation to establish ownership of that block ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 96
When another PE attempts to read a modified word in that cache block, a miss occurs and the resultant block is transferred False sharing miss Occur when a block a block is invalidate (and a subsequent reference causes a miss) because some word in the block, other than the one being read, is written to The block is shared, but no word in the cache is actually shared, and this miss would not occur if the block size were a single word Assume that words x1 and x2 are in the same cache block, which is in the shared state in the caches of P1 and P2. Assuming the following sequence of events, identify each miss as a true sharing miss or a false sharing miss.
Example Result True sharing miss (invalidate P2) 2: False sharing miss x2 was invalidated by the write of P1, but that value of x1 is not used in P2 3: False sharing miss The block containing x1 is marked shared due to the read in P2, but P2 did not read x1. A write miss is required to obtain exclusive access to the block ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 97
4: False sharing miss 5: True sharing miss
Distributed Shared-Memory Architectures Distributed shared-memory architectures Separate memory per processor Local or remote access via memory controller The physical address space is statically distributed Coherence Problems Simple approach: uncacheable shared data are marked as uncacheable and only private data are kept in caches very long latency to access memory for shared data Alternative: directory for memory blocks The directory per memory tracks state of every block in every cache which caches have a copies of the memory block, dirty vs. clean, ... Two additional complications The interconnect cannot be used as a single point of arbitration like the bus Because the interconnect is message oriented, many messages must have explicit responses
To prevent directory becoming the bottleneck, we distribute directory entries with ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 98
memory, each keeping track of which processors have copies of their memory blocks
Directory Protocols Similar to Snoopy Protocol: Three states Shared: 1 or more processors have the block cached, and the value in memory is up-to-date (as well as in all the caches) Uncached: no processor has a copy of the cache block (not valid in any cache) Exclusive: Exactly one processor has a copy of the cache block, and it has written the block, so the memory copy is out of date The processor is called the owner of the block In addition to tracking the state of each cache block, we must track the processors that have copies of the block when it is shared (usually a bit vector for each memory block: 1 if processor has copy) Keep it simple(r): Writes to non-exclusive data => write miss Processor blocks until access completes Assume messages received and acted upon in order sent
local node: the node where a request originates home node: the node where the memory location and directory entry of an address ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 99
reside remote node: the node that has a copy of a cache block (exclusive or shared)
Comparing to snooping protocols: identical states stimulus is almost identical write a shared cache block is treated as a write miss (without fetch the block) cache block must be in exclusive state when it is written any shared block must be up to date in memory write miss: data fetch and selective invalidate operations sent by the directory ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 100
controller (broadcast in snooping protocols)
Directory Operations: Requests and Actions Message sent to directory causes two actions: Update the directory More messages to satisfy request Block is in Uncached state: the copy in memory is the current value; only possible requests for that block are: Read miss: requesting processor sent data from memory &requestor made only sharing node; state of block made Shared. Write miss: requesting processor is sent the value & becomes the Sharing node. The block is made Exclusive to indicate that the only valid copy is cached. Sharers indicates the identity of the owner. Block is Shared => the memory value is up-to-date: Read miss: requesting processor is sent back the data from memory & requesting processor is added to the sharing set. Write miss: requesting processor is sent the value. All processors in the set Sharers are sent invalidate messages, & Sharers is set to identity of requesting processor. The state of the block is made Exclusive. Block is Exclusive: current value of the block is held in the cache of the processor identified by the set Sharers (the owner) => three possible directory requests: Read miss: owner processor sent data fetch message, causing state of block in owners cache to transition to Shared and causes owner to send data to directory, where it is written to memory & sent back to requesting processor. Identity of requesting processor is added to set Sharers, which still contains the identity of the processor that was the owner (since it still has a readable copy). State is shared. Data write-back: owner processor is replacing the block and hence must write it back, making memory copy up-to-date (the home directory essentially becomes the owner), the block is now Uncached, and the Sharer set is empty. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 101
Write miss: block has a new owner. A message is sent to old owner causing the cache to send the value of the block to the directory from which it is sent to the requesting processor, which becomes the new owner. Sharers is set to identity of new owner, and state of block is made Exclusive.
Synchronization: The Basics Synchronization mechanisms are typically built with user-level software routines that rely on hardware supplied synchronization instructions. Why Synchronize? Need to know when it is safe for different processes to use shared data Issues for Synchronization: Uninterruptable instruction to fetch and update memory (atomic operation); User level synchronization operation using this primitive; For large scale MPs, synchronization can be a bottleneck; techniques to reduce contention and latency of synchronization
Uninterruptable Instruction to Fetch and Update Memory Atomic exchange: interchange a value in a register for a value in memory 0 _ synchronization variable is free 1 _ synchronization variable is locked and unavailable Set register to 1 & swap New value in register determines success in getting lock 0 if you succeeded in setting the lock (you were first) 1 if other processor had already claimed access Key is that exchange operation is indivisible Test-and-set: tests a value and sets it if the value passes the test Fetch-and-increment: it returns the value of a memory location and atomically increments it 0 _ synchronization variable is free Hard to have read & write in 1 instruction: use 2 instead ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 102
Load linked (or load locked) + store conditional Load linked returns the initial value Store conditional returns 1 if it succeeds (no other store to same memory location since preceding load) and 0 otherwise Example doing atomic swap with LL & SC: try: mov R3,R4 ; mov exchange value
ll R2,0(R1) ; load linked sc R3,0(R1) ; store conditional beqz R3,try ; branch store fails (R3 = 0) mov R4,R2 ; put load value in R4
Example doing fetch & increment with LL & SC: try: ll R2,0(R1) ; load linked addi R2,R2,#1 ; increment (OK if regreg) sc R2,0(R1) ; store conditional beqz R2,try ; branch store fails (R2 = 0)
User Level SynchronizationOperation Using this Primitive Spin locks: processor continuously tries to acquire, spinning around a loop trying to get the lock li R2,#1 lockit: exch R2,0(R1) ; atomic exchange bnez R2,lockit ; already locked? What about MP with cache coherency? Want to spin on cache copy to avoid full memory latency Likely to get cache hits for such variables Problem: exchange includes a write, which invalidates all other copies; this generates considerable bus traffic Solution: start by simply repeatedly reading the variable; when it changes, then ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 103
try exchange (test and test&set): try: li R2,#1 lockit: lw R3,0(R1) ;load var bnez R3,lockit ; _ 0 _ not free _ spin exch R2,0(R1) ; atomic exchange bnez R2,try ; already locked?
Memory Consistency Models What is consistency? When must a processor see the new value? e.g., seems that P1: A = 0; P2: B = 0; ..... ..... A = 1; B = 1; L1: if (B == 0) ... L2: if (A == 0) ... Impossible for both if statements L1 & L2 to be true? What if write invalidate is delayed & processor continues? Memory consistency models: what are the rules for such cases? Sequential consistency: result of any execution is the same as if the accesses of each processor were kept in order and the accesses among different processors were interleaved _ assignments before ifs above SC: delay all memory accesses until all invalidates done Schemes faster execution to sequential consistency Not an issue for most programs; they are synchronized A program is synchronized if all access to shared data are ordered by synchronization operations write (x) ... release (s) {unlock} ... acquire (s) {lock} ... ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 104
read(x) Only those programs willing to be nondeterministic are not synchronized: data race: outcome f(proc. speed) Several Relaxed Models for Memory Consistency since most programs are synchronized; characterized by their attitude towards: RAR, WAR, RAW, WAW to different addresses
Relaxed Consistency Models: The Basics Key idea: allow reads and writes to complete out of order, but to use synchronization operations to enforce ordering, so that a synchronized program behaves as if the processor were sequentially consistent By relaxing orderings, may obtain performance advantages Also specifies range of legal compiler optimizations on shared data Unless synchronization points are clearly defined and programs are synchronized, compiler could not interchange read and write of 2 shared data items because might affect the semantics of the program 3 major sets of relaxed orderings: 1. W_R ordering (all writes completed before next read) Because retains ordering among writes, many programs that operate under sequential consistency operate under this model, without additional synchronization. Called processor consistency 2. W _ W ordering (all writes completed before next write) 3. R _ W and R _ R orderings, a variety of models depending on ordering restrictions and how synchronization operations enforce ordering Many complexities in relaxed consistency models; defining precisely what it means for a write to complete; deciding when processors can see values that it has written
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 105
UNIT VI
REVIEW OF MEMORY HIERARCHY
Unlimited amount of fast memory - Economical solution is memory hierarchy - Locality - Cost performance Principle of locality - Most programs do not access all code or data uniformly. Locality occurs - Time (Temporal locality) - Space (spatial locality) Guidelines ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 106
Smaller hardware can be made faster Different speed and sizes
Goal is provide a memory system with cost per byte than the next lower level Each level maps addresses from a slower, larger memory to a smaller but faster memory higher in the hierarchy. Address mapping Address checking. Hence protection scheme for address for scrutinizing addresses are also part of the memory hierarchy.
Why More on Memory Hierarchy? ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 107
The importance of memory hierarchy has increased with advances in performance of processors.
Prototype ` When a word is not found in cache Fetched from memory and placed in cache with the address tag. Multiple words( block) is fetched for moved for efficiency reasons. key design Set associative Set is a group of block in the cache. Block is first mapped on to set. Find mapping Searching the set Chosen by the address of the data: (Block address) MOD(Number of sets in cache) n-block in a set Cache replacement is called n-way set associative. Cache data - Cache read. - Cache write. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 108
Write through: update cache and writes through to update memory. Both strategies - Use write buffer. this allows the cache to proceed as soon as the data is placed in the buffer rather than wait the full latency to write the data into memory. Metric used to measure the benefits is miss rate No of access that miss No of accesses Write back: updates the copy in the cache. Causes of high miss rates Three Cs model sorts all misses into three categories Compulsory: every first access cannot be in cache Compulsory misses are those that occur if there is an infinite cache Capacity: cache cannot contain all that blocks that are needed for the program. As blocks are being discarded and later retrieved. Conflict: block placement strategy is not fully associative Block miss if blocks map to its set.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 109
Miss rate can be a misleading measure for several reasons So, misses per instruction can be used per memory reference
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 110
Cache Optimizations Six basic cache optimizations 1. Larger block size to reduce miss rate: - To reduce miss rate through spatial locality. - Increase block size. - Larger block size reduce compulsory misses. - But they increase the miss penalty. 2. Bigger caches to reduce miss rate: - capacity misses can be reduced by increasing the cache capacity. - Increases larger hit time for larger cache memory and higher cost and power. 3. Higher associativity to reduce miss rate: - Increase in associativity reduces conflict misses. 4. Multilevel caches to reduce penalty: - Introduces additional level cache - Between original cache and memory. - L1- original cache L2- added cache. L1 cache: - small enough - speed matches with clock cycle time. L2 cache: - large enough - capture many access that would go to main memory. Average access time can be redefined as Hit timeL1+ Miss rate L1 X ( Hit time L2 + Miss rate L2 X Miss penalty L2) 5. Giving priority to read misses over writes to reduce miss penalty: - write buffer is a good place to implement this optimization. - write buffer creates hazards: read after write hazard. 6. Avoiding address translation during indexing of the cache to reduce hit time: - Caches must cope with the translation of a virtual address from the processor to a physical address to access memory. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 111
- common optimization is to use the page offset. - part that is identical in both virtual and physical addresses- to index the cache.
Advanced Cache Optimizations Reducing hit time Small and simple caches Way prediction Trace caches Increasing cache bandwidth Pipelined caches Multibanked caches Nonblocking caches Reducing Miss Penalty Critical word first Merging write buffers Reducing Miss Rate Compiler optimizations Reducing miss penalty or miss rate via parallelism Hardware prefetching Compiler prefetching
First Optimization : Small and Simple Caches Index tag memory and then compare takes time _ Small cache can help hit time since smaller memory takes less time to index E.g., L1 caches same size for 3 generations of AMD microprocessors: K6, Athlon, and Opteron Also L2 cache small enough to fit on chip with the processor avoids time penalty of going off chip Simple _ direct mapping Can overlap tag check with data transmission since no choice ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 112
Access time estimate for 90 nm using CACTI model 4.0 Median ratios of access time relative to the direct-mapped caches are 1.32, 1.39, and 1.43 for 2-way, 4-way, and 8-way caches
Second Optimization: Way Prediction How to combine fast hit time of Direct Mapped and have the lower conflict misses of 2-way SA cache? Way prediction: keep extra bits in cache to predict the way, or block within the set, of next cache access.
Multiplexer is set early to select desired block, only 1 tag comparison performed that clock cycle in parallel with reading the cache data
Miss _ 1st check other blocks for matches in next clock cycle Accuracy 85% Drawback: CPU pipeline is hard if hit takes 1 or 2 cycles - Used for instruction caches vs. data caches
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 113
Third optimization: Trace Cache Find more instruction level parallelism? How to avoid translation from x86 to microops? Trace cache in Pentium 4 1. Dynamic traces of the executed instructions vs. static sequences of instructions as determined by layout in memory Built-in branch predictor 2. Cache the micro-ops vs. x86 instructions Decode/translate from x86 to micro-ops on trace cache miss + 1. _ better utilize long blocks (dont exit in middle of block, dont enter at label in middle of block) - 1. _ complicated address mapping since addresses no longer aligned to powerof- 2 multiples of word size - 1. _ instructions may appear multiple times in multiple dynamic traces due to different branch outcomes
Fourth optimization: pipelined cache access to increase bandwidth Pipeline cache access to maintain bandwidth, but higher latency Instruction cache access pipeline stages: 1: Pentium 2: Pentium Pro through Pentium III 4: Pentium 4 - _ greater penalty on mispredicted branches - _ more clock cycles between the issue of the load and the use of the data
Fifth optimization: Increasing Cache Bandwidth Non-Blocking Caches Non-blocking cache or lockup-free cache allow data cache to continue to supply cache hits during a miss requires F/E bits on registers or out-of-order execution requires multi-bank memories ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 114
hit under miss reduces the effective miss penalty by working during miss vs. ignoring CPU requests hit under multiple miss or miss under miss may further lower the effective miss penalty by overlapping multiple misses Significantly increases the complexity of the cache controller as there can be multiple outstanding memory accesses Requires multiple memory banks (otherwise cannot support) Pentium Pro allows 4 outstanding memory misses
Value of Hit Under Miss for SPEC
FP programs on average: AMAT= 0.68 -> 0.52 -> 0.34 -> 0.26 Int programs on average: AMAT= 0.24 -> 0.20 -> 0.19 -> 0.19 8 KB Data Cache, Direct Mapped, 32B block, 16 cycle miss, SPEC 92 ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 115
Sixth optimization: Increasing Cache Bandwidth via Multiple Banks
Rather than treat the cache as a single monolithic block, divide into independent banks that can support simultaneous accesses E.g.,T1 (Niagara) L2 has 4 banks Banking works best when accesses naturally spread themselves across banks _ mapping of addresses to banks affects behavior of memory system Simple mapping that works well is sequential interleaving Spread block addresses sequentially across banks E,g, if there 4 banks, Bank 0 has all blocks whose address modulo 4 is 0; bank 1 has all blocks whose address modulo 4 is 1;
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 116
Seventh optimization: Reduce Miss Penalty: Early Restart and Critical Word First Dont wait for full block before restarting CPU Early restartAs soon as the requested word of the block arrives, send it to the CPU and let the CPU continue execution Spatial locality _ tend to want next sequential word, so not clear size of benefit of just early restart Critical Word FirstRequest the missed word first from memory and send it to the CPU as soon as it arrives; let the CPU continue execution while filling the rest of the words in the block Long blocks more popular today _ Critical Word 1st Widely used
Eight optimization: Merging Write Buffer to Reduce Miss Penalty-
Write buffer to allow processor to continue while waiting to write to memory If buffer contains modified blocks, the addresses can be checked to see if address of new data matches the address of a valid write buffer entry If so, new data are combined with that entry Increases block size of write for write-through cache of writes to sequential words, bytes since multiword writes more efficient to memory The Sun T1 (Niagara) processor, among many others, uses write merging ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 117
Ninth optimization: Reducing Misses by Compiler Optimizations McFarling [1989] reduced caches misses by 75% on 8KB direct mapped cache, 4 byte blocks in software Instructions Reorder procedures in memory so as to reduce conflict misses Profiling to look at conflicts (using tools they developed) Data Merging Arrays: improve spatial locality by single array of compound elements vs. 2 arrays Loop Interchange: change nesting of loops to access data in order stored in memory Loop Fusion: Combine 2 independent loops that have same looping and some variables overlap Blocking: Improve temporal locality by accessing blocks of data repeatedly vs. going down whole columns or rows
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 118
Merging Arrays Example /* Before: 2 sequential arrays */ int val[SIZE]; int key[SIZE]; /* After: 1 array of stuctures */ struct merge { int val; int key; }; struct merge merged_array[SIZE]; Reducing conflicts between val & key; improve spatial locality
Conflict misses in caches not FA vs. Blocking size Lam et al [1991] a blocking factor of 24 had a fifth the misses vs. 48 despite both fit in cache
Tenth optimization Reducing Misses by Hardware Prefetching of Instructions & Data ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 119
Prefetching relies on having extra memory bandwidth that can be used without penalty Instruction Prefetching Typically, CPU fetches 2 blocks on a miss: the requested block and the next consecutive block. Requested block is placed in instruction cache when it returns, and prefetched block is placed into instruction stream buffer Data Prefetching Pentium 4 can prefetch data into L2 cache from up to 8 streams from 8 different 4 KB pages Prefetching invoked if 2 successive L2 cache misses to a page, if distance between those cache blocks is < 256 bytes
Eleventh optimization: Reducing Misses by Software Prefetching Data Data Prefetch Load data into register (HP PA-RISC loads) Cache Prefetch: load into cache (MIPS IV, PowerPC, SPARC v. 9) Special prefetching instructions cannot cause faults; a form of speculative execution Issuing Prefetch Instructions takes time ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 120
Is cost of prefetch issues < savings in reduced misses? Higher superscalar reduces difficulty of issue bandwidth The techniques to improve hit time, bandwidth, miss penalty and miss rate generally affect the other components of the average memory access equation as well as the complexity of the memory hierarchy.
MEMORY HIERARCHY DESIGN
AMAT and Processor Performance AMAT = Average Memory Access Time Miss-oriented Approach to Memory Access CPIExec includes ALU and Memory instructions Separating out Memory component entirely CPIALUOps does not include memory instructions
Summary: Caches The Principle of Locality: Program access a relatively small portion of the address space at any instant of time. Temporal Locality OR Spatial Locality: Three Major Categories of Cache Misses: Compulsory Misses: sad facts of life. Example: cold start misses. Capacity Misses: increase cache size Conflict Misses: increase cache size and/or associativity
Where Misses Come From? Classifying Misses: 3 Cs Compulsory The first access to a block is not in the cache, Also called cold start misses or first reference misses. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 121
(Misses in even an Infinite Cache) Capacity If the cache cannot contain all the blocks needed during execution of a program, Conflict If block-placement strategy is set associative or direct mapped, conflict misses (in addition to compulsory & capacity misses) will occur because a block can be discarded and later retrieved if too many blocks map to its set. (Misses in N-way Associative, Size X Cache) More recent, 4th C: Coherence Misses caused by cache coherence
Write Policy: Write Through: needs a write buffer. Write Back: control can be complex ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 122
Summary: The Cache Design Space Several interacting dimensions cache size block size associativity replacement policy write-through vs write-back The optimal choice is a compromise Simplicity often wins
Cache Organization? Assume total cache size not changed
What happens if: Which of 3Cs is obviously affected? Change Block Size Change Cache Size Change Cache Internal Organization Change Associativity Change Compiler
Cache Optimization Summary
How to Improve Cache Performance? Cache optimizations 1. Reduce the miss rate 2. Reduce the miss penalty 3. Reduce the time to hit in the cache ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 123
Cache Optimisation Why improve Cache performance:
Review: 6 Basic Cache Optimizations Reducing hit time 1.Address Translation during Cache Indexing Reducing Miss Penalty 2. Multilevel Caches 3. Giving priority to read misses over write misses Reducing Miss Rate 4. Larger Block size (Compulsory misses) 5. Larger Cache size (Capacity misses) 6. Higher Associativity (Conflict misses)
11 Advanced Cache Optimizations Reducing hit time 1. Small and simple caches 2. Way prediction 3. Trace caches ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 124
Increasing cache bandwidth 4. Pipelined caches 5. Multibanked caches 6. Nonblocking caches Reducing Miss Penalty 7. Critical word first 8. Merging write buffers Reducing Miss Rate 9.Compiler optimizations Reducing miss penalty or miss rate via parallelism 10.Hardware prefetching 11.Compiler prefetching
1. Fast Hit times via Small and Simple Caches Index tag memory and then compare takes time Small cache can help hit time since smaller memory takes less time to index E.g., L1 caches same size for 3 generations of AMD icroprocessors: K6, Athlon, and Opteron Also L2 cache small enough to fit on chip with the processor avoids time penalty of going off chip Simple direct mapping Can overlap tag check with data transmission since no choice 2. Fast Hit times via Way Prediction How to combine fast hit time of Direct Mapped and have the lower conflict misses of 2-way SA cache? Way prediction: keep extra bits in cache to predict the way, or block within the set, ofnext cache access. Multiplexer is set early to select desired block, only 1 tag comparison performed that clock cycle in parallel with reading the cache data Miss - 1st check other blocks for matches in next clock cycle ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 125
3. Fast Hit times via Trace Cache Find more instruction level parallelism? How avoid translation from x86 to microops?- Trace cache in Pentium 4 1. Dynamic traces of the executed instructions vs. static sequence of instructions as determined by layout in memory Built-in branch predictor 2. Cache the micro-ops vs. x86 instructions - Decode/translate from x86 to micro-ops on trace cache miss + 1. better utilize long blocks (dont exit in middle of block, dont enter at label in middle of block) - 1. complicated address mapping since addresses no longer aligned to power-of-2 multiples of word size - 1. instructions may appear multiple times in multiple dynamic traces due to different branch outcomes
4: Increasing Cache Bandwidth by Pipelining Pipeline cache access to maintain bandwidth, but higher latency Instruction cache access pipeline stages: 1: Pentium 2: Pentium Pro through Pentium III 4: Pentium 4 - greater penalty on mispredicted branches - more clock cycles between the issue of the load and the use of the data
5. Increasing Cache Bandwidth: Non-Blocking Caches- Reduce Misses/Penalty Non-blocking cache or lockup-free cache allow data cache to continue to supply cache hits during a m iss requires F/E bits on registers or out-of-order execution ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 126
requires multi-bank memories hit under miss reduces the effective miss penalty by working during miss vs. ignoring CPU requests hit under multiple miss or miss under miss may further lower the effective miss penalty by overlapping multiple misses Significantly increases the complexity of the cache controller as there can be multiple outstanding memory accesses Requires muliple memory banks (otherwise cannot support) Penium Pro allows 4 outstanding memory misses
6: Increasing Cache Bandwidth via Multiple Banks Rather than treat the cache as a single monolithic block, divide into independent banks that can support simultaneous accesses E.g.,T1 (Niagara) L2 has 4 banks Banking works best when accesses naturally spread themselves across banks I mapping of addresses to banks affects behavior of memory system
Simple mapping that works well is sequential interleaving Spread block addresses sequentially across banks E,g, if there 4 banks, Bank 0 has all blocks whose address modulo 4 is 0; bank 1 has all blocks whose address modulo 4 is 1; . ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 127
7. Reduce Miss Penalty: Early Restart and Critical Word First Dont wait for full block before restarting CPU Early restartAs soon as the requested word of the block arrives, send it to the CPU and let the CPU continue execution Spatial locality - tend to want next sequential word, so not clear size of benefit of just early restart Critical Word FirstRequest the missed word first from memory and send it to the CPU as soon as it arrives; let the CPU continue execution while filling the rest of the words in the block
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 128
8. Merging Write Buffer to Reduce Miss Penalty Write buffer to allow processor to continue while waiting to write to memory If buffer contains modified blocks, the addresses can be checked to see if address of new data matches the address of a valid write buffer entry -If so, new data are combined with that entry Increases block size of write for write-through cache of writes to sequential words, bytes since multiword writes more efficient to memory The Sun T1 (Niagara) processor, among many others, uses write merging
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 129
9. Reducing Misses by Compiler Optimizations McFarling [1989] reduced caches misses by 75% on 8KB direct mapped cache, 4 byte blocks in software Instructions Reorder procedures in memory so as to reduce conflict misses Profiling to look at conflicts (using tools they developed) Data Merging Arrays: improve spatial locality by single array of compound elements vs. 2 arrays Loop Interchange: change nesting of loops to access data in order stored in memory Loop Fusion: Combine 2 independent loops that have same looping and some variables overlap Blocking: Improve temporal locality by accessing blocks of data repeatedly vs. going down whole columns or rows Compiler Optimizations- Reduction comes from software (no Hw ch.) Loop Interchange ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 130
Motivation: some programs have nested loops that access data in nonsequential order Solution: Simply exchanging the nesting of the loops can make the code access the data in the order it is stored => reduce misses by improving spatial locality; reordering maximizes use of data in a cache block before it is discarded Loop Interchange Example /* Before */ for (j = 0; j < 100; j = j+1) for (i = 0; i < 5000; i = i+1) x[i][j] = 2 * x[i][j]; /* After */ for (i = 0; i < 5000; i = i+1) for (j = 0; j < 100; j = j+1) x[i][j] = 2 * x[i][j]; Blocking Motivation: multiple arrays, some accessed by rows and some by columns Storing the arrays row by row (row major order) or column by column (column major order) does not help: both rows and columns are used in every iteration of the loop (Loop Interchange cannot help) Solution: instead of operating on entire rows and columns of an array, blocked algorithms operate on submatrices or blocks => maximize accesses to the data loaded into the cache before the data is replaced
Blocking Example /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) {r = 0; for (k = 0; k < N; k = k+1){ r = r + y[i][k]*z[k][j];}; x[i][j] = r; ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 131
}; /* After */ for (jj = 0; jj < N; jj = jj+B) for (kk = 0; kk < N; kk = kk+B) for (i = 0; i < N; i = i+1) for (j = jj; j < min(jj+B,N); j = j+1) {r = 0; for (k = kk; k < min(kk+B,N); k = k + 1) r = r + y[i][k]*z[k][j]; x[i][j] = x[i][j] + r; }; Snapshot of x, y, z when i=1 White:
White: not yet touched Light: older access Dark: newer access Before. The Age of Accesses to x, y, Z
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 132
Merging Arrays Motivation: some programs reference multiple arrays in the same dimension with the same indices at the same time => these accesses can interfere with each other,leading to conflict misses Solution: combine these independent matrices into a single compound array, so that a single cache block can contain the desired elements Merging Arrays Example
Loop Fusion Some programs have separate sections of code that access with the same loops, performing different computations on the common data Solution: Fuse the code into a single loop => the data that are fetched into the cache can be used repeatedly before being swapped out => reducing misses via improved temporal locality
Loop Fusion Example Summary of Compiler Optimizations- to Reduce Cache Misses (by hand)
10. Reducing Misses by Hardware Prefetching of Instructions & Data Prefetching relies on having extra memory bandwidth that can be used without penalty ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 133
Instruction Prefetching Typically, CPU fetches 2 blocks on a miss: the requested block and the next consecutive block. Requested block is placed in instruction cache when it returns, and prefetched block is placed into instruction stream buffer
Data Prefetching Pentium 4 can prefetch data into L2 cache from up to 8 streams from 8 different 4 KB pages Prefetching invoked if 2 successive L2 cache misses to a page,if distance between those cache blocks is < 256 bytes
11. Reducing Misses by Software Prefetching Data Data Prefetch Load data into register (HP PA-RISC loads) Cache Prefetch: load into cache (MIPS IV, PowerPC, SPARC v. 9) Special prefetching instructions cannot cause faults; a form of speculative execution Issuing Prefetch Instructions takes time Is cost of prefetch issues < savings in reduced misses? Higher superscalar reduces difficulty of issue bandwi
Compiler Optimization vs. Memory Hierarchy Search Compiler tries to figure out memory hierarchy optimizations New approach: Auto-tuners 1st run variations of program on computer to find best combinations of optimizations (blocking, padding, ) and algorithms, then produce C code to be compiled for that computer Auto-tuner targeted to numerical method E.g., PHiPAC (BLAS), Atlas (BLAS), Sparsity (Sparse linear algebra), Spiral (DSP), FFT-W ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 134
Cache Optimization Summary Comparison of the 11 techniques
Main Memory Background Performance of Main Memory: Latency: Cache Miss Penalty Access Time: time between request and word arrives Cycle Time: time between requests Bandwidth: I/O & Large Block Miss Penalty (L2) Main Memory is DRAM: Dynamic Random Access Memory Dynamic since needs to be refreshed periodically (8 ms, 1% time) Addresses divided into 2 halves (Memory as a 2D matrix): RAS or Row Access Strobe CAS or Column Access Strobe Cache uses SRAM: Static Random Access Memory No refresh (6 transistors/bit vs. 1 transistor ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 135
Size: DRAM/SRAM - 4-8, Cost/Cycle time: SRAM/DRAM - 8-16 Main Memory Deep Background Out-of-Core, In-Core, Core Dump? Core memory? Non-volatile, magnetic Lost to 4 Kbit DRAM (today using 512Mbit DRAM) Access time 750 ns, cycle time 1500-3000 ns DRAM logical organization (4 Mbit) Quest for DRAM Performance 1. Fast Page mode Add timing signals that allow repeated accesses to row buffer without nother row access time Such a buffer comes naturally, as each array will buffer 1024 to 2048 bits for each access 2. Synchronous DRAM (SDRAM) Add a clock signal to DRAM interface, so that the repeated transfers would not bear overhead to synchronize with DRAM controller 3. Double Data Rate (DDR SDRAM) Transfer data on both the rising edge and falling edge of the DRAM clock signal I doubling the peak data rate DDR2 lowers power by dropping the voltage from 2.5 to 1.8 volts + offers higher clock rates: up to 400 MHz DDR3 drops to 1.5 volts + higher clock rates: up to 800 MHz 4.Improved Bandwidth, not Latency DRAM name based on Peak Chip Transfers / Sec DIMM name based on Peak DIMM MBytes / Sec Need for Error Correction! Motivation: Failures/time proportional to number of bits! As DRAM cells shrink, more vulnerable ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 136
Went through period in which failure rate was low enough without error correction that people didnt do correction DRAM banks too large now Servers always corrected memory systems Basic idea: add redundancy through parity bits Common configuration: Random error correction SEC-DED (single error correct, double error detect) One example: 64 data bits + 8 parity bits (11% overhead) Really want to handle failures of physical components as well Organization is multiple DRAMs/DIMM, multiple DIMMs Want to recover from failed DRAM and failed DIMM! Chip kill handle failures width of single DRAM chip
DRAM Technology Semiconductor Dynamic Random Access Memory Emphasize on cost per bit and capacity Multiplex address lines cutting # of address pins in half Row access strobe (RAS) first, then column access strobe (CAS) Memory as a 2D matrix rows go to a buffer Subsequent CAS selects subrow Use only a single transistor to store a bit Reading that bit can destroy the information Refresh each bit periodically (ex. 8 milliseconds) by writing back Keep refreshing time less than 5% of the total time DRAM capacity is 4 to 8 times that of SRAM DIMM: Dual inline memory module DRAM chips are commonly sold on small boards called DIMMs DIMMs typically contain 4 to 16 DRAMs Slowing down in DRAM capacity growth Four times the capacity every three years, for more than 20 years New chips only double capacity every two year, since 1998 ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 137
DRAM performance is growing at a slower rate RAS (related to latency): 5% per year CAS (related to bandwidth): 10%+ per year
RAS improvement SRAM Technology Cache uses SRAM: Static Random Access Memory SRAM uses six transistors per bit to prevent the information from being disturbed when read _no need to refresh SRAM needs only minimal power to retain the charge in the standby mode _ good for embedded applications No difference between access time and cycle time for SRAM Emphasize on speed and capacity SRAM address lines are not multiplexed SRAM speed is 8 to 16x that of DRAM Improving Memory Performance in a Standard DRAM Chip Fast page mode: time signals that allow repeated accesses to buffer without another row access time Synchronous RAM (SDRAM): add a clock signal to DRAM interface, so that the repeated transfer would not bear overhead to synchronize with the controller Asynchronous DRAM involves overhead to sync with controller Peak speed per memory module 8001200MB/sec in 2001 Double data rate (DDR): transfer data on both the rising edge and falling edge of DRAM clock signal Peak speed per memory module 16002400MB/sec in 2001
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 138
Protection: Virtual Memory and Virtual Machines Slide Sources: Based on Computer Architecture by Hennessy/Patterson. Supplemented from various freely downloadable sources Security and Privacy Innovations in Computer Architecture and System software Protection through Virtual Memory Protection from Virtual Machines Architectural requirements Performance Protection via Virtual Memory Processes Running program Environment (state) needed to continue running it Protect Processes from each other Page based virtual memory including TLB which caches page table entries Example: Segmentation and paging in 80x86 Processes share hardware without interfering with each other Provide User Process and Kernel Process ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 139
Readable portion of Processor state: User supervisor mode bit Exception enable/disable bit Memory protection information System call to transfer to supervisor mode Return like normal subroutine to user mode Mechanism to limit memory access Memory protection Virtual Memory Restriction on each page entry in page table Read, write, execute privileges Only OS can update page table TLB entries also have protection field Bugs in OS Lead to compromising security Bugs likely due to huge size of OS code Protection via Virtual Machines Virtualization Goal: Run multiple instances of different OS on the same hardware Present a transparent view of one or more environments (M-to-N mapping of M real resources, N virtual resources) Protection via Virtual Machines Virtualization- cont. Challenges: Have to split all resources (processor, memory, hard drive, graphics card, networking card etc.) among the different OS -> virtualize the resources The OS can not be aware that it is using virtual resources instead of real resources
Problems with virtualization ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 140
Two components when using virtualization: Virtual Machine Monitor (VMM) Virtual Machine(s) (VM) Para-virtualization: Operating System has been modified in order to run as a VM Fully Virtualized: No modification required of an OS to run as a VM
Virtual Machine Monitor-hypervisor Isolates the state of each guest OS from each other Protects itself from guest software Determines how to map virtual resources to physical resources Access to privileged state Address translation I/O Exceptions and interrupts Relatively small code ( compared to an OS) VMM must run in a higher privilege mode than guest OS Managing Virtual Memory Virtual memory offers many of the features required for hardware virtualization Separates the physical memory onto multiple processes Each process thinks it has a linear address space of full size Processor holds a page table translating virtual addresses used by a process and the according physical memory Additional information restricts processes from Reading a page of on another process or Allow reading but not modifying a memory page or Do not allow to interpret data in the memory page as instructions and do not try to execute them Virtual Memory management thus requires Mechanisms to limit memory access to protected memory ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 141
At least two modes of execution for instructions Privileged mode: an instruction is allowed to do what it whatever it wants -> kernel mode for OS Non-privileged mode: user-level processes Intel x86 Architecture: processor supports four levels Level 0 used by OS Level 3 used by regular applications Provide mechanisms to go from non-privileged mode to privileged mode -> system call Provide a portion of processor state that a user process can read but not modify E.g. memory protection information Each guest OS maintains its page tables to do the mapping from virtual address to physical address Most simple solution: VMM holds an additional table which maps the physical address of a guest OS onto the machine address Introduces a third level of redirection for every memory access Alternative solution: VMM maintains a shadow page table of each guest OS Copy of the page table of the OS Page tables still works with regular physical addresses Only modifications to the page table are intercepted by the VMM
Protection via Virtual Machines -some definitions VMs include all emulation methods to provide a standard software interface Different ISAs can be used (emulated) on the native machine When the ISAs match the hardware we call it (operating) system virtual machines Multiple OSes all share the native hardware
Cost of Processor Virtualisation VM is much smaller than traditional OS ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 142
Isolation portion is only about 10000 lines for a VMM Processor bound programs have very little virtualisation overhead I/O bound jobs have more overhead ISA emulation is costly
Other benefits of VMs Managing software Complete software stack Old Oses like DOS Current stable OS Next OS release Managing Hardware Multiple servers avoided VMs enable hardware sharing Migration of a running VM to another m/c For balancing load or evacuate from failing HW Requirements of a VMM Guest sw should behave exactly on VM as if on native hw Guest sw should not be able to change allocation of RT resources directly Timer interrupts should be virtualised Two processor modes- system and user Priveleged subset of instruction available only in system mode
More issues on VM usage ISA support for virtual machine IBM360 support 80x86 do no support Use of virtual memory ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 143
Concept of virtual- real- physical memories Instead of extra indirection use shadow page table Virtualising I/Os More i/o More diversity Physical disks to partitioned virtual disks Network cards time sliced
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 144
UNIT IV
HARDWARE AND SOFTWARE FOR VLIW AND EPIC
Loop Level Parallelism- Detection and Enhancement
Static Exploitation of ILP Use compiler support for increasing parallelism Supported by hardware Techniques for eliminating some types of dependences Applied at compile time (no run time support) Finding parallelism Reducing control and data dependencies Using speculation Unrolling Loops High-level for (i=1000; i>0; i=i-1) x[i] = x[i] + s; C equivalent of unrolling to block four iterations into one: for (i=250; i>0; i=i-1) { x[4*i] = x[4*i] + s; x[4*i-1] = x[4*i-1] + s; x[4*i-2] = x[4*i-2] + s; x[4*i-3] = x[4*i-3] + s; } Enhancing Loop-Level Parallelism Consider the previous running example: for (i=1000; i>0; i=i-1) x[i] = x[i] + s; there is no loop-carried dependence where data used in a later iteration depends on data produced in an earlier one in other words, all iterations could (conceptually) be executed in parallel ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 145
Contrast with the following loop: for (i=1; i<=100; i=i+1) { A[i+1] = A[i] + C[i]; /* S1 */ B[i+1] = B[i] + A[i+1]; /* S2 */ } what are the dependences? A Loop with Dependences For the loop: for (i=1; i<=100; i=i+1) { A[i+1] = A[i] + C[i]; /* S1 */ B[i+1] = B[i] + A[i+1]; /* S2 */ }
what are the dependences? There are two different dependences: loop-carried: (prevents parallel operation of iterations) S1 computes A[i+1] using value of A[i] computed in previous iteration S2 computes B[i+1] using value of B[i] computed in previous iteration not loop-carried: (parallel operation of iterations is ok) S2 uses the value A[i+1] computed by S1 in the same iteration The loop-carried dependences in this case force successive iterations of the loop to execute in series. Why? S1 of iteration i depends on S1 of iteration i-1 which in turn depends on , etc. Another Loop with Dependences Generally, loop-carried dependences hinder ILP if there are no loop-carried dependences all iterations could be executed in parallel even if there are loop-carried dependences it may be possible to parallelize the loop an analysis of the dependences is required
For the loop: for (i=1; i<=100; i=i+1) { A[i] = A[i] + B[i]; /* S1 */ B[i+1] = C[i] + D[i]; /* S2 */ }
what are the dependences? There is one loop-carried dependence: ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 146
S1 uses the value of B[i] computed in a previous iteration by S2 but this does not force iterations to execute in series. Why? because S1 of iteration i depends on S2 of iteration i-1, and the chain of dependences stops here!
Parallelizing Loops with Short Chains of Dependences Parallelize the loop: for (i=1; i<=100; i=i+1) { A[i] = A[i] + B[i]; /* S1 */ B[i+1] = C[i] + D[i]; /* S2 */ } Parallelized code: A[1] = A[1] + B[1]; for (i=1; i<=99; i=i+1) { B[i+1] = C[i] + D[i]; A[i+1] = A[i+1] + B[i+1]; } B[101] = C[100] + D[100]; the dependence between the two statements in the loop is no longer loop-carried and iterations of the loop may be executed in parallel
Loop-Carried Dependence Detection: affine array index: a x i+b To detect loop-carried dependence in a loop, the Greatest Common Divisor (GCD) test can be used by the compiler, which is based on the following: If an array element with index: a x i + b is stored and element: c x i + d of the same array is loaded later where index runs from m to n, a dependence exists if the following two conditions hold: 1.There are two iteration indices, j and k , m <= j , k <= n (within iteration limits) 2.The loop stores into an array element indexed by: a x j + b and later loads from the same array the element indexed by: c x k + d ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 147
Thus: a x j + b = c x k + d The Greatest Common Divisor (GCD) Test If a loop carried dependence exists, then : GCD(c, a) must divide (d-b) The GCD test is sufficient to guarantee no loop carried dependence However there are cases where GCD test succeeds but no dependence exits because GCD test does not take loop bounds into account Example: for (i=1; i<=100; i=i+1) { x[2*i+3] = x[2*i] * 5.0; } a = 2 b = 3 c = 2 d = 0 GCD(a, c) = 2 d - b = -3 2 does not divide -3 _ No loop carried dependence possible.
Example- Loop Iterations to be Independent Finding multiple types of dependences for (i=1; i<=100; i=i+1) { Y[i] = X[i] / c; /* S1 */ X[i] = X[i] + c; /* S2 */ Z[i] = Y[i] + c; /* S3 */ Y[i] = c - Y[i]; /* S4 */ } Answer The following dependences exist among the four statements: 1. There are true dependences from S1 to S3 and from S1 to S4 because of Y[i]. These are not loop carried, so they do not prevent the loop from being considered parallel. These dependences will force S3 and S4 to wait for S1 to complete. 2. There is an antidependence from S1 to S2, based on X[i]. 3. There is an antidependence from S3 to S4 for Y[i]. 4. There is an output dependence from S1 to S4, based on Y[i]. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 148
Eliminating false dependencies The following version of the loop eliminates these false (or pseudo) dependences. for (i=1; i<=100; i=i+1 { /* Y renamed to T to remove output dependence */ T[i] = X[i] / c; /* X renamed to X1 to remove antidependence */ X1[i] = X[i] + c; /* Y renamed to T to remove antidependence */ Z[i] = T[i] + c; Y[i] = c - T[i]; } Drawback of dependence analysis When objects are referenced via pointers rather than array indices (but see discussion below) When array indexing is indirect through another array, which happens with many representations of sparse arrays When a dependence may exist for some value of the inputs, but does not exist in actuality when the code is run since the inputs never take on those values When an optimization depends on knowing more than just the possibility of a dependence, but needs to know on which write of a variable does a read of that variable depend
Points-to analysis Relies on information from three major sources: 1. Type information, which restricts what a pointer can point to. 2. Information derived when an object is allocated or when the address of an object is taken, which can be used to restrict what a pointer can point to. For example, if p always points to an object allocated in a given source line and q never points to that object, then p and q can never point to the same object. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 149
3. Information derived from pointer assignments. For example, if p may be assigned the value of q, then p may point to anything q points to.
Eliminating dependent computations copy propagation, used to simplify sequences like the following: DADDUI R1,R2,#4 DADDUI R1,R1,#4 to DADDUI R1,R2,#8 Tree height reduction they reduce the height of the tree structure representing a computation, making it wider but shorter.
Recurrence Recurrences are expressions whose value on one iteration is given by a function that depends onthe previous iterations. sum = sum + x; sum = sum + x1 + x2 + x3 + x4 + x5; If unoptimized requires five dependent operations, but it can be rewritten as sum = ((sum + x1) + (x2 + x3)) + (x4 + x5); evaluated in only three dependent operations.
Scheduling and Structuring Code for Parallelism Static Exploitation of ILP Use compiler support for increasing parallelism Supported by hardware Techniques for eliminating some types of dependences Applied at compile time (no run time support) Finding parallelism Reducing control and data dependencies Using speculation ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 150
Techniques to increase the amount of ILP For processor issuing more than one instruction on every clock cycle. Loop unrolling, software pipelining, trace scheduling, and superblock scheduling
Software pipelining Symbolic loop unrolling Benefits of loop unrolling with reduced code size Instructions in loop body selected from different loop iterations Increase distance between dependent instructions in
Software pipelined loop Loop: SD F4,16(R1) #store to v[i] ADDD F4,F0,F2 #add to v[i-1] LD F0,0(R1) #load v[i-2] ADDI R1,R1,-8 BNE R1,R2,Loop 5 cycles/iteration (with dynamic scheduling and renaming) Need startup/cleanup code
#startup, assume i runs from 0 to n ADDI R1,R1-16 #point to v[n-2] LD F0,16(R1) #load v[n] ADDD F4,F0,F2 #add v[n] LD F0,8(R1) #load v[n-1] ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 152
#body for (i=2;i<=n-2;i++) Loop: SD F4,16(R1) #store to v[i] ADDD F4,F0,F2 #add to v[i-1] LD F0,0(R1) #load v[i-2] ADDI R1,R1,-8 BNE R1,R2,Loop #cleanup SD F4,8(R1) #store v[1] ADDD F4,F0,F2 #add v[0] SD F4,0(R1) #store v[0] Software pipelining versus unrolling
Performance effects of SW pipelining vs. unrolling Unrolling reduces loop overhead per iteration SW pipelining reduces startup-cleanup pipeline overhead
Software pipelining versus unrolling (cont.) Software pipelining
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 153
Advantages Less code space than conventional unrolling Loop runs at peak speed during steady state Overhead only at loop initiation and termination Complements unrolling
Disadvantages Hard to overlap long latencies Unrolling combined with SW pipelining Requires advanced compiler transformations
Global Code Scheduling Global code scheduling aims to compact a code fragment with internal control structure into the shortest possible sequence that preserves the data and control dependences.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 154
Global code scheduling aims to compact a code fragment with internal control structure into the shortest possible sequence that preserves the data and control dependences Data dependences are overcome by unrolling In the case of memory operations, using dependence analysis to determine if two references refer to the same address. Finding the shortest possible sequence of dependent instructions- critical path Reduce the effect of control dependences arising from conditional nonloop branches by moving code. Since moving code across branches will often affect the frequency of execution of such code, effectively using global code motion requires estimates of the relative frequency of different paths. if the frequency information is accurate, is likely to lead to faster code. Global code scheduling- cont. Global code motion is important since many inner loops contain conditional statements. Effectively scheduling this code could require that we move the assignments to B and C to earlier in the execution sequence, before the test of A.
Factors for compiler Global code scheduling is an extremely complex problem What are the relative execution frequencies What is the cost of executing the computation How will the movement of B change the execution time Is B the best code fragment that can be moved What is the cost of the compensation code ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 155
Trace Scheduling: Focusing on the Critical Path
Code generation sequence
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 156
Trace Scheduling, Superblocks and Predicated Instructions For processor issuing more than one instruction on every clock cycle. Loop unrolling, software pipelining, trace scheduling, and superblock scheduling
Trace Scheduling Used when Predicated execution is not supported Unrolling is insufficient Best used If profile information clearly favors one path over the other Significant overheads are added to the infrequent path Two steps : Trace Selection Trace Compaction ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 157
Trace Selection Likely sequence of basic blocks that can be put together Sequence is called a trace What can you select? Loop unrolling generates long traces Static branch prediction forces some straight-line code behavior Trace Selection
(cont.) Trace Example If the shaded portion in previous code was frequent path and it was unrolled 4 times : _ Trace exits are jumps off the frequent path Trace entrances are returns to the trace ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 158
Trace Compaction Squeeze these into smaller number of wide instructions Move operations as early as it can be in a trace Pack the instructions into as few wide instructions as possible Simplifies the decisions concerning global code motion All branches are viewed as jumps into or out of the trace Bookkeeping Cost is assumed to be little Best used in scientific code with extensive loops
Super Blocks for Global Scheduling ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 159
Motivation : Entries and exits into trace schedule code are complicated Compiler cannot do a good cost analysis about compensation code Superblocks Are like traces One entry point Unlike traces Different exit points Common in for loops Single entry and exit points Code motion across exit only need be considered
Superblock Construction
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 160
Tail duplication Creates a separate block that corresponds to the portion of trace after the entry When proceeding as per prediction Take the path of superblock code When exit from superblock Residual loop that handles rest of the iterations
Analysis on Superblocks Reduces the complexity of bookkeeping and scheduling ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 161
Unlike the trace approach Can have larger code size though Assessing the cost of duplication Compilation process is not simple any more
H/W Support : Conditional Execution Also known as Predicated Execution Enhancement to instruction set Can be used to eliminate branches All control dependences are converted to data dependences Instruction refers to a condition Evaluated as part of the execution True? Executed normally False? Execution continues as if the instruction were a no-op Example : Conditional move between registers
Example if (A==0) S = T; Straightforward Code BNEZ R1, L; ADDU R2, R3, R0 L: Conditional Code CMOVZ R2, R3, R1 Annulled if R1 is not 0 Conditional Instruction Can convert control to data dependence ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 162
In vector computing, its called if conversion. Traditionally, in a pipelined system Dependence has to be resolved closer to front of pipeline For conditional execution Dependence is resolved at end of pipeline, closer to the register write
Another example A = abs(B) if (B < 0) A = -B; else A = B; Two conditional moves One unconditional and one conditional move The branch condition has moved into the instruction Control dependence becomes data dependence
Limitations of Conditional Moves Conditional moves are the simplest form of predicated instructions Useful for short sequences For large code, this can be inefficient Introduces many conditional moves Some architectures support full predication All instructions, not just moves Very useful in global scheduling Can handle nonloop branches nicely Eg : The whole if portion can be predicated if the frequent path is not taken
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 163
Assume : Two issues, one to ALU and one to memory; or branch by itself Wastes a memory operation slot in second cycle Can incur a data dependence stall if branch is not taken R9 depends on R8
Predicated Execution Assume : LWC is predicated load and loads if third operand is not 0
One instruction issue slot is eliminated On mispredicted branch, predicated instruction will not have any effect ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 164
If sequence following the branch is short, the entire block of the code can be predicated
Some Complications Exception Behavior Must not generate exception if the predicate is false If R10 is zero in the previous example LW R8, 0(R10) can cause a protection fault If condition is satisfied A page fault can still occur Biggest Issue Decide when to annul an instruction Can be done during issue Early in pipeline Value of condition must be known early, can induce stalls Can be done before commit Modern processors do this Annulled instructions will use functional resources Register forwarding and such can complicate implementation
Limitations of Predicated Instructions Annulled instructions still take resources Fetch and execute atleast For longer code sequences, benefits of conditional move vs branch is not clear Only useful when predicate can be evaluated early in the instruction stream What if there are multiple branches? Predicate on two values? Higher cycle count or slower clock rate for predicated instructions More hardware overhead MIPS, Alpha, Pentium etc support partial predication IA-64 has full predication
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 165
Hardware support for Compiler Speculation H/W Support : Conditional Execution Also known as Predicated Execution Enhancement to instruction set Can be used to eliminate branches All control dependences are converted to data dependences Instruction refers to a condition Evaluated as part of the execution True? Executed normally False? Execution continues as if the instruction were a no-op Example : Conditional move between registers Example if (A==0) S = T; Straightforward Code BNEZ R1, L; ADDU R2, R3, R0 L: Conditional Code CMOVZ R2, R3, R1 Annulled if R1 is not 0 Conditional Instruction Can convert control to data dependence In vector computing, its called if conversion. Traditionally, in a pipelined system Dependence has to be resolved closer to front of pipeline For conditional execution ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 166
Dependence is resolved at end of pipeline, closer to the register write Another example A = abs(B) if (B < 0) A = -B; else A = B; Two conditional moves One unconditional and one conditional move The branch condition has moved into the instruction Control dependence becomes data dependence
Limitations of Conditional Moves Conditional moves are the simplest form of predicated instructions Useful for short sequences For large code, this can be inefficient Introduces many conditional moves Some architectures support full predication All instructions, not just moves Very useful in global scheduling Can handle nonloop branches nicely Eg : The whole if portion can be predicated if the frequent path is not taken Example Assume : Two issues, one to ALU and one to memory; or branch by itself Wastes a memory operation slot in second cycle Can incur a data dependence stall if branch is not taken R9 depends on R8
Predicated Execution Assume : LWC is predicated load and loads if third operand is not 0 One instruction issue slot is eliminated ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 167
On mispredicted branch, predicated instruction will not have any effect If sequence following the branch is short, the entire block of the code can be predicated
Predication Some Complications Exception Behavior Must not generate exception if the predicate is false If R10 is zero in the previous example LW R8, 0(R10) can cause a protection fault If condition is satisfied A page fault can still occur Biggest Issue Decide when to annul an instruction Can be done during issue -- Early in pipeline Value of condition must be known early, can induce stalls Can be done before commit Modern processors do this Annulled instructions will use functional resources Register forwarding and such can complicate implementation
Limitations of Predicated Instructions Annulled instructions still take resources Fetch and execute atleast For longer code sequences, benefits of conditional move vs branch is not clear Only useful when predicate can be evaluated early in the instruction stream What if there are multiple branches? Predicate on two values? Higher cycle count or slower clock rate for predicated instructions More hardware overhead MIPS, Alpha, Pentium etc support partial predication IA-64 has full predication ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 168
UNIT V
LARGE SCALE MULTIPROCESSORS AND SCIENTIFIC APPLICATION
Preserve control and data flow, precise interrupts in Predication Speculative predicated instructions may not throw illegal exceptions LWC may not throw exception if R10 == 0 LWC may throw recoverable page fault if R10 6= 0 Instruction conversion to nop Early condition detection may not be possible due to data dependence Late condition detection incurs stalls and consumes pipeline resources needlessly Instructions may be dependent on multiple branches Compiler able to find instruction slots and reorder
Hardware support for speculation Alternatives for handling speculative exceptions Hardware and OS ignore exceptions from speculative instructions Mark speculative instructions and check for exceptions Additional instructions to check for exceptions and recover Registers marked with poison bits to catch exceptions upon read Hardware buffers instruction results until instruction is no longer speculative
Exception classes Recoverable: exception from speculative instruction may harm performance, but not preciseness Unrecoverable: exception from speculative instruction compromises preciseness
Instruction causing exception returns undefined value Value not used if instruction is speculative Incorrect result if instruction is non-speculative Compiler generates code to throw regular exception Rename registers receiving speculative results
Solution I: Ignore exceptions Example
Solution II: mark speculative instructions
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 170
R4 marked with poison bit
Use of R4 in SD raises exception if SLD raises exception Generate exception when result of offending instruction is used for the first time OS code needs to save poison bits during context switching
Solution IV HW mechanism like a ROB Instructions are marked as speculative How many branches speculatively moved Action (T/NT) assumed by compiler Usually only one branch Other functions like a ROB
HW support for Memory Reference Speculation Moving stores across loads To avoid address conflict Special instruction checks for address conflict Left at original location of load instruction Acts like a guardian On speculative load HW saves address Speculation failed if a stores changes this address before check nstruction ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 171
Fix-up code re-executes all speculated instructions
IA-64 and Itanium Processor Introducing The IA-64 Architecture
Itanium and Itanium2 Processor Slide Sources: Based on Computer Architecture by Hennessy/Patterson. Supplemented from various freely downloadable sources IA-64 is an EPIC
IA-64 largely depends on software for parallelism VLIW Very Long Instruction Word EPIC Explicitly Parallel Instruction Computer VLIW points VLIW Overview RISC technique Bundles of instructions to be run in parallel Similar to superscaling Uses compiler instead of branch prediction hardware
EPIC EPIC Overview Builds on VLIW Redefines instruction format Instruction coding tells CPU how to process data Very compiler dependent Predicated execution EPIC pros and cons EPIC Pros: Compiler has more time to spend with code Time spent by compiler is a one-time cost ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 172
Reduces circuit complexity
Chip Layout Itanium Architecture Diagram
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 173
Itanium Specs 4 Integer ALU's 4 multimedia ALU's 2 Extended Precision FP Units 2 Single Precision FP units 2 Load or Store Units 3 Branch Units 10 Stage 6 Wide Pipeline 32k L1 Cache 96K L2 Cache 4MB L3 Cache(extern) 800Mhz Clock
Itanium2 Specs 6 Integer ALU's 6 multimedia ALU's 2 Extended Precision FP Units 2 Single Precision FP units 2 Load and Store Units 3 Branch Units 8 Stage 6 Wide Pipeline 32k L1 Cache 256K L2 Cache 3MB L3 Cache(on die) ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 175
1Ghz Clock initially Up to 1.66Ghz on Montvale
Itanium2 Improvements Initially a 180nm process Increased to 130nm in 2003 Further increased to 90nm in 2007 Improved Thermal Management Clock Speed increased to 1.0Ghz Bus Speed Increase from 266Mhz to 400Mhz
L3 cache moved on die Faster access rate
IA-64 Pipeline Features Branch Prediction Predicate Registers allow branches to be turned on or off Compiler can provide branch prediction hints Register Rotation Allows faster loop execution in parallel Predication Controls Pipeline Stages Cache Features L1 Cache 4 way associative 16Kb Instruction 16Kb Data L2 Cache Itanium 6 way associative 96 Kb Itanium2 ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 176
8 way associative 256 Kb Initially 256Kb Data and 1Mb Instruction on Montvale! Cache Features L3 Cache Itanium 4 way associative Accessible through FSB 2-4Mb Itanium2 2 4 way associative On Die 3Mb Up to 24Mb on Montvale chips(12Mb/core)! Register Specification _128, 65-bit General Purpose Registers _128, 82-bit Floating Point Registers _128, 64-bit Application Registers _8, 64-bit Branch Registers _64, 1-bit Predicate Registers Register Model _128 General and Floating Point Registers _32 always available, 96 on stack _As functions are called, compiler allocates a specific number of local and output registers to use in the function by using register allocation instruction Alloc. _Programs renames registers to start from 32 to 127. _Register Stack Engine (RSE) automatically saves/restores stack to memory when needed ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 177
_RSE may be designed to utilize unused memory bandwidth to perform register spill and fill operations in the background
On function call, machine shifts register window such that previous output registers become new locals starting at r32
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 178
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 179
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 180
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 181
Instruction Encoding Each instruction includes the opcode and three operands Each instructions holds the identifier for a corresponding Predicate Register Each bundle contains 3 independent instructions Each instruction is 41 bits wide Each bundle also holds a 5 bit template field
Provides an extensive set of hints that the compiler uses to tell the hardware about likely branch behavior (taken or not taken, amount to fetch at branch target) and memory operations (in what level of the memory hierarchy to cache data).
_Use predicates to eliminate branches, move instructions across branches _Conditional execution of an instruction based on predicate register (64 1-bit predicate registers) _Predicates are set by compare instructions _Most instructions can be predicated each instruction code contains predicate field _If predicate is true, the instruction updates the computation state; otherwise, it behaves like a nop
Scheduling and Speculation Basic block: code with single entry and exit, exit point can be multiway branch Control Improve ILP by statically move ahead long latency code blocks. path is a frequent execution path ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 183
Schedule for control paths Because of branches and loops, only small percentage of code is executed regularly Analyze dependences in blocks and paths Compiler can analyze more efficiently - more time, memory, larger view of the program Compiler can locate and optimize the commonly executed blocks
Control speculation _ Not all the branches can be removed using predication. _ Loads have longer latency than most instructions and tend to start timecritical chains of instructions _ Constraints on code motion on loads limit parallelism _ Non-EPIC architectures constrain motion of load instruction _ IA-64: Speculative loads, can safely schedule load instruction before one or more prior branches ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 184
Control Speculation _Exceptions are handled by setting NaT (Not a Thing) in target register _Check instruction-branch to fix-up code if NaT flag set _Fix-up code: generated by compiler, handles exceptions _NaT bit propagates in execution (almost all IA-64 instructions) _NaT propagation reduces required check points
Speculative Load _ Load instruction (ld.s) can be moved outside of a basic block even if branch target is not known _ Speculative loads does not produce exception - it sets the NaT _ Check instruction (chk.s) will jump to fix-up code if NaT is set Data Speculation _ The compiler may not be able to determine the location in memory being referenced (pointers) _ Want to move calculations ahead of a possible memory dependency _ Traditionally, given a store followed by a load, if the compiler cannot determine if the addresses will be equal, the load cannot be moved ahead of the store. _ IA-64: allows compiler to schedule a load before one or more stores _ Use advance load (ld.a) and check (chk.a) to implement _ ALAT (Advanced Load Address Table) records target register, memory address accessed, and access size
Data Speculation 1. Allows for loads to be moved ahead of stores even if the compiler is unsure if addresses are the same 2. A speculative load generates an entry in the ALAT 3. A store removes every entry in the ALAT that have the same address 4. Check instruction will branch to fix-up if the given address is not in the ALAT
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 185
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 186
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 187
Use address field as the key for comparison If an address cannot be found, run recovery code ALAT are smaller and simpler implementation than equivalent structures for superscalars
Register Model _128 General and Floating Point Registers _32 always available, 96 on stack _As functions are called, compiler allocates a specific number of local and output registers to use in the function by using register allocation instruction Alloc. _Programs renames registers to start from 32 to 127. _Register Stack Engine (RSE) automatically saves/restores stack to memory when needed _RSE may be designed to utilize unused memory bandwidth to perform register spill and fill operations in the background
On function call, machine shifts register window such that previous output registers become new locals starting at r32 Software Pipelining ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 188
_loops generally encompass a large portion of a programs execution time, so its important to expose as much loop-level parallelism as possible. _Overlapping one loop iteration with the next can often increase the parallelism. Software Pipelining
We can implement loops in parallel by resolve some problems. _Managing the loop count, _Handling the renaming of registers for the pipeline, _Finishing the work in progress when the loop ends, _Starting the pipeline when the loop is entered, and _Unrolling to expose cross-iteration parallelism. IA-64 gives hardware support to compilers managing a software pipeline Facilities for managing loop count, loop termination, and rotating registers The combination of these loop features and predication enables the compiler to generate compact code, which performs the essential work of the loop in a highly parallel form.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 189
UNIT VI COMPUTER ARITHMETIC
Introduction, Basic Techniques of Integer Arithmetic: Although computer arithmetic is sometimes viewed as a specialized part of CPU design, it is very important part. This was brought home for Intel in 1994 whentheir Pentium chip was discovered to have a bug in the divide algorithm. This floating-point flaw resulted in a flurry of bad publicity for Intel and also cost them a lot of money. Intel took a $300 million write-off to cover the cost of replacing the buggy chips. In this appendix we will study some basic floating-point algorithms, including the division algorithm used on the Pentium. Although a tremendous variety of algorithms have been proposed or use in floating-point accelerators, actual implementations are usually based on refinements nd variations of the few basic algorithms presented here. In addition to choosing algorithms for addition, subtraction, multiplication, and division, the computer architect must make other choices. What precisions should be implemented? How should exceptions be handled? This appendix will give you the background for making these and other decisions. Our discussion of floating point will focus almost exclusively on the IEEE floating-point standard (IEEE 754) because of its rapidly increasing acceptance. Although floating- point arithmetic involves manipulating exponents and shifting fractions, the bulk of the time in floating-point operations is spent operating on fractions using integer algorithms (but not necessarily sharing the hardware that implements integer instructions). Thus, after our discussion of floating point, we will take a more detailed look at integer algorithms. Some good references on computer arithmetic, in order from least to most detailed, are Chapter 4 of Patterson and Hennessy [1994]; Chapter 7 of Hamacher, Vranesic, and Zaky [1984]; Gosling [1980]; and Scott [1985]. Readers who have studied computer arithmetic before will find most of this section to be review.
Ripple-Carry Addition Adders are usually implemented by combining multiple copies of simple components. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 190
The natural components for addition are half adders and full adders The half adder takes two bits a and b as input and produces a sum bit s and a carry bit c out as output. Mathematically, s= (a + b ) mod 2 , and c out = ( a + b )/2 The half adder is also called a (2,2) adder, since it takes two inputs and produces two outputs. The full adder is a (3,2) adder and is defined by or the logic equations
Basic Techniques of Integer Arithmetic The principal problem in constructing an adder for n -bit numbers out of smaller pieces is propagating the carries from one piece to the next. The most obvious way to solve this is with a ripple-carry adder, consisting of n full adders, as illustrated in Figure H.1. (In the figures in this appendix, the least-significant bit is always on the right.) The inputs to the adder are a represents the number output of the I th adder is fed into the c I +1 input of thenext adder (the (I + 1)-th adder) with the lower-order carry-in c 0 set to 0. Since the low-order carry-in is wired to 0, the low-order adder could be a half adder. Later, however, we will see that setting the low-order carry-in bit to 1 is useful for performing subtraction. In general, the time a circuit takes to produce an output is proportional to the maximum numb er of logic levels through which a signal travels. However, determining the exact relationship between logic levels and timings is highly technology dependent. Therefore, when comparing adders we will simply compare the number of logic levels in each one. How many levels are there for a ripple-carry adder? It takes two levels to compute are 32 for integer arithmetic and 53 for doubleprecision floating point. The ripple-carry adder is the slowest adder, but also the cheapest. It can be built with only n simple cells, connected in a simple, regular way. Because the ripple-carry adder is relatively slow compared with the designs discussed in Secti on H.8, you might wonder why it is used at all. In technologies like CMOS, even though ripple adders take time O( n ), the constant factor is very small. In such cases short ripple adders are often used as building blocks in larger adders.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 191
Ripple-carry adder, consisting of n full adders.The carry-out of one full adder is connected to the carry-in of the adder for the next most-significant bit. The carries ripple from the least-significant bit (on the right) to the most-significant bit (on the left).
Radix-2 Multiplication and Division The simplest multiplier computes the product of two unsigned numbers, one bit at a time, as illustrated in Figure H.2(a). The numbers to be multiplied are an1an2 a0 and bn1bn2 b0, and they are placed in registers A and B, respectively. Register P is initially 0. Each multiply step has two parts. Multiply Step (i) If the least-significant bit of A is 1, then register B, containing bn1bn 2 0, is added to P; otherwise 00 00 is added to P. The sum is placed back into P.
Each multiplication step consists of adding the contents of P to either B or 0 (depending on the low-order bit of A), replacing P with the sum, and then shifting both P and A one bit right. Each division step involves first shifting P and A one bit left, subtracting B from P, and, if the difference is nonnegative, putting it into P. If the
Floating Point, Floating-Point Multiplication, Many applications require numbers that arent integers. There are a number of ways that nonintegers can be represented. One is to use fixed point; that is, use integer arithmetic and simply imagine the binary point somewhere other than just to the right of the least- significant digit. Adding two such numbers can be done with an integer add, whereas multiplication requires some extra shifting. Other representations that have been proposed involve storing the logarithm of a number and doing multiplication by adding the logarithms, or using a pair of integers (a,b) to represent the fraction a/b. However, only one noninteger representation has gained widespread use, and that is floating point. In this system, a computer word is divided int o two parts, an exponent and a significand. As an example, an exponent of 3 and significand of 1.5 might represent the number 1.5 23 = 0.1875. The advantages of standardizing a particular representation are obvious. Numerical analysts can build up high-quality software libraries, computer ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 192
designers can develop techniques for implementing high-performance hardware, and hardware vendors can build standard accelerators. Given the predominance of the floating-point representation, it appears unlikely that any other representation will come into widespread use. The semantics of floating-point instructions are not as clear-cut as the semantics of the rest of the instruction set, and in the past the behavior of floating-point operations varied considerably from one computer family to the next. The variations involved such things as the number of bits allocated to the exponent and significand, the range of exponents, how rounding was carried out, and the actions taken on exceptional conditions like underflow and overflow. Computer architecture books used to dispense advice on how to deal with all these details, but fortunately this is no longer necessary. Thats because the computer industry is rapidly converging on the format specified by IEEE standard 754-1985 (also an international standard, IEC 559). The advantages of using a standard variant of floating point are similar to those for using floating point over other noninteger representations. 1. When rounding a halfway result to the nearest floating-point number, it picks the one that is even. 2. It includes the special values NaN, , and . 3. It uses denormal numbers to represent the result of computations whose value is less than 1.0 4. It rounds to nearest by default, but it also has three other rounding modes. 5. It has sophisticated facilities for handling exceptions. To elaborate on (1), note that when operating on two floating-point numbers, the result is usually a number that cannot be exactly represented as another floating- point number. For example, in a floating-point system using base 10 and two significant digits, 6.1 0.5 = 3.05. This needs to be rounded to two digits. Should it be rounded to 3.0 or 3.1? In the IEEE standard, such halfway cases are rounded to the number whose low- order digit is even. That is, 3.05 rounds to 3.0, not 3.1. The standard actually has four rounding modes. The default is round to nearest, which rounds ties to an even number as just explained. The other modes are round toward 0, round toward +, and round toward . We will elaborate on the other differences in following sections ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 193
Special Values and Denormals Probably the most notable feature of the standard is that by default a computation continues in the face of exceptional conditions, such as dividing by 0 or taking the square root of a negative number. For example, the result of taking the square root of a negative number I s a NaN (Not a Number), a bit pattern that does not represent an ordinary number. As an example of how NaNs might be useful, consider the code for a zero finder that takes a function F as an argument and evaluates F at various points to determine a zero for it. If the zero finder accidentally probes outside the valid values for F, F may well cause an exception. Writing a zero finder that deals with this case is highly language and operating-system dependent, because it relies on how the operating system reacts to exceptions and how this reaction is mapped back into the programming language. In IEEE arithmetic it is easy to write a zero finder that handles this situation and runs on many different systems. After each evaluation of F, it simply checks to see whether F has returned a NaN; if so, it knows it has probed outside the domain of F. In IEEE arithmetic, if the input to an operation is a NaN, the output is NaN (e.g., 3 + NaN = NaN). Because of this rule, writing floating-point subroutines that can accept NaN as an argument rarely requires any special case checks. For example, suppose that arccos is computed in terms of arctan, using the formula arccos x = 2 arctan( ). If arctan handles an argument of NaN properly, arccos will automatically do so too. Thats because if x is a NaN, 1 + x, 1 x, (1 + x)/(1 x), and will also be NaNs. No checking for NaNs is required. 1 x1 + x 1 x1 + x
While the result of is a NaN, the result of 1/0 is not a NaN, but +which is another special value. The standard defines arithmetic on infinities (there is both +and ) using rules such as 1/= 0. The formula arccos x = 2 arctan( ) illustrates how infinity arithmetic can be used. Since arctan x asymptotically approaches /2 as x approaches , it is natural to define arctan() = /2, in which case arccos(1) will automatically be computed correctly as 2 arctan() = . The final kind of special values in the standard ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 194
are denormal numbers. In many floating-point systems, if Emin is the smallest exponent, a number less than 1.0 2Emin cannot be represented, and a floating-point operation that results in a number less than this is simply flushed to 0. In the IEEE standard, on the other hand, numbers less than 1.0 2Emin are represented using significands less than 1. This is called gradual underflow. Thus, as numbers decrease in magnitude below 2Emin, they gradually lose their significance and are only represented by 0 when all their significance has been shifted out. For example, in base 10 with four significant figures, let x = 1.234 10Emin. Then x/10 will be rounded to 0.123 10Emin, having lost a digit of precision. Similarly x/100 rounds to 0.012 10Emin, and x/1000 to 0.001 10Emin, while x/10000 is finally small enough to be rounded to 0. Denormals make dealing with small numbers more predictable by maintaining familiar properties such as x = y x y = 0. For example, in a flushto- zero system (again in base 10 with four significant digits), if x = 1.256 10Emin and y = 1.234 10Emin, then x y = 0.022 10Emin, which flushes to zero. So even though x y, the computed value of x y = 0. This never happens with gradual underflow. In this example, x y = 0.022 10Emin is a denormal number, and so the computation of x y is exact.
Representation of Floating-Point Numbers Let us consider how to represent single-precision numbers in IEEE arithmetic. Single- precision numbers are stored in 32 bits: 1 for the sign, 8 for the exponent, and 23 for the fraction. The exponent is a signed number represented using the bias method (see the subsection Signed Numbers, page H-7) with a bias of 127. The term biased exponent refers to the unsigned number contained in bits 1 through 8 and unbiased exponent (or just exponent) means the actual power to which 2 is to be raised. The fraction represents a number less than 1, but the significand of the floating-point number is 1 plus the fraction part. In other words, if e is the biased exponent (value of the exponent field) and f is the value of the fraction field, the number being represented is 1. f 2e127.
Example What single-precision number does the following 32-bit word represent? ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 195
1 10000001 01000000000000000000000 1 1 x1 + x H-16 _ Appendix H Computer Arithmetic Answer Considered as an unsigned number, the exponent field is 129, making the value of the exponent 129 127 =2. The fraction part is .012 = .25, making the significand 1.25. Thus, this bit pattern represents the number 1.25 22 = 5. The fractional part of a floating-point number (.25 in the example above) must not be confused with the significand, which is 1 plus the fractional part. The leading 1 in the significand 1. f does not appear in the representation; that is, the leading bit is implicit. When performing arithmetic on IEEE format numbers, the fraction part is usually unpacked, which is to say the implicit 1 is made explicit. Figure H.7 summarizes the parameters for single (and other) precisions. It shows the exponents for single precision to range from 126 to 127; accordingly, the biased exponents range from 1 to 254. The biased exponents of 0 and 255 are used to represent special values. This is summarized in Figure H.8. When the biased exponent is 255, a zero fraction field represents infinity, and a nonzero fraction field represents a NaN. Thus, there is an entire family of NaNs. When the biased exponent and the fraction field are 0, then the number represented is 0. Because of the implicit leading 1, ordinary numbers always have a significand greater than or equal to 1. Thus, a special convention such as this is required to represent 0. Denormalized numbers are implemented by having a word with a zero exponent field represent the number 0. f
Format parameters for the IEEE 754 floating-point standard. The first row gives the number of bits in the significand. The blanks are unspecified parameters. outside the range Emin e Emax, then that number has a special interpretation as indicated in the table. The primary reason why the IEEE standard, like most other floating-point formats, uses biased exponents is that it means nonnegative numbers are ordered in the same way as integers. That is, the magnitude of floating-point numbers can be compared using an integer comparator. Another (related) advantage is that 0 is represented by a word of all ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 196
0s. The downside of biased exponents is that adding them is slightly awkward, because it requires that the bias be subtracted from their sum. The simplest floating-point operation is multiplication, so we discuss it first. A binary floating-point number x is represented as a significand and an exponent, x = s 2e. The formula (s1 2e1) (s2 2e2) = (s1 s2) 2e1+e2 shows that a floating-point multiply algorithm has several parts. The first part multiplies the significands using ordinary integer multiplication. Because floatingpoint numbers are stored in sign magnitude form, the multiplier need only deal with unsigned numbers (although we have seen that Booth recoding handles signed twos complement numbers painlessly). The second part rounds the result. If the significands are unsigned p-bit numbers (e.g., p = 24 for single precision), then the product can have as many as 2p bits and must be rounded to a p-bit number. The third part computes the new exponent. Because exponents are stored with a bias, this involves subtracting the bias from the sum of the biased exponents.
Floating-Point Multiplication Appendix H Computer Arithmetic 10000010 10000011 + 10000001 10000110 Since this is 134 decimal, it represents an exponent of 134 bias = 134 127 = 7, as expected. The interesting part of floating-point multiplication is rounding. Some of the different cases that can occur are illustrated in Figure H.9. Since the cases are similar in all bases, the figure uses human-friendly base 10, rather than base 2. In the figure, p = 3, so the final result must be rounded to three significant digits. The three most-significant digits are in boldface. The fourth most-significant digit (marked with an arrow) is the round digit, denoted by r. If the round digit is less than 5, then the bold digits represent the rounded result. If the round digit is greater than 5 (as in (a)), then 1 must be added to the least-significant bold digit. If the round digit is exactly 5 (as in (b)), then additional digits ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 197
must be examined to decide between truncation or incrementing by 1. It is only necessary to know if any digits past 5 are nonzero. In the algorithm below, this will be recorded in a sticky bit. Comparing (a) and (b) in the figure shows that there are two possible positions for the round digit (relative to the least-significant digit of the product). Case (c) illustrates that when adding 1 to the least-significant bold digit, there may be a carry-out. When this happens, the final significand must be 10.0. There is a straightforward method of handling rounding using the multiplier of Figure H.2 (page H-4) together with an extra sticky bit. If p is the number of bits in the significand, then the A, B, and P registers should be p bits wide. Multiply the two significands to obtain a 2p-bit product in the (P,A) registers (see Figure H.9 Examples of rounding a multiplication. Using base 10 and p = 3, parts (a) and (b) illustrate that the result of a multiplication can have either 2p 1 or 2p digits, and hence the position where a 1 is added when rounding up (just left of the arrow) can vary. Part (c) shows that rounding up can cause a carry-out.
Denormals Checking for underflow is somewhat more complex because of denormals. In single precision, if the result has an exponent less than 126, that does not necessarily indicate underflow, because the result might be a denormal number. For example, the product of (1 264) with (1 265) is 1 2129, and 129 is below the legal exponent limit. But this result is a valid denormal number, namely, 0.125 2126. In general, when the unbiased exponent of a product dips below 126, the resulting product must be shifted right and the exponent incremented until the Rounding mode Sign of result 0 Sign of result < 0 +1 if r s ++1 if r s 0 Nearest +1 if r p0 or r s +1 if r p0 or r s Let S be the magnitude of the preliminary result. Blanks mean that the p most-significant bits of S are the ctual result bits. If the condition listed is true, add 1 to the pth most- significant bit of S. The symbols r and s represent the round and sticky bits, while p0 is the pth mostsignificant bit of S. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 198
If this process causes the entire significand to be shifted out, then underflow has occurred. The precise definition of underflow is somewhat subtlesee Section H.7 for details. When one of the operands of a multiplication is denormal, its significand will have leading zeros, and so the product of the significands will also have leading zeros. If the exponent of the product is less than 126, then the result is denormal, so right-shift and increment the exponent as before. If the exponent is greater than 126, the result may be a normalized number. In this case, left-shift the product (while decrementing the exponent) until either it becomes normalized or the exponent . Denormal numbers present a major stumbling block to implementing floating-point multiplication, because they require performing a variable shift in the multiplier, which wouldnt otherwise be needed. Thus, high-performance, floating-point multipliers often do not handle denormalized numbers, but instead trap, letting software handle them. A few practical codes frequently underflow, even when working properly, and these programs will run quite a bit slower on systems that require denormals to be processed by a trap handler. So far we havent mentioned how to deal with operands of zero. This can be handled by either testing both operands before beginning the multiplication or testing the product afterward. If you test afterward, be sure to handle the case 0 properly: This results in NaN, not 0. Once you detect that the result is 0, set the biased exponent to 0. Dont forget about the sign. The sign of a product is the XOR of the signs of the operands, even when the result is 0.
Precision of Multiplication In the discussion of integer multiplication, we mentioned that designers must decide whether to deliver the low-order word of the product or the entire product. A similar issue arises in floating-point multiplication, where the exact product can be rounded to the precision of the operands or to the next higher precision. In the case of integer multiplication, none of the standard high-level languages contains a construct that would generate a single times single gets double instruction. The situation is different for floating point. Many languages allow assigning the product of two single-precision variables to a double-precision one, and the construction can also be exploited by ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 199
numerical algorithms. The best-known case is using iterative refinement to solve linear systems of equations.
Floating-Point Addition, Division and Remainder, More on Floating-Point Arithmetic
Floating-Point Addition First, the sum of the binary 6-bit numbers 1.100112 and 1.100012 25: When the summands are shifted so they have the same exponent, this is 1.10011 + .0000110001 Using a 6-bit adder (and discarding the low-order bits of the second addend) gives 1.10011 + .00001 1.10100 The first discarded bit is 1. This isnt enough to decide whether to round up. The rest of the discarded bits, 0001, need to be examined. Or actually, we just need to record whether any of these bits are nonzero, storing this fact in a sticky bit just as in the multiplication algorithm. So for adding two p-bit numbers, a p- bit adder is sufficient, as long as the first discarded bit (round) and the OR of the rest of the bits (sticky) are kept. Then Figure H.11 can be used to determine if a roundup is necessary, just as with multiplication. In the example above, sticky is 1, so a roundup is necessary. The final sum is 1.101012. Heres another example: 1.11011 + .0101001 A 6- bit adder gives 1.11011 + .01010 10.00101 Because of the carry-out on the left, the round bit isnt the first discarded bit; rather, it is the low-order bit of the sum (1). The discarded bits, 01, are ORed together to make sticky. Because round and sticky are both 1, the high-order 6 bits of the sum, 10.00102, must be rounded up for the final answer of 10.00112. Because the top bits canceled, the first discarded bit (the guard bit) is needed to fill in the least-significant bit of the sum, which becomes 0.1111102, and the second discarded bit becomes the round bit. This is analogous to case (1) in the multiplication algorithm (see page H-19). The round bit of 1 isnt enough to decide whether to round up. Instead, we need to OR all the remaining bits (0001) into a sticky bit. In this case, sticky is 1, so the final result must be rounded up to 0.111111. This example shows that if subtraction causes the most-significant bit to cancel, then one guard bit is needed. It is natural to ask whether two guard bits are needed for the case when the two most-significant bits cancel. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 200
The answer is no, because if x and y are so close that the top two bits of x y cancel, then x y will be exact, so guard bits arent needed at all.To summarize, addition is more complex than multiplication because,depending on the signs of the operands, it may actually be a subtraction. If it is an addition, there can be carry-out on the left, as in the second example. If it is subtraction, there can be cancellation, as in the third example. In each case, the position of the round bit is different. However, we dont need to compute the exact sum and then round. We can infer it from the sum of the high-order p bits together with the round and sticky bits. The rest of this section is devoted to a detailed discussion of the floating-point addition algorithm. Let a1 and a2 be the two numbers to be added. The notations ei and si are used for the exponent and significand of the addends ai. This means that the floating-point inputs have been unpacked and that si has an explicit leading bit. To add a1 and a2, perform these eight steps. 1. If e1< e2, swap the operands. This ensures that the difference of the exponents satisfies d = e1 e2 0. Tentatively set the exponent of the result to e1. 2. If the signs of a1 and a2 differ, replace s2 by its twos complement. 3. Place s2 in a p-bit register and shift it d = e1 e2 places to the right (shifting in 1s if s2 was complemented in the previous step). From the bits shifted out, set g to the most- significant bit, r to the next most-significant bit, and set sticky to the OR of the rest. 4. Compute a preliminary significand S = s1 + s2 by adding s1 to the p-bit register containing s2. If the signs of a1 and a2 are different, the most-significant bit of S is 1, and there was no carry-out, then S is negative. Replace S with its twos complement. This can only happen when d = 0. 5. Shift S as follows. If the signs of a1 and a2 are the same and there was a carryout in step 4, shift S right by one, filling in the high-order position with 1 (the carry-out). Otherwise shift it left until it is normalized. When left-shifting, on the first shift fill in the low-order position with the g bit. After that, shift in zeros. Adjust the exponent of the result accordingly. 6. Adjust r and s. If S was shifted right in step 5, set r := low-order bit of S before shifting and s := g OR r OR s. If there was no shift, set r := g, s := r OR s. If there was a single left shift, dont change r and s. If there were two or more left shifts, r := 0, s := 0. (In the ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 201
last case, two or more shifts can only happen when a1 and a2 have opposite signs and the same exponent, in which case the computation s1 + s2 in step 4 will be exact.) 7. Round S using Figure H.11; namely, if a table entry is nonempty, add 1 to the low- order bit of S. If rounding causes carry-out, shift S right and adjust the exponent. This is the significand of the result. 8. Compute the sign of the result. If a1 and a2 have the same sign, this is the sign of the result. If a1 and a2 have different signs, then the sign of the result depends on which of a1, a2 is negative, whether there was a swap in step 1, and whether S was replaced by its twos complement in step H.12. must twos complement sum, giving S = 0.010. 5. Shift left twice, so S = 1.000, exp = exp 2, or exp = 2. 6. Two left shifts, so r = g = s = 0. 7. No addition required for rounding. 8. Answer is sign S 2exp or sign 1.000 2 2. Get sign from Figure H.12. Since complement but no swap and sign(a1) is , the sign of sum is +. Thus answer = 1.0002 22.
Speeding Up Addition Lets estimate how long it takes to perform the algorithm above. Step 2 may require an addition, step 4 requires one or two additions, and step 7 may require an addition. If it takes T time units to perform a p-bit add (where p = 24 for single precision, 53 for double), then it appears the algorithm will take at least 4T time units. But that is too pessimistic. If step 4 requires two adds, then a1 and a2 have the same exponent and different signs. But in that case the difference is exact, and so no roundup is required in step 7. Thus only three additions will ever occur. Similarly, it appears that a variable shift may be required both in step 3 and step 5. But if |e1 e2| 1, then step 3 requires a right shift of at most one place, so only step 5 needs a variable shift. And if |e1 e2| > 1, then step 3 needs a variable shift, but step 5 will require a left shift of at most one place. So only a single variable shift will be performed. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 202
Still, the algorithm requires three sequential adds, which, in the case of a 53-bit double- precision significand, can be rather time consuming. A number of techniques can speed up addition. One is to use pipelining. The Putting It All Together section gives examples of how some commercial chips pipeline addition. Another method (used on the Intel 860 [Kohn and Fu 1989]) is to perform two additions in parallel. We now explain how this reduces the latency from 3T to T. There are three cases to consider. First, suppose that both operands have the same sign. We want to combine the addition operations from steps 4 and 7. The position of the high-order bit of the sum is not known ahead of time, because the addition in step 4 may or may not cause a carry-out. Both possibilities are accounted for by having two adders. The first adder assumes the add in step 4 will not result in a carry-out. Thus the values of r and s can be computed before the add is actually done. If r and s indicate a roundup is necessary, the first adder will compute S = s1 + s2 + 1, where the notation +1 means adding 1 at the position of the least-significant bit of s1. This can be done with a regular adder by setting the low-order carry-in bit to 1. If r and s indicate no roundup, the adder computes S = s1 + s2 as usual. One extra detail: when r = 1, s = 0, you will also need to know the low- order bit of the sum, which can also be computed in advance very quickly. The second adder covers the possibility that there will be carry-out. The values of r and s and the position where the roundup 1 is added are different from above, but again they can be quickly computed in advance. It is not known whether there will be a carry-out until after the add is actually done, but that doesnt matter. By doing both adds in parallel, one adder is guaranteed to reduce the correct answer. The next case is when a1 and a2 have opposite signs, but the same exponent. The sum a1 + a2 is exact in this case (no roundup is necessary), but the sign isnt known until the add is completed. So dont compute the twos complement (which requires an add) in step 2, but instead compute s1 + s2 + 1 and s1 + s2 +1 in parallel. The first sum has the result of simultaneously complementing s1 and computing the sum, resulting in s2 s1. The second sum computes s1 s2. One of these will be nonnegative and hence the correct final answer. Once again, all the additions are done in one step using two adders operating in parallel. The last case, when a1 and a2 have opposite signs and different exponents, is more complex. If |e1e2| > 1, the location of the le ading bit of the ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 203
difference is in one of two locations, so there are two cases just as in addition. When |e1e2| = 1, cancellation is possible and the leading bit could be almost anywhere. However, only if the leading bit of the difference is in the same position as the leading bit of s1 could a roundup be necessary. So one adder assumes a roundup, the other assumes no roundu . Thus the addition of step 4 and the rounding of step 7 can Denormalized Numbers Unlike multiplication, for addition very little changes in the preceding description if one of the inputs is a denormal number. There must be a test to see if the exponent field is 0. If it is, then when unpacking the significand there will not be a leading 1. By setting the biased exponent to 1 when unpacking a denormal, the algorithm works unchanged. To deal with den ormalized outputs, step 5 must be modified slightly. Shift S until it is normalized, or until the exponent becomes Emin (that is, the biased exponent becomes 1). If the exponent is Emin and, after rounding, the high-order bit of S is 1, then the result is a normalized number and should be packed in the usual way, by omitting the 1. If, on the other hand, the high-order bit is 0, the result is denormal. When the result is unpacked, the exponent field must be set to 0. discusses the exact rules for detecting underflow. Incidentally, detecting overflow is very easy. It can only happen if step 5 involves a shift right and the biased exponent at that point is bumped up to 255 in single precision (or 2047 for double precision), or if this occurs after rounding. In this section, well discuss floating-point division and remainder. Iterative Division We earlier discussed an algorithm for integer division. Converting it into a floating- point division algorithm is similar to converting the integer multiplication algorithm into floating point. The formula (s1 2e1) / (s2 2e2) = (s1 / s2) 2e1e2 operands is slightly different from integer division. Load s2 into B and s1 into P. The A register is not needed to hold the operands. Then the integer algorithm for division (with the one small change of skipping the very first left shift) can be used, and the result will be of the form q0.q1To round, simply compute two additional quotient bits (guard and round) and use the remainder as the sticky bit. The guard digit is necessary because the first quotient bit might be 0. However, since the numerator and denominator ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 204
are both normalized, it is not possible for the two most-significant quotient bits to be 0. This algorithm produces one quotient bit in each step. A different approach to division converges to the quotient at a quadratic rather than a linear rate. An actual machine that uses this algorithm will be discussed in Section H.10. First, we will describe the two main iterative algorithms, and then we will discuss the pros and cons of iteration when compared with the direct algorithms. There is a general technique fo r constructing iterative algorithms, alled Newtons iteration, shown in Figure H.13. First, cast the problem in the form of finding the zero of a function. Then, starting from a guess for the zero, approximate the function by its tangent at that guess and form a new guess based on where the tangent has a zero. If xi is a guess at a zero, then the tangent line has the equation Floating-Point Remainder For nonnegative integers, integer division and remainder satisfya = (a DIV b)b + a REM b, 0 a REM b b A floating-point remainder x REM y can be similarly defined as x = INT(x/y)y + x REM y. How should x/y be converted to an integer? The IEEE remainder function uses the round-to-even rule. That is, pick n = INT (x/y) so that x/y n1/2. If two different n satisfy this relation, pick the even one. Then REM is defined to be x yn. Unlike integers where 0 a REM b b, for floating-point numbers x REM yy/2. Although this defines REM precisely, it is not a practical operational definition, because n can be huge. In single precision, n could be as large as 2127/2126 = 2253. There is a natural way to compute REM if a direct division algorithm is used. Proceed as if you were computing x/y. If x = s12e1 and y = s22e2 and the divider is as in Figure H.2(b) (page H-4), then load s1 into P and s2 into B. After e1 e2 division steps, the P register will hold a number r of the form x yn satisfying _ 0 r < y. Since the IEEE remainder satisfies REMy/2, REM is equal to either r or r y. It is only necessary to keep track of the last quotient bit produced, which is needed to resolve halfway cases. Unfortunately, e1 e2 can be a lot of steps, and floating-point units typically have a maximum amount of time they are allowed to spend on one instruction. Thus, it is usually not possible to implement REM directly. None of the chips discussed in Section H.10 implements REM, but they could by providing a remainder-step instructionthis is what is done on the Intel 8087 family. A remainder ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 205
step takes as arguments two numbers x and y, and performs divide steps until either the remainder is in P or n steps have been performed, where n is a small number, such as the number of steps required for division in the highest-supported precision. Then REM can be implemented as a software routine that calls the RE M step instruction (e1 e2)/ntimes, initially using x as the numerator, but then replacing it with the remainder from the previous REM step. REM can be used for computing trigonometric functions. To simplify things, imagine that we are working in base 10 with five significant figures, and consider computing sin x. Suppose that x = 7. Then we can reduce by = 3.1416 and compute sin(7) = sin(7 2 3.1416) = sin(0.7168) instead. But suppose we wa nt to compute sin(2.0 105). Then 2 105/3.1416 = 63661.8, which in our five -place system comes out to be 63662. Since multiplying 3.1416 times 63662 gives 200000.5392, which rounds to 2.0000 105, argument reduction reduces 2 105 to 0, which is not even close to being correct. The problem is that our five-place system does not have the precision to do correct argument reduction. Suppose we had the REM operator. Then we could compute 2 105 REM 3.1416 and get .53920.However, this is still not correct because we used 3.1416, which is an approximation for . The value of 2 105 REM is .071513. Traditionally, there have been two approaches to computing periodic functions with large arguments. The first is to return an error for their value when x is large. The second is to store to a very large number of places and do exact argumentreduction. The REM operator is not much help in either of these situations. There is a third approach that has been used in some math libraries, such as the Berkeley UNIX 4.3bsd release. In these libraries, is computed to the nearestfloating-point number. Lets call this machine , and denote it by Then when computing sin x, reduce x using x REM . As we saw in the above example, x REM is quite differen t from x REM when x is large, so that computing sin x as sin(x REM ) will not give the exact value of sin x. However, computing trigonometric functions in this fashion has the property that all familiar identities (such as sin2 x + cos2 x = 1) are true to within a few rounding errors. Thus, using REM together with machine provides a simple method of computing ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 206
trigonometric functions that is accurate for small arguments and still may be useful for large arguments. When REM is used for argument reduction, it is very handy if it also returns the low- order bits of n (where x REM y = x ny). This is because a practical implementation of trigonometric functions will reduce by something smaller than 2. For example, it might use /2, exploiting identities such as sin(x /2) = cos x, sin(x ) = sin x. Then the low bits of n are needed to choose the correct identity. Before leaving the subject of floating-point arithmetic, we present a few additional topics. Fused Multiply-Add Probably the most common use of floating-point units is performing matrix operations, and the most frequent matrix operation is multiplying a matrix times a matrix (or vector), which boils down to computing an inner product, x1 y1 + x2 y2 + . . . + xn yn. Computing this requires a series of multiply-add combinations. Motivated by this, the IBM RS/6000 introduced a single instruction that computes ab + c, the fused multiply- add. Although this requires being able to read three operands in a single instruction, it has the potential for improving the performance of computing inner products. The fused multiply-add computes ab + c exactly and then rounds. Although rounding only once increases the accuracy of inner products somewhat, that is not its primary motivation. There are two main advantages of rounding once. First, as we saw in the previous sections, rounding is expensive to implement because it may require an addition. By rouding only once, an addition operation has been eliminated. Second, the extra accuracy of fused multiply-add can be used to compute correctly rounded division and square root when these are not available directly in hardware. Fused multiply-add can also be used to implement efficient floating-point multiple-precision packages. The implementation of correctly rounded division using fused multiply-add has many details, but the main idea is simple. Consider again the example from Section H.6 (page H-31), which was computing a/b with a = 13, b = 51. Then 1/b rounds to b= .020, and abrounds to q= .26, which is not the correctly rounded quotient. Applying fused multiply-add twice will correctly adjust the More on Floating-Point Arithmetic ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 207
The standard specifies four precisions: single, single extended, double, and double extended. The properties of these precisions are summarized in Figure H.7 (page H-16). Implementations are not required to have all four precisions, but are encouraged to support either the combination of single and single extended or all of single, double, and double extended. Because of the widespread use of double precision in scientific computing, double precision is almost always implemented. Thus the computer designer usually only has to decide whether to support double extended and, if so, how many bits it should have. The Motorola 68882 and Intel 387 coprocessors implement extended precision using the smallest allowable size of 80 bits (64 bits of significand). However, many of the more recently designed, high-performance floating-point chips do not implement 80-bit extended precision. One reason is that the 80-bit width of extended precision is awkward for 64-bit buses and registers. Some new architectures, such as SPARC V8 and PA-RISC, specify a 128-bit extended (or quad) precision. They have established a de facto convention for quad that has 15 bits of exponent and 113 bits of significand. Although most high-level languages do not provide access to extended precision, it is very useful to writers of mathematical software. As an example, consider writing a library routine to compute the length of a vector (x,y) in the plane, namely, . If x is larger than 2Emax/2, then computing this in the obvious way will overflow. This means that either the allowable exponent range for this subroutine will be cut in half or a more complex algorithm using scaling will have to be employed. But if extended precision is available, then the simple algorithm will work. Computing the length of a vector is a simple task, and it is not difficult to come up with an algorithm that doesnt overflow. However, there are more complex problems for which extended precision means the difference between a simple, fast algorithm and a much more complex one. One o the best examples of this is binary-to-decimal conversion. An efficient algorithm for binary-to-decimal conversion that makes essential use of extended precision is very readably presented in Coonen [1984]. This algorithm is also briefly sketched in Goldberg [1991]. Computing accurate values for transcendental functions is another example of a problem that is made much easier if extended precision is present.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 208
Speeding Up Integer Addition Carry-Lookahead An n-bit adder is just a combinational circuit. It can therefore be written by a logic formula whose form is a sum of products and can be computed by a circuit with two levels of logic. How do you figure out what this circuit looks like? From Equation H.2.1 (page H-3) the formula for the ith sum can be written as H.8.1 si = ai bi ci + ai bi ci + ai bi ci + ai bi ci where ci is both the carry-in to the ith adder and the carry-out from the (i1)-st adder. The problem with this formula is that although we know the values of ai and bithey are inputs to the circuitwe dont know ci. So our goal is to write ci in terms of ai and bi. To accomplish this, we first rewrite Equation H.2.2 (page H-3) as H.8.2 ci = gi 1+ p i 1c i 1, g i 1= a i 1b i 1, p i 1 = a i 1 + b i 1 Here is the reason for the symbols p and g: If gi1 is true, then ci is certainly true, so a carry is generated. Thus, g is for generate. If pi1 is true, then if ci1 is true, it is propagated to ci. Start with Equation H.8.1 and use Equation H.8.2 to replace ci with gi 1 + pi1ci1. Then, use Equation H.8.2 with i 1 in place of i to replace ci1 with ci2, and so on. This gives the result H.8.3 ci = g i1 + p i1 gi2 + p i1 pi2gi3 + + p i1 pi2 p1 g0 + p i1 pi2 p1p0c0 An adder that computes carries using Equation H.8.3 is called a carrylookahead adder, or CLA. A CLA requires one logic level to form p and g, two levels to form the carries, and two for the sum, for a grand total of five logic levels. This is a vast improvement over the 2n levels required for the ripple-carry adder. Unfortunately, as is evident from Equation H.8.3 or from Figure H.14, a carry-lookahead adder on n bits requires a fan-in of n + 1 at the OR gate as well as at the rightmost AND gate. Also, the pn1 signal must drive n AND gates. In addition, the rather irregular structure and m any long wires of Figure H.14 make it impractical to build a full carry- lookahead adder when n is large. However, we can use the carry-lookahead idea to build an adder that has about log2n logic levels (substantially fewer than the 2n required by a ripple-carry adder) and yet has a simple, regular structure. The idea is to build up the ps and gs in steps. We have already seen that ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 209
c1 = g0 + c0p0 This says there is a carry-out of the 0th position (c1) either if there is a carry generated in the 0th position or if there is a carry into the 0th position and the carry propagates. Similarly, c2 = G01 + P01c0 H.8 Speeding Up Integer Addition G01 means there is a carry generated out of the block consisting of the first two bits. P01 means that a carry propagates through this block. P and G have the following logic equations: G01 = g1 + p1g0 P01 = p1p0 With these preliminaries out of the way, we can now show the design of a practical CLA. The adder consists of two parts. The first part computes various values of P and G from pi and gi, using Equations H.8.5 and H.8.6; the second part uses these P and G values to compute all the carries via Equation H.8.4. The first part of the design is shown in Figure H.15. At the top of the diagram, input numbers a7. . . a0 and b7. . . b0 are converted to ps and gs using cells of type 1. Then various Ps and Gs are generated by combining cells of type 2 in a binary tree structure. The second part of the design is shown in Figure H.16. By feeding c0 in at the bottom of this tree, all the carry bits come out at the top. Each cell must know a pair of (P,G) values in order to do the conversion, and the value it needs is written inside the cells. Now compare Figures H.15 and H.16. There is a one-to-one correspondence between cells, and the value of (P,G) needed by the carry-generating cells is exactly the value known by the corresponding (P,G)- generating cells. The combined cell is shown in Figure H.17. The numbers to be added flow into the top and downward through the tree, combining with c0 at the bottom and flowing back up the tree to form the carries. Note that one thing is missing from Figure H.17: a small piece of extra logic to compute c8 for the carry-out of the adder. The bits in a CLA must pass through about log2 n logic levels, compared with 2n for a ripple-carry adder. This is a substantial speed improvement, especially for a large n. Whereas the ripple-carry adder had n cells, however, the CLA has. ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 210
The multiplication and division algorithms presented in Section H.2 are fairly slow, producing 1 bit per cycle (although that cycle might be a fraction of the CPU instruction cycle time). In this section we discuss various techniques for higher-performance multiplication and division, including the division algorithm used in the Pentium chip.
Shifting over Zeros Although the technique of shifting over zeros is not currently used much, it is instructive to consider. It is distinguished by the fact that its execution time is operand dependent. Its lack of use is primarily attributable to its failure to offer enough speedup over bit-at-a- time algorithms. In addition, pipelining, synchronization with the CPU, and good compiler optimization are difficult with algorithms that run in variable time. In multiplication, the idea behind shifting over zeros is to add logic that detects when the low-order bit of the A register is 0 (seeFigure H.2(a) on page H-4) and, if so, skips the addition step and proceedsdirectly to the shift stephence the term shifting over zeros. What about shifting for division? In nonrestoring division, an ALU operation (either an addition or subtraction) is performed at every step. There appears to be no opportunity for kipping an operation. But think about division this way: To compute a/b, subtract multiples of b rom a, and then report how many subtractions were done. At each stage of the subtraction rocess the remainder must fit into the P register. In the case when the remainder is a small positive number, you normally subtract b; but suppose instead you only shifted the remainder and subtracted b the next time. As long as the remainder was sufficiently small (its high-order bit 0), after shifting it still would fit into the P register, and no information would be lost. However, this method does require changing the way we keep track of the number of times b has been subtracted from a. This idea usually goes under the name of SRT division, for Sweeney Robertson, and Tocher, who independently proposed algorithms of this nature. The main extra complication of SRT division is that the quotient bits cannot be determined immediately from the sign of P at each step, as they can be in ordinary nonrestoring division. More precisely, to divide a by b where a and b are n-bit numbers, load a and b into the A and B registers, respectively, of Figure H.2 SRT Division ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 211
1. If B has k leading zeros when expressed using n bits, shift all the registers left k bits. 2. For i = 0, n 1, (a) If the top three bits of P are equal, set qi = 0 and shift (P,A) one bit left. (b) If the top three bits of P are not all equal and P is negative, set qi = 1 (also written as 1), shift (P,A) one bit left, and add B. (c) Otherwise set qi = 1, shift (P,A) one bit left, and subtract B. End loop 3. If the final remainder is negative, correct the remainder by adding B, and correct the quotient by subtracting 1 from q0. Finally, the remainder must be shifted k bits right, where k is the initial shift. A numerical example is given in Figure H.23. Although we are discuss in integer division, it helps in explaining the algorithm to imagine the binary point just left of the most-significant bit. This changes Figure H.23 from 010002/00112 to 0.10002/.00112. Since the binary point is changed in both the numerator and denominator, the quotient is not affected. The (P,A) register pair holds the remainder and is a twos complement number. For example, if P contains 111102 and A = 0, then the remainder is 1.11102 = 1/8. If r is the value of there mainder, then 1 r < 1. Given these preliminaries, we can now analyze the SRT division algorithm. The first step of the algorithm shifts b so that b 1/2. The rule for which ALU operation to perform is this: If 1/4 r < 1/4 (true whenever the top three bits of P are equal), then compute 2r by shifting (P,A) left one bit; else if r < 0 (and hence r < 1/4, since otherwise it would have been eliminated by the first condition), then compute 2r + b by shifting and then adding, else r 1/4 and subtract b from 2r. Using b 1/2, it is easy to check that these rules keep 1/2 r < 1/2. For no restoring division, we only have r b, and we need P to be n + 1 bits wide. But for SRT division, the bound on r is tighter, namely, 1/2 r < 1/2. Thus, we can save a bit by eliminating the high-order bit of P (and b and the adder). In particular, the test for equality of the top three bits of P becomes a test on ust two bits.The algorithm might change slightly in an implementation of SRT division. After each ALU operation, the P register can be shifted as many places as necessary to make either r 1/4 or r < 1/4. By shifting k places, k quotient bits are set equal to zero all at once. For this reason SRT ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 212
division is sometimes described as one that keeps the remainder normalized to r 1/4.
Notice that the value of the quotient bit computed in a given step is based on which operation is performed in that step (which in turn depends on the result of the operation from the previous step). This is in contrast to nonrestoring division, where the quotient bit computed in the ith step depends on the result of the operation in the same step. This difference is reflected in the fact that when the final remainder is negative, the last quotient bit must be adjusted in SRT division, but not in nonrestoring division. However, the key fact about the quotient bits in SRT division is that they can include 1. Although Figure H.23 shows the quotient bits being stored in the low-order bits of A, an actual implementation cant do this because you cant fit the three values 1, 0, 1 into one bit. Furthermore, the quotient must be converted to ordinary twos complement in a full adder. A common way to do this is to accumulate the positive quotient bits in one register and the negative quotient bits in another, and then subtract the two registers after all the bits are known. Because there is more than one way to write a number in terms of the digits 1, 0, 1, SRT division is said to use a redundant quotient representation.
The differences between SRT division and ordinary nonrestoring division can be summarized as follows: 1. ALU decision rule: In nonrestoring division, it is determined by the sign of P; in SRT, it is determined by the two most-significant bits of P. 2. Final quotient: In nonrestoring division, it is immediate from the successive signs of P; in SRT, there are three quotient digits (1, 0, 1), and the final quotient must be computed in a full n-bit adder. 3. Speed: SRT division will be faster on operands that produce zero quotient bits. The simple version of the SRT division algorithm given above does not offer enough of a speedup to be practical in most cases. However, later on in this section we will study variants of SRT division that are quite practical.
ADVANCED COMPUTER ARCHITECTURE 12SCS23
Dept of CS&E, SJBIT Page 213
Fallacies and Pitfalls Fallacy Underflows rarely occur in actual floating-point application code. Although most codes rarely underflow, there are actual codes that underflow frequently. SDRWAVE [Kahaner 1988], which solves a one-dimensional wave equation, is one such example. This program underflows quite frequently, even when functioning properly. Measurements on one machine show that adding hardware support for gradual underflow would cause SDRWAVE to run about 50% faster. Fallacy Conversions between integer and floating point are rare. In fact, in spice they are as frequent as divides. The assumption that conversions are rare leads to a mistake in the SPARC version 8 instruction set, which does not provide an instruction to move from integer registers to floating-point registers. Pitfall Dont increase the speed of a floating-point unit without increasing its memory bandwidth. A typical use of a floating-point unit is to add two vectors to produce a third vector. If these vectors consist of double-precision numbers, then each floating-point add will use three operands of 64 bits each, or 24 bytes of memory. The memory bandwidth requirements are even greater if the floating-point unit can perform addition and multiplication in parallel (as most do). Pitfall x is not the same as 0 x. This is a fine point in the IEEE standard that has tripped up some designers. Because floating-point numbers use the sign magnitude system, there are two zeros, +0 and 0. The standard says that 0 0 = +0, whereas (0) = 0. Thus x is not the same as 0 x when x = 0.