# US 2006/0136678 A1 · Method and system for reducing program code size

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

- Number: US 2006/0136678 A1
- Document ID: US20060136678A1
- Status: Published application
- Kind: A1
- Application number: 11/020,481
- Filed: 2004-12-22
- Published: 2006-06-22
- Earliest claimed: 2004-12-22
- Assignees: Intel Corporation
- Inventors: Youfeng Wu; Mauricio Breternitz
- Web page: https://patentgrep.com/patent/US20060136678A1

## CPC

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

## Abstract

In a method for reducing code size a replaceable subset of instructions at a first location within a set of instructions and a matching target subset of instructions at a second location within the set of instructions are identified. A base offset and a relative offset are determined. The base offset and the relative offset indicate an absolute offset from the first location to the second location. An instruction to cause a base offset storage element to be loaded with the base offset is inserted prior to the first location. The replaceable subset of instructions is replaced with a second instruction to cause a program counter to be modified based on the relative offset and a value in the base offset register so that the modified program counter indicates the second location.

## Claims

### Claim 1

A method for reducing code size, the method comprising the acts of:
identifying a replaceable subset of instructions at a first location within a set of instructions and a matching target subset of instructions at a second location within the set of instructions;
determining a base offset and a relative offset, wherein the base offset and the relative offset indicate an absolute offset from the first location to the second location;
inserting, prior to the first location, an instruction to cause a base offset storage element to be loaded with the base offset; and
replacing the replaceable subset of instructions with a second instruction to cause a program counter to be modified based on the relative offset and a value in the base offset register, wherein the modified program counter indicates the second location.

### Claim 2 (depends on 1)

A method according to claim 1, further comprising the act of choosing the target subset of instructions from a plurality of candidate target subsets of instructions at different locations.

### Claim 3 (depends on 2)

A method according to claim 2, wherein the act of choosing the target subset of instructions comprises at least one of A, B, and C:
A) determining sizes of candidate second instructions to replace the replaceable subset of instructions, each candidate second instruction to cause the program counter to be modified to indicate the location of the corresponding candidate target subset of instructions; and
choosing the target subset of instructions from the plurality of candidate target subsets based on the sizes of the candidate second instructions;
B) determining respective absolute offsets between the first location and the locations of the plurality of candidate target subsets; and
choosing the target subset of instructions from the plurality of candidate target subsets based on the determined absolute offsets;
C) choosing the target subset of instructions from the plurality of candidate target subsets based on the whether candidate target subsets are located in regions of frequently executed code.

### Claim 4 (depends on 1)

A method according to claim 1, wherein determining the base offset and the relative offset comprises:
determining the absolute offset from the first location to the second location;
determining the base offset based on the absolute offset; and
determining the relative offset based on the absolute offset and the base offset.

### Claim 5 (depends on 4)

A method according to claim 4, wherein determining the relative offset comprises subtracting the base offset from the absolute offset.

### Claim 6 (depends on 4)

A method according to claim 4, further comprising:
identifying a plurality of replaceable subsets of instructions at respective first locations and a plurality of respective matching target subsets of instructions at respective second locations;
determining a plurality of absolute offsets from the respective first locations to the respective second locations;
determining the base offset based on the plurality of absolute offsets; and
determining a plurality of relative offsets based on the plurality of absolute offsets and the base offset.

### Claim 7 (depends on 6)

A method according to claim 6, wherein determining the plurality of relative offsets comprises subtracting the base offset from each absolute offset of the plurality of absolute offsets.

### Claim 8 (depends on 4)

A method according to claim 4, wherein replacing the replaceable subset of instructions with the second instruction comprises:
replacing the replaceable subset of instructions with a third instruction to cause the program counter to be modified based on the absolute offset, wherein the modified program counter indicates the second location; and
replacing the third instruction with the second instruction.

### Claim 9 (depends on 1)

A method according to claim 1, further comprising the act of reordering at least some portions of the set of instructions to attempt to reduce the absolute offset.

### Claim 10

A computer readable medium having stored thereon machine executable instructions, the machine executable instructions capable of causing the machine to:
identify a replaceable subset of instructions at a first location within a set of instructions and a matching target subset of instructions at a second location within the set of instructions;
determine a base offset and a relative offset, wherein the base offset and the relative offset indicate an absolute offset from the first location to the second location;
insert, prior to the first location, an instruction to cause a base offset storage element to be loaded with the base offset; and
replace the replaceable subset of instructions with a second instruction to cause a program counter to be modified based on the relative offset and a value in the base offset register, wherein the modified program counter indicates the second location.

### Claim 11 (depends on 10)

A computer readable medium according to claim 10, the machine executable instructions capable of causing the machine to choose the target subset of instructions from a plurality of candidate target subsets of instructions at different locations.

### Claim 12 (depends on 10)

