# Patent

## Title
Compiler retargeting based on instruction semantic models

## Abstract

Generating a description of compiler code selector rules from an architecture description. A method comprises accessing a target architecture model written in an architecture description language (ADL) and extracting semantic information therefrom to generate a plurality of semantic statements. Rules that map from source code operations to semantic patterns are accessed. The semantic statements are searched for matches for the semantic patterns to generate mappings that serve as a description of compiler code selector rules.

## Background
RELATED APPLICATIONS
This application claims priority to U.S. Provisional Application entitled, “C COMPILER RETARGETING BASED ON INSTRUCTION SEMANTICS MODELS,” to Braun et al., Application No. 60/574,794, filed on May 26, 2004, which application is hereby incorporated by reference.
This application is related to U.S. application, entitled, “METHOD AND DEVICE FOR SIMULATOR GENERATION BASED ON SEMANTIC TO BEHAVIORAL TRANSLATION,” to Braun et al., application Ser. No. 11/139,373, filed May 26, 2005, now U.S. Pat. No. 7,313,773, issued Dec. 25, 2007 concurrently herewith.
This application is related to U.S. application entitled, “GENERATION OF COMPILER DESCRIPTION FROM ARCHITECTURE DESCRIPTION,” to Braun et al., application Ser. No. 10/815,228, filed on Mar. 30, 2004.
This application is related to U.S. application entitled, “METHOD AND SYSTEM OF SCHEDULING INSTRUCTIONS,” to Braun et al., application Ser. No. 11/096,184 filed on Mar. 30, 2005.


FIELD OF THE INVENTION
Embodiments of the present invention relate to the field of software tools for system level design. Specifically, embodiments of the present invention relate to automatically generating compiler code selector rules for a target architecture based on semantic models of the target architecture.
BACKGROUND ART
The design and test of modern electronic devices, such as embedded processors (EP) and systems-on-a-chip (SoC) is a complex process involving many stages. For example, many systems, such as mobile devices, networking products, and modems require new embedded processors (EP). These EPs can either be general purpose, such as microcontrollers and digital signal processors (DSP), or application specific, using application specific instruction set processors (ASIP). Compared to general-purpose processors, ASIPs provide a tradeoff of computational performance and flexibility on the one hand and power consumption on the other. Therefore, ASIPs that are designed to execute specific tasks very efficiently can be found in a wide range of embedded systems.
However, designing systems with ASIPs is far more complex than assembling systems with standard processors. Typically, designing ASIPs comprises an iterative exploration in which hardware and software are explored and modified. This iterative process is referred to as an architecture exploration loop. The architecture exploration typically requires a number of tools, such as an assembler, linker, and simulator. If hardware and software are available, profiling results are acquired that usually lead to architecture modifications making the processor more efficient. To be consistent with these modifications, the software tools potentially need to be changed, as well.
Moreover, the overall design time can be significantly reduced by introducing into the architecture exploration loop a retargetable compiler that reflects the target architecture. Besides reducing the implementation and verification time, the availability of a compiler also increases the system reusability for similar applications.
In contrast to traditional compilers that target only a single processor architecture, retargetable compilers can be altered to generate code for different target processor architectures due to an editable target architecture model. Thus, the retargetable compiler can be used in the architecture exploration phase. Further, retargetable compilers (possibly enhanced with target-specific code optimization techniques) can be used to quickly generate production compilers for the ASIP IP end users for application software development. Thus, efficient architecture exploration and design of ASIPs requires retargetable software development tools, in particular compilers that can be quickly adapted to new target architectures.
One design approach is to model the target architecture in a dedicated description language (ADL) and to generate some tools automatically from the ADL specification. For compiler generation, however, most existing systems are limited either by the manual retargeting effort or by redundancies in the ADL models that lead to potential inconsistencies.
In the context of ASIP design, where a tight link to hardware and system on a chip (SoC) design flows is required, two mainstream approaches to retargetable compilation can be identified. The first one builds on a predefined, yet configurable processor core that can be optimized by the user via addition of custom machine instructions. In this case, semi-custom compiler systems can be used, and retargeting is implemented by making new instructions available to the compiler in the form of “intrinsics.” While this approach offers the advantage of reusing well-proven compiler tools, it restricts the flexibility of the ASIP designer and requires manual (and non-portable) software source code modifications.
The second approach is based on the paradigm of architecture description languages (ADLs) that permit high-level (e.g., beyond Register Transfer Level or RTL) modeling of processors for early design phases such as architecture exploration and system-level verification. A challenge in retargetable compilation based on ADL models, however, is the large variety of potential target architectures, which is essentially only limited by the ADL's capabilities. The ADL approach permits very high flexibility in ASIP design, but demands advanced techniques for efficient compiler retargeting.
A detailed overview of work related to compiler generation from processor architecture description languages (ADLs) or compiler specifications is given by R. Leupers and P. Marwedel in, “Retargetable Compiler Technology for Embedded Systems,” Kluwer Academic Publishers, Boston, October 2001, which is incorporated herein as background material.
SUMMARY OF THE INVENTION
Therefore, it would be advantageous to provide a method and device that reduce the time required for the design exploration phase of architectures such as ASIPs. It would be further advantageous to accurately and efficiently automatically generate a compiler description that may be used in the architecture exploration. It would be still further advantageous to meet the above constraints while being compatible with existing technologies for developing embedded processors, systems-on-a-chip, and ASIPs.
Accordingly, embodiments of the present invention provide methods and devices that automatically generate a compiler for a target architecture based on a semantic description of the target architecture. Embodiments of the present invention provide for easy retargeting of the compiler. More particularity, embodiments of the present invention accurately and efficiently generate a description of compiler code selector rules that may be used in an architecture exploration. For example, the compiler description may be input to a tool that automatically generates a compiler from the compiler description. Moreover, the target architecture model writer does not need substantial knowledge about compilers to write a usable model. Embodiments of the present invention minimize redundancies in the ADL of the target architecture, while simultaneously achieving a high degree of automation. Embodiments of the present invention meet the above constraints while being compatible with existing technologies for developing embedded processors, systems-on-a-chip, and ASIPs. Embodiments of the present invention provide these advantages and others not specifically mentioned above but described in the sections to follow.
One embodiment of the present invention comprises a computer-implemented method of generating a description of compiler code selector rules from an architecture description. The method comprises accessing a target architecture model written in an architecture description language (ADL) and extracting semantic information therefrom to generate a plurality of semantic statements. Rules that map from source code operations to semantic patterns are accessed. The semantic statements are searched for matches for the semantic patterns to generate mappings that serve as a description of compiler code selector rules.
Another embodiment of the present invention comprises, in addition to the above, accessing a library of pre-defined semantic transformations; and applying at least one of the semantic transformations to the extracted semantic information. For example, at least two of the semantic statements that are substantially equivalent to a single one of said semantic patterns are determined.
A further embodiment of the present invention comprises extracting assembly code syntax from the target architecture model and associating the assembly code syntax with the semantic statements.
In a further embodiment, the rules comprise tree patterns with place holders for non-terminal positions. Non-terminals may, for example, represent locations in which to store intermediate results. Non-terminals are extracted from the target architecture model, wherein the rules are permuting with the non-terminals.



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 illustrates an overview of a design flow, involving automatic generation of a retargetable compiler from a description of a target architecture, in accordance with an embodiment of the present invention.
FIG. 2 illustrates a diagram of automatic generation of a retargetable compiler from a description of a target architecture, in accordance with an embodiment of the present invention.
FIG. 3 illustrates an overview of code selector rule generation, in accordance with an embodiment of the present invention.
FIG. 4 reviews a one-to-one mapping procedure of a basic rule, in accordance with an embodiment of the present invention.
FIG. 5 illustrates an example of a semantic transformation, in accordance with an embodiment of the present invention.
FIG. 6 illustrates an example of many-to-one mapping, in accordance with an embodiment of the present invention.
FIG. 7 is a flowchart illustrating a computer process of generating compiler code selector rules from a target architecture description, in accordance with an embodiment of the present invention.
FIG. 8 is an exemplary computer system that may serve as a platform upon which embodiments of the present invention may be executed.
FIG. 9 shows a block diagram of simulator generation from a semantic instruction-set description, in accordance with an embodiment of the present invention.
FIG. 10 is a flowchart illustrating steps of a process of automatically generating a simulator from an architecture description, in accordance with an embodiment of the present invention.
FIG. 11 is a flowchart illustrating steps of a process of automatically generating simulators on different abstraction levels from a common target architecture model, in accordance with an embodiment of the present invention.



