# US 9,436,450 B2 · Method and apparatus for optimising computer program code

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 9,436,450 B2
- Document ID: US9436450B2
- Status: Granted
- Kind: B2
- Application number: 14/531,024
- Filed: 2014-11-03
- Published: 2016-03-03
- Granted: 2016-09-06
- Earliest claimed: 2014-09-01
- Assignees: Freescale Semiconductor, Inc.
- Applicants: Mihai Daniel Oprea; Ciprian Arbone; Bogdan Florin Ditu
- Inventors: Mihai Daniel Oprea; Ciprian Arbone; Bogdan Florin Ditu
- Web page: https://patentgrep.com/patent/US9436450B2

## CPC

- G06F 8/4441: {Reducing the execution time required by the program code}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method and apparatus for optimizing computer program code. The method comprises identifying at least one set of candidate instructions within the computer program code, each candidate instruction comprising an instruction for writing a constant value to memory and the at least one set comprising a plurality of candidate instructions. The method further comprises computing an aggregate constant value for the at least one set of candidate instructions, and replacing the at least one set of candidate instructions with at least one instruction for writing the aggregate constant value to memory.

## Claims

### Claim 1

A method of optimising computer program code, the method comprising:
identifying at least one set of candidate instructions within the computer program code, each candidate instruction comprising an instruction for writing a constant value to memory and the at least one set comprising a plurality of candidate instructions;
checking the validity of aggregating candidate instructions by checking whether the candidate instructions have volatile operands: computing an aggregate constant value for the at least one set of candidate instructions in response to the candidate instructions not having volatile operands; and replacing the at least one set of candidate instructions with at least one instruction for writing the aggregate constant value to memory.

### Claim 2 (depends on 1)

The method of claim 1, wherein the computer program code comprises low level intermediate language computer program code.

### Claim 3 (depends on 2)

The method of claim 2, wherein the method comprises identifying candidate instructions using a same hardware architecture addressing mode.

### Claim 4 (depends on 1)

The method of claim 1, wherein the method comprises identifying candidate instructions using a same hardware architecture addressing mode.

### Claim 5 (depends on 1)

The method of claim 1, wherein the at least one set of candidate instructions comprises instructions that write constant values to a single contiguous block of memory.

### Claim 6 (depends on 1)

The method of claim 1, wherein the method further comprises checking
whether registers used by the instructions are modified between the candidate instructions within the computer program code.

### Claim 7 (depends on 6)

The method of claim 6, wherein the method comprises selecting as the at least one set of candidate instructions for which to compute an aggregate constant value the largest set of candidate instructions for which a valid aggregate constant value is achievable.

### Claim 8 (depends on 1)

The method of claim 1, wherein the method comprises selecting as the at least one set of candidate instructions for which to compute an aggregate constant value the largest set of candidate instructions for which a valid aggregate constant value is achievable.

### Claim 9 (depends on 1)

The method of claim 1, wherein replacing the at least one set of candidate instructions with at least one instruction for writing the aggregate constant value to memory comprises:
replacing the at least one set of candidate instructions with at least one library copy routine for copying the aggregate constant value to memory from a data section within an object file.

### Claim 10 (depends on 9)

The method of claim 9, wherein the method comprises:
evaluating at least one efficiency metric for each of the instructions replacement options of: (i) replacing the at least one set of candidate instructions with at least one more efficient write instruction for writing the aggregate constant value to memory, and (ii) replacing the at least one set of candidate instructions with at least one library copy routine for copying the aggregate constant value from a data section within an object file to memory; and
implementing one of the instruction replacement options based at least partly on the efficiency metric evaluation.

### Claim 11 (depends on 10)

The method of claim 10, wherein the at least one efficiency metric comprises at least one of:
code size; and
code execution speed.

### Claim 12

A computer program code optimisation apparatus comprising at least one processor arranged to optimise computer program code;
wherein the at least one processing component is arranged to:
identify candidate instructions within the computer program code, each candidate instruction comprising an instruction for writing a constant value to memory;
check the validity of aggregating candidate instructions by checking whether the candidate instructions have volatile operands;
select at least one set of candidate instructions comprising a plurality of candidate instructions, in response to the candidate instruction not having volatile operands;
compute an aggregate constant value for the at least one set of candidate instructions; and replace the at least one set of candidate instructions with at least one instruction for writing the aggregate constant value to memory.

### Claim 13

A non-transitory computer program product having executable program code stored therein for optimising computer program code, the program code operable for:
identifying candidate instructions within the computer program code, each candidate instruction comprising an instruction for writing a constant value to memory;
checking the validity of aggregating candidate instructions by checking whether the candidate instructions have volatile operands;
selecting at least one set of candidate instructions comprising a plurality of candidate instructions, in response to the candidate instruction not having volatile operands;
computing an aggregate constant value for the at least one set of candidate instructions; and
replacing the at least one set of candidate instructions with at least one instruction for writing the aggregate constant value to memory.

### Claim 14 (depends on 13)

The non-transitory computer program product of claim 13, wherein the non-transitory computer program product comprises at least one from a group including: a hard disk, a CD-ROM, an optical storage device, a magnetic storage device, a Read Only Memory (ROM) a Programmable Read Only Memory (PROM) an Erasable Programmable Read Only Memory (EPROM) an Electrically Erasable Programmable Read Only Memory (EEPROM) and a Flash memory.