A computer readable medium according to claim 10, the machine executable instructions capable of causing the machine to:
determine the absolute offset from the first location to the second location;
determine the base offset based on the absolute offset; and
determine the relative offset based on the absolute offset and the base offset.

### Claim 13 (depends on 10)

A computer readable medium according to claim 10, the machine executable instructions capable of causing the machine to reorder at least some portions of the set of instructions to attempt to reduce the absolute offset.

### Claim 14

A system for compressing computer executable code, the system comprising:
a first computer readable medium to store a set of instructions to be compressed;
a second computer readable medium;
a processor coupled to the first computer readable medium and the second computer readable medium, the processor configured according to executable instructions stored on the second computer readable medium to:
identify a replaceable subset of instructions at a first location within the set of instructions stored on the first computer readable medium and a matching target subset of instructions at a second location within the set of instructions,
determine a base offset and a relative offset, wherein the base offset and the relative offset indicate an absolute offset from the first location to the second location,
insert, prior to the first location, an instruction in the set of instructions stored on the first computer readable medium to cause a base offset storage element to be loaded with the base offset, and
replace the replaceable subset of instructions with a second instruction to cause a program counter to be modified based on the relative offset and a value in the base offset register, wherein the modified program counter indicates the second location.

### Claim 15 (depends on 14)

A system according to claim 14, wherein the first computer readable medium comprises the second computer readable medium.

### Claim 16 (depends on 14)

A system according to claim 14, further comprising a third computer readable medium to store source code;
wherein the processor is configured according to executable instructions stored on the second computer readable medium to compile at least some of the source code to generate the set of instructions stored on the first computer readable medium.

### Claim 17 (depends on 16)

A system according to claim 16, wherein the first computer readable medium comprises the third computer readable medium.

### Claim 18 (depends on 16)

A system according to claim 16, wherein the processor is configured according to executable instructions stored on the second computer readable medium to generate machine readable instructions based on the set of instructions stored on the first computer readable medium.

### Claim 19 (depends on 14)

A system according to claim 14, further comprising a third computer readable medium to store assembly language code;
wherein the processor is configured according to executable instructions stored on the second computer readable medium to assemble at least some of the assembly language code to generate the set of instructions stored on the first computer readable medium.

### Claim 20 (depends on 19)

A system according to claim 19, wherein the first computer readable medium comprises the third computer readable medium.

### Claim 21

A method for executing a computer program, the method comprising the acts of:
in response to a first instruction, setting a base offset storage element of a processor with a value;
in response to a second instruction that indicates a relative offset and a length, modifying a program counter of the processor based on the value in the base offset register and the relative offset;
executing a number of instructions starting at a second location indicated by the program counter modified in response to the second instruction, wherein the length indicates the number of instructions;
after executing the number of instructions starting at the second location, modifying the program counter to point to a third instruction adjacent to and subsequent to the second instruction.

### Claim 22 (depends on 21)

A method according to claim 21, further comprising:
in response to the first instruction, selecting one base offset storage element from a plurality of base offset storage elements of the processor, the first instruction indicating the one base offset storage element;
in response to the first instruction, loading the selected base offset storage element with the value;
in response to the second instruction, selecting the one base offset storage element from the plurality of base offset storage elements of the processor, the second instruction indicating the one base offset storage element;
in response to the second instruction, modifying the program counter of the processor based on the value in the one base offset register and the relative offset.

### Claim 23 (depends on 21)

A method according to claim 21, further comprising determining a third location of the third instruction in response to the second instruction;
wherein modifying the program counter to point to the third instruction comprises loading the third location into a storage element to store the program counter.

### Claim 24 (depends on 21)

A method according to claim 21, comprising at least one of:
subtracting the relative offset and the base offset from a current program counter value in response to the second instruction; and
adding the relative offset and the base offset to a current program counter value in response to the second instruction.

### Claim 25 (depends on 21)

A method according to claim 21, wherein the first instruction comprises an opcode and a first parameter, the first parameter to indicate the base offset.

### Claim 26 (depends on 25)

A method according to claim 25, wherein the first instruction further comprises a second parameter to indicate one of a plurality of base offset storage elements.

### Claim 27 (depends on 26)

A method according to claim 26, wherein the opcode of the first instruction indicates one of a plurality of base offset storage elements.

### Claim 28 (depends on 21)

A method according to claim 21, wherein the second instruction comprises an opcode, a first parameter, and a second parameter, the first parameter to indicate the relative offset and the second parameter to indicate the length.

### Claim 29 (depends on 28)

A method according to claim 28, wherein the second instruction further comprises a third parameter to indicate one of a plurality of base offset storage elements.

### Claim 30 (depends on 28)

A method according to claim 28, wherein the opcode of the second instruction indicates one of a plurality of base offset storage elements.

### Claim 31

