Method performed by a microcontroller for managing a NOP instruction and corresponding microcontroller
11614938 · 2023-03-28
Assignee
Inventors
- Giulio Martinozzi (Agrate Brianza, IT)
- Federica Arosio (Agrate Brianza, IT)
- Lorenzo Di Lalla (Agrate Brianza, IT)
Cpc classification
G06F9/3836
PHYSICS
G06F9/30145
PHYSICS
International classification
Abstract
Disclosed herein is a method for managing of NOP instructions in a microcontroller, the method comprising duplicating all jump instructions causing a NOP instruction to form a new instruction set; inserting an internal NOP instruction into each of the jump instructions; when a jump instruction is executed, executing a subsequent instruction of the new instruction set; and executing the internal NOP instruction when an execution of the subsequent instruction is skipped.
Claims
1. A microcontroller using codes requiring NOP instructions including: a pipeline for managing a plurality of instructions of a code to be used by the microcontroller, the plurality of instructions including jump instructions causing corresponding NOP instructions; and a NOP manager unit comprising: an instruction decoder combiner block connected to an output terminal of the NOP manager unit and having an internal output terminal providing an internal NOP code signal; and an instruction decoder sequence block having an input terminal receiving memory instructions and an output terminal connected to the output terminal of the NOP manager unit and configured to receive the internal NOP code signal from the instruction decoder combiner block.
2. The microcontroller of claim 1, wherein the instruction decoder sequence block comprises at least a MUX having a first input terminal receiving the memory instructions and a second input terminal receiving an idle instruction NOP, wherein the output terminal is connected to the output terminal of the NOP manager unit, and wherein the MUX is driven by the internal NOP code signal.
3. The microcontroller of claim 1, wherein the instruction decoder sequence block is further configured to receive at least a clock signal of the microcontroller.
4. The microcontroller of claim 1, wherein the instruction decoder combiner block comprises: an input portion connected to the output terminal of the NOP manager unit; and an output portion connected to the internal output terminal of the instruction decoder combiner block, wherein the input portion and the output portion of the instruction decoder combiner block are connected to each other, and wherein the input portion is configured to provide an operation code to the output portion of the instruction decoder combiner block.
5. The microcontroller of claim 1, wherein the instruction decoder sequence block of the NOP manager unit further includes a data latch which receives a clock signal of the microcontroller and is connected to the output terminal of the NOP manager unit to provide an internal memory instruction.
6. The microcontroller of claim 1, wherein the NOP manager unit further comprises an additional internal latch, inserted between the internal output terminal of the instruction decoder combiner block and the instruction decoder sequence block.
7. The microcontroller of claim 6, wherein the additional internal latch of the NOP manager unit is configured to receive the clock signal of the microcontroller and provide at a further internal output terminal a further internal NOP code signal to the instruction decoder sequence block.
8. The microcontroller of claim 7, wherein the pipeline comprises: a memory block configured to store a plurality of memory instructions at a corresponding plurality of address signal values; an instruction register connected to the memory block and configured to receive from the memory block the memory instructions and store corresponding register instructions; an instruction decoder connected to the instruction register and configured to decode the register instructions being received from the instruction register; and a final destination register connected to the instruction decoder and configured to store final instructions to be executed being received from the instruction decoder.
9. The microcontroller of claim 8, wherein the execution of a final instruction makes a change in a destination register.
10. The microcontroller of claim 9, further comprising the destination register.
Description
BRIEF DESCRIPTION OF THE DRAWINGS
(1) Various embodiments of the present disclosure will now be described more fully hereinafter with reference to the accompanying drawings; however, the embodiments may be embodied in different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the embodiments to those skilled in the art.
(2) In the drawing figures, dimensions may be exaggerated for clarity of illustration. It will be understood that when an element is referred to as being “between” two elements, it can be the only element between the two elements, or one or more intervening elements may also be present. Like reference numerals refer to like elements throughout.
(3) The characteristics and advantages of the present disclosure will be apparent from the following description of embodiments thereof given by way of indicative and non-limiting examples with reference to the annexed drawings, in which
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
DETAILED DESCRIPTION
(14) Hereinafter, embodiments of the present disclosure will be described. In drawings, thicknesses and distances are expressed for convenience of description, and may be exaggerated and illustrated as compared with actual physical thicknesses and distances. In the present specification, a known configuration unrelated to the present disclosure may be omitted. In the specification, when reference numerals are annotated to components in each drawing, it should be noted that like reference numerals denote like elements even though they are depicted in several drawings.
(15)
(16) In an embodiment, the pipeline structure 100 comprises a memory block, for example, a ROM memory 110 receiving an address signal ROM_ADD corresponding to a plurality of memory instructions I stored as ROM_DATA in ROM memory 110. The memory instructions I are read by ROM memory 110 and stored in a further block of the pipeline structure 100, in particular an instruction register 120, connected to the ROM memory 110 and receiving therefrom the memory instructions I and storing a corresponding latched instruction ROMDATA_L also indicated as register instructions E.
(17) In an embodiment, the pipeline structure 100 may also comprise an instruction decoder 130, being connected to the instruction register 120 and receiving therefrom the register instructions E being decoded and sent to a final destination register 140, being connected to the instruction decoder 130 storing the final instructions R to be executed.
(18) Most often microcontrollers are able to simultaneously execute up to two sub-instructions for each clock cycle; in particular, when the bits number of the instruction are lower or equal to resources number that the microcontroller can handle, the executable instructions are divided into three possible sub-sets: output modification instructions or PORT, such as SET/CLEAR of an output port; logic-algebraic instructions or ALU, such as TEST, SUM, AND, OR et al.; and flow instructions or jump (JMP), such as GOTO to a label, CALL a subroutine, RETURN from a subroutine.
(19) In this way, the microcontroller is able to simultaneously execute two sub-instructions according to the following grouping: PORT and JMP; or PORT and ALU; or ALU and JMP.
(20) It should be clarified that jump instructions, in the following, are intended to include all the instructions that force the microcontroller to deviate from a sequential instruction flow, in which the next statement to be executed is an instruction stored at the very next memory address, and make the microcontroller read from another memory position.
(21) In the example shown in the
(22) At the second time t2, a subsequent second address signal ROM_ADD having a value of 11 is read and a subsequent second memory instruction I11 is received by the ROM memory 110, the pipeline structure 100 processing the second memory instruction I11 in the same way as the first memory instruction I10.
(23) When instructions comprise a jump command, as shown for instance in
(24) It is however clear that the inserted NOP instruction after each register/final instruction corresponding to a jump command is a wasted instruction that causes a greater execution time of a microcontroller using the pipeline structure 100 and the NOP instructions.
(25) An additional specific signal could be in this case used to remove the internal NOP instruction after a jump instruction, as indicated schematically in
(26) In this way, the internal NOP instruction can be disabled due to the skipping signal MC_MICRO_INTNOP_SKIP, which can be set by the microcontroller itself during the execution time.
(27) However, it can be verified that using the skipping signal MC_MICRO_INTNOP_SKIP changes the behavior of the execution of the jump instruction. In particular, two main issues arise.
(28) First, not all jump instructions can be managed by the internal skip circuit 200 using the skipping signal MC_MICRO_INTNOP_SKIP and explicit NOP instructions should be introduced after such instructions. In this case, a waste of instruction lines still occurs, and the benefit of the reduction of execution time is lost due to the increased code lines number, as shown for instance in
(29) Furthermore, since the behavior of a jump instruction depends whether or not of the skipping signal MC_MICRO_INTNOP_SKIP is set, it is impossible to understand the behavior of the code simply by reading it, the behavior being a matter of code quality.
(30) Since the code execution depends on the state of the signal disabling the internal NOP instructions, such a code turns out to be not univocally decodable, thereby causing an increased number of errors during the design phase.
(31) The method according to an embodiment comprises a duplication of all jump instructions to allow the execution of a subsequent instruction at the subsequent clock cycle or, inherently, an internal NOP instruction when the jump instructions are executed. In this way, the method provides for obtaining a new instruction set, including the duplicated jump instructions.
(32) In this way, at each jump instruction, the code can be designed in such a way that a subsequent instruction can be executed or, in case this is not possible, the jump instruction itself could be written in order to include an internal NOP instruction, which does not need to be stored in the ROM memory 110 and thus does not require additional code lines.
(33) For instance, consider a case wherein a sequence of two instructions, I1 and I2t, or I1 and I2f are to be implemented, when a condition C is true or false, respectively, such as case 1 as follows.
(34) Case 1: TEST(C); IF (C==1) THEN I2t ELSE I2f
(35) In this case, the microcontroller uses a code with a conditional GOTO instruction at a label and the ROM memory 110 would store file code lines, as shown in
(36) The statement “the subsequent instruction cannot be executed” is intended to mean that a certain algorithm with conditions (IF . . . THEN . . . in the below example) can or cannot be completely codified with jump instructions without internal NOP, i.e., by writing the code in such a way that the instruction written after a conditional jump is executed, from the algorithm viewpoint, irrespective of whether the jump is performed or not. If the programmer is not able to find a sequence of lines of code such as to allow taking advantage of the “jump without internal NOP” feature, then the instruction written after the jump instruction “cannot be executed”, and in such a case it is possible to exploit the jump with internal NOP instruction, without having to explicitly write the NOP in the code, as shown in
(37) In case 1, the instruction written in the line of code immediately under the jump instruction without internal NOP instruction (instruction INST2 in the example) is executed, irrespective of whether the jump instruction is performed or not. INST2 is a subsequent instruction.
(38) In contrast, in case 2, the subsequent instruction (INST2) written after the jump instruction with internal NOP instruction is executed according to whether the jump instruction is performed or not. Plush, the internal NOP instruction is executed when the execution of the instruction (INST2) is skipped.
(39) In particular, it can be verified that the ROM memory 110 comprises file code lines, both in a case the microcontroller with the signal MC_MICRO_INTNOP_SKIP of
(40) It should be noted that Micro 1 and Micro 2 have a same number of code lines and need the same number of clock cycles.
(41) Since the microcontroller is able to simultaneously execute up to two sub-instructions for each clock cycle, in case a number of instructions higher than two are to be executed, the same are subdivided according to two different groupings being able to be simultaneously executed, as shown in
(42) It can be thus verified that the file code lines Micro 2 still comprises four code lines to be executed in three clock cycles for a condition C being true and four clock cycles for a condition C being false, while Micro 1 comprises five code lines, a NOP instruction having been inserted, to be executed in four clock cycles, independently from the condition C.
(43) It should be noted that, even if the code line “I1; IF (C==1) THEN GOTO I_true;” is divided into two lines “IF (C==1) THEN GOTO I_true;” followed by “I1” so as to remove the NOP operation, the number of code lines and the clock cycles needed would be the same.
(44) According to an embodiment, by duplicating all the jump instructions, a best working mode is achieved for Micro 2, having a same execution speed (Case 1) and a lower code lines number (Case 2).
(45) It should be noted that the method according to the embodiment processes and decodes a greater number of instructions, due to the presence of the duplicated jump instructions. It is thus clear that Micro 2, implementing such a method, comprises a decoder with a greater area with respect to Micro 1, the decoder area being tied to the number of instructions to be decoded. Moreover, in case the bit length of the instruction is increased, a corresponding increasing of the memory area wherein the instruction are stored occurs, being a ROM memory or a RAM memory.
(46) For instance, for a code comprising 16 jump instructions over a total number of 46 instructions, according to the method of the embodiment, a total number of 62 instructions are processed, i.e., a significant increased total number of instructions.
(47) Hence, according to an embodiment, the method comprises the identification of: a first group of instructions GR1 including the instructions that are nonessential, in particular the unused instructions or the instructions being called a limited number of time and that can be substituted without affecting the correct working of the microcontroller; and a second group of instructions GR2 including the jump instructions that are mostly used, as schematically shown in
(48) The method according to the embodiment further comprises duplicated instructions of the second group GR2 and an inserted one jump instruction of such second group GR2 in place of an instruction of the first group GR1 of nonessential instructions, to obtain a new instruction set having a reduced number of duplicated jump instructions with respect to the previous embodiment. In this way, an internal NOP instruction is removed after a jump instruction that causes the NOP instruction. A microcontroller with a reduced number of duplicated jump instructions, in accordance with the method according to the embodiment described above, is also indicated as Micro 3.
(49) It can be verified that the selection of the jump instructions to be duplicated and the nonessential instructions to be removed, for instance the unused instructions, is dependent on the particular case analyzed. The code lines of the nonessential instructions are in any case used to code the added jump instructions.
(50) The new instruction set having a reduced number of duplicated jump instructions allows for a clear reading of the code and simplification of the evaluation of its behavior.
(51) The method according to an embodiment compromises between the number of code lines, the execution speed and the area occupation of the microcontroller, by tuning the number of jump instructions to be duplicated. In particular, it can be verified that the file code lines Micro 3 with the new instruction set having a reduced number of duplicated jump instructions, applied on read and program code only, still shows a saving of code lines, even if lower with respect to the file code lines Micro 2, while maintaining an area occupation and an execution time in line with the file code lines Micro 1.
(52) According to an embodiment of the present disclosure, the new instruction set, as obtained by identifying the first group GR1 of nonessential instructions and inserting one jump instruction of the second group GR2 of most used jump instructions in place of an instruction of the first group GR1 is combined with using an internal NOP signal in order to manage the NOP instructions.
(53) More particularly, as shown in
(54) In this way, an internal managing unit 300 is provided within the microcontroller, which comprises the program counter block 310 and the instruction decoder sequence block 320 as well as an instruction decoder combiner block 330, suitably modified to provide the internal NOP code signal INTERNAL_NOP to the program counter block 310 and to the instruction decoder sequence block 320 as well as a jump call to the program counter block 310.
(55) A previous configuration of an internal managing unit 300′ using the externally provided skipping signal MC_MICRO_INTNOP_SKIP is shown in
(56) In such a previous configuration of the internal managing unit 300, the internal NOP code signal INTERNAL_NOP is driven high by the jump flags whenever a jump instruction is being decoded inside the instruction decoder combiner block 330. However, if the skipping signal MC_MICRO_INTNOP_SKIP is set, such an internal NOP code signal INTERNAL_NOP is masked to zero.
(57) The skipping signal MC_MICRO_INTNOP_SKIP is used to remove a NOP instruction after a jump instruction that has caused such a NOP instruction.
(58) It can be verified that the association of an internal NOP code signal INTERNAL_NOP and the new instruction set allows to save code lines, the algorithm with the new instruction set having the same execution time as the one being not modified according to the method.
(59) A block diagram of a NOP manager unit of a microcontroller using a combination of the instruction decoder combiner block providing the internal NOP code signal INTERNAL_NOP to the instruction decoder sequence block is shown in
(60) In particular, the NOP manager unit 400 comprises an instruction decoder combiner block 410 having an input portion 410A connected to an output terminal OUT of the NOP manager unit 400 and providing an operation code OPCODE to an output portion 410B of the instruction decoder combiner block 410, in turn providing at an internal output terminal OUT1 an internal NOP code signal INTERNAL_NOP.
(61) The NOP manager unit 400 further comprises an instruction decoder sequence block 420 receiving the internal NOP code signal INTERNAL_NOP from the instruction decoder combiner block 410 and a clock signal MC_CLK of the microcontroller comprising the NOP manager unit 400. More particularly, the instruction decoder sequence block 420 comprises a MUX having a first input terminal receiving the memory instructions ROM_DATA and a second input terminal receiving an idle instruction NOP 000 . . . 0 and being driven by the internal NOP code signal INTERNAL_NOP received from the internal output terminal OUT1 of the instruction decoder combiner block 410. The instruction decoder sequence block 420 also comprises a ROM DATA latch 420L which receives the clock signal MC_CLK as well as an output signal of the MUX and is connected to the output terminal OUT of the NOP manager unit 400 and provides an internal memory instruction int_ROM_DATA_L.
(62) In particular, in case an instruction needs a JUMP, the internal NOP code signal INTERNAL_NOP is set to 1 and the MUX of the instruction decoder sequence block 420 is set to idle.
(63) Alternatively, as shown in
(64) According to this alternative embodiment, possible glitches of the internal NOP code signal INTERNAL_NOP are vdeleted.
(65) Making reference to this latter embodiment, the flow chart and corresponding timing diagrams of the working of the NOP manager unit 400 are shown in
(66) In particular, at a first operation S1, the operation code OPCODE is verified in order to check if an internal NOP instruction is required. In case of an affirmative response (YES) to the verification of first operation S1, a second operation S2 is performed, setting the internal NOP code signal INTERNAL_NOP equal to 1 and a subsequent third operation S3 sets the internal memory instruction int_ROM_DATA_L equal to the idle instruction NOP 0000 . . . 0, the corresponding changes results in signals corresponding to the rising and falling edges of the clock signal MC_CLK being shown in
(67) Dually, in case of an negative response (NO) to the verification of first operation 51, an alternative second operation S2′ is performed, setting the internal NOP code signal INTERNAL_NOP equal to 0 and a subsequent alternative third operation S3′ sets the internal memory instruction int_ROM_DATA_L equal to the memory instructions ROM_DATA, the corresponding changes results in signals corresponding to the rising and falling edges of the clock signal MC_CLK being shown in
(68) With the aforementioned method and microcontroller, a high performance management of the NOP instructions is obtained, without wasting and even saving code lines while guaranteeing an unaltered execution time, thus overcoming the problems tied to incurring of NOP instructions when the microcontroller operates.
(69) Moreover, according to an embodiment, a suitable compromise between the number of lines code, the execution speed and the area occupation is achieved by tuning the number of jump instructions to be duplicated.
(70) From the foregoing it will be appreciated that, although specific embodiments of the invention have been described herein for purposes of illustration, various modifications may be made without deviating from the spirit and scope of the invention. Accordingly, the invention should not be limited except according to the following appended claims.