The present invention relates to a compiler generating a program including a loop process and to a computer executing a program including a loop process.
A compiler translates a source program written in a programming language into an object program to be executed in a given computer. For that purpose, a program analyzing part of the compiler first analyzes the source program, generates an intermediate code according to the result of the analysis, and then an optimizer applies optimization, such as loop fusion, to the intermediate code in order to improve the efficiency of execution of the program, and an code generator transforms the optimized intermediate code into the target program.
Such a known optimization method by means of a compiler is disclosed in Japanese Patent Laid-Open No. 9-114676, for example.
In that known optimization method, a target program is generated such that a loop cycle is minimized with the main aim of minimizing the number of instructions required for loops or execution time. If the instruction execution frequency of a program is 10 MHz and the number of instruction steps in loop processing is 10, then the loop cycle is 10 MHz/10 steps=1 MHz=1,000 KHz, which overlaps the medium radio frequency band.
Therefore, according to the known loop optimization method that minimizes loop cycles, a radio wave that interferes with radio receivers in the vicinity is emitted, thereby disrupting radio reception. There are many devices affected by an interfering wave, namely noise, in a particular frequency band such as a radio frequency band.
Therefore, an object of the present invention is to provide a compiler and a computer that solve these problems and can reduce generation of noise in a particular frequency band, such as a radio frequency band, to eliminate adverse effects of such noise on devices such as radio receivers.
In order to achieve the object, a compiler of the present invention includes a loop detecting part that detects a loop portion from an intermediate code generated from a source program; a loop program formatting part that, when a loop portion is detected by the loop detecting part, generates a loop processing program for the loop portion; and a loop process changing part that changes the number of instruction steps required for performing the loop processing program generated by the loop program formatting part.
A computer of the present invention includes a memory that stores a series of programs, receives an address signal and an access signal, and outputs a program associated with the address signal in response to the access signal; a CPU that outputs an address signal and an access signal; an address holding circuit that stores a plurality of past address signals outputted from the CPU; a match detecting circuit that compares address signals stored in the address holding circuit with the current address signal being outputted by the CPU and, when finding a match, outputs a wait signal during a plurality of cycles; a CPU control circuit into which a clock signal is inputted and into which a wait signal is inputted from the match detecting circuit, and which outputs the clock signal to the CPU as a control clock signal without modification while the wait signal is negative, and outputs a control clock signal in which the clock signal is kept inactivated for an n cyclic period to the CPU while the wait signal is active.
Embodiments of the present invention will be described with reference to the accompanying drawings.
“A compiler capable of reducing noise in a particular frequency band” according to a first embodiment of the present invention will be described below.
As shown in
One exemplary operation of the compiler 2 of the first embodiment configured as described above will be described below.
First, a source program 1 is inputted into the compile 2 and the program analyzing part 3 generates an intermediate code 4.
Then, the loop detecting part 6 in the loop processing section 5 detects a loop portion from the intermediate code 4 (program) and the loop program formatting part 7 generates a preliminary loop processing program.
The nop instruction adding part 11 modifies the generated preliminary loop processing program by, for example, adding a number n of nop instructions to the program.
An optimization code 8 generated in this way is used to generate target program 9.
As shown in
According to the operation described above, the number of instruction steps of a program including a loop which, if conventional loop processing is used, would generate noise having a frequency in a particular frequency band such as the radio frequency band of a radio broadcast during execution of the program can be significantly changed simply by adding a nop instruction, and the like. Changing per-loop execution time in this way can deviate the frequency of electromagnetic radiation generated based on a loop cyclic period, that is, the frequency of noise, from a particular frequency band such as a radio frequency band, thereby reducing an wave (noise in a particular frequency band) that can cause interference with devices such as radio receivers that can be affected by noise in a particular frequency band.
“A compiler capable of reducing noise in a particular frequency band” according to a second embodiment of the present invention will be described. The same components as those in the first embodiments are labeled with the same reference numbers and description of which will be omitted.
As shown in
The processing instruction adding part 12 changes the number of instruction steps required for performing a loop processing program by executing an operation within a loop multiple consecutive times in a preliminary loop processing program generated by a loop program formatting part 7.
An example of operation of the compiler 2 of the second embodiment configure as described above will be described below.
First, a source program is inputted into the compiler 2 and a program analyzing part 3 generates an intermediate code 4.
Then, a loop detecting part 6 in the loop processing section 5 detects a loop portion from the intermediate code 4 and the loop program formatting part 7 generates a preliminary loop processing program.
The processing instruction adding part 12 modifies the generated preliminary loop processing program into a program in which a loop instruction is repeated n times, for example.
An optimization code 38 generated in this way is used to generate a target program 39.
A program is changed so that, in a loop process consisting of AA (add instruction), BB (cmp instruction), and CC (tbz instruction) as shown in
The number of instruction steps of a program including a loop which, if conventional loop processing is used, would generate noise having a frequency in a particular frequency band such as the radio frequency band of a radio broadcast during execution of the program can be significantly changed (per-loop execution time can be increased by a factor of n) by making a modification so that a loop instruction is repeated n times, for example. Consequently, the frequency of electromagnetic radiation generated based on a loop cyclic period, that is, the frequency of noise, can be deviated from a particular frequency band such as a radio frequency band, thereby reducing an wave (noise in a particular frequency band) that can cause interference with devices such as radio receivers that can be affected by noise in a particular frequency band.
“A compiler capable of reducing noise in a particular frequency band” according to a third embodiment of the present invention will be described. The same components as those in the first embodiment are labeled with the same reference numbers and description of which will be omitted.
As shown in
The branch target adding part 13 has a flag that changes with iterations. The branch target adding part 13 adds a wait operation such as a nop instruction to an operation executed within a loop in a preliminary loop processing program generated by a loop program formatting part 7 and then causes a branch to a target preceding, following, or inside the added wait operation depending on the state of the flag, thereby changing the number of instruction steps required for the loop program handling.
An example of operation performed by the compiler 2 according to the third embodiment configured as described above will be described below.
First, a source program 1 is inputted in the compiler 2 and a program analyzing part 3 generates an intermediate code 4.
Then, a loop detecting part 6 in the loop processing section 5 detects a loop portion from the intermediate code 4 and a loop program formatting part 7 generates a preliminary loop processing program.
The branch target adding part 13 adds a number n of nap instructions before the generated preliminary loop processing program, for example, and provides (n+1) branch conditions so that branches to the nop instructions occur.
An optimization code 8 generated in this way is used to generate a target program 9.
As shown in
The number of instruction steps of a program including a loop which, if conventional loop processing is used, would generate noise having a frequency in a particular frequency band such as the radio frequency band of a radio broadcast during execution of the program can be significantly changed (per-loop execution time can be changed for each loop) without increasing the size of the program, by setting n branch targets for a loop instruction so that a branch occurs to a target preceding, following, or inside an added wait operation. Consequently, the frequency of electromagnetic radiation generated based on a loop cyclic period, that is, the frequency of noise, can be deviated from a particular frequency band such as a radio frequency band, thereby reducing an wave (noise in a particular frequency band) that can cause interference with devices such as radio receivers that can be affected by noise in a particular frequency band.
A compiler according to a fourth embodiment of the present invention will be described. The same components as those in the first embodiment are labeled with the same reference numbers and description of which will be omitted.
As shown in
The loop cyclic-period calculating part 23 calculates the number of instruction steps required for performing a preliminary loop processing program generated by a loop program formatting part 7 and calculates the number of cyclic periods required for performing the loop processing program from the inputted execution frequency (set operating frequency) 21 and the calculated number of instruction steps.
The noise cyclic period determining part 24 determines whether or not the period calculated by the loop cyclic-period calculating part 23 is in the inputted radio frequency band (noise NG frequency band) 22.
If the noise cyclic-period determining unit 24 determines that it is in the radio frequency band 22, the loop cycle changing part 25 makes a modification such as adding one nop instruction to the loop processing program to change the number of instruction steps required for performing the loop processing program. Thus, the cyclic period required for performing the loop processing program that is calculated by the loop cyclic-period calculating part 23 is changed so as to deviate from the radio frequency band 22.
An exemplary operation of the compile 2 of the fourth embodiment configured as described above will be described below.
First, a source program 1, the execution frequency (set operating frequency) 21 of the program, and a radio frequency band (noise NG frequency band) 22 are inputted into the compiler 2 and a program analyzing part 3 generates an intermediate code 4 from the source program 1.
Then, a loop detecting part 6 of a loop processing section 5 detects a loop portion from the intermediate code 4 and a loop program formatting part 7 generates a preliminary loop processing program.
The loop cyclic-period calculating part 23 uses the set operating frequency 21 inputted initially to calculate the loop processing time of the generated preliminary loop processing program and the frequency of noise generated with the loop processing.
The noise cyclic-period determining part 23 determines whether the frequency of noise calculated is within the radio frequency band 22 inputted initially. If it is within the radio frequency band 22, that is, inappropriate, the loop cyclic-period changing part 25 adds one nop instruction (that is to change the number of instruction steps required for processing the loop processing program in order to change the loop cyclic period). These processes are repeated until the frequency of noise deviates from the radio frequency band 22.
An optimization code 8 generated in this way is used to generate a target program 9.
According to the operation described above, the number of instruction steps of a program including a loop which, if conventional loop processing is used, would generate noise having a frequency in the radio frequency band 22 of a radio broadcast (a particular frequency band) during execution of the program is changed by adding a nop instruction, for example to change per-loop execution time. Consequently, the frequency of electromagnetic radiation, that is, the frequency of noise, generated based on the loop cyclic period can be deviated, by changing per-loop execution time, from the radio frequency band (particular frequency band), thereby reducing an wave (noise in the particular frequency band) that can cause interference with devices such as radio receivers.
While the loop cyclic-period changing part 25 adds one nop instruction in the fourth embodiment, the operation of the nop instruction adding part 11 of the first embodiment, the processing instruction adding part 12 of the second embodiment, or the branch target adding part 13 of the third embodiment described earlier can also be used to achieve the same effect.
A computer according to a fifth embodiment of the present invention will be described.
In
Also provided are an address holding circuit 33, a match detecting circuit 34, a ROM (memory) 35, and a CPU control circuit 36.
The address holding circuit 33 stores address signals A1 for the past m (plurality of) cyclic periods that have been outputted from the program counter 32 in the CPU 31.
The match detecting circuit 34 compares a plurality of address signals stored in the address holding circuit 33 with the current address signal A1 outputted from the program counter 32 of the CPU 31 and, if it finds a match, outputs a match detection signal (wait signal) A3 during the period of n cycles.
The ROM 35 stores a series of programs, receives address signals A1 and RE signals (access signals) A4, and outputs programs associate with the address signals A1 as data signals A2 in response to the access signals A4.
The CPU control circuit 36 receives a clock signal A5 and also receives a match signal (wait signal) A3 from the match detection circuit 34. While the match detection signal A3 is negative, the CPU control circuit 36 continues to output a clock signal A5 to the CPU 31 as a control clock signal A6. While the match detection signal A3 is active, the CPU control circuit 36 outputs a control clock signal A6 in which the clock signal A5 is deactivated for n cyclic periods to the CPU 31 in order to bring the CPU 31 to a halt (place and keep the CPU 31 in a sleep mode).
An exemplary operation of the computer configured as described above will be described below.
Address signals A1 are outputted from the program counter 32 in the CPU 31 to the ROM 35 in sequence.
During this, the address holding circuit 33 temporarily holds address signals A1 for m cyclic periods and the mach detection circuit 34 compares the address signals for m cyclic periods with the next address signal A1 provided from the program counter 32. When finding a match, the match detection circuit 34 determines that a loop is being executed and outputs a match detection signal A3 to the CPU control circuit 36 during n cyclic periods of the clock signal A5.
While the match detection signal A3 is negative, the CPU control circuit 36 outputs the clock signal A5 as is to the CPU 31 as the control clock signal A6. On the other hand, while the match detection signal A3 is active, the CPU control circuit 36 outputs control clock signals A6 in which the clock signal A5 is deactivated during n cyclic periods to the CPU 31 in order to bring the CPU 31 to a halt. When the control clock signal A6 indicates the halt state, the CPU 31 enters the sleep mode.
As shown in
According to the above-described processing, when a loop program is detected, the CPU 31 is kept halt during n cyclic periods and therefore the loop cyclic period is changed. Consequently, the cyclic period required for performing the loop processing program is changed and thus electromagnetic radiation generated based on the loop cycle, that is, noise in a particular frequency band can be reduced. Furthermore, because the CPU 31 is kept halt during n cycles, electric current consumption is reduced and therefore the current supply for noise is also reduced, thereby resulting in lower noise.
“A computer capable of reducing noise in a particular frequency band” according to a sixth embodiment of the present invention will be described. The same components as those in the fifth embodiment are labeled with the same reference numbers and description of which will be omitted.
The CPU control circuit 36 in the fifth embodiment is replaced with a memory control circuit 41 and a data control circuit 42.
While a match detection signal A3 from the match detection circuit 34 is negative, the memory control circuit 41 outputs an RE signal A4 provided from a CPU 31 as it is to a ROM 35 as an access signal A7. While the match detection signal A3 is active, the memory control circuit 41 makes and keeps the access signal A7 negative (disables the access signal A4 from the CPU 31 to the ROM 35) during n loop cyclic periods in order to stop access to the ROM 35.
The data control circuit 42 stores programs for the past n (plurality of) loop cyclic periods that have been outputted from the ROM (memory) 35. While the match detection signal A3 outputted from the match detection circuit 34 is negative, the data control circuit 42 outputs programs outputted from the ROM 35, as it is, as control data signals A8 to the CPU 31. While the foregoing match detection signal A3 is active, the data control circuit 42 sequentially outputs held data for n loop cyclic periods to the CPU 31 as control data signals A8.
Programs are provided from the data control circuit 42 to the CPU 31.
In addition, a clock signal A5 is provided to the CPU 31 and the match detection circuit 34.
An exemplary operation of the computer of the sixth embodiment configured as described above will be described below.
Address signals A1 are sequentially outputted from a program counter 32 provided within the CPU 31 to the ROM 35.
During this, an address holding circuit 33 temporarily holds address signals A1 for m cyclic periods and the match detection circuit 34 compares the address signals for m cyclic periods with the next address signal A1 outputted from the program counter 32. When finding a match, the math detection circuit 34 determines that a loop is being executed and outputs a match detection signal A4 for n loop cyclic periods to the memory control circuit 41 and the data control circuit 42.
While the match detection signal A3 is negative, memory control circuit 41 outputs an RE signal A4 provided from the CPU 31 to the ROM 35, as it is, as an access signal A7. While the match detection signal A3 is active, the memory control circuit 41 makes and keeps the access signal A7 negative during n loop cyclic periods in order to stop access to the ROM 35. This stops the output of data signals A2 from the ROM 35.
The data control circuit 42, at the same time, sequentially outputs, held data for n cyclic periods of the loop to the CPU 31 as control data signals A8.
As shown in
According to the operation described above, when a loop program is detected, access to the ROM 35 is made stopped during n cyclic periods. As a result, electric current consumption is reduced and therefore the current supply for noise can be reduced, resulting in lower noise. Thus, generation of noise in a particular frequency band can be reduced.
“A computer capable of reducing noise in a particular frequency band” according to a seventh embodiment of the present invention will be described.
As shown in
The data control circuit 42′ stores programs for the past n (plurality of) loop cyclic periods that have been outputted from the ROM (memory) 35. While the match detection signal A3 from the match detection circuit 34 is negative, the data control circuit 42′ outputs the programs provided from the ROM 35, as it is, as control data signals A8 to the CPU 31. While the match detection signal A3 is active, the data control circuit 42′ adds a wait operation instruction code such as a nop instruction to a program to be provided to the CPU 31 and sequentially outputs held data (programs) for n loops to the CPU 31 as control data signals A8.
An exemplary operation of the computer according to the seventh embodiment configured as described above will be described below.
Address signals A1 are sequentially outputted from a program counter 32 provided in the CPU 31 to the ROM 35.
During this, an address holding circuit 33 temporarily holds address signals A1 for m cyclic periods and a match detection circuit 34 compares the address signals for m cyclic periods with the next address signal A1 outputted from the program counter 32. When finding a match, the match detection circuit 34 determines that a loop is being executed, and outputs a match detection signal A4 to a memory control circuit 41 and the data control circuit 42′ during n loop cyclic periods.
While the match detection signal A3 is negative, the memory control circuit 41 outputs an RE signal A4 provided from the CPU 31, as it is, to the ROM 35 as an access signal A7. On the other hand, while the match detection signal A3 is active, the memory control circuit 41 makes and keeps the access signal A7 negative during n loop cyclic periods in order to stop access to the ROM 35. This halts output of data signals A2 from the ROM 35.
Furthermore, the data control circuit 42′ outputs a nop instruction as a control data signal A8 to the CPU 31 and then sequentially outputs held data for n loop cyclic periods to the CPU 31.
As shown in
According to the operation described above, when a loop program is detected, access to the ROM 35 is made stopped during n cyclic periods of the loop program and the loop processing cyclic periods are also changed. Consequently, electric current consumption and therefore the current supply for noise can be reduced, resulting in lower noise. Thus, generation of noise in a particular frequency band can be reduced.
Because the present invention can reduce generation of noise in a particular frequency band, the present invention makes a computer that can reduce noise in a particular frequency band available as a controller in an environment in which noise in such a particular frequency band is not allowed.
Number | Date | Country | Kind |
---|---|---|---|
2003-281399 | Jul 2003 | JP | national |