DETAILED DESCRIPTION OF THE INVENTION
In the following detailed description of embodiments of the present invention, automatically generating a description of compiler code selector rules from a semantic model of a target architecture, numerous specific details are set forth in order to provide a thorough understanding of the present invention. However, it will be recognized by one skilled in the art that the present invention may be practiced without these specific details or with equivalents thereof. In other instances, well-known methods, procedures, and components have not been described in detail as not to unnecessarily obscure aspects of the present invention.
NOTATION AND NOMENCLATURE
Some portions of the detailed descriptions that follow are presented in terms of procedures, steps, logic blocks, processing, and other symbolic representations of operations on data bits that can be performed on computer memory. These descriptions and representations are the means used by those skilled in the data processing arts to most effectively convey the substance of their work to others skilled in the art. A procedure, computer executed step, logic block, process, etc., is here, and generally, conceived to be a self-consistent sequence of steps or instructions leading to a desired result. The steps are those requiring physical manipulations of physical quantities. Usually, though not necessarily, these quantities take the form of electrical or magnetic signals capable of being stored, transferred, combined, compared, and otherwise manipulated in a computer system. It has proven convenient at times, principally for reasons of common usage, to refer to these signals as bits, values, elements, symbols, characters, terms, numbers, or the like.
It should be borne in mind, however, that all of these and similar terms are to be associated with the appropriate physical quantities and are merely convenient labels applied to these quantities. Unless specifically stated otherwise as apparent from the following discussions, it is appreciated that throughout the present invention, discussions utilizing terms such as “executing” or “receiving” or “generating” or “processing” or “computing” or “translating” or “mapping” or “determining” or “maintaining” or “creating” or “storing” or “constructing” or “accessing” or “extracting” or “selecting” or the like, refer to the action and processes of a computer system, or similar electronic computing device, that manipulates and transforms data represented as physical (electronic) quantities within the computer system's registers and memories into other data similarly represented as physical quantities within the computer system memories or registers or other such information storage, transmission or display devices.
FIG. 1 illustrates an overview of a design flow, which involves automatic generation of a retargetable compiler from a description of a target architecture in accordance with an embodiment of the present invention. The design flow starts with an architecture description language (ADL) description of a target architecture 120, which may be supplied by a user. In accordance with an embodiment of the present invention, the target architecture ADL description 120 is input to one of the automatic tool generators 125, which outputs a compiler 180 adapted for the target architecture.
An instruction set simulator 140 may be automatically generated from the target architecture ADL description 120, in accordance with an embodiment of the present invention. In accordance with an embodiment of the present invention, the target architecture ADL description 120 is input to one of the automatic tool generators 125, which outputs a simulator 140 adapted for the target architecture.
Other tools may be used in the exploration path, such as an assembler 145 and a linker 150. These tools may also be automatically generated from the target architecture description 120, although such automatic generation is not required for the present invention. It is also possible to generate tools and descriptions along the implementation path, such as an HDL description 168, synthesis tools 178, and a gate level model 189. However, generation of these tools and descriptions is not a requirement of the present invention.
Along both the exploration path and the implementation path, the user may evaluate results and modify the target architecture ADL description 120 based thereon. With this approach, the target architecture design is simplified due to a high degree of automation and the fact that the user may specify a single target architecture description 120 for the entire design flow. In a typical design flow, the initial target architecture description may be at a high level of abstraction, wherein the user adds complexity to the target architecture description based on the evaluation results.
Retargetable Compiler Generation
Referring now to FIG. 2, during compiler generation in accordance with embodiments of the present invention, the target architecture description 120 is analyzed and compiler-relevant information is automatically extracted based on semantic information. For example, a semantic description of instructions. From the semantic information, the compiler description generator 160 generates a compiler generator description (CGD), which is input into the compiler generator 170, which outputs the compiler 180. A suitable compiler generator 170 in one embodiment is the COSY® Compiler Development System provided by Associated Computer Experts (ACE) of Amsterdam, The Netherlands. However, the present invention is not limited to using the COSY® Compiler Development System to generate the compiler 180.
The compiler 180 parses the source code 175, applies typical high-level optimizations, utilizes a tree pattern matcher for code selection and conducts a global register allocation. Embodiments of the present invention automatically generate a description of code selector rules that may be used for the tree pattern matcher. The output of the compiler 180 is unscheduled instrumented assembly code 182 that is compliant with the target architecture. Each assembly instruction in the unscheduled instrumented assembly code 182 contains an instruction class identifier and information about the resources (e.g., registers, memory) that it reads or writes. From this input, the Ipacker tool 184 creates a dependence directed acyclic graph (DAG). The DAG is fed into a mixedBT scheduler, which is implemented in the Ipacker tool 184. The scheduling result is assembly code 186 that is compliant with the ADL model of the target architecture. The assembly code 186 is read by the assembler/linker 188. The assembler/linker may be generated from the target architecture description 120 as well. However, the generation of the assembler/linker is not a requirement of the present invention. Finally, executable code 191 is output.
Embodiments of the present invention adapt the compiler backend (or code generator) to the target architecture. A compiler backend typically has a code selector, a register allocator, and an instruction scheduler as its main building blocks. Embodiments of the present invention automatically generate code selector rules for the target architecture based on explicit semantic information in the target architecture ADL.
Techniques for automatically generating register allocator and instruction scheduler portions of the compiler backend from a target architecture ADL are described in co-pending U.S. patent application Ser. No. 10/815,228, entitled “GENERATION OF COMPILER DESCRIPTION FROM ARCHITECTURE DESCRIPTION,” filed on Mar. 30, 2004, and assigned to the assignee of the present invention and incorporated herein by reference, and in co-pending U.S. patent application Ser. No. 11/096,184, entitled “METHOD AND SYSTEM OF SCHEDULING INSTRUCTIONS,” filed on Mar. 30, 2005, and assigned to the assignee of the present invention and incorporated herein by reference. Techniques described in these referenced patent applications employ a semi-automatic Graphical User Interface (GUI) based approach that allow a user to specify the code selector's mapping rules. Furthermore, certain compiler relevant information is automatically extracted from the target architecture ADL.
Embodiments of the present invention do not require a GUI for supplying information for generating compiler code selector rules. Embodiments of the present invention eliminate the semantic gap between the ADL, which captures many details of instruction execution in hardware, and the compiler view of a target architecture, which may require more abstract instruction semantics information. Embodiments of the present invention eliminate this semantic gap by a novel three-phase technique for code selector rule generation based on explicit semantic information in the target architecture ADL model. This includes extracting the mapping rules for the compiler's code selector based on explicit instruction semantics information in the target ADL model.
Embodiments of the present invention use a semantics view of operations that captures behavior at a relatively high abstraction level. In a typical ADL having a behavioral view of operations, state updates of processor resources are described in plain code (e.g., C/C++ code) to achieve flexibility and simulation speed. However, since the same behavior may be described with numerous syntactic variances in, e.g., C/C++, it is generally not possible to automatically extract the operation semantics, (e.g., a more abstract compiler-oriented view) from such a specification. For code generation, the compiler needs information about the semantics of an operation (e.g. whether an operation performs an ADD or SUB on visible data registers), as well as a few side effects like implicit modification of the carry or zero flag.
On the other hand, the compiler does not need information about execution details in hardware, such as access to instruction pipeline registers. Therefore, some of the detailed information in the target architecture ADL is not needed for compiler generation. Embodiments of the present invention, therefore, capture instruction semantics explicitly in the target architecture model by using a limited and precisely defined set of micro-operators in SEMANTICS statements, which describe the instruction set. Micro-operators are atomic elements from which larger elements such as assembly instructions can be constructed. Micro-operators typically describe a computation on processor resources that can be executed by a data path component such as an ALU (e.g. a 16-bit ADD). While micro-operators are a convenient way to capture instruction semantics, the present invention is not limited to using micro-operators as described herein to achieve a semantic description of the target architecture instruction set.
FIG. 3 illustrates an overview of code selector rule generation and use thereof in a compiler, in accordance with an embodiment of the present invention. The mapping of tree-patterns to assembly code 315 used by the compiler 180 may be derived from the description of the code selector rules generated by embodiments of the present invention. The compiler 180 generates a tree-based intermediate representation 310 from the input source code 175 per known techniques. The compiler 180 uses the code selector rules 315 to produce assembly code 182 from the intermediate representation 310.
The automatic generation of the code selector rules involves extracting information from the target architecture ADL model 120, which may comprise a semantic section and a syntax section. The semantic section describes what an instruction does. The syntax section describes the actual assembly code for a machine instruction. From the semantic section and the syntax section, a semantics-to-assembly database 335 is created by an embodiment of the present invention.
FIG. 3 also depicts two databases comprising a priori knowledge. A basic rules database 325 comprises basic rules that map from a tree intermediate representation to semantics. In other words, this basic rule database 325 has basic rules each of which maps from a source code operation to a semantic statement that describes a machine instruction that is capable of performing the source code operation. An exemplary basic rule is depicted in Table IX herein.
A tree-IR-to-assembly database 340 is automatically generated from the basic rule database 325 and the semantics-to-assembly database 335 by an embodiment of the present invention. Content from the tree-IR-to-assembly database 340 may be used in a compiler generator description (CGD), which may be input into a compiler generator, such as compiler generator 170 of FIG. 2. The compiler generator description will typically include other information to generate aspects of the compiler other than the code selector rules.
Another database is a semantic transformation database 330. This database 330 may comprise pre-defined semantic transformations that map from a single semantic statement to a plurality of semantic statements. This semantic transform information is typically used to look for combinations of semantic statements in the semantics-to-assembly database 335 that equate to single semantic statements in the basic rules database 325, as will be discussed more fully herein.
An exemplary ADL that may be used to describe target architectures is the LISA language. A LISA processor description typically comprises a resource specification and an operation tree. The resource portion may describe memories, caches, processor registers, signals, and pipelines. The operation tree may be a hierarchical specification of instruction coding, syntax, and behavior. For example, the operation may provide for different views on primitive operations of the target machine such as assembly syntax, pipeline timing, binary encoding, and behavior, e.g., state transitions of the processor resources.
Depending on the abstraction level of the model (e.g., instruction accurate or cycle accurate), an operation may describe an entire instruction, a part of an instruction (e.g., an immediate operand), or even a piece of a functional unit (e.g., a stage of a pipelined multiplier). Each operation may contain a number of sections describing the attributes of the operation dependent on its purpose. As an example, an operation modeling (a part of) an instruction usually contains a SYNTAX section specifying the instruction's assembly syntax. An exemplary operation with a behavioral section is shown in Table I.










