Claims
- 1. A method, performed by a compiler executing on a CPU, for constant bit folding an expression having a result determined by binary operations on a plurality of operands in the form of integer bit sets, with each bit set having either a constant or a non-constant in each bit position of the bit set, said method comprising the acts of:
for each operand, forming an operand known-bit set having a first value in bit positions where a corresponding bit position in an associated operand has a constant value and with the known-bit set having a second value in bit positions where a corresponding bit position in the associated operand has a non-constant value; for each operand, forming an operand value bit set having bit values, in bit positions corresponding to bit positions in the known-bit set equal to the first value, having a constant value equal to the corresponding bit values in the associated operand; logically processing the operand known-bit sets and operand value bit sets for all operands to form a result known-bit set, having a first value for bit positions corresponding to bit positions in the result having constant values; and forming a result value bit set having bit values, in bit positions corresponding the bit positions having the first value in said result known-bit set, equal constant values of the result bit set at those values.
- 2. The method of claim 1 where said step of logical processing further comprises the acts of:
performing selected logical operations, correlated to operations in the expression, on the bits of said operand known-bit sets and operand value bit sets.
- 3. The method of claim 1 further comprising the steps of:
performing selected logical operations, correlated to operations in the expression, on the operand known-bit sets and operand value bit sets to obtain a non-influence bit set for a first operand having a first value at bit positions of the first operand that have no influence on the values of bit positions of the result.
- 4. The method of claim 2 where the expression has a result equal to the binary not (˜) operation of a first operand (x), with the operand known-bit set represented by Mx and the operand value bit set represented by Cx, said method comprising the steps of:
setting the result known-bit set, M, equal to Mx; and setting the result value bit set, C, equal to C=˜Cx & M.
- 5. The method of claim 2 where the expression has a result equal to the binary or (|) operation of a first operand (x) and a second operand (y), with the operand known-bit sets represented by Mx and My and the operand value bit sets represented by Cx and Cy, said method comprising the steps of:
setting the result value bit set, C, equal to Cx|Cy; and setting the result known-bit set, M, equal to Mx & My|C.
- 6. The method of claim 5 further comprising the step of:
setting the first operand non-influence bit set equal to Nx equal to Cy|N, and setting the second operand non-influence bit set, Ny, equal to Cx|N, where N={0,0,0,0}.
- 7. The method of claim 2 where the expression has a result equal to the binary and (&) operation of a first operand (x) and a second operand (y), with the operand known-bit sets represented by Mx and My and the operand value bit sets represented by Cx and Cy, said method comprising the steps of:
setting the result known-bit set, M, equal to Mx & My|Mx & ˜Cx|My & ˜Cy; and setting the result value bit set, C, equal to Cx & Cy.
- 8. The method of claim 7 further comprising the step of:
setting the first operand non-influence bit set equal to Nx equal to ˜(My & ˜Cy)|N, and setting the second operand non-influence bit set, Ny, equal to ˜(Mx & ˜Cx)|N where N={0,0,0,0}.
- 9. The method of claim 2 where the expression has a result equal to the binary xor (ˆ ) operation of a first operand (x) and a second operand (y), with the operand known-bit sets represented by Mx and My and the operand value bit sets represented by Cx and Cy, said method comprising the steps of:
setting the result known-bit set, M, equal to Mx & My; and setting the result value bit set, C, equal to (Cxˆ Cy) & M.
- 10. The method of claim 2 where the expression has a result equal to the binary addition (+) operation of a first operand (x) and a second operand (y), with the operand known-bit sets represented by Mx and My and the operand value bit sets represented by Cx and Cy, said method comprising the steps of:
setting the result value bit set, C, equal to Cx+Cy; setting the result-known bit set, M, equal to Mx & My & (Cˆ ˜((Cx|˜Mx)+(Cy|˜My))) & (Cˆ ˜(Cx+(Cy|˜My))) & (Cˆ ˜((Cx|˜Mx)+Cy)); and resetting the result value bit set, C, equal to C & M.
- 11. The method of claim 2 where the expression has a result equal to the binary subtraction (−) operation of a first operand (x) and a second operand (y), with operand known-bit sets represented by Mx and My and the operand value bit sets represented by Cx and Cy, said method comprising the steps of:
setting the result value bit set, C, equal to Cx—Cy; setting the result known bit set, M, equal to Mx & My & (Cˆ ˜((Cx|˜Mx)−(Cy|˜My))) & (Cˆ ˜(Cx−(Cy|˜My))) & (Cˆ ˜((Cx|Mx)−Cy)); and resetting the result value bit set, C, equal to C & M.
- 12. The method of claim 2 where the expression has a result equal to the binary multiplication (x) operation of a first operand (x) and a second operand (y), with the operand known-bit sets represented by Mx and My and the operand value bit sets represented by Cx and Cy, said method comprising the steps of:
setting the result value bit set, M, equal to −(My & 1); setting the result value bit set, C, equal to −(Cy& 1); setting the result known bit set, M, equal to M=Mx & M|Mx & ˜Cx|My & ˜C; resetting the result value bit set, C, equal to C & Cx; setting an iteration counter, i, equal to 1; and repeating the following sequence of steps, until the value of the iteration counter, i, equals the size of the result value bit set, C, in bits:
resetting Mx=Mx<<1; resetting Mx=Mx|1; resetting Cx=Cx<<1; resetting My=My>>1; resetting Cy=Cy>>1; setting a first internal variable Myy=−(Myy & 1); setting a second internal variable Cyy=−(Cy & 1); setting a first internal variable Myy=Mx & Myy|Mx & ˜Cx|Myy & ˜Cyy; setting Cyy=Cyy & Cx; setting a third internal variable CC=C+Cyy; setting M=M & Myy & (CCˆ ˜((C|˜M)+(Cyy|˜Myy))) & (CCˆ ˜(C+(Cyy|˜Myy))) & (CCˆ ˜((C|˜M)+Cyy)); setting C=CC & M; and increasing the value of iteration counter, i, by 1.
- 13. A computer program product comprising:
a computer readable medium embodying program code therein for, when executed by a processor, causing a computer to constant bit fold an expression having a result determined by binary operations on a plurality of operands in the form of integer bit sets, with each bit set having either a constant or a non-constant in each bit position of the bit set, said program code comprising: for each operand, program code for forming an operand known-bit set having a first value in bit positions where a corresponding bit position in an associated operand has a constant value and with the known-bit set having a second value in bit positions where a corresponding bit position in the associated operand has a non-constant value; for each operand, program code for forming an operand value bit set having bit values, in bit positions corresponding to bit positions in the known-bit set equal to the first value, having a constant value equal to the corresponding bit values in the associated operand; program code for logically processing the operand known-bit sets and operand value bit sets for all operands to form a result known-bit set, having a first value for bit positions corresponding to bit positions in the result having constant values; and program code for forming a result value bit set having bit values, in bit positions corresponding the bit positions having the first value in said result known-bit set, equal constant values of the result bit set at those values.
- 14. The computer program product of claim 13 further comprising:
computer program code for performing selected logical operations, correlated to operations in the expression, on the bits of said operand known-bit sets and operand value bit sets.
CROSS-REFERENCES TO RELATED APPLICATIONS
[0001] This application claims priority from U.S. patent Application Ser. No. 09/506,408, filed Feb. 17, 2000, the disclosure of which is incorporated herein by reference in its entirety for all purposes.
Continuation in Parts (1)
|
Number |
Date |
Country |
Parent |
09506408 |
Feb 2000 |
US |
Child |
09967369 |
Sep 2001 |
US |