WO2016056081A1 - コード変換プログラム、コード変換装置およびコード変換方法 - Google Patents

コード変換プログラム、コード変換装置およびコード変換方法 Download PDF

Info

Publication number
WO2016056081A1
WO2016056081A1 PCT/JP2014/076931 JP2014076931W WO2016056081A1 WO 2016056081 A1 WO2016056081 A1 WO 2016056081A1 JP 2014076931 W JP2014076931 W JP 2014076931W WO 2016056081 A1 WO2016056081 A1 WO 2016056081A1
Authority
WO
WIPO (PCT)
Prior art keywords
instruction
code
bit string
data
shift
Prior art date
Application number
PCT/JP2014/076931
Other languages
English (en)
French (fr)
Inventor
敬 荒川
Original Assignee
富士通株式会社
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 富士通株式会社 filed Critical 富士通株式会社
Priority to PCT/JP2014/076931 priority Critical patent/WO2016056081A1/ja
Priority to JP2016552748A priority patent/JP6222374B2/ja
Publication of WO2016056081A1 publication Critical patent/WO2016056081A1/ja

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/483Computations with numbers represented by a non-linear combination of denominational numbers, e.g. rational numbers, logarithmic number system or floating-point numbers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/76Arrangements for rearranging, permuting or selecting data according to predetermined rules, independently of the content of the data

