1 Guaranteeing the Correctness of MC for ARM Richard Barton.

Slides:



Advertisements
Similar presentations
Dr. Ken Hoganson, © August 2014 Programming in R COURSE NOTES 2 Hoganson Language Translation.
Advertisements

Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
RISC / CISC Architecture By: Ramtin Raji Kermani Ramtin Raji Kermani Rayan Arasteh Rayan Arasteh An Introduction to Professor: Mr. Khayami Mr. Khayami.
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
1/1/ /e/e eindhoven university of technology Microprocessor Design Course 5Z008 Dr.ir. A.C. (Ad) Verschueren Eindhoven University of Technology Section.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
16/13/2015 3:30 AM6/13/2015 3:30 AM6/13/2015 3:30 AMIntroduction to Software Development What is a computer? A computer system contains: Central Processing.
Behavioral Design Outline –Design Specification –Behavioral Design –Behavioral Specification –Hardware Description Languages –Behavioral Simulation –Behavioral.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
February 21, 2008 Center for Hybrid and Embedded Software Systems Mapping A Timed Functional Specification to a Precision.
Table 1. Software Hierarchy Levels.. Essential Tools An assembler is a program that converts source-code programs into a machine language (object file).
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
EE694v-Verification-Lect5-1- Lecture 5 - Verification Tools Automation improves the efficiency and reliability of the verification process Some tools,
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
Prardiva Mangilipally
© 2009 Acehub Vista Sdn. Bhd Introduction to ARM ® Processors.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Your Interactive Guide to the Digital World Discovering Computers 2012.
Activity 1 - WBs 5 mins Go online and spend a moment trying to find out the difference between: HIGH LEVEL programming languages and LOW LEVEL programming.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Precision Going back to constant prop, in what cases would we lose precision?
Language Evaluation Criteria
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Xactium xDSLs Run Models Not Code Tony Clark
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Invitation to Computer Science, Java Version, Second Edition.
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
What Do I Represent?. Translators – Module Knowledge Areas Revisiting object code When we disassemble code we can view the opcodes used This is just a.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1.4 Representation of data in computer systems Instructions.
CSC 480 Software Engineering Test Planning. Test Cases and Test Plans A test case is an explicit set of instructions designed to detect a particular class.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
Internals of SimpleScalar Simulators CPEG323 Tutorial Long Chen November, 2005.
Representation of Data - Instructions Start of the lesson: Open this PowerPoint from the A451 page – Representation of Data/ Instructions How confident.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Computer Organization IS F242. Course Objective It aims at understanding and appreciating the computing system’s functional components, their characteristics,
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Chapter 10 Application Development
The architecture of the P416 compiler
Andreas Hoffmann Andreas Ropers Tim Kogel Stefan Pees Prof
Assembler, Compiler, MIPS simulator
14 Compilers, Interpreters and Debuggers
Chapter 1 OBJECT-ORIENTED ANALYSIS AND DESIGN
Microprocessor and Assembly Language
Processor (I).
CS/COE0447 Computer Organization & Assembly Language
TRANSLATORS AND IDEs Key Revision Points.
Precision Timed Machine (PRET)
SDLC Model A framework that describes the activities performed at each stage of a software development project.
CSCE Fall 2013 Prof. Jennifer L. Welch.
Baisc Of Software Testing
CSCE Fall 2012 Prof. Jennifer L. Welch.
Introduction to Microprocessor Programming
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Lecture 4: Instruction Set Design/Pipelining
Programming language translators
Dynamic Binary Translators and Instrumenters
Presentation transcript:

1 Guaranteeing the Correctness of MC for ARM Richard Barton

2 The MC Layer  The Machine Code layer is a single location for Target specific information for representing machine instructions.  Multi-platform  Multi-directional  Table-generated JIT code Assembly (.s) Object File (.o) Front End Code (.c) Optimiser Code Generator MC

3 Definition of the problem  The MC layer is a cornerstone of LLVM.  It is used by compilers, assemblers, debuggers and JIT compilers.  We need this component to be trustworthy in order for great tools to be built with it.  How can we guarantee the correctness that we need?

