1. Field of the Invention
The present invention relates to preparing assembly language source code. Embodiments of the present invention relate to techniques for assisting a user when preparing assembly language source code.
2. Description of the Prior Art
Techniques for preparing assembly language source code are known. Typically, a text editor is provided which enables a user to enter a sequence of assembly language instructions intended to be executed on a target processor core. Using the text editor, the user can navigate around the sequence of assembly language instructions and edit those instructions prior to those instructions being provided to a compiler.
Once the compiler has compiled the source code and created a target image comprising a sequence of machine code instructions, that target image may then be executed on the target processor core.
It is desired to provide improved techniques for preparing assembly language source code.
According to one aspect of the present invention there is provided a method of assisting a user when preparing assembly language source code to be executed by a processor core, the assembly language source code comprising a sequence of assembly language instructions, the method comprising the steps of: receiving an assembly language instruction entered by the user; determining, with reference to a model representing the operation of the processor core when executing the sequence of assembly language instructions, whether a predetermined condition will occur due to a relationship between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions which will cause the processor core to operate in an undesirable manner; and if the predetermined condition occurs, displaying to the user an indication of the relationship between the assembly code instruction and the at least one other assembly code instruction which will cause the processor core to operate in the undesirable manner.
The present invention recognises that programming using assembly language source code is a highly specialised activity. This is because to produce efficient code in this way requires a great deal of in-depth knowledge of the operation of the assembly language instructions and their interaction with the target processor core. Such programming is often reserved for extremely specialised tasks where the software engineer wishes to be certain that particular machine code instructions will be executed in a predetermined sequence on the target processor. Accordingly, it is desirable that the compiler generates the target image representing the assembly language instructions as faithfully as possible. Hence, many of the optimising functions that may be provided in a compiler for a high level language would typically be prevented from being included in an assembly language compiler in order to ensure that the target image fully reflects the source code.
However, the present invention also recognises that such an approach provides a number of drawbacks. For example, unless the software engineer has a complete and through grasp of the detailed operation of the assembly language source code on the target processor and can also fully comprehend the extensive interactions between instructions, the performance of the source code may be less than may otherwise be possible.
Accordingly, the present invention provides a technique which assists the user when preparing assembly language source code by identifying relationships between assembly code instructions which will cause the processor to operate undesirably.
When an assembly language instruction is entered by a user a determination is made as to whether a predetermined condition will occur as a result of a relationship between the entered assembly code instruction and another instruction in the sequence of assembly language instructions. This determination is made by referring to a model which models the operation of the processor core when executing the sequence of assembly language instructions. Should it be determined that a predetermined condition will occur then an indication is provided to the user which shows the relationship between the instructions which will cause the processor core to operate in an undesirable fashion.
It will be appreciated that providing such an indication assists the user when preparing the assembly language source code by alerting him to the fact that the performance of the code when being executed on the processor core may not be as high as may be possible.
Also, it will be appreciated that because these complex relationships and undesirable conditions can be identified by the model rather than relying on the knowledge of the user, the skill level of the user need not be as high as previously required. Furthermore, time the user needs to spend analysing the code need not be as high as previously required since these relationships will be identified automatically. Accordingly, programming using assembly language source code becomes more achievable for a wider range of users and the cost of producing such code may be reduced.
In embodiment, the undesirable manner comprises the processor core operating non-optimally due to the relationship between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions.
Hence, the relationship between the assembly code instructions may cause the processor to operate in a manner which is less than the optimum performance possible from the processor core.
In one embodiment, the predetermined condition comprises an interlock due to a dependency between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions which would cause the processor core to stall until the interlock has cleared.
Accordingly, the model is operable to determine when a dependence will occur between assembly code instructions resulting in an interlock. It will be appreciated that the occurrence of such an interlock will typically cause the processor core to stall until the interlock is cleared and that this will detrimentally affect the performance of the processor core.
In one embodiment, the step of displaying comprises highlighting the assembly code instruction and the at least one other assembly code instruction in the sequence of assembly language instructions which would cause the processor to stall until the interlock has cleared.
Hence, the instructions which will cause the interlock to occur will be highlighted and displayed to the user. This enables the user to rapidly and easily identify the instructions which will lead to reduced performance.
In one embodiment, the step of displaying comprises highlighting attributes of the assembly code instruction and the at least one other assembly code instruction in the sequence of assembly language instructions which would cause the processor to stall until the interlock has cleared.
Highlighting attributes, such as the registers or the memory locations which cannot be accessed until after the interlock has been cleared, enables the user to more precisely identify the exact cause of the poor performance of the processor core.
In one embodiment, the predetermined condition comprises the presence of a predetermined assembly language instruction as the assembly language instruction, the predetermined assembly language instruction being substitutable by an alternative assembly language instruction which is executable by the processor core in a more efficient manner within the sequence of assembly language instructions.
Hence, the model is able to determine when an alternative instruction could be used to replace an assembly language instruction present in the sequence, that alternative instruction executing more efficiently than the instruction which it could replace. It will be appreciated that in some situations some instructions may always execute more efficiently than others, irrespective of any relationship between them, and in those situations the user may simply be displayed with an indication of the particular single instruction which causes the processor to operate in an undesirable manner.
In one embodiment, the step of displaying comprises highlighting the predetermined assembly code instruction.
Accordingly, the user can readily identify those instructions which may be replaced by other instructions which would execute more efficiently.
In one embodiment, the method further comprises displaying an indication of the alternative assembly language instruction which is executable in a more efficient manner within the sequence of assembly language instructions by the processor core.
Hence, not only can the user be provided with an indication of an instruction which may not execute as efficiently as expected but he may also be provided with a suggested alternative instruction which will execute more efficiently.
In one embodiment, the predetermined condition comprises the presence of a plurality of predetermined assembly language instructions, the plurality of predetermined assembly language instructions including the assembly language instruction, the plurality predetermined assembly language instructions being substitutable by an alternative assembly language instruction which is executable in a more efficient manner by the processor core.
Accordingly, the model may also identify a situation where a number of instructions within the sequence of instructions would execute less efficiently than an alternative, typically single, replacement assembly language instruction.
In one embodiment, the step of displaying comprises highlighting the plurality of predetermined assembly code instructions.
By highlighting those instructions the user is able to readily identify the problem instructions.
In one embodiment, the method further comprises displaying an indication of the alternative assembly language instruction which is executable in a more efficient manner by the processor core.
Hence, the user may also be provided with a suggested alternative instruction which could be used to replace the less efficient combination of instructions.
In one embodiment, the method further comprises, in response to the user selecting one of the sequence of assembly language instructions, determining with reference to the model representing the operation of the processor core when executing the sequence of assembly language instructions, an earliest and a latest position within the sequence of assembly language instructions which the one of the sequence of assembly language instructions can be moved without altering the function of the sequence of assembly language instructions; and displaying to the user an indication of the earliest and the latest position within the sequence of assembly language instructions which the one of the sequence of assembly language instructions can be moved without altering the function of the sequence of assembly language instructions.
Hence, in the event that the user selects an instruction within the sequence, the model determines whether that instruction may be relocated to different positions within the sequence of instructions without affecting the intended operation of that sequence of instructions. The user is then provided with an indication of the earliest possible position within the sequence and the latest possible position within the sequence that the instruction could be moved to without causing the sequence of instructions to operate in a different way. It will be appreciated that this enables the user to readily appreciate the limits within which an instruction may be moved within the sequence without causing the code to behave differently.
In one embodiment, said predetermined condition comprises the presence of a predetermined assembly language instruction as said assembly language instruction, said predetermined assembly language instruction being substitutable by an alternative plurality of predetermined assembly language instructions which are executable in a more efficient manner by said processor core.
Hence, the user may also be provided with a suggested alternative sequence of instructions which could be used to replace the less efficient instruction.
In one embodiment, the method further comprises receiving an indication that at least one assembly code instruction is to be placed at a new position within the sequence of assembly language instructions thereby providing a revised sequence of assembly language instructions; determining, with reference to the model representing the operation of the processor core when executing the revised sequence of assembly language instructions, whether a predetermined condition will occur due to a relationship between assembly code instructions in the revised sequence of assembly language instructions which will cause the processor core to operate in an undesirable manner; and if the predetermined condition occurs, displaying to the user an indication of the relationship between the assembly code instructions in the revised sequence of assembly language instructions which will cause the processor core to operate in an undesirable manner.
Hence, when an indication is received that the ordering of the instructions within the sequence is to be changed, the model determines whether that new sequence of instructions will cause the processor core to operate undesirably and to display that to the user if such undesirable operation is identified. Accordingly, the user will be provided with feedback on the performance of the altered sequence in response to the sequence being altered. It will be appreciated that this is a useful tool when re-sequencing or editing instructions.
In one embodiment, the method further comprises, in the event that the predetermined condition occurs, applying a set of predetermined rules such that at least one assembly code instruction is selected to be placed at a new position within the sequence of assembly language instructions thereby providing the revised sequence of assembly language instructions.
Hence, should a predetermined condition occur, a set of rules may be applied which selects one or more assembly code instructions to be placed at different positions within the sequence of assembly language instructions. In this way, the re-sequencing of instructions can occur based on an automated process in order to address any problems within the sequence.
In one embodiment, the step of receiving comprises receiving from a user the indication that at least one assembly code instruction is to be placed at the new position within the sequence of assembly language instructions thereby providing the revised sequence of assembly language instructions.
Accordingly, the user may alternatively select one or more assembly code instructions and place them in different locations within the sequence.
In one embodiment, the assembly language source code is to be executed by any one of a plurality of processor cores and the step of determining comprises determining, with reference to a model representing the operation of each of the plurality of processor cores when executing the sequence of assembly language instructions, whether a predetermined condition will occur due to a relationship between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions which will cause the one of the plurality of processor cores to operate in an undesirable manner.
Hence, the model is able to determine whether a problem will occur when executing the source code on any of a number of different processor cores. It will be appreciated that this provides significant advantages to the user since any one user is unlikely to have an in-depth understanding of the operation of such a range of processor cores. This provides significant benefits when the sequence of instructions is to be recompiled for execution on a different target processor core.
In one embodiment, the assembly language source code is to be executed using any one of a plurality of instruction sets executable by the processor core and the step of determining comprises determining, with reference to a model representing the operation of each of the plurality of instructions sets executable by the processor core, whether a predetermined condition will occur due to a relationship between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions which will cause the processor core to operate in an undesirable manner.
Similarly, the model may determine when a problem may occur when executing the sequence of instructions using a different instruction set. It will be appreciated that this would be highly useful to the user when using different instruction sets. For example, an indication can be provided when a problem occurs when using one instruction set which will enable a decision to be taken on whether to execute that and/or other instructions using an alternative supported instruction set.
According to a second aspect of the present invention there is provided a computer program operable when executed on a computer to assist a user when preparing assembly language source code to be executed by a processor core, the assembly language source code comprising a sequence of assembly language instructions, the computer program comprising: an interface module operable to receive an assembly language instruction entered by the user; a model representing the operation of the processor core when executing the sequence of assembly language instructions operable to determine whether a predetermined condition will occur due to a relationship between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions which will cause the processor core to operate in an undesirable manner; and a display module operable if the predetermined condition occurs to display to the user an indication of the relationship between the assembly code instruction and the at least one other assembly code instruction which will cause the processor core to operate in the undesirable manner.
According to a third aspect of the present invention there is provided a data processing apparatus for assisting a user when preparing assembly language source code to be executed by a processor core, the assembly language source code comprising a sequence of assembly language instructions, the data processing apparatus comprising: an interface for receiving an assembly language instruction entered by the user; model logic representing the operation of the processor core when executing the sequence of assembly language instructions for determining whether a predetermined condition will occur due to a relationship between the assembly code instruction and at least one other assembly code instruction in the sequence of assembly language instructions which will cause the processor core to operate in an undesirable manner; and a display controller for displaying to the user, if the predetermined condition occurs, an indication of the relationship between the assembly code instruction and the at least one other assembly code instruction which will cause the processor core to operate in the undesirable manner.
Embodiments of the present invention will now be described with reference to the accompanying drawings in which:
As will be explained in more detail with reference to
The user's interactions with the GUI 20 is provided to the code state machine 40 either directly or via the parser 30. In the event that the user enters a new assembly language instruction then the GUI 20 passes this instruction to the parser 30 which then parses the instruction and provides the parsed code to the code state machine 40. In the event that the user adjusts the sequence of the instructions displayed on the GUI 20 or performs some other command, information relating to the re-sequencing or command is passed directly to the code state machine 40.
The code state machine 40 contains state information relating to the complete sequence of assembly language instructions entered. The code state machine 40, in conjunction with the processor model 60 which models the operation of the processor, or of a number of processors, each of which may support more than one instruction set. The code state machine 40 in conjunction with the processor model 60 simulates the operation of the processor when executing the sequence of assembly code instructions and determines with reference to a condition list (not shown) whether a condition exists between any of those instructions which will result in the processor core executing in a less than optimal manner. Hence, the condition list is pre-programmed with a predetermined list of relationships which, if they exist between instructions in the sequence will result in a condition which causes the processor core to not execute instructions in the most efficient manner possible.
Accordingly, the processor model 60, in conjunction with the code state machine 40, provides an indication of any instructions within the sequence of instruction which would, if left as they currently are, will result in the processor core operating less efficiently than would otherwise be possible. It will be appreciated that providing such an indication is readily possible given a knowledge of the detailed instruction timings of a particular processor core.
This information, detailing the non-optimal instructions, is provided to the graphical user interface 20 and the graphical user interface 20 responds by highlighting the offending instructions and indicating, where appropriate, the particular attributes of those instructions which result in non-optimal performance, as will be explained in more detail with reference to FIGS. 3 to 7 below.
The details of the non-optimal instructions are also provided to an optimiser 70. The optimiser 70 will review this information and will determine, based upon a pre-programmed, predetermined set of rules, whether there are any optimisations which could be performed. If the optimiser function has been activated by the user, through the GUI 20, then an indication of these optimisations may be provided to the GUI 20 for display to the user. These optimisations may be determined by the optimiser through interaction with the code state machine 40 and the processor model 60. For example, the optimiser 70 may provide an indication of how to re-sequence the instructions or how it would be possible to substitute some instructions for other instructions, as will also be described in more detail with reference to FIGS. 3 to 7 below. Again, it will be appreciated that providing such an indication is readily possible given a knowledge of the detailed instruction timings of a particular processor core.
In the event that the user makes a change to the instructions, either himself or by selecting one of the suggested optimisations provided by the optimiser 70, then this change to the sequence of instructions then fed-back to the code state machine 40 either directly or via the parser 30, where appropriate.
In this way, it will be appreciated that the user is assisted in producing the assembly language source code since he is alerted to any relationships between assembly code instructions (such as a hazard condition leading to an interlock situation) which would cause the processor core to operate in a non-optimal manner.
At step S10, user input is provided via the GUI 20. This user input may comprise, for example, entering a new instruction, re-sequencing instructions, editing or deleting instructions, accepting suggested optimisations, and the like.
At step S20, the GUI 20 determines whether the user input related to the provision of a new or edited instruction, in which case processing proceeds to step S30 or whether the input related to some change in the arrangement of the sequence of instructions, in which case processing proceeds to step S40.
At step S30, the parser 30 generates parsed code from the entered or edited instruction and passes this parsed code to the code state machine 40.
At step S40, the code state machine 40 generates code state representing the new or changed sequence of instructions.
At step S50, the code state machine 40, in conjunction with the processor models 60, simulates the operation of the processor core when executing the sequence of instructions. Also, the code state machine 40, in conjunction with the processor models 60, identifies any non-optimal instructions and the relationships between them by reference to a rule set which indicates relationships between instructions which will result in the non-optimal performance of the processor core. Information relating to these inefficient instructions and the relationships between them is passed to the optimiser 70 and to the GUI 20 in order to update the screen displayed to the user, as will be explained in more detail with reference to FIGS. 3 to 7 below.
At step S60, a determination is made as to whether auto-optimisation should occur.
If no auto-optimisation is to occur (meaning that the optimiser 70 has not been activated) then the details of the non-optimal instructions and the relationships between those instructions which cause poor performance are provided to the GUI 20. The GUI 20 then highlights to the user those instructions and the relationships which will result in poor performance.
In the event that auto optimisation is to occur (meaning that the optimiser 70 has been activated) then, at step S80, the optimiser 70 will adjust the instructions within the sequence of instructions by either moving one or more of those instructions in accordance with predetermined rules or by substituting some instructions with other instructions and will feed that information back to the code state machine 40. The code state machine 40 will then once again, in conjunction with the processor model 60, determine whether any non-optimal instructions still exist. This will continue until either all of the non-optimised instructions have been resolved or until a minimum number of those non-optimal instructions remain.
Whilst
Accordingly, a technique is provided which assists the user when preparing assembly language source code by identifying relationships between assembly code instructions which will cause the processor to operate undesirably. This determination is made dynamically as the code is entered or changed and provides near real-time feedback to the user of any optimisations that could be made by the user to improve the performance of the code. Providing such an indication assists the user when preparing the assembly language source code by alerting him to the fact that the performance of the code when being executed on the processor core may not be as high as may be possible.
Because complex relationships leading to undesirable conditions can be identified by the model rather than relying on the knowledge of the user, the skill level of the user may be lower than previously required. Also, the time the user needs to spend analysing the code need not be as high as previously required since these relationships will be identified automatically. Accordingly, programming using assembly language source code becomes more achievable for a wider range of users and the cost of producing such code may be reduced.
Although a particular embodiment of the invention has been described herein, it would be apparent that the invention is not limited thereto, and that many modifications and additions may be made within the scope of the invention. For example, various features of the following dependent claims could be made with features of the independent claims without departing from the scope of the present invention.