Patent ID: 7840953

Claim:
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 an absolute offset from a first location to the second location: determining a base offset based on the absolute offset; determining a relative offset based on the absolute offset and the base offset, wherein a sum of the base offset and the relative offset equals the absolute offset from the first location to the second location; inserting, prior to the first location, a first instruction to cause a base offset storage element to be loaded with the base offset; replacing the replaceable subset of instructions with a second instruction to cause a program counter to be modified by the sum of the relative offset and the base offset loaded in the base offset register by the first instruction, wherein the modified program counter indicates the second location; wherein matching a target subset of instructions at the second location includes choosing the target subset of instructions from a plurality of candidate target subsets of instructions at different locations; wherein 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 whether candidate target subsets are located in regions of frequently executed code.