Class Horner

java.lang.Object
  extended by Horner

public class Horner
extends java.lang.Object

Class used to generate the Horner equations for multiplication expressed in terms of shifts and addes.

Author:
Craig A. Lindley

Field Summary
private static int GEN_CODE
           
private static int GEN_EQU
           
private static int GEN_EQU_AND_CODE
           
private  int numberBits
           
private  boolean useCSD
           
 
Constructor Summary
Horner(int numberBits, boolean useCSD)
          Class constructor
 
Method Summary
private  java.lang.String determineLastTermOfFraction(boolean guardBit, boolean signBit)
          Determine last term of fractional representation
 void displayOutput(double number, int out)
          Generate and display the output for a given number
private  java.lang.String generateCode(Holder holder)
          Generate the MSP430 code for the multiplier contained in the holder.
private  void generateDecimalCode(java.lang.StringBuffer sb, Holder holder)
          Generate the MSP430 code for the decimal portion of the multiplier contained in the holder.
private  void generateDecimalEquations(java.lang.StringBuffer sb, Holder holder)
          Generate the Horner equations for decimal portion of the multiplier contained in the holder.
private  java.lang.String generateEquations(Holder holder)
          Generate the Horner equations for the multiplier contained in the holder.
private  void generateFractionCode(java.lang.StringBuffer sb, Holder holder, boolean wasDecimalPart)
          Generate the MSP430 code for fraction portion of the multiplier contained in the holder.
private  void generateFractionEquations(java.lang.StringBuffer sb, Holder holder, boolean wasDecimalPart)
          Generate the Horner equations for fraction portion of the multiplier contained in the holder.
static void main(java.lang.String[] args)
          Main entry point used for testing
static void usage(java.lang.String msg)
          Print out a usage string and terminate program operation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GEN_EQU

private static final int GEN_EQU
See Also:
Constant Field Values

GEN_CODE

private static final int GEN_CODE
See Also:
Constant Field Values

GEN_EQU_AND_CODE

private static final int GEN_EQU_AND_CODE
See Also:
Constant Field Values

numberBits

private int numberBits

useCSD

private boolean useCSD
Constructor Detail

Horner

public Horner(int numberBits,
              boolean useCSD)
Class constructor

Parameters:
useCSD - should be set true if CSD is to be used as optimization false if not.
Method Detail

determineLastTermOfFraction

private java.lang.String determineLastTermOfFraction(boolean guardBit,
                                                     boolean signBit)
Determine last term of fractional representation

Parameters:
guardBit - the guard bit associated with fraction
signBit - the sign bit associated with the fraction
Returns:
String containing last term addin if any

generateDecimalEquations

private void generateDecimalEquations(java.lang.StringBuffer sb,
                                      Holder holder)
Generate the Horner equations for decimal portion of the multiplier contained in the holder.

Parameters:
sb - StringBuffer object to generate equations in
holder - Holder object containing a representation

generateFractionEquations

private void generateFractionEquations(java.lang.StringBuffer sb,
                                       Holder holder,
                                       boolean wasDecimalPart)
Generate the Horner equations for fraction portion of the multiplier contained in the holder.

Parameters:
holder - Holder object containing a representation
sb - StringBuffer object to generate equations in
wasDecimalPart - true if number has a decimal part; false if number was only fractional part.

generateDecimalCode

private void generateDecimalCode(java.lang.StringBuffer sb,
                                 Holder holder)
Generate the MSP430 code for the decimal portion of the multiplier contained in the holder.

Parameters:
sb - StringBuffer object to generate code in
holder - Holder object containing a representation

generateFractionCode

private void generateFractionCode(java.lang.StringBuffer sb,
                                  Holder holder,
                                  boolean wasDecimalPart)
Generate the MSP430 code for fraction portion of the multiplier contained in the holder.

Parameters:
holder - Holder object containing a representation
sb - StringBuffer object to generate equations in
wasDecimalPart - true if number has a decimal part; false if number was only fractional part.

generateEquations

private java.lang.String generateEquations(Holder holder)
Generate the Horner equations for the multiplier contained in the holder.

Parameters:
holder - Holder object containing the decimal and fraction representation of the multiplier
Returns:
A String containing the Horner equations

generateCode

private java.lang.String generateCode(Holder holder)
Generate the MSP430 code for the multiplier contained in the holder.

Parameters:
holder - Holder object containing the decimal and fraction representation of the multiplier
Returns:
A String containing the generated code

displayOutput

public void displayOutput(double number,
                          int out)
Generate and display the output for a given number

Parameters:
number - multiplier to generate the output for
out - 0 is no output, 1 is code output, 2 is equation output and 3 is both code and equation output. Code output is for the MSP430 microcontroller.

usage

public static void usage(java.lang.String msg)
Print out a usage string and terminate program operation


main

public static void main(java.lang.String[] args)
Main entry point used for testing

Parameters:
args - double number to generate outputx for. If no args are specified canned numbers are used for equation generation. Numbers and equations are written to stdout.