4 What is the functionality of MC?  Decode:  interpret instruction bit patterns  Encode  output instruction bit patterns  Assemble  Interpret instruction assembly  Disassemble  output instruction assembly  We will not be testing the interface between LLVM and MC. decode LLVM MCInst encode assemble disassemble Bit pattern 0xE Assembly ADDS r0, r1, #1

5 Our Strategy for solution  Exhaustive checking of the problem space against a known correct implementation with the same functionality.  We think that our strategy is architecture agnostic.

6 Our Strategy for solution  Exhaustive checking of the problem space against a known correct implementation with the same functionality.  We think that our strategy is architecture agnostic.  What do we mean by exhaustive?

7 Our Strategy for solution  Exhaustive checking of the problem space against a known correct implementation with the same functionality.  We think that our strategy is architecture agnostic.  What do we mean by exhaustive?  What do we mean by the whole problem space?

8 What is the problem space?  Problem space has 4 dimensions  Instruction encoding  e.g. 0 – 2^32 for ARM  Instruction set  e.g. ARM vs. Thumb, x86_32 vs. x86_64,...  Architecture variant  e.g. ARMv6 vs. ARMv7, MIPS IV vs. MIPS V,...  MC Functionality  4 possible values {encode, decode, disassemble, assemble}

9 What is the problem space for ARM?  Test space has 4 dimensions  Instruction encoding  2^32 possible values  Instruction set  2 possible values: ARM, Thumb  Architecture variant  28 pre-ARMv7 architecture + extensions combinations  176 ARMv7 architecture + extensions combinations  204 possible values  MC Functionality  4 possible values {encode, decode, disassemble, assemble}  The whole test space has O(7 trillion) points  7,009,386,627,072 points

10 Testing decode and disassemble  The below diagram illustrates one chain of transformations that test two MC functions.  The ‘golden’ components are considered bug free. LLVM MCInst UAL assembly LLVM MC disassemble Reference Impl. assemble and encode LLVM MC decode Bit pattern 1Bit pattern 2 == ?

11 Testing encode  Now that we have found and fixed all the bugs in MC’s decoder, it becomes ‘golden’  We can use it to test encoding. LLVM MCInst LLVM MC decode LLVM MC encode Bit pattern 1Bit pattern 2 == ?

12 Testing assemble  Testing assembling is similar to testing disassembling.  We iterate over the instruction encodings in each case as they are easier to enumerate than UAL strings. LLVM MCInst UAL assembly LLVM MC assemble LLVM MC decode and disassemble LLVM MC encode Bit pattern 1Bit pattern 2 == ?

13 Implementation Details  A test suite needs a name.  We have named this test suite the MC Hammer Tests

14 Icodec: our reference implementation  A set of libraries that provide an abstraction of instruction encodings. It can be regarded as an implementation of the Unified Assembler Language providing a unified view of several similar instruction sets.  Handles encode, decode, assembling and disassembling.  Used in the ARM Compiler toolchain.  A golden reference implementation – no known bugs!  Is ARM proprietary IP.

15 What is the test space for ARM?  Test space has 4 dimensions  Instruction encoding  2^32 possible values  Instruction set  2 possible values: ARM, Thumb  Architecture variant  204 possible values  MC Functionality  4 possible values {encode, decode, disassemble, assemble}  The whole test space has O(7 trillion) points  7,009,386,627,072 points  Even at 100,000 tests/s this would take 3.3 years to cover

16 Can we make this smaller?  Some cores do not support certain instruction sets  e.g. ARMv6M is Thumb only (Cortex-M0)  Some architecture and extensions combinations are not permitted.  e.g. ARMv7 with VFPv2  ARMv7 architecture extensions are often orthogonal  e.g. VFP/NEON and security extensions  For a plain Cortex-A8 core there are O(34 billion) points  34,359,738,368 points

17 Slicing the Test Space  The Test Suite will run on a slice of the test space.  A slice is a 4-tuple describing a subset of the possible values of each dimension.  For example:  0x0 – 0x0000FFFF x ARMv5TE x Thumb x assemble  0x0 – 0xFFFFFFFF x ARMv7-A + VFPv3 + Adv. SIMDv1 + Half Precision Extension + Security Extensions x ARM x encode_decode  0bXXXX_0000_0001_XXXX_0000_XXXX_1001_XXXX x ARMv7-A x ARM x disassemble