Definitions

  • the present invention relates to a code conversion program, a code conversion device, and a code conversion method.
  • processors such as CPU (Central Processing Unit) can execute basic instructions that perform bit operations by regarding data expressed in binary numbers as bit strings.
  • Basic instructions related to bit operations include instructions for logical operations such as bit inversion (NOT), logical sum (OR), logical product (AND), exclusive logical sum (XOR), arithmetic shift, logical shift, and rotation. Instructions for shift operations such as shifts may be included. Complex processing for a bit string can also be realized by combining such basic instructions.
  • a computer capable of shifting only a part of bits in data has been proposed.
  • This computer accepts a shift instruction including a first field for designating a shift amount and a second field for designating a bit area for which shifting is prohibited.
  • the computer has a shift circuit and a selector circuit.
  • the shift circuit shifts data according to the shift amount specified in the first field.
  • the selector circuit selects the bit of the original data for the bit position belonging to the bit area specified in the second field and outputs it to the register.
  • the selector circuit selects the bit of the shift data output from the shift circuit and outputs it to the register for the bit position that does not belong to the bit area specified in the second field.
  • This semiconductor integrated circuit has a bit string generation circuit and an index calculation circuit.
  • the bit string generation circuit generates another bit string indicating whether adjacent bits are the same or different for the bit string indicating each floating-point number.
  • the exponent calculation circuit calculates a logical sum of other bit sequences corresponding to a plurality of floating-point numbers generated by the bit sequence generation circuit, and determines a common exponent based on the bit sequence of the logical sum.
  • bit string in the data is all 0 (0 column) or all 1 (1 column), that is, the values of all bits included in the bit string. It is mentioned to determine whether or not.
  • a bit string indicating an exponent may be all 0 or all 1.
  • some programs that handle floating point numbers such as a numerical calculation library, frequently check whether the bit string of the exponent part, which is a part of the data, is all 1 or all 0.
  • processors do not have a dedicated instruction for determining whether a part of a bit string in data is all 0s or all 1s. Therefore, as described above, a program for determining all 0s or all 1s is created using basic instructions such as logical operation instructions and shift instructions, and there is a problem that the efficiency of the determination process is not good. .
  • some processors can execute a complex instruction that instructs a shift operation and a logical operation with one instruction. If such a compound instruction can be used, there is room for efficient decision processing for a partial bit string.
  • an object of the present invention is to provide a code conversion program, a code conversion device, and a code conversion method capable of improving the efficiency of determination processing for a partial bit string.
  • a code conversion program for causing a computer to execute the following processing.
  • the first code is converted into a second code that can use a complex instruction that instructs a shift operation and a logical operation on the result of the shift operation with one instruction
  • the first code A first instruction for determining whether a part of a bit string is a string of 0, a second instruction for determining whether a part of a bit string is a string of 1, and a result of the first instruction and the second instruction
  • a determination code including the third instruction to be synthesized is detected.
  • a compound instruction in which an argument is set so that at least a part of the bit string is shifted by the shift operation and a part of the bit string after the shift and the other bit string in the data are synthesized by the logical operation; Then, another determination code including the fourth instruction for comparing the result of the compound instruction with the data is generated. Another determination code is included in the second code.
  • a second storage unit that can store a first code and a composite instruction that instructs the first code to perform a shift operation and a logical operation on the result of the shift operation with one instruction can be used.
  • a code conversion device is provided that includes a conversion unit that converts the code into a code.
  • a code conversion method executed by a computer is provided.
  • the determination process for the partial bit string can be made efficient.
  • FIG. 1 is a diagram illustrating a code conversion apparatus according to the first embodiment.
  • the code conversion apparatus 10 converts the first code 13 into the second code 14.
  • the first code 13 and the second code 14 describe processing to be executed by the processor using instructions, and may be called programs.
  • the code conversion apparatus 10 may be a compiler.
  • the first code 13 is source code or intermediate code
  • the second code 14 is intermediate code, assembly code or object code (machine language code).
  • the code conversion device 10 may be an assembler.
  • the first code 13 is an assembly code
  • the second code 14 is an object code.
  • the code conversion device 10 may be a binary optimizer. In that case, the first code 13 and the second code 14 are object codes.
  • the code conversion apparatus 10 may be a computer that executes a conversion program such as a compile program, an assembly program, or a binary optimization program.
  • the computer may be a client computer (also referred to as a terminal device) operated by a user or a server computer accessed from the client computer.
  • the second code 14 or the object code generated based on the second code 14 may be executed by a processor included in the code conversion apparatus 10 or may be executed by a processor included in another computer. .
  • the code conversion device 10 includes a storage unit 11 and a conversion unit 12.
  • the storage unit 11 may be a volatile storage device such as a RAM (Random Access Memory) or a non-volatile storage device such as an HDD (Hard Disk Drive) or a flash memory.
  • the conversion unit 12 can be realized using a processor.
  • the processor may be a CPU or DSP (Digital Signal Processor).
  • the processor may include an application-specific electronic circuit such as ASIC (Application Specific Integrated Circuit) or FPGA (Field Programmable Gate Array).
  • ASIC Application Specific Integrated Circuit
  • FPGA Field Programmable Gate Array
  • the processor executes a program stored in a memory such as a RAM.
  • a set of multiple processors may be referred to as a “processor”.
  • the storage unit 11 stores the first code 13.
  • the first code 13 includes a determination code 13a.
  • a part of the bit string in the data is all 0 (0 column) or all 1 (1 column), that is, all the bits included in the part bit string have the same value. This is a code for determining whether or not.
  • the determination code 13a includes an instruction M1 for determining whether a part of the bit string in the data is a string of 0, an instruction M2 for determining whether the part of the bit string is a string of 1, and the results of the instructions M1 and M2. Including an instruction M3.
  • the determination code 13a may include another instruction that masks a bit string other than the determination target bit string included in the data to 0 before the instruction M1.
  • the other instruction can be realized by using an AND instruction, for example.
  • the instruction M1 may be an instruction for comparing the masked data with sample data whose determination target bit string is all 0, and can be realized by using, for example, a comparison instruction.
  • the instruction M2 may be an instruction for comparing the masked data with sample data whose determination target bit string is all 1, and can be realized by using, for example, a comparison instruction.
  • the instruction M3 is an OR instruction that calculates the logical sum of the results of the instructions M1 and M2, for example.
  • the conversion unit 12 converts the first code 13 stored in the storage unit 11 into the second code 14.
  • the second code 14 is optimized so that the processing efficiency is improved (for example, at least one of improvement in processing speed and reduction in memory usage is realized).
  • instructions depending on the architecture of the processor executing the second code 14 or the object code generated from the second code 14 may be used.
  • a composite instruction described below can be used in the second code 14 as an architecture-dependent instruction.
  • This compound instruction instructs a shift operation and one or more logical operations based on the result of the shift operation with one instruction. For example, it is possible to instruct the processor to perform a shift on the data, perform an AND operation on the shift result, and further perform an OR operation on the AND operation result.
  • a processor capable of interpreting a compound instruction has an arithmetic circuit capable of continuously executing a shift operation and one or more logical operations.
  • the conversion unit 12 detects the determination code 13 a as an optimization target from the first code 13. Then, based on the determination code 13a, the conversion unit 12 generates a determination code 14a that provides the same processing result as the determination code 13a.
  • the determination code 14a is an optimization of the determination code 13a using a compound instruction, and includes a compound instruction MC and an instruction M4.
  • an argument is set so that at least a bit string to be determined is shifted in the data by a shift operation, and the bit string after the shift and another bit string in the data are synthesized by a logical operation.
  • the entire data is shifted by a shift operation, a bit string in a desired range is extracted from the shifted data by an AND operation, and a bit string in the desired range is combined with another bit string in the data by an OR operation.
  • the instruction M4 is a comparison instruction that compares the result of the compound instruction MC with the original data.
  • the conversion unit 12 includes the generated determination code 14 a in the second code 14.
  • the data is 8-bit data of x1, x2, x3, x4, x5, x6, x7, and x8, and it is determined whether the 4-bit values of x3, x4, x5, and x6 are the same.
  • the bit string x3, x4, x5, x6 is extracted, it is determined whether the bit string is 0000 by the instruction M1, and it is determined whether the bit string is 1111 by the instruction M2.
  • the instruction M3 determines whether one of the results of the instructions M1 and M2 is true. As a result, it can be determined whether the bit string x3, x4, x5, x6 is all 0 or all 1, that is, whether all the bit values are the same.
  • the determination code 14a only the bit string to be determined among the data x1, x2, x3, x4, x5, x6, x7, and x8 is shifted by the compound instruction MC.
  • the bit string to be determined is arithmetically shifted by one bit to the right.
  • the original data is converted into x1, x2, x3, x3, x4, x5, x7, and x8.
  • the instruction M4 determines whether the data converted by the compound instruction MC and the original data are the same.
  • the determination code 13 a for determining whether a part of the bit string in the data is a 0 column or a 1 column is detected from the first code 13. Then, based on the determination code 13a, only a part of the bit string is shifted using the compound instruction, and the determination code 14a for comparing the shifted data with the original data is generated.
  • the determination code 14a can obtain the same processing result as the determination code 13a by using a compound instruction that instructs a shift operation and a logical operation with one instruction.
  • the number of instructions of the second code 14 can be reduced as compared with the first code 13.
  • the number of instructions arranged on the critical path can be reduced. Therefore, it is possible to efficiently determine whether or not all bits belonging to a certain bit range have the same value.
  • the compiling apparatus converts source code described in a high-level language into machine-readable object code via the intermediate code described in the intermediate language. At this time, the compiling device performs various optimizations on the intermediate code so that the execution efficiency of the object code is improved.
  • FIG. 2 is a block diagram illustrating a hardware example of the compiling device.
  • the compiling device 100 includes a CPU 101, a RAM 102, an HDD 103, an image signal processing unit 104, an input signal processing unit 105, a medium reader 106, and a communication interface 107. Each of the above units is connected to the bus 108.
  • the CPU 101 is a processor including an arithmetic circuit that executes program instructions.
  • the CPU 101 loads at least a part of the program and data stored in the HDD 103 into the RAM 102 and executes the program.
  • the CPU 101 may include a plurality of processor cores
  • the compiling device 100 may include a plurality of processors
  • the processes described below may be executed in parallel using a plurality of processors or processor cores.
  • a set of processors (multiprocessor) may be called a “processor”.
  • the RAM 102 is a volatile semiconductor memory that temporarily stores programs executed by the CPU 101 and data used by the CPU 101 for calculations.
  • the compiling device 100 may include a memory of a type other than the RAM, or may include a plurality of memories.
  • the HDD 103 is a non-volatile storage device that stores an OS (Operating System), software programs such as middleware and application software, and data.
  • the program includes a compiled program.
  • the compiling device 100 may include other types of storage devices such as a flash memory and an SSD (Solid State Drive), and may include a plurality of nonvolatile storage devices.
  • the image signal processing unit 104 outputs an image to the display 31 connected to the compiling device 100 in accordance with an instruction from the CPU 101.
  • a CRT (Cathode Ray Tube) display a liquid crystal display (LCD: Liquid Crystal Display), a plasma display (PDP: Plasma Display Panel), an organic EL (OEL: Organic Electro-Luminescence) display, or the like can be used.
  • LCD Liquid Crystal Display
  • PDP Plasma Display Panel
  • OEL Organic Electro-Luminescence
  • the input signal processing unit 105 acquires an input signal from the input device 32 connected to the compiling apparatus 100 and outputs it to the CPU 101.
  • the input device 32 a mouse, a touch panel, a touch pad, a pointing device such as a trackball, a keyboard, a remote controller, a button switch, or the like can be used.
  • a plurality of types of input devices may be connected to the compiling apparatus 100.
  • the medium reader 106 is a reading device that reads a program and data recorded on the recording medium 33.
  • the recording medium 33 for example, a magnetic disk such as a flexible disk (FD) or HDD, an optical disk such as a CD (Compact Disk) or a DVD (Digital Versatile Disk), a magneto-optical disk (MO: Magneto-Optical disk), A semiconductor memory or the like can be used.
  • the medium reader 106 stores the program and data read from the recording medium 33 in the RAM 102 or the HDD 103.
  • the communication interface 107 is connected to the network 30 and communicates with other computers via the network 30.
  • the communication interface 107 may be a wired communication interface connected to a communication device such as a switch by a cable, or may be a wireless communication interface connected to a base station or an access point by a wireless link.
  • the compiling device 100 may not include the medium reader 106, and may not include the image signal processing unit 104 and the input signal processing unit 105 when control is possible from a terminal device operated by the user. Further, the display 31 and the input device 32 may be formed integrally with the casing of the compiling apparatus 100.
  • the compiling device 100 is an example of the code conversion device 10 according to the first embodiment.
  • the CPU 101 is an example of the conversion unit 12.
  • the RAM 102 or the HDD 103 is an example of the storage unit 11.
  • FIG. 3 is a block diagram illustrating an example of functions of the compiling device.
  • the compiling device 100 includes a file storage unit 110, a compiler 121, and a linker 122.
  • the file storage unit 110 is realized as a storage area secured in the RAM 102 or the HDD 103, for example.
  • the compiler 121 and the linker 122 are realized as programs executed by the CPU 101, for example.
  • a program in which the compiler 121 is mounted may be referred to as a compiled program.
  • a program in which the linker 122 is mounted may be called a link program.
  • the file storage unit 110 stores a source file 111, an intermediate file 112, an object file 113, and an executable file 114.
  • the source file 111 stores source code written in a high-level language.
  • the source file 111 is created by the user.
  • the intermediate file 112 stores intermediate code written in an intermediate language used inside the compiler 121.
  • the object file 113 stores an object code described in machine language.
  • the intermediate file 112 and the object file 113 are generated by the compiler 121.
  • the executable file 114 is a file in a format executable by a processor, obtained by combining fragmented object codes.
  • the executable file 114 is generated by the linker 122.
  • the compiler 121 reads source code from the source file 111 and compiles it in accordance with a compile command input from the user. During the compilation process, the compiler 121 writes intermediate code into the intermediate file 112. The compiler 121 generates object code corresponding to the source code and writes it in the object file 113.
  • the linker 122 detects a library or other object file that is referenced by the object code. The linker 122 combines the detected library or other object file with the object file 113 to generate an executable file 114.
  • the compiler 121 includes an input unit 130, an optimization unit 140, and an output unit 150.
  • the input unit 130 includes a source code input unit 131, a lexical analysis unit 132, a semantic analysis unit 133, and an intermediate code generation unit 134.
  • the optimization unit 140 includes an intermediate code input unit 141, an analysis unit 142, an optimization execution unit 143, and an intermediate code output unit 144.
  • the output unit 150 includes an intermediate code input unit 151 and an object code generation unit 152.
  • the source code input unit 131 reads source code from the source file 111 specified by the compile command.
  • the lexical analyzer 132 performs lexical analysis on the source code read by the source code input unit 131. In lexical analysis, a character string included in a source code is divided into minimum unit words called “tokens”.
  • the semantic analysis unit 133 performs syntax analysis and semantic analysis on the token sequence generated by the lexical analysis unit 132. In the syntax analysis, based on the grammar of the programming language, a sequence of tokens is analyzed to generate a syntax tree. In semantic analysis, semantic information is added to the syntax tree, and the relationship between variable definitions and references is analyzed.
  • the intermediate code generation unit 134 generates an intermediate code based on the syntax tree generated by the semantic analysis unit 133 and writes it to the intermediate file 112.
  • the intermediate code input unit 141 reads the intermediate code from the intermediate file 112.
  • the analysis unit 142 searches the intermediate code read by the intermediate code input unit 141 for an instruction that can be optimized, and selects an optimization method. Optimization includes deleting unnecessary variables and intermediate calculations, reducing loops and conditional branches, and automatic parallelization. In addition, the optimization includes grouping simple instructions each instructing one operation into a composite instruction instructing a plurality of operations. Among the complex instructions, there are instructions dependent on the processor architecture.
  • the analysis unit 142 selects an optimization method in consideration of the target processor architecture.
  • the optimization execution unit 143 converts the intermediate code read by the intermediate code input unit 141 according to the optimization method selected by the analysis unit 142.
  • the analysis of the intermediate code by the analysis unit 142 and the conversion of the intermediate code by the optimization execution unit 143 may be repeatedly executed. That is, the analysis unit 142 may search for instructions that can be further optimized from the intermediate code converted by the optimization execution unit 143.
  • the intermediate code output unit 144 writes the intermediate code converted by the optimization execution unit 143 to the intermediate file 112.
  • the intermediate code input unit 151 reads the optimized intermediate code from the intermediate file 112.
  • the object code generation unit 152 converts the intermediate code read by the intermediate code input unit 151 into an object code described in machine language.
  • the object code generation unit 152 may temporarily convert the intermediate code into assembly code and convert the assembly code into object code. Then, the object code generation unit 152 writes the object code to the object file 113.
  • FIG. 4 is a block diagram illustrating a hardware example of the processor.
  • a processor 200 having hardware as shown in FIG. 4 is assumed as a target processor architecture.
  • the processor 200 has registers R0, R1,..., R63 (64 registers).
  • Registers R0, R1,..., R63 are 64-bit general-purpose registers that can be used from program instructions.
  • the 64 registers can be identified by a 6-bit register number.
  • the processor 200 has an arithmetic circuit that performs a shift logic composite operation (SL composite operation) in response to a shift logic composite instruction (SL composite instruction).
  • SL composite operation a shift logic composite operation
  • SL composite instruction a shift logic composite instruction
  • an SL compound operation including a shift operation and a logic operation is executed.
  • the SL complex operation in a broad sense includes the following operations.
  • the SL compound operation in a broad sense includes calculation steps 1, 2, and 3.
  • the shift amount (s1, s2,%) Designated in the designated direction (d1, d2,%) Is designated for each of the plurality of reference operands (rs1, rs2,). Shift operations of types (k1, k2,%) are performed.
  • the shift direction is right or left.
  • the type of shift operation is one of logical shift, arithmetic shift, and rotational shift.
  • a logical operation of a specified type (la1, la2,%) Is performed between each result of the calculation step 1 and a specified bit string (m1, m2,).
  • the types of logical operations include logical product (AND), logical sum (OR), exclusive logical sum (XOR), negative logical product (NAND), negative logical sum (NOR), and negative exclusive logical sum (XNOR). included.
  • the result of the operation step 2 is synthesized using the specified logical operations (lb1, lb2,...) In the specified order, and one definition operand (rd) is calculated.
  • the processor 200 is implemented with a subset of SL compound operations in a broad sense (in a narrow sense, SL compound operations in the second embodiment).
  • the processor 200 includes shift circuits 201 and 202, AND circuits 203 and 204, and OR circuits 205 and 206 as arithmetic circuits used for executing the SL compound instruction.
  • the shift circuit 201 shifts the data stored in the register having the register number rs1 (hereinafter sometimes referred to as R (rs1)).
  • R (rs1) the register number
  • the parameter d1 indicates the shift direction
  • the parameter k1 indicates the type of shift operation
  • the parameter s1 indicates the shift amount.
  • the shift circuit 202 shifts the data in the register R (rs2) based on the parameters d2, k2, and s2.
  • the parameter d2 indicates the shift direction
  • the parameter k2 indicates the type of shift operation
  • the parameter s2 indicates the shift amount.
  • the AND circuit 203 calculates a logical product between the result of the shift circuit 201 and the data of the register R (m1).
  • the AND circuit 204 calculates a logical product between the result of the shift circuit 202 and the data of the register R (m2).
  • the OR circuit 205 calculates a logical sum between the result of the AND circuit 203 and the result of the AND circuit 204.
  • the OR circuit 206 calculates a logical sum between the result of the OR circuit 205 and the data in the register R (rs3).
  • the result of the SL composite operation calculated by the OR circuit 206 is stored in the register R (rd).
  • FIG. 5 is a diagram showing a format example of the shift logic compound instruction.
  • An SL compound instruction in the format of instruction format 41 is input to the processor 200.
  • the instruction format 41 includes a 22-bit instruction code and 6-bit register numbers rd, rs1, rs2, rs3, shift_ctrl, m1, and m2, respectively.
  • the register R (rd) can be said to be a definition operand of the SL compound instruction.
  • the registers R (rs1), R (rs2), R (rs3), R (shift_ctrl), R (m1), and R (m2) can be said to be reference operands of the SL compound instruction.
  • the instruction code indicates that the instruction type is an SL compound instruction (SL_COMPOUND).
  • the register number rd indicates a register that stores the result of the SL compound operation.
  • the register number rs1 indicates a register in which data to be input to the shift circuit 201 is stored.
  • the register number rs2 indicates a register in which data to be input to the shift circuit 202 is stored.
  • the register number rs3 indicates a register in which data to be input to the OR circuit 206 is stored.
  • the register number shift_ctrl indicates a register in which a parameter value is stored.
  • the register number m1 indicates a register in which the mask bit string of the AND circuit 203 is stored.
  • the register number m2 indicates a register in which the mask bit string of the AND circuit 204 is stored.
  • a bit string in the format of the parameter format 42 is stored in the register R (shift_ctrl).
  • the parameter format 42 includes 1-bit parameters d1 and d2, 2-bit parameters k1 and k2, and 7-bit parameters s1 and s2.
  • the remaining 44 bits are unused bits (don't care 1, 2).
  • the parameter d1 indicates the shift direction of the shift circuit 201.
  • the parameter d2 indicates the shift direction of the shift circuit 202.
  • the parameter k1 indicates the type of shift operation of the shift circuit 201.
  • the parameter k2 indicates the type of shift operation of the shift circuit 202.
  • the parameter s1 indicates the number of bits as the shift amount of the shift circuit 201.
  • the parameter s2 indicates the number of bits as the shift amount of the shift circuit 202.
  • the program (executable file 114) generated by the compiling device 100 may cause the processor 200 to process floating point data.
  • IEEE 754 format floating point data is handled.
  • FIG. 6 is a diagram illustrating a format example of floating point data.
  • the floating point format 43 includes a 1-bit sign part S, an 11-bit exponent part E, and a 52-bit mantissa part F.
  • the floating-point data has the following meaning.
  • the floating point data means positive zero.
  • the exponent part E is 0 in all bits, and the mantissa part F is 1 or more, the floating-point data means a positive underflow state (a positive denormalized number).
  • the exponent part E is all bits 1 (all-bits-on), and the mantissa part F is all bits 0, the floating-point data means positive infinity.
  • the floating point data means a positive non-numeric value (NaN: Not a Number).
  • the floating-point data means a positive normalized number (normal floating-point number).
  • the floating-point data means negative zero.
  • the floating point data means a negative underflow state (negative denormalized number).
  • the floating-point data means negative infinity.
  • the floating-point data means a negative non-numeric value (NaN).
  • the exponent E is all bits 0 or all bits 1. For example, when checking whether the floating-point data indicates positive zero, positive infinity, negative zero, or negative infinity, the exponent E is all bits 0 or all bits 1, In addition, it is determined whether or not the mantissa part F is all 0 bits.
  • FIG. 7 is a diagram illustrating a first calculation example of partial bit string match determination.
  • a logical product is calculated between the data in the register R (rs1) and the bit string in the register R (rs2).
  • the register R (rs1) stores floating point data.
  • the register R (rs2) stores a mask bit string.
  • the mask bit string is a bit string in which the bit corresponding to the exponent E is set to 1 and the other bits are set to 0. E1, E2,..., E11 included in the exponent part E are extracted by the AND operation 211.
  • a comparison operation (EQ operation) 212 executed in response to one comparison instruction, the result of the AND operation 211 is compared with the bit string of the register R (m1). If they match, “1” is output, and if they do not match, “0” is output.
  • the register R (m1) stores a comparison bit string. This comparison bit string is a bit string in which all bits are set to zero.
  • the comparison operation 213 executed in response to the other comparison instruction, the result of the AND operation 211 is compared with the bit string of the register R (rs2). If they match, “1” is output, and if they do not match, “0” is output.
  • the bit string of the register R (rs2) is reused as a comparison bit string in the comparison operation 213.
  • the OR operation 214 executed in response to the OR instruction, a logical sum is calculated between the result of the comparison operation 212 and the result of the comparison operation 213.
  • the OR operation 214 outputs 1. That is, when the exponent part E is all 0 bits or all 1 bits, the final result is “1”; otherwise, the final result is “0”.
  • FIG. 8 is a diagram illustrating a second calculation example of partial bit string match determination.
  • a logical product is calculated between the data in the register R (rs1) and the bit string in the register R (rs2).
  • the register R (rs1) stores floating point data.
  • the register R (rs2) stores a mask bit string.
  • This mask bit string is a bit string in which the bits corresponding to the exponent part E and the mantissa part F are set to 1 and the other bits are set to 0.
  • the bit corresponding to the mantissa part F is also set to 1.
  • the result of the AND operation 211 is compared with the bit string of the register R (m1).
  • the register R (m1) stores a comparison bit string.
  • This comparison bit string is a bit string in which all bits are set to zero. Since the determination condition of the mantissa part F is all 0 bits, the bit corresponding to the mantissa part F of this comparison bit string is set to all 0 bits. If the determination condition of the mantissa part F is other than all bits 0, the bit corresponding to the mantissa part F of this comparison bit string may be changed according to the determination condition.
  • the result of the AND operation 211 is compared with the bit string of the register R (m2).
  • Another bit string for comparison is stored in the register R (m2).
  • the other comparison bit string is a bit string in which the bit corresponding to the exponent E is set to 1 and the other bits are set to 0. Since the judgment condition of the mantissa part F is all 0 bits, the bit corresponding to the mantissa part F of the other comparison bit string is set to all 0 bits.
  • the determination condition of the mantissa part F is other than all bits 0, the bit corresponding to the mantissa part F of the other comparison bit string may be changed in accordance with the determination condition in the same manner as the bit string of the register R (m1). .
  • comparison operation 212 it is determined whether the exponent part E is all bits 0 and the mantissa part F is all bits 0.
  • comparison operation 213 it is determined whether exponent part E is all 1 bits and mantissa part F is all 0 bits.
  • OR operation 214 a logical sum is calculated between the result of the comparison operation 212 and the result of the comparison operation 213. When the exponent part E is all bits 0 or all bits 1 and the mantissa part F is all bits 0, the final result output from the OR operation 214 is “1”. The result is “0”.
  • FIG. 9 is a diagram illustrating a third calculation example of partial bit string match determination.
  • the shift operation 221 is executed by the shift circuit 201 and the shift operation 222 is executed by the shift circuit 202 in accordance with the SL compound instruction.
  • an AND operation 223 is executed by the AND circuit 203
  • an AND operation 224 is executed by the AND circuit 204
  • an OR operation 225 is executed by the OR circuit 205
  • an OR operation 226 is executed by the OR circuit 206.
  • a comparison operation 227 is executed in response to the comparison instruction.
  • a 1-bit logical shift is performed on the floating point data stored in the register R (rs1) in the right direction.
  • the shift operation 222 the floating-point data stored in the register R (rs1) is not changed.
  • a logical product is calculated between the result of the shift operation 221 and the mask bit string stored in the register R (m1).
  • This mask bit string is a bit string in which bits other than the most significant bit (MSB: Most Significant Bit) among bits corresponding to the exponent part E are set to 1 and other bits are set to 0.
  • MSB Most Significant Bit
  • a bit string in which the exponent part E is 0, E1, E2,..., E10 and the mantissa part F is all 0 bits is generated.
  • a logical product is calculated between the result of the shift operation 222 and another mask bit string stored in the register R (m2).
  • the other mask bit string is a bit inversion of the mask bit string of the register R (m1).
  • a bit string in which the exponent E is E1, 0, 0,..., 0 and the other bits are the same as the original floating point data is generated.
  • a logical sum is calculated between the result of the AND operation 223 and the result of the AND operation 224.
  • a bit string in which the exponent part E is E1, E1, E2,..., E10 and the other bits are the same as the original floating point data is generated.
  • This bit string corresponds to the floating-point data in which only the exponent part E is arithmetically shifted by one bit to the right.
  • a logical sum is calculated between the result of the OR operation 225 and the bit string stored in the register R (rs3). However, a bit string of all 0 bits is stored in the register R (rs3). Therefore, in the OR operation 226, the result of the OR operation 225 is not changed.
  • the comparison operation 227 the result of the OR operation 226 is compared with the original floating point data stored in the register R (rs1). If they match, “1” is output, and if they do not match, “0” is output.
  • FIG. 10 is a diagram illustrating a fourth calculation example of partial bit string match determination.
  • the shift operations 221, 222, the AND operations 223, 224, the OR operations 225, 226 and the comparison operation 227 are executed as in the case of FIG.
  • the bit string of the register R (m2) input to the AND operation 224 and the bit string of the register R (rs3) input to the OR operation 226 are different from those in FIG.
  • the register R (m2) stores a mask bit string.
  • This masking bit string is a bit string in which the MSB of the bit corresponding to the sign part S and the bit corresponding to the exponent part E is set to 1 and the other bits are set to 0. Since the judgment condition of the mantissa part F is all 0 bits, the bit corresponding to the mantissa part F of this mask bit string is set to all 0 bits. When the condition that some bits of the mantissa part F are 0 (OFF constraint) is given, the bit having the OFF constraint among the bits corresponding to the mantissa part F is set to 0 and corresponds to the mantissa part F Other bits may be set to 1 among the bits to be processed.
  • the bit string stored in the register R is a bit string of all 0 bits. Since the determination condition of the mantissa part F is all 0 bits, the bit corresponding to the mantissa part F of this bit string is set to all 0 bits. When the condition that some bits of the mantissa part F are 1 (ON constraint) is given, the bit having the ON constraint among the bits corresponding to the mantissa part F is set to 1, and the mantissa part F is supported. Of these bits, other bits may be set to 0.
  • the bit having the OFF constraint is set to 0, the bit having the ON constraint is set to 1, and the bit having neither the OFF constraint nor the ON constraint is the original floating The same value as the decimal point data is set.
  • the mantissa part F of the bit string output by the OR operation 226 is all bits 0.
  • the above determination process can be realized by four operations, and when the SL compound instruction is used, the same determination process can be realized by seven operations.
  • two shift operations, two AND operations, and two OR operations are executed continuously in the processor 200 in response to one SL compound instruction.
  • four instructions are issued when the SL compound instruction is not used, and two instructions are issued when the SL compound instruction is used. Therefore, in many cases, the above-described determination process can be executed at higher speed by using the SL compound instruction.
  • the compiling device 100 optimizes the determination process that does not use the SL compound instruction to use the SL compound instruction in the optimization process for the intermediate code.
  • the optimization will be described on the assumption that the calculation shown in FIG. 8 is converted into the calculation shown in FIG. That is, it is assumed that the determination part determines whether the exponent part E is all bits 0 or all bits 1 and the mantissa part F is all bits 0.
  • FIG. 11 is a diagram illustrating an example of optimization using the SL compound instruction.
  • the intermediate code 115 is generated by the intermediate code generation unit 134 of the input unit 130 based on the source code.
  • the intermediate code 115 includes seven instructions of instructions # 1 to # 7.
  • Instruction # 1 is an instruction for storing the constant 0x7FFFFFFFFFFFFF in the register R1.
  • the register R1 corresponds to the register R (rs2) in FIG.
  • the instruction # 2 is an instruction for storing the constant 0x0000000000000000000 in the register R2.
  • the register R2 corresponds to the register R (m1) in FIG.
  • the instruction # 3 is an instruction for storing the constant 0x7FF0000000000000 in the register R3.
  • the register R3 corresponds to the register R (m2) in FIG. Note that the floating point data is stored in the register R0.
  • the register R0 corresponds to the register R (rs1) in FIG.
  • Instruction # 4 is an AND instruction with the registers R0 and R1 as reference operands and the register R4 as definition operands.
  • the register R4 stores a logical product between the floating point data and the constant of the register R1.
  • Instruction # 4 corresponds to AND operation 211 in FIG.
  • the instruction # 5 is a comparison instruction using the registers R4 and R2 as reference operands and the register R5 as a definition operand.
  • the register R5 stores the comparison result between the operation result of the instruction # 4 and the constant of the register R2.
  • the instruction # 5 corresponds to the comparison operation 212 in FIG.
  • Instruction # 6 is a comparison instruction using registers R4 and R3 as reference operands and register R6 as a defined operand.
  • the register R6 stores the comparison result between the operation result of the instruction # 4 and the constant of the register R3.
  • Instruction # 6 corresponds to the comparison operation 213 in FIG.
  • the instruction # 7 is an OR instruction using the registers R5 and R6 as reference operands and the register R7 as a definition operand.
  • the register R7 stores the logical sum of the comparison result of the instruction # 5 and the comparison result of the instruction # 6.
  • Instruction # 7 corresponds to OR operation 214 in FIG.
  • one register (definition operand) is defined by one instruction and is referenced by one or more instructions.
  • the intermediate code 116 is converted from the intermediate code 115 by the optimization execution unit 143 of the optimization unit 140.
  • the intermediate code 116 includes six instructions of instructions # 11 to # 16.
  • Instruction # 11 is an instruction for storing the constant 0x000000000000000 in the register R8.
  • the register R8 corresponds to the register R (rs3) in FIG.
  • the instruction # 12 is an instruction for storing the constant 0x0000000100000000 in the register R9.
  • the constant of the register R9 has the format of the parameter format 42 in FIG.
  • the instruction # 13 is an instruction for storing the constant 0x3FF0000000000000 in the register R10.
  • the register R10 corresponds to the register R (m1) in FIG.
  • the instruction # 14 is an instruction for storing the constant 0xC000000000000000000 in the register R11.
  • the register R11 corresponds to the register R (m2) in FIG.
  • Instruction # 15 is an SL compound instruction (SL_COMPOUND) having the registers R0, R8, R9, R10, and R11 as reference operands and the register R12 as a definition operand.
  • the register R12 corresponds to the register R (rd) in FIG.
  • the register R12 stores a bit string in which only the exponent part E of the floating point data is arithmetically shifted by one bit to the right and the mantissa part F is replaced with all zeros.
  • the instruction # 16 is a comparison instruction using the registers R0 and R12 as reference operands and the register R7 as a definition operand. Instruction # 16 corresponds to the comparison operation 227 of FIG.
  • the register R7 stores a comparison result between the operation result of the instruction # 15 and the original floating point data.
  • FIG. 12 is a flowchart illustrating an example of a compilation procedure.
  • S1 When a compile command is input from the user, the source code input unit 131 reads the source code from the source file 111 specified by the compile command.
  • the lexical analyzer 132 performs lexical analysis on the source code and divides it into token strings.
  • the semantic analysis unit 133 performs syntax analysis and semantic analysis on the token sequence obtained by the lexical analysis, and generates a syntax tree.
  • the intermediate code generation unit 134 generates an intermediate code corresponding to the source code based on the syntax tree and writes it to the intermediate file 112.
  • the intermediate code input unit 141 reads the intermediate code from the intermediate file 112.
  • the analysis unit 142 detects code that can be optimized from the intermediate code.
  • the code that can be optimized includes a code that implements a process (partial bit string match determination) for determining whether or not some of the bit strings in the data are all 0s or all 1s.
  • the partial bit string match determination includes a case where an OFF constraint or an ON constraint is applied to other bits in the data. Details of the method of detecting the partial bit string match determination code will be described later.
  • the analysis unit 142 selects an optimization method for the detected code that can be optimized.
  • the optimization using the SL compound instruction is selected for the partial bit string match determination code.
  • the optimization execution unit 143 optimizes the intermediate code by the method selected by the analysis unit 142 (updates the intermediate code). Details of optimization using the SL compound instruction will be described later.
  • the intermediate code output unit 144 writes (overwrites) the intermediate code optimized by the optimization execution unit 143 to the intermediate file 112.
  • the temporary data used in steps S3 and S4 will be described.
  • FIG. 13 is a diagram illustrating a structure example of instruction data and dependency data.
  • the analysis unit 142 When analyzing the intermediate code, the analysis unit 142 generates instruction data for each instruction included in the intermediate code. The analysis unit 142 generates dependency data for each dependency relationship between instructions. The generated instruction data and dependency data are stored in the RAM 102.
  • the instruction data 161 includes items of instruction number, instruction code, definition operand, reference operand, immediately preceding instruction, and immediately following instruction.
  • the instruction number is identification information for identifying an instruction in the intermediate code. For example, a line number can be used.
  • the instruction code indicates the type of instruction such as an assignment instruction (SET instruction), an AND instruction, an OR instruction, or a comparison instruction.
  • the definition operand indicates a register in which the result of the instruction is written. One definition operand is designated for one instruction.
  • the reference operand indicates a register storing data referred to by the instruction or a constant referred to by the instruction. One or more reference operands are designated per instruction.
  • the immediately preceding instruction indicates an instruction described immediately before the instruction in the intermediate code.
  • the immediately following instruction indicates an instruction described immediately after the instruction in the intermediate code.
  • the instruction data 161 shown in FIG. 13 corresponds to the instruction # 1 in FIG.
  • the dependency data 162 includes items of an edge number, a definition operand, a definition instruction, and a reference instruction.
  • the edge number is identification information for identifying a definition reference relationship in which another instruction refers to a register (definition operand) in which data is written by one instruction.
  • the definition operand indicates a register in which data is written by one instruction and referenced by another instruction.
  • the definition instruction indicates an instruction for writing data into a register, that is, an instruction having the register as a definition operand.
  • the reference instruction indicates an instruction that refers to a register, that is, an instruction having the register as a reference operand.
  • FIG. 14 is a diagram illustrating a structure example of target processing data.
  • the analysis unit 142 generates target process data each time a partial bit string match determination code is detected from the intermediate code.
  • the generated target processing data is stored in the RAM 102.
  • the target process data 163 includes items of process ID, replacement target instruction, definition operand, reference operand, determination bit, OFF constraint bit, ON constraint bit, and ignore bit.
  • the process ID is identification information for identifying the detected partial bit string match determination code.
  • the replacement target instruction indicates the last instruction included in the partial bit string match determination code.
  • the definition operand indicates a register that stores the result of partial bit string match determination.
  • the reference operand indicates a register that stores input data (for example, floating point data) to be subjected to partial bit string match determination.
  • the determination bit indicates a range of a bit string for determining whether all 0s or all 1s are present.
  • the OFF constraint bit indicates a bit for determining whether or not the value is 0.
  • the ON constraint bit indicates a bit for determining whether or not the value is 1.
  • the ignore bit indicates a bit other than the determination bit, the OFF constraint bit, and the ON constraint bit.
  • the target processing data 163 shown in FIG. 14 corresponds to the calculation of FIG. 8 and the intermediate code 115 of FIG.
  • FIG. 15 is a flowchart illustrating an exemplary procedure for detecting an optimization target. This optimization target detection is executed in step S3 described above.
  • the analysis unit 142 determines whether there are remaining instructions in the instruction data set. If there are remaining instructions, the process proceeds to step S11, and if not, the process ends. (S11) The analysis unit 142 selects one instruction from the set of instruction data (instr). Normally, instructions are selected in ascending order of instruction numbers.
  • step S12 The analysis unit 142 determines whether the instruction code of the instruction instr selected in step S11 is OR (logical sum). If the instruction code is OR, the process proceeds to step S13. If the instruction code is not OR, the process proceeds to step S10.
  • the analysis unit 142 identifies two reference operands of the instruction instr.
  • the analysis unit 142 searches the set of dependency data for a definition instruction (cmp_instr [1]) that defines the first reference operand.
  • the analysis unit 142 searches for a definition instruction (cmp_instr [2]) that defines the second reference operand.
  • the analysis unit 142 determines whether the instruction codes of both the instruction cmp_instr [1] and the instruction cmp_instr [2] are EQ (comparison). If the instruction code is EQ, the process proceeds to step S15. If not, the process proceeds to step S10.
  • the analysis unit 142 identifies two reference operands of the instruction cmp_instr [1].
  • the analysis unit 142 searches the set of dependency data for a definition instruction (and_instr [1]) that defines the first reference operand.
  • the analysis unit 142 searches for a definition instruction (set_instr [1]) that defines the second reference operand.
  • the analysis unit 142 identifies two reference operands of the instruction cmp_instr [2].
  • the analysis unit 142 searches the set of dependency data for a definition instruction (and_instr [2]) that defines the first reference operand.
  • the analysis unit 142 searches for a definition instruction (set_instr [2]) that defines the second reference operand.
  • step S17 The analysis unit 142 determines whether the instruction and_instr [1] searched in step S15 and the instruction and_instr [2] searched in step S16 are the same instruction. If they are the same, the process proceeds to step S18. If they are different, the process proceeds to step S10.
  • step S18 In the analysis unit 142, the instruction code of the instruction and_instr [1] is AND (logical product), and the instruction codes of both the instruction set_instr [1] and the instruction set_instr [2] are SET (assignment). Judge. If the condition is satisfied, the process proceeds to step S19. If the condition is not satisfied, the process proceeds to step S10.
  • the analysis unit 142 identifies the second reference operand of the instruction and_instr [1].
  • the analysis unit 142 searches the set of dependency data for a definition instruction (set_instr [0]) that defines the second reference operand.
  • step S20 The analysis unit 142 determines whether the instruction code of the instruction set_instr [0] searched in step S19 is SET (assignment). If the instruction code is SET, the process proceeds to step S21, and if not, the process proceeds to step S10.
  • FIG. 16 is a flowchart (continued) illustrating an example of the procedure for detecting the optimization target.
  • the analysis unit 142 generates target process data 163.
  • the analysis unit 142 sets the replacement target instruction of the target processing data 163 to the instruction instr.
  • the analysis unit 142 sets the definition operand of the target process data 163 as the definition operand of the instruction instr, and sets the reference operand as the first reference operand of the instruction and_instr [1].
  • the analysis unit 142 defines variables mask_bit, cmp_bit [1], and cmp_bit [2].
  • the analysis unit 142 sets the reference operand (constant) of the instruction set_instr [0] in the variable mask_bit.
  • the analysis unit 142 sets the reference operand (constant) of the instruction set_instr [1] in the variable cmp_bit [1], and sets the reference operand (constant) of the instruction set_instr [2] in the variable cmp_bit [2].
  • the analysis unit 142 calculates the determination bit of the target processing data 163 as AND (XOR (cmp_bit [1], cmp_bit [2]), mask_bit).
  • the analysis unit 142 calculates the OFF constraint bit of the target processing data 163 as AND (NOR (cmp_bit [1], cmp_bit [2]), mask_bit).
  • the analysis unit 142 calculates the ON restriction bit of the target processing data 163 as AND (AND (cmp_bit [1], cmp_bit [2]), mask_bit).
  • the analysis unit 142 calculates the neglected bit of the target processing data 163 as NOT (mask_bit).
  • step S24 The analysis unit 142 determines whether or not the determination bit calculated in step S23 is all 0 (sequence of 0). If the determination bits are all 0, the partial bit string match determination is not substantially performed, so the target process data 163 is discarded and the process proceeds to step S10. If the determination bit is not all 0, the process proceeds to step S25.
  • step S25 The analysis unit 142 determines whether “1” included in the determination bit calculated in step S23 is continuous. If the determination bit “1” is continuous, the process proceeds to step S26. When the determination bit “1” is discontinuous, the target processing data 163 is discarded because the target bit is not an optimization target, and the process proceeds to step S10.
  • FIG. 17 is a flowchart illustrating an exemplary procedure for executing optimization.
  • step S4 This optimization execution is executed in step S4 described above.
  • the analysis unit 142 determines whether there is unselected target processing data among the target processing data generated by the optimization target detection of FIGS. If there is an unselected item, the process proceeds to step S31. If all are selected, the process proceeds to step S41.
  • the analysis unit 142 selects one target process data.
  • the analysis unit 142 defines variables D_rs3, D_shift_ctrl, D_m1.
  • the analysis unit 142 substitutes the ON restriction bit described in the target process data selected in Step S31 for the variable D_rs3.
  • the analysis unit 142 substitutes the constant 0x0000000100000000 for the variable D_shift_ctrl.
  • the analysis unit 142 substitutes the determination bit described in the target process data into the variable D_m1.
  • the analysis unit 142 inverts the most significant “1” of the variable D_m1 to “0”.
  • the analysis unit 142 defines a variable D_m2. Further, the analysis unit 142 extracts the OFF constraint bit from the target processing data. Then, the analysis unit 142 substitutes AND (NOT (D_m1), NOT (OFF constraint bit)) for the variable D_m2.
  • the analysis unit 142 defines variables ref and def.
  • the analysis unit 142 assigns the reference operand described in the processing target data to the variable ref, and assigns the definition operand described in the processing target data to the variable def.
  • the analysis unit 142 generates a SET instruction that assigns the value of D_rs3 to the register R (rs3) (new_instr [1]).
  • the analysis unit 142 generates a SET instruction that assigns the value of D_shift_ctrl to the register R (shift_ctrl) (new_instr [2]).
  • the analysis unit 142 generates a SET instruction that assigns the value of D_m1 to the register R (m1) (new_instr [3]).
  • the analysis unit 142 generates a SET instruction that assigns the value of D_m2 to the register R (m2) (new_instr [4]).
  • the analysis unit 142 may arbitrarily select a free register as the registers R (rs3), R (shift_ctrl), R (m1), and R (m2).
  • the analysis unit 142 uses the registers R (ref), R (rs3), R (shift_ctrl), R (m1), and R (m2) as reference operands, and the SL composite having the register R (rd) as a definition operand.
  • An instruction is generated (new_instr [5]). Note that the analysis unit 142 may arbitrarily select a free register as the register R (rd).
  • the analysis unit 142 generates a comparison instruction using the registers R (ref) and R (rd) as reference operands and the register R (def) as a definition operand (new_instr [6]).
  • a register that stores input data for example, floating point data
  • a register that stores a final determination result are the same before and after optimization.
  • the analysis unit 142 determines whether the instructions new_instr [1], new_instr [2], new_instr [3], new_instr [4], new_instr [5], and new_instr [6] are all empty (NULL). If the condition is satisfied, the process proceeds to step S40. If the condition is not satisfied, the instruction generated in steps S36 to S38 is discarded, and the process proceeds to step S30.
  • the optimization execution unit 143 executes the instructions new_instr [1], new_instr [2], new_instr [3], new_instr [4], new_instr [5], new_instr [6] in the above order with respect to the intermediate code. insert.
  • the insertion position is next to the replacement target instruction described in the processing target data selected in step S31. Then, the process proceeds to step S30.
  • FIG. 18 is a flowchart (continuation) illustrating an example of the procedure for performing optimization.
  • the optimization execution unit 143 deletes, from the intermediate code, instructions that are no longer necessary as a result of optimization.
  • the instructions that are no longer necessary include the pre-optimization instructions detected in steps S10 to S20 described above. This process is sometimes called Dead Code Elimination.
  • the optimization execution unit 143 determines whether the instruction generated in the above steps S36 to S38 is present in the loop. If it exists inside the loop, the optimization execution unit 143 moves the instructions new_instr [1], new_instr [2], new_instr [3], and new_instr [4], which are SET instructions, before the loop. As a result, it is not necessary to repeatedly substitute constants into the registers R (rs3), R (shift_ctrl), R (m1), and R (m2). This process is sometimes called Invariant Code Motion.
  • a partial bit string (for example, the exponent part E of floating point data) in the input data is all 0 or all 1 from the intermediate code before optimization. Is detected.
  • the detected code is optimized to a code using the SL compound instruction.
  • the SL compound instruction By using the SL compound instruction, data obtained by shifting only a part of the bit string in the input data can be generated with one instruction. As a result, the number of instructions in the program can be reduced, and the processing by the processor 200 can be speeded up.
  • automatic parallelization becomes easy.
  • the conversion to the code using the SL compound instruction is realized in the compiler 121.
  • the conversion may be performed in another device or other software.
  • the conversion may be performed in an assembler that converts assembly code into object code or a binary optimizer that analyzes and optimizes object code.
  • the information processing according to the first embodiment can be realized by causing the code conversion apparatus 10 to execute a program.
  • the information processing according to the second embodiment can be realized by causing the compiling device 100 to execute a program.
  • the program can be recorded in a computer-readable recording medium (for example, the recording medium 33).
  • a computer-readable recording medium for example, the recording medium 33.
  • the recording medium for example, a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like can be used.
  • Magnetic disks include FD and HDD.
  • Optical disks include CD, CD-R (Recordable) / RW (Rewritable), DVD, and DVD-R / RW.
  • the program may be recorded and distributed on a portable recording medium. In this case, the program may be copied from a portable recording medium to another recording medium such as an HDD (for example, the HDD 103) and executed.
  • an HDD for example, the HDD 103

Abstract

 部分ビット列に対する判定処理を効率化する。 コード変換装置(10)は、第1のコード(13)を、シフト演算と論理演算とを1つの命令で指示する複合命令(MC)を使用可能な第2のコード(14)に変換する。変換部(12)は、データの中の一部のビット列が0の列であるか判定する命令(M1)と、当該一部のビット列が1の列であるか判定する命令(M2)と、命令(M1,M2)の結果を合成する命令(M3)とを含む判定コード(13a)を検出する。変換部(12)は、シフト演算によって少なくとも上記一部のビット列がシフトされ、論理演算によってシフト後の上記一部のビット列とデータの中の他のビット列とが合成されるように引数を設定した複合命令(MC)と、複合命令(MC)の結果とデータとを比較する命令(M4)とを含む判定コード(14a)を生成する。

Description

コード変換プログラム、コード変換装置およびコード変換方法
 本発明はコード変換プログラム、コード変換装置およびコード変換方法に関する。
 CPU(Central Processing Unit)などのプロセッサの多くは、2進数で表現されたデータをビット列とみなしてビット演算を行う基本的な命令を実行することができる。ビット演算に関する基本的な命令には、ビット反転(NOT)・論理和(OR)・論理積(AND)・排他的論理和(XOR)などの論理演算の命令や、算術シフト・論理シフト・回転シフトなどのシフト演算の命令が含まれ得る。ビット列に対する複雑な処理についても、このような基本的な命令を組み合わせることで実現可能である。
 ただし、論理演算命令やシフト命令などの基本的な命令のみを用いて、ビット列に対する複雑な処理を実現しようとすると、発行する命令が多くなってしまう場合がある。例えば、1つのレジスタに格納されたデータの中から、不連続な2つのビット列を抽出して結合する処理を考える。この処理を実現するプログラムの一例として、抽出するビット列毎にAND命令を用いて当該ビット列以外の部分をマスクし、ビット列毎にシフト命令を用いて位置調整を行い、OR命令を用いて2つのビット列を結合するものが考えられる。この場合、少なくとも5つの基本的な命令が発行されることになる。
 これに対し、頻繁に実行され得る処理については、基本的な命令の他に専用の命令を用意し、ハードウェアによって高速に実行できるようにすることが提案されている。
 例えば、データの中の一部分のビットのみシフトすることができる計算機が提案されている。この計算機は、シフト量を指定する第1のフィールドとシフトを禁止するビット領域を指定する第2のフィールドとを含むシフト命令を受け付ける。計算機は、シフト回路とセレクタ回路とを有する。シフト回路は、第1のフィールドで指定されたシフト量に応じてデータをシフトする。セレクタ回路は、第2のフィールドで指定されたビット領域に属するビット位置については、元のデータのビットを選択してレジスタに出力する。一方、セレクタ回路は、第2のフィールドで指定されたビット領域に属さないビット位置については、シフト回路が出力するシフトデータのビットを選択してレジスタに出力する。
 また、複数の浮動小数点数の指数部をブロック単位で共通化する(正規化する)半導体集積回路が提案されている。正規化では、ブロック内の浮動小数点数の中で指数の最大値を特定し、当該最大値に応じて各浮動小数点数の仮数部をシフトする。この半導体集積回路は、ビット列生成回路と指数算出回路とを有する。ビット列生成回路は、各浮動小数点数を示すビット列について、隣接するビットが同じか異なるかを示す他のビット列を生成する。指数算出回路は、ビット列生成回路が生成した複数の浮動小数点数に対応する他のビット列の論理和を算出し、論理和のビット列に基づいて共通の指数を決定する。
特開2000-99327号公報 国際公開第2011/161859号
 ところで、プロセッサに実行させたい処理として、データ中の一部のビット列がオール0(0の列)またはオール1(1の列)であるか否か、すなわち、ビット列に含まれる全てのビットの値が一致しているか否かを判定することが挙げられる。例えば、IEEE(Institute of Electrical and Electronics Engineers)754に規定された浮動小数点数の規格では、データが特殊な数値を表しているとき、指数部を示すビット列がオール0またはオール1になる場合がある。このため、数値計算ライブラリなど、浮動小数点数を扱うプログラムの中には、データの一部分である指数部のビット列がオール1またはオール0であるか否かを頻繁にチェックするものがある。
 しかし、多くのプロセッサには、データ中の一部のビット列がオール0またはオール1であるか否か判定する専用の命令は用意されていない。そのため、前述のように論理演算命令やシフト命令などの基本的な命令を用いて、オール0またはオール1を判定するプログラムが作成されることになり、判定処理の効率が良くないという問題がある。一方で、プロセッサの中には、1つの命令でシフト演算と論理演算とを指示する複合命令を実行することができるものがある。このような複合命令を活用することができれば、部分ビット列に対する判定処理を効率化できる余地がある。
 1つの側面では、本発明は、部分ビット列に対する判定処理を効率化できるコード変換プログラム、コード変換装置およびコード変換方法を提供することを目的とする。
 1つの態様では、コンピュータに以下の処理を実行させるコード変換プログラムが提供される。第1のコードを、シフト演算とシフト演算の結果に対する論理演算とを1つの命令で指示する複合命令を使用可能な第2のコードに変換する場合に、第1のコードから、データの中の一部のビット列が0の列であるか判定する第1の命令と、一部のビット列が1の列であるか判定する第2の命令と、第1の命令および第2の命令の結果を合成する第3の命令とを含む判定コードを検出する。判定コードに基づいて、シフト演算によって少なくとも一部のビット列がシフトされ、論理演算によってシフト後の一部のビット列とデータの中の他のビット列とが合成されるように引数を設定した複合命令と、複合命令の結果とデータとを比較する第4の命令とを含む他の判定コードを生成する。第2のコードに他の判定コードを含める。
 また、1つの態様では、第1のコードを記憶する記憶部と、第1のコードを、シフト演算とシフト演算の結果に対する論理演算とを1つの命令で指示する複合命令を使用可能な第2のコードに変換する変換部と、を有するコード変換装置が提供される。また、1つの態様では、コンピュータが実行するコード変換方法が提供される。
 1つの側面では、部分ビット列に対する判定処理を効率化できる。
 本発明の上記および他の目的、特徴および利点は本発明の例として好ましい実施の形態を表す添付の図面と関連した以下の説明により明らかになるであろう。
第1の実施の形態のコード変換装置を示す図である。 コンパイル装置のハードウェア例を示すブロック図である。 コンパイル装置の機能例を示すブロック図である。 プロセッサのハードウェア例を示すブロック図である。 シフト論理複合命令のフォーマット例を示す図である。 浮動小数点データのフォーマット例を示す図である。 部分ビット列一致判定の第1の演算例を示す図である。 部分ビット列一致判定の第2の演算例を示す図である。 部分ビット列一致判定の第3の演算例を示す図である。 部分ビット列一致判定の第4の演算例を示す図である。 SL複合命令を用いた最適化の例を示す図である。 コンパイルの手順例を示すフローチャートである。 命令データと依存性データの構造例を示す図である。 対象処理データの構造例を示す図である。 最適化対象検出の手順例を示すフローチャートである。 最適化対象検出の手順例を示すフローチャート(続き)である。 最適化実行の手順例を示すフローチャートである。 最適化実行の手順例を示すフローチャート(続き)である。
 以下、本実施の形態を図面を参照して説明する。
 [第1の実施の形態]
 図1は、第1の実施の形態のコード変換装置を示す図である。
 第1の実施の形態のコード変換装置10は、第1のコード13を第2のコード14に変換する。第1のコード13および第2のコード14は、命令を用いてプロセッサに実行させる処理を記述したものであり、プログラムと呼ばれてもよい。
 コード変換装置10としては、様々な種類の変換装置が考えられる。例えば、コード変換装置10は、コンパイラでもよい。その場合、第1のコード13はソースコードまたは中間コードであり、第2のコード14は中間コード、アセンブリコードまたはオブジェクトコード(機械語コード)である。また、コード変換装置10は、アセンブラでもよい。その場合、第1のコード13はアセンブリコードであり、第2のコード14はオブジェクトコードである。また、コード変換装置10は、バイナリオプティマイザでもよい。その場合、第1のコード13および第2のコード14は、オブジェクトコードである。
 コード変換装置10は、コンパイルプログラム、アセンブリプログラム、バイナリ最適化プログラムなどの変換プログラムを実行するコンピュータであってもよい。コンピュータは、ユーザが操作するクライアントコンピュータ(端末装置と言うこともできる)でもよいし、クライアントコンピュータからアクセスされるサーバコンピュータでもよい。なお、第2のコード14または第2のコード14に基づいて生成されるオブジェクトコードは、コード変換装置10が備えるプロセッサに実行させてもよいし、他のコンピュータが備えるプロセッサに実行させてもよい。
 コード変換装置10は、記憶部11および変換部12を有する。記憶部11は、RAM(Random Access Memory)などの揮発性の記憶装置でもよいし、HDD(Hard Disk Drive)やフラッシュメモリなどの不揮発性の記憶装置でもよい。変換部12は、プロセッサを用いて実現できる。プロセッサは、CPUやDSP(Digital Signal Processor)であってもよい。また、プロセッサは、ASIC(Application Specific Integrated Circuit)やFPGA(Field Programmable Gate Array)などの特定用途の電子回路を含んでもよい。プロセッサは、例えば、RAMなどのメモリに記憶されたプログラムを実行する。複数のプロセッサの集合(マルチプロセッサ)を「プロセッサ」と呼ぶこともある。
 記憶部11は、第1のコード13を記憶する。第1のコード13は、判定コード13aを含む。判定コード13aは、データの中の一部のビット列がオール0(0の列)またはオール1(1の列)であるか、すなわち、当該一部のビット列に含まれる全てのビットの値が同一であるか判定するコードである。判定コード13aは、データの中の一部のビット列が0の列であるか判定する命令M1と、当該一部のビット列が1の列であるか判定する命令M2と、命令M1,M2の結果を合成する命令M3とを含む。
 判定コード13aは、命令M1の前に、データに含まれる判定対象のビット列以外の他のビット列を0にマスクする他の命令を含んでもよい。当該他の命令は、例えば、AND命令を用いて実現できる。命令M1は、マスクされたデータと判定対象のビット列がオール0であるサンプルデータとを比較する命令であってもよく、例えば、比較命令を用いて実現できる。命令M2は、マスクされたデータと判定対象のビット列がオール1であるサンプルデータとを比較する命令であってもよく、例えば、比較命令を用いて実現できる。命令M3は、例えば、命令M1,M2の結果の論理和を算出するOR命令である。
 変換部12は、記憶部11に記憶された第1のコード13を第2のコード14に変換する。このとき、第2のコード14は、処理効率が向上するように(例えば、処理速度の向上およびメモリ使用量の削減の少なくとも一方が実現されるように)最適化される。最適化においては、第2のコード14または第2のコード14から生成されるオブジェクトコードを実行するプロセッサのアーキテクチャに依存した命令を使用してもよい。
 第1の実施の形態では、アーキテクチャ依存の命令として、以下に説明する複合命令を第2のコード14において使用可能であるものとする。この複合命令は、シフト演算と当該シフト演算の結果に基づく1以上の論理演算とを、1つの命令で指示するものである。例えば、データに対してシフトを行い、シフト結果に対してAND演算を行い、AND演算の結果に対して更にOR演算を行うことを、1つの複合命令によってプロセッサに指示することができる。複合命令を解釈可能なプロセッサは、シフト演算と1以上の論理演算とを連続的に実行することができる演算回路を有している。
 変換部12は、第1のコード13の中から、最適化対象として判定コード13aを検出する。すると、変換部12は、判定コード13aに基づいて、判定コード13aと同じ処理結果が得られる判定コード14aを生成する。判定コード14aは、複合命令を用いて判定コード13aを最適化したものであり、複合命令MCと命令M4を含む。
 複合命令MCに対しては、シフト演算によってデータのうち少なくとも判定対象のビット列がシフトされ、論理演算によってシフト後のビット列とデータ中の他のビット列とが合成されるように、引数が設定される。例えば、シフト演算によってデータ全体がシフトされ、AND演算によってシフト後のデータから所望の範囲のビット列が抽出され、OR演算によって所望の範囲のビット列とデータ中の他のビット列とが合成される。複合命令MCを実行することで、データの中の判定対象となる一部のビット列のみシフトすることができる。シフトは、例えば、右方向への1ビットの算術シフトとする。命令M4は、複合命令MCの結果と元のデータとを比較する比較命令である。変換部12は、生成した判定コード14aを第2のコード14に含めるようにする。
 ここで、判定コード14aによって判定コード13aと同じ処理結果が得られることを説明する。一例として、データはx1,x2,x3,x4,x5,x6,x7,x8の8ビットデータであり、x3,x4,x5,x6の4ビットの値が同一か判定するとする。
 判定コード13aでは、ビット列x3,x4,x5,x6が抽出され、命令M1によってこのビット列が0000であるか判定され、命令M2によってこのビット列が1111であるか判定される。そして、命令M3によって、命令M1,M2の結果の何れか一方が真であるか判定される。これにより、ビット列x3,x4,x5,x6がオール0またはオール1か、すなわち、全てのビットの値が同じであるか否か判定できる。
 一方、判定コード14aでは、複合命令MCによって、データx1,x2,x3,x4,x5,x6,x7,x8のうち判定対象のビット列のみシフトされる。ここでは、判定対象のビット列が右方向に1ビットだけ算術シフトされるとする。これにより、元のデータがx1,x2,x3,x3,x4,x5,x7,x8に変換される。そして、命令M4によって、複合命令MCで変換されたデータと元のデータが同一か否か判定される。
 命令M4の結果が真となる条件は、比較するビット列の間で同じ位置にあるビットの値が同じであること、すなわち、x3=x3かつx3=x4かつx4=x5かつx5=x6が成立していることである。この等式をまとめると、命令M4の結果が真となる条件は、x3=x4=x5=x6となる。これは、判定対象のビット列x3,x4,x5,x6がオール0またはオール1であることを意味する。よって、判定コード14aにおける命令M4の結果は、判定コード13aにおける命令M3の結果と一致する。
 第1の実施の形態のコード変換装置10によれば、第1のコード13から、データ中の一部のビット列が0の列または1の列であるか判定する判定コード13aが検出される。そして、判定コード13aに基づいて、複合命令を用いて上記の一部のビット列のみをシフトし、シフトしたデータと元のデータとを比較する判定コード14aが生成される。判定コード14aは、シフト演算と論理演算とを1つの命令で指示する複合命令を利用して、判定コード13aと同じ処理結果を得ることができるものである。
 これにより、第2のコード14の命令数を第1のコード13よりも削減することができる。特に、クリティカルパス上に並ぶ命令の数を削減することができる。よって、あるビット範囲に属する全てのビットが同じ値か否かの判定を効率的に行うことができる。
 [第2の実施の形態]
 次に、第2の実施の形態を説明する。第2の実施の形態のコンパイル装置は、高級言語で記述されたソースコードを、中間言語で記述された中間コードを経由して、機械可読なオブジェクトコードに変換する。このとき、コンパイル装置は、オブジェクトコードの実行効率が向上するように、中間コードに対して各種の最適化を行う。
 図2は、コンパイル装置のハードウェア例を示すブロック図である。
 コンパイル装置100は、CPU101、RAM102、HDD103、画像信号処理部104、入力信号処理部105、媒体リーダ106および通信インタフェース107を有する。上記のユニットは、それぞれバス108に接続されている。
 CPU101は、プログラムの命令を実行する演算回路を含むプロセッサである。CPU101は、HDD103に記憶されたプログラムやデータの少なくとも一部をRAM102にロードし、プログラムを実行する。なお、CPU101は複数のプロセッサコアを備えてもよく、コンパイル装置100は複数のプロセッサを備えてもよく、以下で説明する処理を複数のプロセッサまたはプロセッサコアを用いて並列に実行してもよい。また、複数のプロセッサの集合(マルチプロセッサ)を「プロセッサ」と呼んでもよい。
 RAM102は、CPU101が実行するプログラムやCPU101が演算に用いるデータを一時的に記憶する揮発性の半導体メモリである。なお、コンパイル装置100は、RAM以外の種類のメモリを備えてもよく、複数個のメモリを備えてもよい。
 HDD103は、OS(Operating System)やミドルウェアやアプリケーションソフトウェアなどのソフトウェアのプログラム、および、データを記憶する不揮発性の記憶装置である。プログラムには、コンパイルプログラムが含まれる。なお、コンパイル装置100は、フラッシュメモリやSSD(Solid State Drive)などの他の種類の記憶装置を備えてもよく、複数の不揮発性の記憶装置を備えてもよい。
 画像信号処理部104は、CPU101からの命令に従って、コンパイル装置100に接続されたディスプレイ31に画像を出力する。ディスプレイ31としては、CRT(Cathode Ray Tube)ディスプレイ、液晶ディスプレイ(LCD:Liquid Crystal Display)、プラズマディスプレイ(PDP:Plasma Display Panel)、有機EL(OEL:Organic Electro-Luminescence)ディスプレイなどを用いることができる。
 入力信号処理部105は、コンパイル装置100に接続された入力デバイス32から入力信号を取得し、CPU101に出力する。入力デバイス32としては、マウスやタッチパネルやタッチパッドやトラックボールなどのポインティングデバイス、キーボード、リモートコントローラ、ボタンスイッチなどを用いることができる。また、コンパイル装置100に、複数の種類の入力デバイスが接続されていてもよい。
 媒体リーダ106は、記録媒体33に記録されたプログラムやデータを読み取る読み取り装置である。記録媒体33として、例えば、フレキシブルディスク(FD:Flexible Disk)やHDDなどの磁気ディスク、CD(Compact Disc)やDVD(Digital Versatile Disc)などの光ディスク、光磁気ディスク(MO:Magneto-Optical disk)、半導体メモリなどを使用できる。媒体リーダ106は、例えば、記録媒体33から読み取ったプログラムやデータをRAM102またはHDD103に格納する。
 通信インタフェース107は、ネットワーク30に接続され、ネットワーク30を介して他のコンピュータと通信を行う。通信インタフェース107は、スイッチなどの通信装置とケーブルで接続される有線通信インタフェースでもよいし、基地局またはアクセスポイントと無線リンクで接続される無線通信インタフェースでもよい。
 なお、コンパイル装置100は、媒体リーダ106を備えていなくてもよく、ユーザが操作する端末装置から制御可能である場合は画像信号処理部104や入力信号処理部105を備えていなくてもよい。また、ディスプレイ31や入力デバイス32が、コンパイル装置100の筐体と一体に形成されていてもよい。コンパイル装置100は、第1の実施の形態のコード変換装置10の一例である。CPU101は、変換部12の一例である。RAM102またはHDD103は、記憶部11の一例である。
 図3は、コンパイル装置の機能例を示すブロック図である。
 コンパイル装置100は、ファイル記憶部110、コンパイラ121およびリンカ122を有する。ファイル記憶部110は、例えば、RAM102またはHDD103に確保した記憶領域として実現される。コンパイラ121およびリンカ122は、例えば、それぞれCPU101が実行するプログラムとして実現される。コンパイラ121を実装したプログラムは、コンパイルプログラムと呼ぶことがある。リンカ122を実装したプログラムは、リンクプログラムと呼ぶことがある。
 ファイル記憶部110は、ソースファイル111、中間ファイル112、オブジェクトファイル113および実行可能ファイル114を記憶する。ソースファイル111は、高級言語で記述されたソースコードを格納する。ソースファイル111は、ユーザによって作成される。中間ファイル112は、コンパイラ121の内部で使用される中間言語で記述された中間コードを格納する。オブジェクトファイル113は、機械語で記述されたオブジェクトコードを格納する。中間ファイル112およびオブジェクトファイル113は、コンパイラ121によって生成される。実行可能ファイル114は、断片的なオブジェクトコードを結合して得られる、プロセッサによって実行可能な形式のファイルである。実行可能ファイル114は、リンカ122によって生成される。
 コンパイラ121は、ユーザから入力されるコンパイルコマンドに応じて、ソースファイル111からソースコードを読み込み、コンパイルする。コンパイルの過程で、コンパイラ121は、中間ファイル112に中間コードを書き込む。コンパイラ121は、ソースコードに対応するオブジェクトコードを生成し、オブジェクトファイル113に書き込む。リンカ122は、オブジェクトファイル113が生成されると、オブジェクトコードで参照されているライブラリや他のオブジェクトファイルを検出する。リンカ122は、検出したライブラリや他のオブジェクトファイルとオブジェクトファイル113とを結合して、実行可能ファイル114を生成する。
 コンパイラ121は、入力部130、最適化部140および出力部150を有する。入力部130は、ソースコード入力部131、字句解析部132、意味解析部133および中間コード生成部134を有する。最適化部140は、中間コード入力部141、解析部142、最適化実行部143および中間コード出力部144を有する。出力部150は、中間コード入力部151およびオブジェクトコード生成部152を有する。
 ソースコード入力部131は、コンパイルコマンドで指定されたソースファイル111からソースコードを読み込む。字句解析部132は、ソースコード入力部131が読み込んだソースコードに対して、字句解析を行う。字句解析では、ソースコードに含まれる文字列が、「トークン」と呼ばれる最小単位の語に分割される。意味解析部133は、字句解析部132が生成したトークンの列に対して、構文解析および意味解析を行う。構文解析では、プログラミング言語の文法に基づいて、トークンの列が解析されて構文木が生成される。意味解析では、構文木に対して意味論的情報が付加され、変数の定義と参照の関係などが解析される。中間コード生成部134は、意味解析部133が生成した構文木に基づいて中間コードを生成し、中間ファイル112に書き出す。
 中間コード入力部141は、中間ファイル112から中間コードを読み込む。解析部142は、中間コード入力部141が読み込んだ中間コードの中から最適化可能な命令を検索し、最適化方法を選択する。最適化には、不要な変数および途中計算の削除、ループや条件分岐の削減、自動並列化などが含まれる。また、最適化には、それぞれ1つの演算を指示する単純命令をまとめて、複数の演算を指示する複合命令に変換することが含まれる。複合命令の中には、プロセッサアーキテクチャ依存の命令が存在する。解析部142は、ターゲットのプロセッサアーキテクチャを考慮して最適化方法を選択する。
 最適化実行部143は、解析部142が選択した最適化方法に従って、中間コード入力部141が読み出した中間コードを変換する。解析部142による中間コードの解析と最適化実行部143による中間コードの変換とは、繰り返し実行されることもある。すなわち、解析部142は、最適化実行部143によって変換された中間コードから、更に最適化可能な命令を検索するようにしてもよい。中間コード出力部144は、最適化実行部143が変換した中間コードを中間ファイル112に書き出す。
 中間コード入力部151は、中間ファイル112から最適化済みの中間コードを読み込む。オブジェクトコード生成部152は、中間コード入力部151が読み出した中間コードを、機械語で記述されたオブジェクトコードに変換する。オブジェクトコード生成部152は、中間コードをアセンブリコードに一旦変換し、アセンブリコードをオブジェクトコードに変換するようにしてもよい。そして、オブジェクトコード生成部152は、オブジェクトコードをオブジェクトファイル113に書き出す。
 次に、実行可能ファイル114を実行するプロセッサについて説明する。
 図4は、プロセッサのハードウェア例を示すブロック図である。
 第2の実施の形態では、図4に示すようなハードウェアを有するプロセッサ200を、ターゲットのプロセッサアーキテクチャとして想定する。プロセッサ200は、レジスタR0,R1,…,R63(64個のレジスタ)を有する。レジスタR0,R1,…,R63は、それぞれプログラムの命令から使用できる64ビットの汎用レジスタである。64個のレジスタは、6ビットのレジスタ番号で識別することができる。
 また、プロセッサ200は、シフト論理複合命令(SL複合命令)に応じてシフト論理複合演算(SL複合演算)を行う演算回路を有している。1つのSL複合命令を受けて、シフト演算および論理演算を含むSL複合演算が実行される。第2の実施の形態では、広義のSL複合演算は以下のような演算を含むものとする。
 広義のSL複合演算は、演算ステップ1,2,3を含む。演算ステップ1では、複数の参照オペランド(rs1,rs2,…)それぞれに対して、指定された方向(d1,d2,…)に指定されたシフト量(s1,s2,…)だけ、指定された種類(k1,k2,…)のシフト演算を行う。シフト方向は、右または左である。シフト演算の種類は、論理シフト、算術シフトおよび回転シフトの何れかである。
 演算ステップ2では、演算ステップ1の結果それぞれと指定されたビット列(m1,m2,…)との間で、指定された種類(la1,la2,…)の論理演算を行う。論理演算の種類には、論理積(AND)、論理和(OR)、排他的論理和(XOR)、否定論理積(NAND)、否定論理和(NOR)、否定排他的論理和(XNOR)が含まれる。演算ステップ3では、演算ステップ2の結果を、指定された順序で指定された論理演算(lb1,lb2,…)を用いて合成し、1つの定義オペランド(rd)を算出する。
 ただし、広義のSL複合演算をプロセッサ上で完全に実装することは容易でない。そこで、プロセッサ200には、以下に説明するように、広義のSL複合演算のサブセット(第2の実施の形態における狭義のSL複合演算)が実装されている。
 具体的には、プロセッサ200は、SL複合命令の実行に用いられる演算回路として、シフト回路201,202、AND回路203,204およびOR回路205,206を有する。シフト回路201は、パラメータd1,k1,s1に基づいて、レジスタ番号rs1のレジスタ(以下では、R(rs1)のように記載することがある)に格納されたデータをシフトする。シフト回路201に関して、パラメータd1はシフト方向を示し、パラメータk1はシフト演算の種類を示し、パラメータs1はシフト量を示す。シフト回路202は、パラメータd2,k2,s2に基づいて、レジスタR(rs2)のデータをシフトする。シフト回路202に関して、パラメータd2はシフト方向を示し、パラメータk2はシフト演算の種類を示し、パラメータs2はシフト量を示す。
 AND回路203は、シフト回路201の結果とレジスタR(m1)のデータとの間で論理積を算出する。AND回路204は、シフト回路202の結果とレジスタR(m2)のデータとの間で論理積を算出する。OR回路205は、AND回路203の結果とAND回路204の結果との間で論理和を算出する。OR回路206は、OR回路205の結果とレジスタR(rs3)のデータとの間で論理和を算出する。OR回路206が算出したSL複合演算の結果は、レジスタR(rd)に格納される。
 図5は、シフト論理複合命令のフォーマット例を示す図である。
 命令フォーマット41の形式のSL複合命令が、プロセッサ200に入力される。命令フォーマット41は、22ビットの命令コードと、それぞれ6ビットのレジスタ番号rd,rs1,rs2,rs3,shift_ctrl,m1,m2を含む。レジスタR(rd)は、SL複合命令の定義オペランドと言うことができる。レジスタR(rs1),R(rs2),R(rs3),R(shift_ctrl),R(m1),R(m2)は、SL複合命令の参照オペランドと言うことができる。
 命令コードは、命令の種類がSL複合命令(SL_COMPOUND)であることを示す。レジスタ番号rdは、SL複合演算の結果を格納するレジスタを示す。レジスタ番号rs1は、シフト回路201に入力するデータが格納されたレジスタを示す。レジスタ番号rs2は、シフト回路202に入力するデータが格納されたレジスタを示す。レジスタ番号rs3は、OR回路206に入力するデータが格納されたレジスタを示す。レジスタ番号shift_ctrlは、パラメータの値が格納されたレジスタを示す。レジスタ番号m1は、AND回路203のマスク用ビット列が格納されたレジスタを示す。レジスタ番号m2は、AND回路204のマスク用ビット列が格納されたレジスタを示す。
 レジスタR(shift_ctrl)には、パラメータフォーマット42の形式のビット列が格納される。パラメータフォーマット42は、1ビットのパラメータd1,d2と、2ビットのパラメータk1,k2と、7ビットのパラメータs1,s2を含む。残りの44ビットは、使用されないビットである(don’t care1,2)。
 パラメータd1は、シフト回路201のシフト方向を示す。パラメータd2は、シフト回路202のシフト方向を示す。パラメータd1,d2について、「0」は右シフトを示し、「1」は左シフトを示す。パラメータk1は、シフト回路201のシフト演算の種類を示す。パラメータk2は、シフト回路202のシフト演算の種類を示す。パラメータk1,k2について、「00」は論理シフトを示し、「01」は算術シフトを示し、「10」は回転シフトを示す。パラメータk1,k2の値として「11」は使用されない。パラメータs1は、シフト回路201のシフト量としてのビット数を示す。パラメータs2は、シフト回路202のシフト量としてのビット数を示す。
 ところで、コンパイル装置100が生成するプログラム(実行可能ファイル114)は、浮動小数点データをプロセッサ200に処理させることがある。第2の実施の形態では、IEEE754形式の浮動小数点データを扱うこととする。
 図6は、浮動小数点データのフォーマット例を示す図である。
 浮動小数点数を64ビットで表現する場合、浮動小数点フォーマット43は、1ビットの符号部Sと、11ビットの指数部Eと、52ビットの仮数部Fとを含む。符号部Sと指数部Eと仮数部Fの組み合わせに応じて、浮動小数点データは以下のような意味をもつ。
 符号部Sが0、指数部Eが全ビット0(all-bits-off)、仮数部Fが全ビット0の場合、その浮動小数点データは正のゼロを意味する。符号部Sが0、指数部Eが全ビット0、仮数部Fが1以上の値の場合、その浮動小数点データは正のアンダーフロー状態(正の非正規化数)を意味する。符号部Sが0、指数部Eが全ビット1(all-bits-on)、仮数部Fが全ビット0の場合、その浮動小数点データは正の無限大を意味する。符号部Sが0、指数部Eが全ビット1、仮数部Fが1以上の値の場合、その浮動小数点データは正の非数値(NaN:Not a Number)を意味する。符号部Sが0、指数部Eが0より大きく最大値(all-bits-on)より小さい場合、その浮動小数点データは正の正規化数(正常な浮動小数点数)を意味する。
 符号部Sが1、指数部Eが全ビット0、仮数部Fが全ビット0の場合、その浮動小数点データは負のゼロを意味する。符号部Sが1、指数部Eが全ビット0、仮数部Fが1以上の値の場合、その浮動小数点データは負のアンダーフロー状態(負の非正規化数)を意味する。符号部Sが1、指数部Eが全ビット1、仮数部Fが全ビット0の場合、その浮動小数点データは負の無限大を意味する。符号部Sが1、指数部Eが全ビット1、仮数部Fが1以上の値の場合、その浮動小数点データは負の非数値(NaN)を意味する。符号部Sが1、指数部Eが0より大きく最大値(all-bits-on)より小さい場合、その浮動小数点データは負の正規化数を意味する。
 このように、IEEE754形式の浮動小数点データでは、指数部Eが全ビット0であるか、指数部Eが全ビット1であるか、仮数部Fが全ビット0であるかに応じて、その意味が異なる。浮動小数点データを扱うプログラムでは、入力された浮動小数点データをチェックするときに、全ビット0や全ビット1を判定することになる。
 例えば、浮動小数点データが正の正規化数および負の正規化数以外を示しているかチェックするとき、指数部Eが全ビット0または全ビット1であるか否か判定することになる。また、例えば、浮動小数点データが正のゼロ、正の無限大、負のゼロ、負の無限大の何れかを示しているかチェックするとき、指数部Eが全ビット0または全ビット1であり、かつ、仮数部Fが全ビット0であるか否か判定することになる。
 次に、浮動小数点データに対する次の4つの演算の例を説明する。(1)SL複合命令を用いずに、指数部Eが全ビット0または全ビット1であるか判定する。(2)SL複合命令を用いずに、指数部Eが全ビット0または全ビット1であり、かつ、仮数部Fが全ビット0であるか判定する。(3)SL複合命令を用いて、指数部Eが全ビット0または全ビット1であるか判定する。(4)SL複合命令を用いて、指数部Eが全ビット0または全ビット1であり、かつ、仮数部Fが全ビット0であるか判定する。
 図7は、部分ビット列一致判定の第1の演算例を示す図である。
 SL複合命令を用いずに、指数部Eが全ビット0または全ビット1であるか判定する場合、例えば、1つのAND命令と2つの比較命令と1つのOR命令が発行される。
 AND命令に応じて実行されるAND演算211では、レジスタR(rs1)のデータとレジスタR(rs2)のビット列との間で論理積が算出される。レジスタR(rs1)には、浮動小数点データが格納されている。レジスタR(rs2)には、マスク用ビット列が格納されている。このマスク用ビット列は、指数部Eに対応するビットが1に設定され、それ以外のビットが0に設定されたビット列である。AND演算211によって、指数部Eに含まれるE1,E2,…,E11が抽出される。
 一方の比較命令に応じて実行される比較演算(EQ演算)212では、AND演算211の結果とレジスタR(m1)のビット列とが比較される。両者が一致する場合は「1」が出力され、一致しない場合は「0」が出力される。レジスタR(m1)には、比較用ビット列が格納されている。この比較用ビット列は、全ビットが0に設定されたビット列である。他方の比較命令に応じて実行される比較演算213では、AND演算211の結果とレジスタR(rs2)のビット列とが比較される。両者が一致する場合は「1」が出力され、一致しない場合は「0」が出力される。レジスタR(rs2)のビット列は、比較演算213では比較用ビット列として再利用されることになる。
 すなわち、比較演算212において指数部Eが全ビット0であるか否か判定され、比較演算213において指数部Eが全ビット1であるか否か判定される。OR命令に応じて実行されるOR演算214では、比較演算212の結果と比較演算213の結果との間で論理和が算出される。比較演算212,213の何れか一方が「1」を出力するとき、OR演算214は1を出力する。すなわち、指数部Eが全ビット0または全ビット1である場合、最終的な結果は「1」になり、それ以外の場合、最終的な結果は「0」になる。
 図8は、部分ビット列一致判定の第2の演算例を示す図である。
 SL複合命令を用いずに、指数部Eが全ビット0または全ビット1であり、かつ、仮数部Fが全ビット0であるか判定する場合、例えば、1つのAND命令と2つの比較命令と1つのOR命令が発行される。これにより、図7の場合と同様に、AND演算211と比較演算212,213とOR演算214が実行される。ただし、AND演算211および比較演算212,213に入力されるビット列が、図7の場合と異なる。
 AND演算211では、レジスタR(rs1)のデータとレジスタR(rs2)のビット列との間で論理積が算出される。レジスタR(rs1)には、浮動小数点データが格納されている。レジスタR(rs2)には、マスク用ビット列が格納されている。このマスク用ビット列は、指数部Eと仮数部Fに対応するビットが1に設定され、それ以外のビットが0に設定されたビット列である。仮数部Fに対してビット判定を行うため、仮数部Fに対応するビットも1に設定されている。AND演算211によって、指数部Eに含まれるE1,E2,…,E11と仮数部Fに含まれるF1,F2,…,F52が抽出される。
 比較演算212では、AND演算211の結果とレジスタR(m1)のビット列とが比較される。レジスタR(m1)には、比較用ビット列が格納されている。この比較用ビット列は、全ビットが0に設定されたビット列である。仮数部Fの判定条件が全ビット0であるため、この比較用ビット列の仮数部Fに対応するビットが全ビット0に設定されている。仮数部Fの判定条件が全ビット0以外の場合は、この比較用ビット列の仮数部Fに対応するビットを判定条件に合わせて変更すればよい。
 比較演算213では、AND演算211の結果とレジスタR(m2)のビット列とが比較される。レジスタR(m2)には、他の比較用ビット列が格納されている。当該他の比較用ビット列は、指数部Eに対応するビットが1に設定され、それ以外のビットが0に設定されたビット列である。仮数部Fの判定条件が全ビット0であるため、当該他の比較用ビット列の仮数部Fに対応するビットが全ビット0に設定されている。仮数部Fの判定条件が全ビット0以外の場合は、レジスタR(m1)のビット列と同様に、当該他の比較用ビット列の仮数部Fに対応するビットを判定条件に合わせて変更すればよい。
 すなわち、比較演算212において、指数部Eが全ビット0かつ仮数部Fが全ビット0であるか判定される。また、比較演算213において、指数部Eが全ビット1かつ仮数部Fが全ビット0であるか判定される。OR演算214では、比較演算212の結果と比較演算213の結果との間で論理和が算出される。指数部Eが全ビット0または全ビット1であり仮数部Fが全ビット0である場合、OR演算214から出力される最終的な結果は「1」になり、それ以外の場合、最終的な結果は「0」になる。
 図9は、部分ビット列一致判定の第3の演算例を示す図である。
 SL複合命令を用いて、指数部Eが全ビット0または全ビット1であるか判定する場合、例えば、1つのSL複合命令と1つの比較命令が発行される。プロセッサ200では、SL複合命令に応じて、シフト回路201でシフト演算221が実行され、シフト回路202でシフト演算222が実行される。更に、AND回路203でAND演算223が実行され、AND回路204でAND演算224が実行され、OR回路205でOR演算225が実行され、OR回路206でOR演算226が実行される。また、プロセッサ200では、比較命令に応じて、比較演算227が実行される。
 シフト演算221では、レジスタR(rs1)に格納された浮動小数点データに対して、右方向に1ビットの論理シフトが行われる。シフト演算221を実現するため、パラメータd1=0、パラメータk1=00、パラメータs1=1に設定される。これにより、指数部EはS,E1,…,E10となり、仮数部FはE11,F1,…,F51となる。シフト演算222では、レジスタR(rs1)に格納された浮動小数点データを変更しない。シフト演算222を実現するため、パラメータd2=0、パラメータk2=00、パラメータs2=0に設定される。ただし、パラメータd2,k2の値は任意の値でよい。
 AND演算223では、シフト演算221の結果とレジスタR(m1)に格納されたマスク用ビット列との間で、論理積が算出される。このマスク用ビット列は、指数部Eに対応するビットのうち最上位ビット(MSB:Most Significant Bit)以外のビットが1に設定され、それ以外のビットが0に設定されたビット列である。これにより、指数部Eが0,E1,E2,…,E10、仮数部Fが全ビット0のビット列が生成される。AND演算224では、シフト演算222の結果とレジスタR(m2)に格納された他のマスク用ビット列との間で、論理積が算出される。当該他のマスク用ビット列は、レジスタR(m1)のマスク用ビット列をビット反転したものである。これにより、指数部EがE1,0,0,…,0、その他のビットが元の浮動小数点データと同じビット列が生成される。
 OR演算225では、AND演算223の結果とAND演算224の結果の間で論理和が算出される。これにより、指数部EがE1,E1,E2,…,E10、その他のビットが元の浮動小数点データと同じビット列が生成される。このビット列は、浮動小数点データのうち指数部Eのみ、右方向に1ビットだけ算術シフトしたものに相当する。OR演算226では、OR演算225の結果とレジスタR(rs3)に格納されたビット列との間で論理和が算出される。ただし、レジスタR(rs3)には、全ビット0のビット列が格納される。そのため、OR演算226では、OR演算225の結果が変更されない。
 このように、SL複合命令を用いることで、1つの命令で、浮動小数点データのうち指数部Eのみをシフトしたビット列を生成することができる。比較演算227では、OR演算226の結果とレジスタR(rs1)に格納された元の浮動小数点データとが比較される。両者が一致する場合は「1」が出力され、一致しない場合は「0」が出力される。
 OR演算226の結果と元の浮動小数点データとが一致する条件は、指数部Eに含まれる各ビットの値が一致すること、すなわち、E1=E1,E1=E2,E2=E3,…,E10=E11が成立することである。これは、E1=E2=E3=…=E10=E11と言い換えることができる。よって、比較演算227は、指数部Eの全ビットの値が同一であるか、すなわち、全ビット0または全ビット1であるか判定していることになる。
 図10は、部分ビット列一致判定の第4の演算例を示す図である。
 SL複合命令を用いて、指数部Eが全ビット0または全ビット1であり、かつ、仮数部Fが全ビット0であるか判定する場合、例えば、1つのSL複合命令と1つの比較命令が発行される。これにより、図9の場合と同様に、シフト演算221,222、AND演算223,224、OR演算225,226および比較演算227が実行される。ただし、AND演算224に入力されるレジスタR(m2)のビット列と、OR演算226に入力されるレジスタR(rs3)のビット列とが、図9の場合と異なる。
 レジスタR(m2)には、マスク用ビット列が格納されている。このマスク用ビット列は、符号部Sに対応するビットと指数部Eに対応するビットのMSBが1に設定され、それ以外のビットが0に設定されたビット列である。仮数部Fの判定条件が全ビット0であるため、このマスク用ビット列の仮数部Fに対応するビットが全ビット0に設定されている。仮数部Fの一部のビットが0であるという条件(OFF制約)が与えられている場合、仮数部Fに対応するビットのうちOFF制約のあるビットを0に設定し、仮数部Fに対応するビットのうち他のビットを1に設定すればよい。
 レジスタR(rs3)に格納されたビット列は、全ビット0のビット列である。仮数部Fの判定条件が全ビット0であるため、このビット列の仮数部Fに対応するビットが全ビット0に設定されている。仮数部Fの一部のビットが1であるという条件(ON制約)が与えられている場合、仮数部Fに対応するビットのうちON制約のあるビットを1に設定し、仮数部Fに対応するビットのうち他のビットを0に設定すればよい。
 これにより、OR演算226の結果に含まれる仮数部Fにおいて、OFF制約があるビットが0に設定され、ON制約があるビットが1に設定され、OFF制約もON制約もないビットは元の浮動小数点データと同じ値が設定される。図10の例では、仮数部Fの全ビットにOFF制約が与えられているため、OR演算226が出力するビット列の仮数部Fは全ビット0になっている。このようなビット列と元の浮動小数点データとを比較することで、仮数部Fに対するOFF制約やON制約を考慮できる。
 以上説明したように、SL複合命令を用いない場合は4つの演算によって上記の判定処理を実現でき、SL複合命令を用いた場合は7つの演算によって同じ判定処理を実現できる。ただし、後者の場合、2つのシフト演算と2つのAND演算と2つのOR演算は、1つのSL複合命令を受けてプロセッサ200の内部で連続的に実行されるものである。命令数の観点からは、SL複合命令を用いない場合は4つの命令が発行され、SL複合命令を用いた場合は2つの命令が発行される。よって、多くの場合、SL複合命令を用いた方が上記の判定処理を高速に実行することができる。
 そこで、コンパイル装置100は、中間コードに対する最適化処理の中で、SL複合命令を使用しない判定処理をSL複合命令を使用するように最適化する。以下では、図8に示した演算を図10に示した演算に変換する場合を想定して、最適化について説明する。すなわち、判定処理として、指数部Eが全ビット0または全ビット1であり、かつ、仮数部Fが全ビット0であるか判定するものを想定する。
 図11は、SL複合命令を用いた最適化の例を示す図である。
 中間コード115は、ソースコードに基づいて入力部130の中間コード生成部134が生成したものである。中間コード115は、命令#1~#7の7つの命令を含む。
 命令#1は、定数0x7FFFFFFFFFFFFFFFをレジスタR1に格納する命令である。レジスタR1は、図8のレジスタR(rs2)に相当する。命令#2は、定数0x0000000000000000をレジスタR2に格納する命令である。レジスタR2は、図8のレジスタR(m1)に相当する。命令#3は、定数0x7FF0000000000000をレジスタR3に格納する命令である。レジスタR3は、図8のレジスタR(m2)に相当する。なお、浮動小数点データは、レジスタR0に格納されるものとする。レジスタR0は、図8のレジスタR(rs1)に相当する。
 命令#4は、レジスタR0,R1を参照オペランドとし、レジスタR4を定義オペランドとするAND命令である。レジスタR4には、浮動小数点データとレジスタR1の定数との間の論理積が格納される。命令#4は、図8のAND演算211に対応する。命令#5は、レジスタR4,R2を参照オペランドとし、レジスタR5を定義オペランドとする比較命令である。レジスタR5には、命令#4の演算結果とレジスタR2の定数との間の比較結果が格納される。命令#5は、図8の比較演算212に対応する。
 命令#6は、レジスタR4,R3を参照オペランドとし、レジスタR6を定義オペランドとする比較命令である。レジスタR6には、命令#4の演算結果とレジスタR3の定数との間の比較結果が格納される。命令#6は、図8の比較演算213に対応する。命令#7は、レジスタR5,R6を参照オペランドとし、レジスタR7を定義オペランドとするOR命令である。レジスタR7には、命令#5の比較結果と命令#6の比較結果の論理和が格納される。命令#7は、図8のOR演算214に対応する。
 なお、中間コード115において、1つのレジスタ(定義オペランド)は1つの命令によって定義され、1または2以上の命令によって参照されるものとする。
 中間コード116は、最適化部140の最適化実行部143が中間コード115から変換したものである。中間コード116は、命令#11~#16の6つの命令を含む。
 命令#11は、定数0x0000000000000000をレジスタR8に格納する命令である。レジスタR8は、図10のレジスタR(rs3)に相当する。命令#12は、定数0x0000000100000000をレジスタR9に格納する命令である。レジスタR9の定数は、図5のパラメータフォーマット42の形式をもつ。命令#13は、定数0x3FF0000000000000をレジスタR10に格納する命令である。レジスタR10は、図10のレジスタR(m1)に相当する。命令#14は、定数0xC000000000000000をレジスタR11に格納する命令である。レジスタR11は、図10のレジスタR(m2)に相当する。
 命令#15は、レジスタR0,R8,R9,R10,R11を参照オペランドとし、レジスタR12を定義オペランドとするSL複合命令(SL_COMPOUND)である。レジスタR12は、図10のレジスタR(rd)に相当する。レジスタR12には、浮動小数点データのうち指数部Eのみが右方向に1ビットだけ算術シフトされ、仮数部Fがオール0に置換されたビット列が格納される。命令#16は、レジスタR0,R12を参照オペランドとし、レジスタR7を定義オペランドとする比較命令である。命令#16は、図10の比較演算227に対応する。レジスタR7には、命令#15の演算結果と元の浮動小数点データとの間の比較結果が格納される。
 次に、コンパイル装置100によるコンパイル処理について説明する。
 図12は、コンパイルの手順例を示すフローチャートである。
 (S1)ソースコード入力部131は、ユーザからコンパイルコマンドが入力されると、コンパイルコマンドで指定されたソースファイル111からソースコードを読み出す。字句解析部132は、ソースコードに対して字句解析を行い、トークンの列に分割する。
 (S2)意味解析部133は、字句解析によって得られたトークンの列に対して構文解析および意味解析を行い、構文木を生成する。中間コード生成部134は、構文木に基づいて、ソースコードに対応する中間コードを生成し、中間ファイル112に書き出す。
 (S3)中間コード入力部141は、中間ファイル112から中間コードを読み出す。解析部142は、中間コードの中から最適化可能なコードを検出する。最適化可能なコードには、データの中の一部のビット列がオール0またはオール1であるか否か判定する処理(部分ビット列一致判定)を実装したコードが含まれる。部分ビット列一致判定には、データの中の他のビットに対してOFF制約またはON制約が与えられている場合も含まれる。部分ビット列一致判定のコードを検出する方法の詳細は後述する。
 (S4)解析部142は、検出した最適化可能なコードに対して、最適化方法を選択する。部分ビット列一致判定のコードに対しては、SL複合命令を利用した最適化が選択される。最適化実行部143は、解析部142が選択した方法で中間コードを最適化する(中間コードを更新する)。SL複合命令を用いた最適化の詳細は後述する。
 (S5)中間コード出力部144は、最適化実行部143で最適化された中間コードを、中間ファイル112に書き込む(上書きする)。
 ここで、ステップS3,S4で使用される一時データについて説明する。
 図13は、命令データと依存性データの構造例を示す図である。
 中間コードを解析するとき、解析部142は、中間コードに含まれる命令毎に命令データを生成する。また、解析部142は、命令間の依存関係毎に依存性データを生成する。生成された命令データおよび依存性データは、RAM102に記憶される。
 命令データ161は、命令番号、命令コード、定義オペランド、参照オペランド、直前命令および直後命令の項目を有する。命令番号は、中間コードの中で命令を識別する識別情報であり、例えば、行番号を用いることができる。命令コードは、代入命令(SET命令)、AND命令、OR命令、比較命令などの命令の種類を示す。定義オペランドは、命令の結果が書き込まれるレジスタを示す。1つの命令につき、1つの定義オペランドが指定される。参照オペランドは、命令で参照されるデータを格納したレジスタまたは命令で参照される定数を示す。1つの命令につき、1または2以上の参照オペランドが指定される。直前命令は、中間コードにおいて当該命令の1つ前に記載された命令を示す。直後命令は、中間コードにおいて当該命令の1つ後に記載された命令を示す。
 なお、図13に示した命令データ161は、図11の命令#1に対応する。命令#1について、命令番号=1、命令コード=SET、定義オペランド=R1、参照オペランド=C(0x7FFFFFFFFFFFFFFF)、直前命令=0、直後命令=2である。
 依存性データ162は、エッジ番号、定義オペランド、定義命令および参照命令の項目を有する。エッジ番号は、一の命令によってデータが書き込まれたレジスタ(定義オペランド)を他の命令が参照するという、定義参照関係を識別する識別情報である。定義オペランドは、一の命令によってデータが書き込まれ他の命令によって参照されるレジスタを示す。定義命令は、レジスタにデータを書き込む命令、すなわち、当該レジスタを定義オペランドとしてもつ命令を示す。参照命令は、レジスタを参照する命令、すなわち、当該レジスタを参照オペランドとしてもつ命令を示す。
 なお、図13に示した依存性データ162は、図11の命令#1と命令#4の間の依存関係に対応する。命令#1と命令#4の間の依存関係について、エッジ番号=1、定義オペランド=R1、定義命令=1、参照命令=4である。
 図14は、対象処理データの構造例を示す図である。
 解析部142は、中間コードから部分ビット列一致判定のコードを検出する毎に、対象処理データを生成する。生成された対象処理データは、RAM102に記憶される。
 対象処理データ163は、処理ID、置換対象命令、定義オペランド、参照オペランド、判定ビット、OFF制約ビット、ON制約ビットおよび無視ビットの項目を有する。処理IDは、検出された部分ビット列一致判定のコードを識別する識別情報である。置換対象命令は、部分ビット列一致判定のコードに含まれる末尾の命令を示す。
 定義オペランドは、部分ビット列一致判定の結果を格納するレジスタを示す。参照オペランドは、部分ビット列一致判定の対象となる入力データ(例えば、浮動小数点データ)を格納するレジスタを示す。判定ビットは、オール0またはオール1であるか否か判定するビット列の範囲を示す。OFF制約ビットは、値が0であるか否か判定するビットを示す。ON制約ビットは、値が1であるか否か判定するビットを示す。無視ビットは、判定ビット、OFF制約ビットおよびON制約ビット以外のビットを示す。
 なお、図14に示した対象処理データ163は、図8の演算および図11の中間コード115に対応する。中間コード115について、処理ID=1、置換対象命令=7、定義オペランド=R7、参照オペランド=R0である。また、指数部Eがオール0またはオール1の判定対象であるため、判定ビット=0x7FF0000000000000である。仮数部F全体に対してOFF制約が与えられているため、OFF制約ビット=0x000FFFFFFFFFFFFFである。ON制約は存在しないため、ON制約ビット=0x0000000000000000である。符号部Sについては条件が与えられていないため、無視ビット=0x8000000000000000である。
 次に、上記のステップS3,S4の詳細を説明する。
 図15は、最適化対象検出の手順例を示すフローチャートである。
 この最適化対象検出は、上記のステップS3で実行される。
 (S10)解析部142は、命令データの集合の中に残りの命令があるか判断する。残りの命令がある場合はステップS11に処理が進み、ない場合は処理が終了する。
 (S11)解析部142は、命令データの集合の中から命令を1つ選択する(instr)。通常は、命令番号の小さい順に命令を選択していく。
 (S12)解析部142は、ステップS11で選択した命令instrの命令コードがOR(論理和)であるか判断する。命令コードがORである場合はステップS13に処理が進み、ORでない場合はステップS10に処理が進む。
 (S13)解析部142は、命令instrの2つの参照オペランドを特定する。解析部142は、依存性データの集合から、第1参照オペランドを定義している定義命令(cmp_instr[1])を検索する。同様に、解析部142は、第2参照オペランドを定義している定義命令(cmp_instr[2])を検索する。
 (S14)解析部142は、命令cmp_instr[1]と命令cmp_instr[2]の両方の命令コードがEQ(比較)であるか判断する。命令コードがEQである場合はステップS15に処理が進み、EQでない場合はステップS10に処理が進む。
 (S15)解析部142は、命令cmp_instr[1]の2つの参照オペランドを特定する。解析部142は、依存性データの集合から、第1参照オペランドを定義している定義命令(and_instr[1])を検索する。同様に、解析部142は、第2参照オペランドを定義している定義命令(set_instr[1])を検索する。
 (S16)解析部142は、命令cmp_instr[2]の2つの参照オペランドを特定する。解析部142は、依存性データの集合から、第1参照オペランドを定義している定義命令(and_instr[2])を検索する。同様に、解析部142は、第2参照オペランドを定義している定義命令(set_instr[2])を検索する。
 (S17)解析部142は、ステップS15で検索した命令and_instr[1]とステップS16で検索した命令and_instr[2]が同じ命令か判断する。同じ場合はステップS18に処理が進み、異なる場合はステップS10に処理が進む。
 (S18)解析部142は、命令and_instr[1]の命令コードがAND(論理積)であり、かつ、命令set_instr[1]と命令set_instr[2]の両方の命令コードがSET(代入)であるか判断する。条件を満たす場合はステップS19に処理が進み、条件を満たさない場合はステップS10に処理が進む。
 (S19)解析部142は、命令and_instr[1]の第2参照オペランドを特定する。解析部142は、依存性データの集合から、第2参照オペランドを定義している定義命令(set_instr[0])を検索する。
 (S20)解析部142は、ステップS19で検索した命令set_instr[0]の命令コードがSET(代入)であるか判断する。命令コードがSETである場合はステップS21に処理が進み、SETでない場合はステップS10に処理が進む。
 図16は、最適化対象検出の手順例を示すフローチャート(続き)である。
 (S21)解析部142は、対象処理データ163を生成する。解析部142は、対象処理データ163の置換対象命令を命令instrに設定する。また、解析部142は、対象処理データ163の定義オペランドを命令instrの定義オペランドに設定し、参照オペランドを命令and_instr[1]の第1参照オペランドに設定する。
 (S22)解析部142は、変数mask_bit,cmp_bit[1],cmp_bit[2]を定義する。解析部142は、変数mask_bitに命令set_instr[0]の参照オペランド(定数)を設定する。解析部142は、変数cmp_bit[1]に命令set_instr[1]の参照オペランド(定数)を設定し、変数cmp_bit[2]に命令set_instr[2]の参照オペランド(定数)を設定する。
 (S23)解析部142は、対象処理データ163の判定ビットを、AND(XOR(cmp_bit[1],cmp_bit[2]),mask_bit)と算出する。解析部142は、対象処理データ163のOFF制約ビットを、AND(NOR(cmp_bit[1],cmp_bit[2]),mask_bit)と算出する。解析部142は、対象処理データ163のON制約ビットを、AND(AND(cmp_bit[1],cmp_bit[2]),mask_bit)と算出する。解析部142は、対象処理データ163の無視ビットを、NOT(mask_bit)と算出する。
 (S24)解析部142は、ステップS23で算出した判定ビットがオール0(0の列)であるか判断する。判定ビットがオール0の場合、部分ビット列一致判定が実質的に行われないため、対象処理データ163が破棄されてステップS10に処理が進む。判定ビットがオール0でない場合、ステップS25に処理が進む。
 (S25)解析部142は、ステップS23で算出した判定ビットに含まれる「1」は連続しているか判断する。判定ビットの「1」が連続している場合、ステップS26に処理が進む。判定ビットの「1」が不連続である場合、最適化の対象にならないため、対象処理データ163が破棄されてステップS10に処理が進む。
 (S26)解析部142は、AND(cmp_bit[1],判定ビット)=0またはAND(cmp_bit[1],判定ビット)=判定ビットか判断する。条件を満たす場合はステップS27に処理が進み、満たさない場合はステップS10に処理が進む。
 (S27)解析部142は、ステップS10~S20で検出した命令を最適化対象として採用し、対象処理データ163を保存する。そして、ステップS10に処理が進む。
 図17は、最適化実行の手順例を示すフローチャートである。
 この最適化実行は、上記のステップS4で実行される。
 (S30)解析部142は、図15,16の最適化対象検出で生成された対象処理データのうち、未選択の対象処理データがあるか判断する。未選択のものがある場合はステップS31に処理が進み、全て選択された場合はステップS41に処理が進む。
 (S31)解析部142は、対象処理データを1つ選択する。
 (S32)解析部142は、変数D_rs3,D_shift_ctrl,D_m1を定義する。解析部142は、ステップS31で選択した対象処理データに記載されたON制約ビットを、変数D_rs3に代入する。解析部142は、定数0x0000000100000000を変数D_shift_ctrlに代入する。解析部142は、対象処理データに記載された判定ビットを変数D_m1に代入する。
 (S33)解析部142は、変数D_m1の最上位の「1」を「0」に反転する。
 (S34)解析部142は、変数D_m2を定義する。また、解析部142は、対象処理データからOFF制約ビットを抽出する。そして、解析部142は、変数D_m2に、AND(NOT(D_m1),NOT(OFF制約ビット))を代入する。
 (S35)解析部142は、変数ref,defを定義する。解析部142は、変数refに、処理対象データに記載された参照オペランドを代入し、変数defに、処理対象データに記載された定義オペランドを代入する。
 (S36)解析部142は、レジスタR(rs3)にD_rs3の値を代入するSET命令を生成する(new_instr[1])。解析部142は、レジスタR(shift_ctrl)にD_shift_ctrlの値を代入するSET命令を生成する(new_instr[2])。解析部142は、レジスタR(m1)にD_m1の値を代入するSET命令を生成する(new_instr[3])。解析部142は、レジスタR(m2)にD_m2の値を代入するSET命令を生成する(new_instr[4])。なお、解析部142は、レジスタR(rs3),R(shift_ctrl),R(m1),R(m2)として、空いているレジスタを任意に選択してよい。
 (S37)解析部142は、レジスタR(ref),R(rs3),R(shift_ctrl),R(m1),R(m2)を参照オペランドとし、レジスタR(rd)を定義オペランドとするSL複合命令を生成する(new_instr[5])。なお、解析部142は、レジスタR(rd)として、空いているレジスタを任意に選択してよい。
 (S38)解析部142は、レジスタR(ref),R(rd)を参照オペランドとし、レジスタR(def)を定義オペランドとする比較命令を生成する(new_instr[6])。入力データ(例えば、浮動小数点データ)が格納されるレジスタと、最終的な判定結果が格納されるレジスタは、最適化の前後で同じである。
 (S39)解析部142は、命令new_instr[1],new_instr[2],new_instr[3],new_instr[4],new_instr[5],new_instr[6]が全て空(NULL)でないか判断する。条件を満たす場合、ステップS40に処理が進む。条件を満たさない場合、ステップS36~S38で生成された命令が破棄され、ステップS30に処理が進む。
 (S40)最適化実行部143は、命令new_instr[1],new_instr[2],new_instr[3],new_instr[4],new_instr[5],new_instr[6]を、中間コードに対して上記の順に挿入する。挿入位置は、ステップS31で選択された処理対象データに記載された置換対象命令の次である。そして、ステップS30に処理が進む。
 図18は、最適化実行の手順例を示すフローチャート(続き)である。
 (S41)最適化実行部143は、最適化に伴って不要となった命令を中間コードから削除する。不要となった命令には、前述のステップS10~S20で検出された最適化前の命令が含まれる。この処理は、Dead Code Eliminationと呼ぶことがある。
 (S42)最適化実行部143は、上記のステップS36~38で生成した命令がループ内部に存在するか判断する。ループ内部に存在する場合、最適化実行部143は、SET命令である命令new_instr[1],new_instr[2],new_instr[3],new_instr[4]を、ループの前に移動する。これにより、レジスタR(rs3),R(shift_ctrl),R(m1),R(m2)への定数の代入を繰り返さなくて済む。この処理は、Invariant Code Motionと呼ぶことがある。
 第2の実施の形態のコンパイル装置100によれば、最適化前の中間コードから、入力データの中の一部のビット列(例えば、浮動小数点データの指数部E)がオール0またはオール1であるか判定するコードが検出される。そして、検出されたコードが、SL複合命令を用いたコードに最適化される。SL複合命令を用いることで、入力データの中の一部のビット列のみシフトしたデータを1命令で生成することができる。これにより、プログラム中の命令数を削減することができ、プロセッサ200による処理を高速化できる。また、クリティカルパス上に並ぶ命令(依存関係があり直列的に実行することを要する命令)が少なくなるため、自動並列化が容易となる。
 更に、SL複合命令に与える参照オペランドの値を適切に設定することで、オール0またはオール1の判定に加えて、他の特定のビットが0であるか否かの判定や、他の特定のビットが1であるか否かの判定を併せて行うことができる。このとき、命令数は増加しない。よって、特に、浮動小数点データのチェックを効率的に行うことができる。
 なお、第2の実施の形態では、コンパイラ121の中でSL複合命令を利用したコードへの変換を実現したが、他の装置または他のソフトウェアの中で当該変換を行ってもよい。例えば、アセンブリコードをオブジェクトコードに変換するアセンブラや、オブジェクトコードを解析して最適化するバイナリオプティマイザの中で当該変換を行ってもよい。
 前述のように、第1の実施の形態の情報処理は、コード変換装置10にプログラムを実行させることで実現できる。また、第2の実施の形態の情報処理は、コンパイル装置100にプログラムを実行させることで実現できる。
 プログラムは、コンピュータ読み取り可能な記録媒体(例えば、記録媒体33)に記録しておくことができる。記録媒体としては、例えば、磁気ディスク、光ディスク、光磁気ディスク、半導体メモリなどを使用できる。磁気ディスクには、FDおよびHDDが含まれる。光ディスクには、CD、CD-R(Recordable)/RW(Rewritable)、DVDおよびDVD-R/RWが含まれる。プログラムは、可搬型の記録媒体に記録されて配布されることがある。その場合、可搬型の記録媒体からHDDなどの他の記録媒体(例えば、HDD103)にプログラムをコピーして実行してもよい。
 上記については単に本発明の原理を示すものである。更に、多数の変形や変更が当業者にとって可能であり、本発明は上記に示し、説明した正確な構成および応用例に限定されるものではなく、対応する全ての変形例および均等物は、添付の請求項およびその均等物による本発明の範囲とみなされる。
 10 コード変換装置
 11 記憶部
 12 変換部
 13 第1のコード
 13a,14a 判定コード
 14 第2のコード
 M1,M2,M3,M4 命令
 MC 複合命令

Claims (5)

  1.  コンピュータに、
     第1のコードを、シフト演算と前記シフト演算の結果に対する論理演算とを1つの命令で指示する複合命令を使用可能な第2のコードに変換する場合に、
     前記第1のコードから、データの中の一部のビット列が0の列であるか判定する第1の命令と、前記一部のビット列が1の列であるか判定する第2の命令と、前記第1の命令および前記第2の命令の結果を合成する第3の命令とを含む判定コードを検出し、
     前記判定コードに基づいて、前記シフト演算によって少なくとも前記一部のビット列がシフトされ、前記論理演算によってシフト後の前記一部のビット列と前記データの中の他のビット列とが合成されるように引数を設定した前記複合命令と、前記複合命令の結果と前記データとを比較する第4の命令とを含む他の判定コードを生成し、
     前記第2のコードに前記他の判定コードを含める、
     処理を実行させるコード変換プログラム。
  2.  前記論理演算は、前記シフト演算の結果に対する第1の論理演算と、前記第1の論理演算の結果に対する第2の論理演算とを含み、
     前記他の判定コードの生成では、前記シフト演算によって前記データがシフトされ、前記第1の論理演算によって前記シフト演算の結果からシフト後の前記一部のビット列が抽出され、前記第2の論理演算によってシフト後の前記一部のビット列と前記他のビット列とが合成されるように、前記引数を設定する、
     請求項1記載のコード変換プログラム。
  3.  前記第1の命令は、前記一部のビット列が0の列であり、かつ、前記他のビット列のうちの少なくとも一部のビットが所定のビット条件を満たすか判定することを示し、
     前記第2の命令は、前記一部のビット列が1の列であり、かつ、前記少なくとも一部ビットが前記所定のビット条件を満たすか判定することを示し、
     前記他の判定コードの生成では、前記論理演算によって前記少なくとも一部のビットが前記所定のビット条件に応じた値に置換されるように、前記引数を設定する、
     請求項1または2記載のコード変換プログラム。
  4.  第1のコードを記憶する記憶部と、
     前記第1のコードを、シフト演算と前記シフト演算の結果に対する論理演算とを1つの命令で指示する複合命令を使用可能な第2のコードに変換する変換部と、
     を有し、前記変換部は、
     前記第1のコードから、データの中の一部のビット列が0の列であるか判定する第1の命令と、前記一部のビット列が1の列であるか判定する第2の命令と、前記第1の命令および前記第2の命令の結果を合成する第3の命令とを含む判定コードを検出し、
     前記判定コードに基づいて、前記シフト演算によって少なくとも前記一部のビット列がシフトされ、前記論理演算によってシフト後の前記一部のビット列と前記データの中の他のビット列とが合成されるように引数を設定した前記複合命令と、前記複合命令の結果と前記データとを比較する第4の命令とを含む他の判定コードを生成し、
     前記第2のコードに前記他の判定コードを含める、
     コード変換装置。
  5.  コンピュータが実行するコード変換方法であって、
     第1のコードを、シフト演算と前記シフト演算の結果に対する論理演算とを1つの命令で指示する複合命令を使用可能な第2のコードに変換する場合に、
     前記第1のコードから、データの中の一部のビット列が0の列であるか判定する第1の命令と、前記一部のビット列が1の列であるか判定する第2の命令と、前記第1の命令および前記第2の命令の結果を合成する第3の命令とを含む判定コードを検出し、
     前記判定コードに基づいて、前記シフト演算によって少なくとも前記一部のビット列がシフトされ、前記論理演算によってシフト後の前記一部のビット列と前記データの中の他のビット列とが合成されるように引数を設定した前記複合命令と、前記複合命令の結果と前記データとを比較する第4の命令とを含む他の判定コードを生成し、
     前記第2のコードに前記他の判定コードを含める、
     コード変換方法。
PCT/JP2014/076931 2014-10-08 2014-10-08 コード変換プログラム、コード変換装置およびコード変換方法 WO2016056081A1 (ja)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/JP2014/076931 WO2016056081A1 (ja) 2014-10-08 2014-10-08 コード変換プログラム、コード変換装置およびコード変換方法
JP2016552748A JP6222374B2 (ja) 2014-10-08 2014-10-08 コード変換プログラム、コード変換装置およびコード変換方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/JP2014/076931 WO2016056081A1 (ja) 2014-10-08 2014-10-08 コード変換プログラム、コード変換装置およびコード変換方法

Publications (1)

Publication Number Publication Date
WO2016056081A1 true WO2016056081A1 (ja) 2016-04-14

Family

ID=55652740

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2014/076931 WO2016056081A1 (ja) 2014-10-08 2014-10-08 コード変換プログラム、コード変換装置およびコード変換方法

Country Status (2)

Country Link
JP (1) JP6222374B2 (ja)
WO (1) WO2016056081A1 (ja)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0651955A (ja) * 1992-07-28 1994-02-25 Toshiba Corp 浮動小数点演算機能を持つ情報処理装置
JP2000099327A (ja) * 1998-09-28 2000-04-07 Mitsubishi Electric Corp 計算機
US6601079B1 (en) * 1997-12-29 2003-07-29 Intel Corporation Converting between different floating point exponent representations
JP2008236175A (ja) * 2007-03-19 2008-10-02 Nec Corp フレーム同期装置およびフレーム同期方法
JP2013206291A (ja) * 2012-03-29 2013-10-07 Fujitsu Ltd プログラム、コード生成方法および情報処理装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH0651955A (ja) * 1992-07-28 1994-02-25 Toshiba Corp 浮動小数点演算機能を持つ情報処理装置
US6601079B1 (en) * 1997-12-29 2003-07-29 Intel Corporation Converting between different floating point exponent representations
JP2000099327A (ja) * 1998-09-28 2000-04-07 Mitsubishi Electric Corp 計算機
JP2008236175A (ja) * 2007-03-19 2008-10-02 Nec Corp フレーム同期装置およびフレーム同期方法
JP2013206291A (ja) * 2012-03-29 2013-10-07 Fujitsu Ltd プログラム、コード生成方法および情報処理装置

Also Published As

Publication number Publication date
JP6222374B2 (ja) 2017-11-01
JPWO2016056081A1 (ja) 2017-06-15

Similar Documents

Publication Publication Date Title
JP5039948B2 (ja) プログラムを最適化するコンパイラ
JP5646737B2 (ja) 条件付き比較命令
JP6245031B2 (ja) コンパイルプログラム、コンパイル方法およびコンパイル装置
US9823911B2 (en) Method and apparatus for compiling code based on a dependency tree
JPH02217926A (ja) コード生成方法
JP5966509B2 (ja) プログラム、コード生成方法および情報処理装置
US9395986B2 (en) Compiling method and compiling apparatus
JP6164054B2 (ja) 情報処理装置、コンパイル方法およびコンパイラプログラム
US9213548B2 (en) Code generation method and information processing apparatus
KR20190015285A (ko) Cpu 이용 및 코드 리팩토링을 위한 쿼리 최적화기
US8935512B2 (en) Instruction operation code generation system
US8127281B2 (en) Method and apparatus for efficient multiple-pattern based matching and transformation of intermediate language expression trees
US10990073B2 (en) Program editing device, program editing method, and computer readable medium
JP2013214832A (ja) 圧縮及び伸長システム、圧縮装置、伸長装置、圧縮及び伸長方法、圧縮プログラム及び伸長プログラム
JP6222374B2 (ja) コード変換プログラム、コード変換装置およびコード変換方法
US10108405B2 (en) Compiling apparatus and compiling method
KR102270789B1 (ko) 프로세서 및 프로세서의 명령어 처리 방법
US20140344795A1 (en) Computer-readable recording medium, compiling method, and information processing apparatus
US20170115973A1 (en) Operating method of semiconductor device and semiconductor system
JPWO2017204139A1 (ja) データ処理装置、データ処理方法、およびプログラム記録媒体
JP6897213B2 (ja) コード生成装置、コード生成方法及びコード生成プログラム
JP2022140995A (ja) 情報処理装置、コンパイルプログラムおよびコンパイル方法
US7676799B1 (en) Address simplification by binary transformation
JP3727039B2 (ja) コンパイラにおける乗算実施方法
JP2024030940A (ja) ソースコード変換プログラムおよびソースコード変換方法

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14903513

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2016552748

Country of ref document: JP

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14903513

Country of ref document: EP

Kind code of ref document: A1