TABLE I










OPERATION ADD {




DECLARE {




GROUP src1, dst = { reg };




GROUP src2 = { reg II imm };}




SYNTAX { “add” dst “,” src1 “,” src2 }




CODING { 0b0000 src1 src2 dst }




BEHAVIOR {




dst = src1 + src2;




if ( ((src1 < 0) && (src2 < 0))




II ((src1 > 0) && (src2 > 0) && (dst < 0))




II ((src1 > 0) && (src2 < 0) && (src1 > -src2))




II ((src1 < 0) && (src2 > 0) && (-src1 < src2)))




)




{ carry = 1; }}}










The conventional operation In Table I (describing a simple add instruction) illustrates that even for this relatively simple operation, it is nearly impossible to extract the operation's semantics from the behavioral description. In particular, when considering the flexibility of languages such as “C,” the presented description is only one technique to model an add with carry flag computation. From the example, one can derive the requirements for a semantic operation description: uniqueness, simplicity, and flexibility. For most operations, there should be only a single, concise way to define the semantics, while the grammar of a SEMANTICS section should be flexible enough to describe complex operations. Embodiments of the present invention provide for a semantic extension to an ADL such as LISA. However, the present invention is not limited to LISA.
A simplified ADL operation example having a SEMANTIC statement or section is given in Table II. The target architecture may be described by a number of such operations. The SEMANTIC statement describes what the operation does and may be used in the automatic generation of the code selector of a compiler, in accordance with embodiments of the present invention. Table II shows the ADD operation from Table I using a SEMANTICS statement, in accordance with an embodiment of the present invention, instead of a BEHAVIOR section. An operation may include both a SEMANTICS section and a BEHAVIOR section, but that is not required. A single SEMANTICS statement consisting of a single micro-operator may be used to precisely describe the purpose of the operation.










TABLE II










OPERATION ADD {




DECLARE {




GROUP src1, dst = { reg };




GROUP src2 = { reg II imm };}




SYNTAX { “add” dst “,” src1 “,” src2 }




CODING { 0b0000 src1 src2 dst }




SEMANTICS { _ADDI[_C] ( src1, src2 ) -> dst; }}










In most cases, the semantics of an instruction can be described by taking one or more of the instruction's parameters (and possibly other resources such as a stack pointer, general purpose register, memory), performing a computation on those operands, and finally modifying one or more of the instruction's operands (and/or processor resources). Thus, a user can easily construct a semantic description from information such as the above. Such description can be very elegant because information such as pipeline registers, threads, and internal signals typically can be omitted.
As previously discussed, a micro-operator is an atomic element from which larger elements such as assembly instructions can be constructed. Micro-operators are primitive operators that may be similar to instructions of a RISC ISA (reduced instruction set computing instruction set architecture), which allow modeling simple instructions by means a single micro-operator, and complex instructions (as found in CISC (Complex Instruction Set Computer) machines) by a combination of micro-operators.
In the example of Table II, the micro-operator ADDI in the SEMANTICS statement defines the integer addition. Certain micro-operators can read or write flags as a side effect. This is denoted by the C in square brackets specifying that the operator affects the carry flag. A comma-separated list of operands follows in parenthesis, and finally, the pointer (→) specifies the location for the result.
Table III provides a list of exemplary micro-operators that may be used in a semantic statement. The present invention is not limited to this list. Moreover, the present invention is not limited to building SEMANTIC statements with micro-operators. For example, elements other than micro-operators may be used to semantically describe the target architecture instruction set.








TABLE III







ADD
Description Adds two operands


ADDC
Description Adds two operands with carry


SUB
Description Subtracts the operand2 from operandi


SUBC
Description Subtracts the operand2 from operandi with 



carry


MULUU
Description Multiplies the unsigned integer operand1



by unsigned integer operand2


MULIU
Description Multiplies the signed integer operandi by 



unsigned integer operand2


MULII
Description Multiplies the signed integer operandi by 



signed integer operand2


NEG
Description Produces the negative value of the operand 



(twos-complement)


AND
Description Performs a bitwise AND operation on 



operandi and operand2


OR
Description Performs a bitwise OR operation on 



operandi and operand2


XOR
Description Performs a bitwise XOR operation on 



operandi and operand2


NOT
Description Performs a bitwise NOT operation on 



operand


LSL
Description Performs a logical left shift operation on 



operandi by operand2 bits.


LSR
Description Performs a logical right shift on operand1 



by operand2 bits


ASR
Description Performs an arithmetic right shift on 



operand1 by operand2 bits


ROTL
Description Rotational left shift on operand1 by 



operand2 bits


ROTR
Description Rotational right shift on operand1 by 



operand2 bits


SXT
Description Performs a sign extension to the operand


ZXT
Description Performs a zero extension to the operand


INDIR 
Description References a specific memory location 



pointed by operand


NOP
Description Do nothing


INTRINSIC OP 
Description User-defined architecture-specific operations









The operands of the micro-operator can be either terminal elements, such as integer constants, or other operations. In the latter case, the respective operations should contain a SEMANTICS section on their own. In the example in Table IV, the SEMANTICS section of the reg operation defines the semantic type of the operand—here, a 32-bit integer register specified as array R in a RESOURCE section (not shown).