18 Implementation Details  How can we ensure that undefined instructions are correctly transformed? LLVM MCInst UAL assembly LLVM MC disassemble Reference Impl. assemble and encode LLVM MC decode Bit pattern 1Bit pattern 2 == ?

19  How can we ensure that undefined instructions are correctly transformed? LLVM MCInst LLVM MC disassemble Reference Impl. assemble and encode LLVM MC decode Bit pattern 1Bit pattern 2 == ? Undefined instruction Implementation Details

20  How can we ensure that undefined instructions are correctly transformed? Implementation Details Undefined instruction LLVM MCInst LLVM MC disassemble LLVM MC decode Bit pattern 1 Reference Impl. decode and disassemble

21 Implementation Details  How can we ensure that undefined instructions are correctly transformed?  For this you will need at least some decoder implementation as well as an assembler.  We solve this problem by comparing Icodec’s internal representation instead of bit patterns.  We know that MC cannot create an instruction from a bit pattern that should be an undefined instruction.

22 Example Bug: VCVT  VCVT (between floating-point and fixed point)  VCVTEQ.F32.S16 s0,s0,#16  Symptom is a SIGABRT with a bit pattern. Running slice: core_v7A+vfpneon_vfpv3_neonv1 feature_ARM 0x0 - 0x3fffffff encode_decode *** Killed by signal 6 *** (bitpattern eba0a40)

23 Example Bug: VCVT (2)  Investigation showed that the Vd operand was not being mapped into the instruction encoding in tablegen, causing the MCInst to have two too few operands, and the encoder to try to read a non-existent operand.

24 Example Bug: VCVT (3)  Needed to add a split in the class hierarchy for single- and double-precision versions as they encoded Vd differently // Single Precision register class AVConv1XInsS_Encode op1, bits op2, bits op3, bits op4, bit op5, dag oops, dag iops, InstrItinClass itin, string opc, string asm, list pattern> : AVConv1XI { bits dst; // if dp_operation then UInt(D:Vd) else UInt(Vd:D); let Inst{22} = dst{0}; let Inst{15-12} = dst{4-1}; } def VTOSHS : AVConv1XInsS_Encode<0b11101, 0b11, 0b1110, 0b1010, 0, (outs SPR:$dst), (ins SPR:$a, fbits16:$fbits), IIC_fpCVTSI, "vcvt", ".s16.f32\t$dst, $a, $fbits", []> { // Some single precision VFP instructions may be executed on both NEON and // VFP pipelines on A8. let D = VFPNeonA8Domain; }

25 Example Bug: VCVT (4)  Created patch and added test cases.  Re-run slice through MC Hammer to check that it is completely correct slice=[0b x111x1xxxxx101xx1x0xxxx][core_v7a+vfpneon_vfpv3_neonv1] [feature_ARM][encode_decode]

26 Common errors  Regression tests with 0-registers.  Internal inconsistency within MC between uncommonly tested code paths. Probably assemble+encode and decode+disassemble are quite well tested but other combinations like encode/decode are not.  Patch for llvm-mc imminent  MC does not have a good model of unpredictable ARM instructions.  Added a third failure mode for these instructions.  e.g. MUL pc, r0, r1 is

27 How Trustworthy is MC?  Initial indication is that ~10% of all ARM instructions for a Cortex-A8 slice are encoded incorrectly by MC.  18% of ARM instructions incorrect assembled  Test suite performance (1 thread)  For encode decode MC Hammer can run 7 Million tests/s. So one Cortex-A8 slice takes ~ 1 hour.  The assemble/disassemble tests take a few hours  Progress  ~ 2 man months of effort so far  14 patches submitted upstream, 8 accepted.  ~ 0.5% decrease in encoding bugs so far

28 How does this help the community?  We think our approach is the first structured approach to improving the correctness of code generation for ARM in the MC layer.  There is an ongoing effort to make the MC Layer more reliable.  The methodology can easily be applied to other tool chains and other architectures.  Requires a reference implementation, normally an assembler.  Requires a unified assembly syntax

29 The End  Thank you for listening.