A processor, comprising:
a base offset storage element;
a program counter storage element;
an adder having a first input coupled to the base offset storage element, a second input coupled to receive a value stored in the program counter storage element, and an output coupled to the program counter storage element;
an instruction decode unit coupled to base offset storage element and to the program counter storage element, the instruction decode unit also coupled to a third input of the adder, the instruction decode unit configured to:
cause a base offset to be loaded into the base offset storage element in response to a first instruction that indicates the base offset,
cause a relative offset to be coupled to the third input of the adder in response to a second instruction that indicates the relative offset, and
cause the output of the adder to be stored in the program counter storage element.

### Claim 32 (depends on 31)

A processor according to claim 31, wherein the adder is configured to, at least one of:
subtract the first input and the third input from the second input; and
add the first input, the second input, and the third input.

### Claim 33 (depends on 31)

A processor according to claim 31, further comprising a multiplexer to selectively couple the base offset storage element to the first input of the adder;
wherein the instruction decode unit is configured to cause the multiplexer to selectively couple the base offset storage element to the first input of the adder in response to the second instruction.

### Claim 34 (depends on 33)

A processor according to claim 33, further comprising a plurality of base offset storage elements selectively coupled to the first input of the adder via the multiplexer;
wherein the instruction decode unit is configured to cause the base offset indicated by the first instruction to be loaded into a first one of the base offset storage elements in response to the first instruction, the first instruction indicating the first one of the plurality of base offset storage elements.
wherein the instruction decode unit is configured to cause the multiplexer to selectively couple a second one of the plurality of base offset storage elements to the first input of the adder in response to the second instruction, the second instruction indicating the second one of the plurality of base offset storage elements.

### Claim 35 (depends on 31)

A processor according to claim 31, wherein the processor comprises at least one of a complex instruction set computer (CISC) processor, a reduced instruction set computer (RISC) processor, an explicitly parallel instruction computing (EPIC) processor, a very long instruction word (VLIW) processor, a micro signal architecture (MSA) processor, a digital signal processor (DSP), and a pipelined processor.

### Claim 36

A computing system, comprising:
a hard disk storing a set of executable instructions;
a processor coupled to the hard disk, the processor comprising:
a base offset storage element;
a program counter storage element;
an adder having a first input coupled to the base offset storage element, a second input coupled to receive a value stored in the program counter storage element, and an output coupled to the program counter storage element;
an instruction decode unit coupled to base offset storage element and to the program counter storage element, the instruction decode unit also coupled to a third input of the adder;
wherein the instruction decode unit is configured to:
cause a base offset to be loaded into the base offset storage element in response to a first instruction that indicates the base offset,
cause a relative offset to be coupled to the third input of the adder in response to a second instruction that indicates the relative offset, and
cause the output of the adder to be stored in the program counter storage element in response to the second instruction.

### Claim 37 (depends on 36)

A computing system according to claim 36, further comprising a bus to couple the hard disk to the processor.

### Claim 38 (depends on 36)

A computing system according to claim 36, further comprising a computer readable medium coupled to the processor, the computer readable medium comprising at least one of a CD-ROM, a floppy disk, an additional hard drive, a digital versatile disk (DVD), a memory card, a memory stick, a read-only memory (ROM), a random-access memory (RAM), an erasable programmable ROM (EPROM), and an electrically erasable programmable ROM (EEPROM).

### Claim 39

A computer readable medium having stored thereon machine executable instructions, the machine executable instructions comprising:
a first instruction at a first location having a relative offset parameter and a length parameter, the first instruction configured to:
cause a processor to modify a program counter based on the relative offset parameter and a value stored in a base offset storage element,
cause the processor to execute a number of instructions starting at a second location indicated by the program counter modified in response to the first instruction, wherein the length parameter indicates the number of other instructions, and
cause the processor to, after executing the number of instructions starting at the second location, modify the program counter to point to a third instruction adjacent to and subsequent to the second instruction.

### Claim 40 (depends on 39)

A computer readable medium according to claim 39, further comprising a second instruction having a base offset parameter, the second instruction configured to cause the processor to load the base offset storage element with the base offset parameter.

### Claim 41 (depends on 40)

A computer readable medium according to claim 40, wherein the second instruction is configured to load one of a plurality of base offset storage elements with the base offset parameter, wherein the second instruction indicates the one base offset storage element.

### Claim 42 (depends on 41)

A computer readable medium according to claim 41, wherein the second instruction includes at least one of a base offset storage element parameter that indicates the one base offset storage element, and an opcode that indicates the one base offset storage element.

### Claim 43 (depends on 39)

A computer readable medium according to claim 39, wherein the first instruction is configured to cause the processor to modify the program counter based on the relative offset parameter and the value stored in one of a plurality of base offset storage elements, wherein the first instruction indicates the one base offset storage element.

### Claim 44 (depends on 43)

A computer readable medium according to claim 43, wherein the first instruction includes at least one of a base offset storage element parameter that indicates the one base offset storage element, and an opcode that indicates the one base offset storage element.