TABLE IV










OPERATION reg {




DECLARE {




LABEL index;




SYNTAX { “R” index=#U4 }




CODING { index=0bxxxx }




SEMANTICS { _REGI(R[index])<0..31> }}










In general, each operand of a micro-operator can be represented as a 3-tuple (u; v; w) comprising the value/resource (u) and a bit-field specification represented by bit offset (v) and bit width (w). The corresponding 3-tuple for operation reg in Table IV is (u; v; w)=(R[index]; 0; 32).
The same formalism can be applied to the operation ADD depicted in Table II. As no explicit bit-field specification is given in the SEMANTICS section of the ADD operation, the expression shares the specification of the operands. In other words, the addition of two operands (a; 0; 32) and (b; 0; 32) results in the 3-tuple (c; 0; 32), where c is the result of the 32-bit addition of a and b.
The generic 3-tuple operand representation allows for a very compact instruction-set description while keeping the number of required micro-operators small. But there is another advantage: micro-operators can be used as operands for other micro-operators, which is referred to herein as chaining micro-operators.
Note that micro-operators generally do not describe entire source code level (e.g., C-level) operations and machine instructions. As described herein, embodiments of the present invention allow source code operations to be composed of multiple micro-operators (e.g. a 32-bit ADD can be described as a sequence of a 16-bit ADD and another 16-bit ADD with carry). In a similar fashion, embodiments of the present invention enable complex instructions (such as Multiply Accumulate or MAC) by chaining multiple micro-operators.
In order to model complex instructions, two mechanisms may be employed that combine two or more micro-operators, namely, chaining and parallelizing. Both are illustrated in Table V. The example shows the description of a dual multiply-accumulate instruction (DMAC), which carries out a 32×32 multiplication and accumulates the high and low word of the 64-bit result in two separate registers. Each line of the SEMANTICS section in Table V describes one of the MAC operations.








TABLE V








OPERATION DMAC {



DECLARE {



GROUP src1, src2, dst1, dst2 = { reg };



SYNTAX { “dmac ” dst2 “:” dst1 “,” src1 “,” src2 }



SEMANTICS {



_ADDI ( _MULUU( src1 , src2 )<0..31> , dst1 ) -> dst1 ;



_ADDI ( _MULUU( src1 , src2 )<32..63> , dst2 ) -> dst2;}}









The two MACs are executed in parallel, which is reflected in the semantic description by the following exemplary Rule 1, where a statement is defined as a (chain of) micro-operators concluded by a semicolon.
Rule 1: All statements in a single SEMANTICS section are evaluated in parallel.
The individual MAC operations are expressed as additions taking the result of a multiplication as first operand, thus building a micro-operator chain. Chained expression are evaluated in a sequence, as defined by the following exemplary Rule 2:
Rule 2: In a chained micro-operator, the innermost micro-operator (operand) is evaluated before its embracing micro-operator (operator).
The bit-field specification in angle brackets is used to meet the constraint of matching bit widths of the operands of ADDI. The micro-operator approach has at least two major advantages. First, only a small set of micro-operators is sufficient to describe nearly all instructions of a typical architectures by means of SEMANTICS sections without changing the operation structure of the (already existing) models. Second, the chaining mechanism avoids the usage of temporary variables, which guarantees a tree structure for each semantic statement. Such trees are extremely well-suited for compiler generation, as code selectors of compilers (e.g., C compilers) are typically based on tree grammars.
Code Selector Rule Generation
To generate code selectors, embodiments of the present invention employ a tree grammar description of the target instruction set. A tree grammar G=(N; T; P; S) comprises finite sets N and T of nonterminal and terminal symbols, respectively, as well as a set P of (mapping) rules and a start symbol SεN. The terminals T essentially describe the operations of the source language (e.g., C) and thus are target architecture independent. Likewise, the start symbol S requires no special retargeting effort. Typically, only the nonterminals N and the rules P need to be adapted to the target architecture. The nonterminals N basically reflect available, registers, memories, and addressing modes, while rules P defines how source language operations (or combinations of the same) are implemented by target instructions. Each mapping rule in P has the form of a tree pattern that may serve to cover a partial data flow graph during code selection.
Embodiments of the present invention automatically generate the non-terminals (e.g., N) and the mapping rules (e.g., P) from semantic information in a target architecture processor model. Syntax information in the target architecture model may also be used to generate mapping rules. After nonterminal generation, three cases of mapping between source code operations and micro-operators extracted from the semantic portion of the target architecture model are distinguished. Those mapping include one-to-one, one-to-many, and many-to-one.
One-to-one mapping reflects that a single source code operation may be covered by a single micro-operator, which in this case represents one machine instruction.
One-to-many mapping reflects that implementation of a source code operation requires a sequence of multiple micro-operators (or machine instructions). In this case, an embodiment of the present invention provides an extensible library of rewrite rules to establish the required mapping. The semantic transformation database 330 of FIG. 3 is one example of a database comprising rewrite or semantic transformation rules.
In many-to-one mapping complex mapping rules composed of chained micro-operators are generated if the semantic portion of the target architecture comprises chained micro-operators. Such rules go beyond covering the standard set of source code operations and help to optimize code quality. The semantic description of the target architecture is not required to have such chained micro-operators.
Nonterminal Generation
In tree grammar descriptions, nonterminals are temporary variables connecting different grammar rules. For code selectors, they represent locations like registers and memories in processors, which can be used to store intermediate results. According to their semantic meaning, nonterminals can be put into four categories:
Register nonterminals, which represent compiler usable registers.
Immediate nonterminals, which carry constants that can be put into instruction codings.
Addressing mode nonterminals, which imply the address computation.
Condition nonterminals, which are virtual locations used to store comparison results.
The generation of register and immediate nonterminals may be directly related with two micro-operators, _REGI and _IMMI. Table VI and Table VII shows two exemplary operations, which use the _REGI and _IMMI micro-operators respectively.








TABLE VI








OPERATION reg32{



DECLARE{ LABEL index; }



CODING { value=0bx[4] }



SEMANTICS { _REGI(GPR[index])<0,32>; }

















TABLE VII








OPERATION imm8{



DECLARE{ LABEL value; }



CODING { value=0bx[8] }



SEMANTICS { _IMMI(value); }



}









In the semantics section of operation reg32 in Table VI, the use of _REGI micro-operator indicates that the operation corresponds to the read/write access of a register file. The expression GPR[index] denotes the register file resource and related coding element. For example, there may be a resource description in the target ADL description for this register file resource. The bit-width of the registers is given out with <0,32> at the end of the statement, which means offset is 0 and width equals 32.
Provided this information, the generator will create a corresponding 32-bit register nonterminal.
The generation of immediate nonterminals follows a similar way. Referring now to Table VII, in the semantics section of the imm8 operation, the expression value after the micro-operator _IMMI is the coding element, which is used to hold the constant value. Since the bit-width of value can be resolved from the CODING section, explicit bit specification is not necessary for micro-operator _IMMI.
Since addressing mode nonterminals carry operand(s) for address computation, which varies from architecture to architecture, it may be difficult to describe their semantics with single micro-operator. Therefore, an embodiment of the present invention uses a memory access micro-operator _INDIR. It takes a micro-operator expression as operand, which describes the calculation of addresses. Bit specification must exist to define the size of accessed memory unit. Table VIII shows an exemplary operation LOAD, which loads 32 bit data into a register.







TABLE VIII







OPERATION LOAD{


DECLARE{


GROUP imm = { imm8 };


GROUP rs, rd = { reg32 }; \


}


 SEMANTICS { _INDIR(_ADD(rs, _SXT(imm)<0,32>))<0,32>->rd;


}


...}









In the example in Table VIII, the SEMANTICS statement comprises an _ADD micro-operator representing addition and an _SXT representing the sign extension operation. The sign extension micro-operator is used to achieve an equal bit-width operands condition of the _ADD micro-operator, in this example. Suppose the semantics of imm8 and reg32 is defined as in Table VI and Table VII, the LOAD operation in Table VIII implies a register offset (immediate) addressing mode. A corresponding nonterminal will be created from this exemplary LOAD operation.
Condition nonterminals may be used in compilers to properly write results into flag registers. They may be generated by first checking all semantics sections in the target architecture ADL model. If any one of the four predefined flag registers (carry, zero, negative and overflow) is used in the model, a condition nonterminal will be created.
One-to-One Mapping
In general, a mapping rule comprises three parts: a tree pattern, the result of the rule, and one or several associated machine instructions. The tree pattern represents a source code (e.g., C level) computation that can be performed by the machine instruction(s). The result of a mapping rule is normally a nonterminal. However, a mapping rule is not required to produce a result. The machine instructions and nonterminals are architecture specific elements, which are unknown before the target architecture ADL model is developed. To create mapping rules for target architectures, the generator uses basic rules as rule templates. Referring to FIG. 3, the basic rules database 325 comprises these basic rules.
Table IX provides a basic rule example, which corresponds to the addition operation.










TABLE IX










COSYIR mirPlus(a, b)->c;




PATTERN{ _ADD(a,b)->c; }










In the first line of Table IX, the expression mirPlus(a,b) is a tree pattern, wherein mirPlus is the intermediate representation (IR) tree node used in CoSy, which denotes an addition operation. CoSy is used with the COSY® Compiler Development System provided by Associated Computer Experts (ACE) of Amsterdam, The Netherlands. However, the present invention is not limited to CoSy.
In basic mapping rules, nonterminal place-holders are used. For example, “a” and “b” in the example in Table IX serve as non-terminal placeholders. At the end of the COSYIR statement, “c” is the result of the rule, which is also a nonterminal placeholder. Given this basic rule, the rule generator of an embodiment of the present invention will attempt to replace the placeholders with all possible combinations of available nonterminals generated from the target architecture ADL model to form a mapping rule suitable for the target processor.
Inside the parenthesis after the PATTERN keyword in Table IX is a semantics statement. It describes the semantics of the instruction that can perform the required computation. Basic rules may be architecture independent so that the rule generator can reuse them for different processor designs.
In one-to-one mapping, the generator tries to find an instruction (in the target architecture) that has the same semantics as a generated mapping rule has. FIG. 4 reviews the overall one-to-one mapping procedure of a basic rule, in accordance with an embodiment of the present invention. The basic rule 402 in this case is the one from Table IX. Non-terminals 404 “reg” and “imm” have been extracted from the semantic description of the target architecture.
Still referring to FIG. 4, the placeholders in the basic rule are replaced with various permutations of the nonterminals extracted from the target architecture model, as depicted in the permutated basic rules 405. Not all permutations are depicted in FIG. 4. Each permuted rule has a semantic statement 406. The compiler description generator then attempts to match the semantics statements 406 in the permutated rules with instruction semantics 408 extracted from the target architecture ADL model. Instruction semantics 408 and associated assembly code 410 that match that semantics of the permutated rules 405 are shown. Note that a match will not necessarily be found for all of the permutated rules 405. After the matching process in complete, a set of mapping rules 415 suitable for the target architecture is generated.
Referring now to FIG. 3, the compiler generator can search the semantics-to-assembly database 335 to look for the aforementioned instruction semantics 408 that match the semantics 406 in the permutated rules 405. As previously discussed, parsing the target architecture description 120 may create the semantics-to-assembly database 335. Database 340 stores the mapping rules 415, which are suitable for use by the compiler 180.
In one-to-one mapping, the generator tries to find instructions (in the target architecture) directly mapped to the rules generated from the basic library. Nevertheless, the one-to-one mapping is not always successful because a target processor might not be able to perform some operations required by a compiler. For example, a network protocol processor might have no multiplication instructions, which are rarely used in network package processing. In such-cases, one-to-many mapping of source code operations to machine instructions is used.
One-to-Many Mapping
During one-to-many mapping generation, the generator tries to map source code operations to sequences of machine instructions. However, because the performance of using multiple machine instructions is normally inferior to that of using single machine instruction, one-to-many mapping is typically used when the generator fails to find a one-to-one mapping for the operation.
Since the generator selects suitable machine instructions based on the semantics statements associated with the tree patterns, it is important to know what semantics substitutes can be used without affecting the result of computation. For this purpose, semantics transformation is introduced into the mapping rule generator. A semantics transformation specifies a sequence of semantics statements that together perform the same computation carried out by the original statement.
FIG. 5 illustrates an example of a semantic transformation, in accordance with an embodiment of the present invention. In this case, the unmapped rule 502 involves the NEG micro-operator. The unmapped rule 502 may be a rule from the basic library (FIG. 3, 325) for which no semantic match was found in the semantics-to-assembly database 335. The _NEG micro-operator represents a two's complement negation. The transformation 505 provides a mathematically equivalent solution for the NEG micro-operator as the operation-complement (_NOT) and addition of one. The _NOT micro-operator stands for one's complement. The semantic transformation 505 may be stored in a semantics transformation library (FIG. 3, 330). Applying the semantic transformation 505 allows the generation of two mapped rules 510 with associated machine instructions 515.
If the generator fails to find an instruction in the target architecture that performs negation, this semantic transformation 505 can help the generator look for two instructions to do a complement and an addition operation in sequence. In principle this approach can lower any operation only if an equivalent form exists and can be expressed in form of semantics statements.
As previously discussed, an embodiment of the present invention provides a semantic transformation library, which is a set of commonly used semantic transformations. The semantic transformation library, as well as the basic library, is user-extensible. As an example, a user extension may be added to the semantic transformation library if a source code operation needs to be implemented with a specific sequence of instructions.
Many-to-One Mapping
A working code selector description may be fully constructed with only one-to-one and one-to-many mapping, as previously discussed. Nevertheless, many processors implement instructions that can do several computations at a time, e.g., multiply-accumulate (MAC) instruction. These instructions are normally not needed for compilation, but using them can improve code quality. Therefore, an embodiment of the present invention provides many-to-one mapping.
In one-to-one and one-to-many mapping rule generation, tree patterns are generated from basic rules. However in many-to-one mapping, the operations that can be performed by special machine instructions are unpredictable. For example, designers can implement arbitrary operations in one instruction. As a result, it would be difficult for the generator to prepare tree patterns suitable for such instructions. Hence, for many-to-one mapping generation, the generator creates the tree pattern by analyzing the semantics of complex instructions.
In FIG. 6, an example of many-to-one mapping is provided using the MAC instruction, in accordance with an embodiment of the present invention. The semantics 620 of the instruction involves two micro-operators, _ADD and _MULII. The semantics statement 620 and the ASM 630 may be extracted from the target architecture model and stored in a semantics-to-assembly database. The _MULII operator represents signed integer multiplication. As these two micro-operators both correspond to unique compiler IR nodes, the generation of the tree pattern 610 is a one-to-one translation from micro-operators to IR nodes 640a, 640b. In the example, mirPlus 640a is the IR node corresponding to _ADD, and mirMult 640b maps to the _MULII operator. Given the tree pattern 610, a many-to-one mapping rule is generated, which utilizes the MAC instruction 630.
Thus, a compiler generator in accordance with an embodiment of the present invention takes into account not only mapping rules for a working code selector, but also rules that can improve code quality. The basic rules and semantic transformations, provided by default, help the generator create rules that are common to different processors. And architecture specific features are explored through two mechanisms, the user extensible libraries (e.g., basic and semantic transformation) and automatic many-to-one mapping generation. The libraries may be in text format to facilitate easy extension of the compiler generator for future processors.
FIG. 7 illustrates steps of a computer-implemented process 700 of automatically generating a description of compiler code selector rules from semantic information extracted from a target architecture model, in accordance with an embodiment of the present invention. In step 710, semantic information and assembly syntax is extracted from a target architecture model written in an architecture description language (ADL). In step 720, the extracted assembly syntax is associated with the extracted semantic information and stored in a database. For example, the semantic information comprises a number of semantic statements, with appropriate assembly syntax associated with each semantic statement.
In step 730, nonterminals are extracted from the target architecture model. In step 740, basic rules that map from source code operations to semantic patterns are accessed. In step 750, the basic rules are permuted based on the extracted nonterminals to form set of permuted mapping rules.
In step 760, semantics of the permuted mapping rules are matched to the extracted semantic information. For example, the database created in step 720 is searched for semantic statements or patterns that match semantic statements or patterns in the permuted mapping rules. The result of this searching and matching is a set of mapping rules that serve as a description of code selector rules.
It may be that the search of the database does not find a semantic match for some of the semantic patterns in the permuted rules. To handle these, as yet unmapped rules, steps 770, 775, and 780 are performed. In step 770, a library of pre-defined semantic transformations is accessed. The semantic transformations are operable to map one semantic statement to multiple semantic statements. In other words, the semantic transformations are able to determine at least two of the semantic statements in the extracted semantic information that are substantially equivalent to a single semantic pattern in the rules.
In step 780, semantic transformations are created of selected semantic information in the database to achieve semantic matches for permuted rules that are as yet unmapped. In other words, at least semantic statements in the database of extracted semantic information are found that are substantially equivalent to a single semantic pattern in an unmapped rule. In step 780, the as yet unmapped permuted mapping rules are matched to the just created semantic transformations. Thus, semantic matches are found for all rules. In this fashion, a complete description of compiler code selector rules is formed.
In optional step 790, analyzing the semantics of complex instructions in database creates a tree pattern for a new rule. This allows a many-to-one mapping, as previously discussed herein.
Simulator Generation
Embodiments of the present invention automatically generate a simulator from a target architecture description. FIG. 9 shows a block diagram of simulator generation from a semantic instruction-set description, in accordance with an embodiment of the present invention. The parser 910 extracts semantic intermediate information (IR) 915 (e.g., a semantic instruction-set description) from the target architecture description 120. The semantic IR 915 may comprise a number of semantic descriptions of instructions. The SEMANTICS-to-BEHAVIOR translator 920, translates each SEMANTICS section into one or more BEHAVIOR sections to generate a behavioral IR 930. The translator can be understood as a lowering engine operating on the semantic intermediate representation of the target architecture description, wherein the abstract semantic IR is transformed into a behavioral IR. The behavioral IR may be described in the C programming language, although this is not required.
The semantic IR 915 may be input to a compiler description generator 160, in accordance with embodiments of the present invention, to automatically generate a compiler description, which may be input to the compiler generator 170.
The behavioral IR may be input to a variety of software tool generators to automatically generate a variety of software tools. Note that the semantic to behavioral translation is performed on the front-end. Thus, this embodiment of the present invention is compatible with existing backend software generation tools. For example, the behavioral IR 930 may be used to generate interpretive, compiled, or just-in-time cache-compiled simulators. In one embodiment, the simulator generator 940 is implemented by a just-in-time cache-compiled simulator (JIT-CVTM simulator) available from CoWare Corporation of San Jose, Calif., which is suitable to automatically generate a simulator 140 from the behavioral IR 930. Details of a just-in-time cache-compiled simulator are described in U.S. patent application Ser. No. 10/309,554, to Nohl, et al., entitled, “METHOD AND SYSTEM FOR INSTRUCTION-SET ARCHITECTURE SIMULATION USING JUST IN TIME COMPILATION,” and assigned to the assignee of the present application. Said application is hereby incorporated by reference in its entirety.
The behavioral IR 930 may optionally be used as an input to other software generation tools, such as an assembler generator 942, linker generator 944 and an RTL (Register Transfer Level) generator 946.
The micro-operation function library 950 comprises a mapping of micro-operations usable to describe instruction in semantic statements to functions that are invokable by the simulator. Thus, the library 650 has a mapping of micro-operations to a functional description for the micro-operations. The functions are compliant with the C programming language in one embodiment.
Table X depicts an exemplary translation from semantic description of an instruction to a behavioral description of the instruction, in accordance with an embodiment of the present invention. The behavioral description may be used in the automatic generation of a simulator.









TABLE X









SEMANTICS {



 _ADD|[_Z,_C] ( Rs1<4..7>, Rs2<20..23> ) -> Rd<5.8>;



}



BEHAVIOR {



 Rd = ( Rd & (~BITMASK(5,4)) ) |



  ( BIT_EXTRACT










   ( SEM_ADD
( Rs1, 4, 4, /* op1 3-tuple */




 Rs2, 20, 4, /* op2 3-tuple */




 CARRY_FLAG | ZERO_FLAG




),









   0, 4 /* result is also a 3-tuple */



  ) <<5



 ); 



}










The SEMANTICS section in the Table X is for a target architecture that has an instruction-set designed to operate on bit-fields instead of entire registers only. The BEHAVIOR section shows the result of the translation. In this embodiment, the semantic statements comprise micro-operations, as described herein. Each micro-operation in a SEMANTICS statement is translated into a function call that is able to implement the function associated with the micro-operation. The implementation (e.g., C code) of functions is provided in a micro-operation function library (FIG. 9, 950), which can be either inlined or eventually linked to the resulting simulator. Furthermore, the micro-operation itself also represents a 3-tuple (SEM ADD, 0, 4), which facilitates an implementation of chaining.
In Table X, the micro-operation _ADDI in the SEMANTICS section is translated into a call to a SEM_ADD function in the BEHAVIOR section. The SEM_ADD function takes three parameters: two 3-tuple operands (Rs1, 4, 4) and (Rs2, 20, 4), and a specification of the affected flags resulting from the contents of the square brackets following the micro-operation.
The assignment from (SEM ADD, 0, 4) to (Rd, 5, 4) employs a number of bit-manipulation operations, as bitwise and (&), or (I), negate ( ̃), shift (<<), and few macros as BITMASK and BIT EXTRACT. The macros are defined in the micro-operation library, such that they are available for the simulator. The purpose of these bit-manipulations and macros includes converting aspects of the semantic statement into a format that is compatible with the language (e.g., C) of the behavioral section (and ultimately the language in which the functions in the micro-operation library are implemented).
Complex Operations
Not all semantic statements can be translated as simply as the example in Table X. As described in Table V herein, two or more micro-operations in a semantic statement may be chained. For such chained micro-operations, the translation from a semantic section to a behavioral section can be achieved with nested function calls. As further described in Table V herein, two or more micro-operations may be used in parallel. A semantic section with parallel micro-operations can be translated to a behavior section by using clock-sensitive register types instead of simple variables (e.g., C variables).
Table XI depicts a semantic statement having a micro-operation that can be passed parameters. In this example, the GROUP statement in line 3 has a number of arithmetic operators, which may be passed as parameters to the SEMANTICS statement in lines 4-5.








TABLE XI







1
OPERATION arithmetic {


2
 DECLARE {


3
  GROUP ArithOp = { ADD I SUB I MUL I ... };


4
 SEMANTICS {


5
  ArithOp ( Rs1, Rs2 ) -> Rd;}}


6



7
OPERATION ADD {


8
 SEMANTICS {_ADDI }}


9



10
OPERATION SUB {


11
 SEMANTICS {_SUBI }}


12



13
OPERATION MUL {


14
 SEMANTICS {_MULI }}


15



16
OPERATION arithmetic {


17
 DECLARE {


18
  GROUP ArithOp = { ADD I SUB I MUL I ... };


19
SWITCH (ArithOp) {


20
 CASE ADD: { SEMANTICS { _ADDI ( Rs1, Rs2 ) -> Rd; }}


21
 CASE SUB: { SEMANTICS { _SUBI ( Rs1, Rs2 ) -> Rd; }}


22
 CASE MUL: { SEMANTICS { _MULU ( Rs1, Rs2 ) -> Rd; }}}}









In this example, the operation “arithmetic” in lines 1-5 and the operations ADD, SUB, and MUL in lines 7-14 are translated into a single operation “arithmetic” in lines 16-22. In so doing, a single semantic statement in lines 4-5, is translated into three semantic statements in lines 20-22 making use of a SWITCH/CASE control flow statement and the operations in lines 7-14.
In order to generate the corresponding BEHAVIOR sections from the semantic description in lines 1-14, the operations “arithmetic”, ADD, SUB, and MUL are first translated into an equivalent representation still employing SEMANTICS sections. This is achieved by completely removing the SEMANTICS section from operation ADD, and rewriting the operation “arithmetic” into the operation shown in lines 16-22. A similar process is employed for the operations SUB (lines 10-11) and MUL (lines 13-14). The SWITCH/CASE statement in lines 19-22 evaluates the GROUP in line 18, and thus selects only one of the three SEMANTICS sections depending on the operation chosen. This way, the non-terminal micro-operation call has been removed. The individual SEMANTICS sections in lines 20-22 may be translated into BEHAVIOR sections as described herein. For example, micro-operators can be translated to function calls.
Intrinsic Micro-Operations
An embodiment of the present invention allows an intrinsic micro-operation to be defined. Such an intrinsic micro-operation may be user-defined for a special case in which the user either does not desire to use the pre-defined micro-operations or the micro-operations are unable to describe the instruction. This is typically used for complex instructions that are not easily described with the pre-defined semantic micro-operators. An exemplary SEMANTICS section and the generated BEHAVIOR section for an FFS (find first set bit) instruction are shown in Table XII.








TABLE XII








OPERATION FFS {



 SEMANTICS {



  “_FFS” ( Rs, ZeroOrOne, FromLeftOrRight ) -> Rd; }}



 BEHAVIOR { /* Generated from the above */



  Rd = SEM_FFS(Rs, ZeroOrOne, FromLeftOrRight);









The quotation marks around “FFS” indicate an intrinsic micro-operation. From the BEHAVIOR section generated in accordance with an embodiment of the present invention, it can be seen that a C function or macro SEM_FFS should be implemented by the user and added to the micro operation library such that it is available for the simulator.
Rather than using an intrinsic micro-operation, the instruction “FFS” could be described in a behavior section. However, the intrinsic micro operation approach has at least two major advantages. It provides enough information for the compiler generator of one embodiment to automatically generate a compiler-known function. If the source code being compiled invokes a compiler-known function, the compiler can generate the associated instruction that was defined in the target architecture model. This may allow the compiled code to perform the function with single instruction rather than a complex sequence of instructions. Also, it avoids the need for BEHAVIOR section for this instruction, which is important when moving to cycle-accurate level.
Cycle Accurate Modeling and Simulation
In the examples provided in Table X-Table XII, only instruction-accurate (IA) models have been taken into consideration. The use of the SEMANTICS section obsoletes the need for a BEHAVIOR section for most operations, in accordance with embodiments of the present invention. For example, for instruction accurate simulation the user does not need to provide a behavioral description of the instruction set because the semantic description of the instruction set is sufficient for embodiments of the present invention to automatically generate an instruction accurate simulator. Moreover, a compiler can be automatically generated by the same semantic description, in accordance with embodiments of the present invention. Therefore, the target architecture modeling effort is substantially reduced due the presence of a micro-operation library. Moreover consistency is maintained as the same model can be used for automatic generation of the instruction accurate simulator and the compiler.
To automatically generate a cycle accurate (CA) simulator, an embodiment of the present invention uses a behavioral section that provides information at the cycle accurate abstraction level. However, the same target architecture model may be used for the automatic generation of both the instruction accurate simulator and the cycle accurate simulator. The instruction accurate simulator is automatically generated from the semantic section of the model and the cycle accurate simulator is automatically generated from the behavior section of the model. Note that the semantic section and the behavior section describe and co-exist in the same model, but at different levels of abstraction. This avoids the need for two separate target architecture models for generation of an instruction accurate simulator and a cycle accurate simulator, as in known prior art techniques.
Table XIII shows the implementation of an ADD operation from Table X in a cycle accurate model. The first line of the example indicates that the operation only describes behavior of ADD in the execute (EX) stage of a pipeline. From the content of the BEHAVIOR section, two observations are noticeable. It would be extremely difficult to extract the instruction semantics from a cycle-accurate behavior description. It is impossible to generate a cycle-accurate behavior description from a specification of the instruction semantics without assuming a fixed microarchitecture.







TABLE XIII







OPERATION ADD IN pipe.EX {


 DECLARE {


  INSTANCE writeback;


  GROUP src1, dst = { reg };


  GROUP src2 = { reg II imm };}


 SYNTAX {“addc” dst “,” src1 “,” src2 }


 SEMANTICS {_ADDI[_C](src1, src2) -> dst; }


 BEHAVIOR {


  u32 op1, op2, result, carry;


  u1 c;


  if (forward) {


   op1 = PIPELINE_REGISTER(pipe,EX/WB).result;}


  else {


   op1 = PIPELINE_REGISTER(pipe,DC/EX).op1;}


  result = op1 + op2;


  carry = compute_carry(op1, op2, result);


 PIPELINE_REGISTER(EX/WB).result = result;


 PIPELINE_REGISTER(EX/WB).carry = carry; }


ACTIVATION { writeback, carry_update }}









A difference between cycle accurate and instruction accurate models is made up by the way the behavior of an instruction is described. In an instruction accurate model, each instruction is self-contained, which means it is assumed to have completed execution and written its results before the next instruction is decoded. In contrast, in a cycle accurate model, instruction execution might be interleaved, for instance, by means of an instruction pipeline. Hence, the behavioral description of an instruction may be distributed over several operations, which are potentially executed at different clock cycles. Each of such operations obtains the result from the previous operation, possibly performs a computation, and passes its results to the next operation.
Therefore, in order to generate compiler and cycle accurate simulator from a single model, a small amount of redundancy may be incorporated into the description. For example, the semantic section describes the same instruction as the behavior section. However, this relatively small redundancy allows bi-abstract models, in accordance with embodiments of the present invention.
Bi-Abstract Models
Embodiments of the present invention provide for bi-abstract models that describe a single target processor architecture on two abstraction levels at the same time, namely instruction- and cycle-accuracy. This avoids the need to maintain two separate models. Maintaining two separate models leads to inconsistency and increases maintenance cost eventually impairing the benefits of an ADL-based design approach.
Referring again to Table XIII, abstract semantics and microarchitecture behavior co-exist, while syntax and coding (not depicted in Table XIII) are only described once. Furthermore, embodiments of the present invention automatically generate an instruction accurate simulator from the information contained in the SEMANTICS section. Thus, for instruction accurate simulator generation, the existing (cycle accurate) behavior description captured in BEHAVIOR and ACTIVATION sections can be ignored. The instruction accurate simulator may be generated from the translated SEMANTICS sections, in accordance with an embodiment of the present invention. A cycle accurate simulator is automatically generated from the existing BEHAVIOR and ACTIVATION sections, in accordance with an embodiment of the present invention, while ignoring all SEMANTICS sections in the model. However, as discussed herein, the very same model (with the semantic section and the behavior section co-existing at different abstraction levels) can be used to generate both the instruction accurate simulator and the cycle accurate simulator, in accordance with an embodiment of the present invention.
Functional Units
The SEMANTICS formalism is intended to be used for the description of instructions, while the functional description of components that are not part of the instruction-set, for example, a fetch unit, can still employ BEHAVIOR sections. The functional unit may behave differently for the instruction accurate case than the cycle accurate case. One approach to handling the different behavior of functional units on different abstraction levels it to employ preprocessor defines to make either the instruction accurate BEHAVIOR section or the cycle accurate BEHAVIOR section visible to the automatic tool generators, in accordance with an embodiment of the present invention. Alternatively, a functional unit may be described at different abstraction levels by pre-defined components. A parameter may be passed in a behavior section, for example, to select which of two pre-defined components (instruction accurate or cycle accurate) is used.
Exemplary Processes
FIG. 10 is a flowchart illustrating steps of a computer-implemented process 1000 of automatically generating a simulator from an architecture description, in accordance with an embodiment of the present invention. In step 1010, a target architecture model described in an architecture description language (ADL) is accessed. The model comprises a semantic representation of an instruction set for the target architecture. The semantic representation may comprise semantic statements having micro-operations that are able to describe instructions. A library that maps the micro-operations to function calls is provided by an embodiment of the present invention. The user may define intrinsic micro-operations by adding a function to the library, wherein the function implementing the micro-operation is invokable by the simulator. In one embodiment, a semantic statement that receives one of a plurality of passed parameters is translated into a plurality of semantic statements corresponding to the parameters.
In step 1030, each of the semantic statements is transformed to a behavioral representation. Step 1030 may include translating micro-operations in the semantic statements to function calls in the behavioral representation. Moreover, step 1030 may comprise converting the semantic information into a format that is compatible with a programming language of functions used by the simulator.
In step 1040, the simulator is automatically generated from the behavioral representation.
In optional step 1050, a compiler is automatically generated from the semantic representation. Process 1000 then ends.
FIG. 11 is a flowchart illustrating steps of a process 1100 of automatically generating simulators at different abstraction levels from the same target architecture model. In step 1110, a bi-abstract target model comprising a semantic description of an instruction set and a behavioral description of the instruction set is accessed. The semantic and behavioral descriptions describe the same target architecture model at different abstraction levels and co-exist in the model. The semantic description may comprise an instruction accurate model and the behavioral description may comprise a cycle accurate model.
In step 1120, an instruction accurate simulator is automatically generated from the semantic description. Step 1120 may comprise transforming the semantic description to a behavioral representation and automatically generating the simulator from the behavioral representation.
In step 1130, a cycle accurate simulator is automatically generated from the behavioral description. Process 1100 then ends.
Exemplary Computer System Platform
FIG. 8 illustrates circuitry of an exemplary computer system 100, which may form a platform for embodiments of the present invention. The compiler description generator 160, the compiler 180, Ipacker 184, and assembler/linker, as well as the compiler generator 170 may also be implemented using computer system 100. The parser 910, the semantic to behavioral translator 920 and the simulator generator 940 may be implemented by computer system 100. The micro-operation function library (FIG. 9, 950) and databases 330, 335, and 340 in FIG. 3 may be stored in any of the computer readable media of computer system 100.
Computer system 100 includes an address/data bus 99 for communicating information, a central processor 101 coupled with the bus for processing information and instructions, a volatile memory 102 (e.g., random access memory RAM) coupled with the bus 99 for storing information and instructions for the central processor 101 and a non-volatile memory 103 (e.g., read only memory ROM) coupled with the bus 99 for storing static information and instructions for the processor 101. Computer system 100 also includes an optional data storage device 104 (e.g., a magnetic or optical disk and disk drive) coupled with the bus 99 for storing information and instructions.
With reference still to FIG. 8, system 100 may also include an alphanumeric input device 106 including alphanumeric and function keys coupled to bus 99 for communicating information and command selections to central processor unit 101. System 100 may also include a cursor control device 107 coupled to bus 99 for communicating user input information and command selections to central processor unit 101. System 100 of the present embodiment may also include a display device 105 coupled to bus 99 for displaying information. A signal input/output communication device 108 coupled to bus 99 provides communication with external devices.
The preferred embodiments of the present invention are thus described. While the present invention has been described in particular embodiments, it should be appreciated that the present invention should not be construed as limited by such embodiments, but rather construed according to the below claims.

## Claims

1. A computer implemented method for generating a description of compiler code selector rules from an architecture description, the compiler code selector rules for use in a compiler that translates source code into machine instructions of a target processor, the method comprising:
accessing a target processor architecture model of the target processor, the target processor architecture model described in a processor architecture description language, the target processor architecture model comprising semantic information and syntax information for the machine instructions, and description of non-terminals of the target processor;
generating a plurality of semantic statements from semantic information included in the processor architecture model;
applying, to said semantic information, at least one semantic transformation from a library of pre-defined semantic transformations to generate a single semantic statement from a sequence of at least two of said plurality of semantic statements;
generating a plurality of basic rules that map from source code operations to machine instructions comprising:
accessing rules that map from source code operations to semantic patterns,
searching said semantic statements for matches to said semantic patterns, and
mapping a sequence of two or more source code operations to a single machine instruction based on the accessed rules that matches from semantic statements to semantic patterns; and

permuting said basic rules with non-terminals to generate a plurality of mappings that serve as said description of said compiler code selector rules.

2. The method of claim 1, further comprising extracting assembly code syntax from said target processor architecture model and associating said assembly code syntax with said semantic statements.

3. The method of claim 1, wherein said pre-defined semantic transformations comprise transformations that map from a single semantic statement to a plurality of semantic statements.

4. The method of claim 1, wherein said searching comprises mapping a single source code operation to a single machine instruction.

5. The method of claim 1, wherein said searching comprises mapping a single source code operation to more than one machine instruction.

6. The method of claim 1, further comprising creating a tree pattern for a rule not in said accessed rules by analyzing a complex semantic statement of said plurality of semantic statements.

7. A non-transitory computer readable medium configured to store instructions for generating a description of compiler selector rules from an architecture description, the compiler selector rules for use in a compiler that translates source code into machine instructions of a target processor, the instructions when executed by a processor cause the processor to:
access a target processor architecture model of the target processor, the target processor architecture model written in a processor architecture description language, the target processor architecture model comprising semantic information and syntax information for the machine instructions, and description of non-terminals of the target processor;
generate a plurality of semantic statements from semantic information included in the processor architecture model;
apply, to said semantic information, at least one semantic transformation from a library of pre-defined semantic transformations to generate a single semantic statement from a sequence of at least two of said plurality of semantic statements;
generate a plurality of basic rules that map from source code operations to machine instructions comprising:
accessing rules that map from source code operations to semantic patterns,
searching said semantic statements for matches, and
mapping a sequence of two or more source code operations to a single machine instruction based on the accessed rules that matches from semantic statements to semantic patterns; and

permute said basic rules with said non-terminals to generate a plurality of mappings that serve as said description of said compiler code selector rules.

8. The computer readable medium of claim 7, further comprising a library of pre-defined semantic transformations that are operable to transform said extracted semantic information.

9. The computer readable medium of claim 7, wherein said instructions further cause the processor to extract assembly code syntax from said target processor architecture model and associating assembly code syntax with each of said plurality of semantic statements.

10. The computer readable medium of claim 7, wherein the instructions for searching said semantic statements for matches to said semantic patters cause the processor to map a single source code operation to a single machine instruction.

11. The computer readable medium of claim 7, wherein the instructions for searching said semantic statements for matches to said semantic patters cause the processor to map a single source code operation to more than one machine instruction.

12. The computer readable medium of claim 7, wherein said target processor architecture model comprises a hierarchical format.

13. A computer implemented method for generating compiler code selector rules from an architecture description, the compiler code selector rules for use in a compiler that translates source code into machine instructions of a target processor, the method comprising:
generating a plurality of semantic statements from semantic information included in a target processor architecture model of a target processor, the target processor architecture model described in a processor architecture description language, said semantic information describing an instruction set, wherein said target processor architecture model comprises semantic information and syntax information for the machine instructions, and description of non-terminals of the target processor;
associating assembly syntax with semantic information;
applying, to said semantic information, at least one semantic transformation from a library of pre-defined semantic transformations to generate a single semantic statement from a sequence of at least two of said plurality of semantic statements;
accessing basic rules having tree patterns that map from source code operations to semantic patterns;
permuting said basic rules based on said non-terminals to form set of permuted mapping rules; and
matching semantic patterns of said permuted mapping rules to said semantic statements to form a description of said complier code selector rules comprising mappings from source code operations to associated assembly syntax; and
mapping a sequence of two or more source code operations to a single machine instruction based on the accessed rules that matches from semantic statements to semantic patterns.

14. The method of claim 13, wherein said matching semantic patterns comprises mapping a single source code operation to a single machine instruction.

15. The method of claim 13, wherein said matching semantic patterns of said permuted mapping rules to said extracted semantic information comprises mapping a single source code operation to more than one machine instruction.

16. The method of claim 13, wherein said non-terminals represent locations in which to store intermediate results.

17. The method of claim 13, wherein said extracted semantic information comprise micro-operators.

18. The method of claim 13, further comprising inputting a compiler description comprising said description of compiler code selector rules to an automatic compiler generation tool to automatically generate a compiler adapted to said target processor architecture.

19. The method of claim 13, further comprising creating a tree pattern for a rule not in said basic rules by analyzing a complex semantic statement of said extracted semantic information.