Looking for HDL code for sin( a ) and x ** y Functions

Discussion in 'VHDL' started by Derek Simmons, Oct 2, 2006.

  1. Before I get spamed for this I have done a search and I see there are
    references to what I'm looking for on www.opencores.org but for some
    reason I'm unable to connect.

    What I'm looking for is a resource like, if it existed, Numerical
    Receipes in HDL (VHDL/Verilog). I have a need for the basic floating
    point functions like sin( a ) and x ** y. For floating point numbers
    that are only 12 to 18 bits I can use lookup tables but I was wondering
    if there was another way of calculating these values. Most of the books
    I have cover addition/subtraction, multiplication and division but
    nothing more advance or even hints at how to go about it.

    >From sin( a ) and x ** y I plan on deriving cos( a ), tan( a ), cot( a

    ), and yth root of x.

    I'm looking for any helpful or constructive suggestions.

    Thanks,
    Derek
     
    Derek Simmons, Oct 2, 2006
    #1
    1. Advertising

  2. Derek Simmons

    cbr_929rr Guest

    I had similar issues with opencores until now. It is working now.

    Derek Simmons wrote:
    > Before I get spamed for this I have done a search and I see there are
    > references to what I'm looking for on www.opencores.org but for some
    > reason I'm unable to connect.
    >
    > What I'm looking for is a resource like, if it existed, Numerical
    > Receipes in HDL (VHDL/Verilog). I have a need for the basic floating
    > point functions like sin( a ) and x ** y. For floating point numbers
    > that are only 12 to 18 bits I can use lookup tables but I was wondering
    > if there was another way of calculating these values. Most of the books
    > I have cover addition/subtraction, multiplication and division but
    > nothing more advance or even hints at how to go about it.
    >
    > >From sin( a ) and x ** y I plan on deriving cos( a ), tan( a ), cot( a

    > ), and yth root of x.
    >
    > I'm looking for any helpful or constructive suggestions.
    >
    > Thanks,
    > Derek
     
    cbr_929rr, Oct 2, 2006
    #2
    1. Advertising

  3. for integer implementations the cordic algorithm covers most of the
    trigonometric functions
    you need (no multipliers, but some latency)
    Aurash

    Derek Simmons wrote:

    >Before I get spamed for this I have done a search and I see there are
    >references to what I'm looking for on www.opencores.org but for some
    >reason I'm unable to connect.
    >
    >What I'm looking for is a resource like, if it existed, Numerical
    >Receipes in HDL (VHDL/Verilog). I have a need for the basic floating
    >point functions like sin( a ) and x ** y. For floating point numbers
    >that are only 12 to 18 bits I can use lookup tables but I was wondering
    >if there was another way of calculating these values. Most of the books
    >I have cover addition/subtraction, multiplication and division but
    >nothing more advance or even hints at how to go about it.
    >
    >>From sin( a ) and x ** y I plan on deriving cos( a ), tan( a ), cot( a

    >), and yth root of x.
    >
    >I'm looking for any helpful or constructive suggestions.
    >
    >Thanks,
    >Derek
    >
    >
    >



    --
    __
    / /\/\ Aurelian Lazarut
    \ \ / System Verification Engineer
    / / \ Xilinx Ireland
    \_\/\/

    phone: 353 01 4032639
    fax: 353 01 4640324
     
    Aurelian Lazarut, Oct 2, 2006
    #3
  4. Derek Simmons

    cbr_929rr Guest

    If www.opencores.org link does not work, try
    http://www.opencores.org:8080/

    cbr_929rr wrote:
    > I had similar issues with opencores until now. It is working now.
    >
    > Derek Simmons wrote:
    > > Before I get spamed for this I have done a search and I see there are
    > > references to what I'm looking for on www.opencores.org but for some
    > > reason I'm unable to connect.
    > >
    > > What I'm looking for is a resource like, if it existed, Numerical
    > > Receipes in HDL (VHDL/Verilog). I have a need for the basic floating
    > > point functions like sin( a ) and x ** y. For floating point numbers
    > > that are only 12 to 18 bits I can use lookup tables but I was wondering
    > > if there was another way of calculating these values. Most of the books
    > > I have cover addition/subtraction, multiplication and division but
    > > nothing more advance or even hints at how to go about it.
    > >
    > > >From sin( a ) and x ** y I plan on deriving cos( a ), tan( a ), cot( a

    > > ), and yth root of x.
    > >
    > > I'm looking for any helpful or constructive suggestions.
    > >
    > > Thanks,
    > > Derek
     
    cbr_929rr, Oct 2, 2006
    #4
  5. Derek Simmons

    Andrew FPGA Guest

    > >What I'm looking for is a resource like, if it existed, Numerical
    > >Receipes in HDL (VHDL/Verilog).


    Elementary Functions, Algorithms and Implementation by Jean-Michel
    Muller.
    No HDL code but the algorithms are there.
     
    Andrew FPGA, Oct 2, 2006
    #5
  6. Derek Simmons

    Guest

    Derek Simmons wrote:
    > >From sin( a ) and x ** y I plan on deriving cos( a ), tan( a ), cot( a

    > ), and yth root of x.


    Integer exponents are pretty straightforward. It is a similar
    algorithm to multiplication (multiply by 2 and optionally add), but
    with higher order operations (square and optionally multiply).

    Integer roots are probably best done by something like Newton-Raphson.

    Arbitrary powers probably require computing logarithms first. One
    issue with that is that you can't compute them for negative numbers.
    If you just want integer roots, computing arbitrary powers probably
    isn't the best way to do it.
     
    , Oct 2, 2006
    #6
  7. Derek Simmons

    Ray Andraka Guest

    Derek Simmons wrote:
    > Before I get spamed for this I have done a search and I see there are
    > references to what I'm looking for on www.opencores.org but for some
    > reason I'm unable to connect.
    >
    > What I'm looking for is a resource like, if it existed, Numerical
    > Receipes in HDL (VHDL/Verilog). I have a need for the basic floating
    > point functions like sin( a ) and x ** y. For floating point numbers
    > that are only 12 to 18 bits I can use lookup tables but I was wondering
    > if there was another way of calculating these values. Most of the books
    > I have cover addition/subtraction, multiplication and division but
    > nothing more advance or even hints at how to go about it.
    >
    >>From sin( a ) and x ** y I plan on deriving cos( a ), tan( a ), cot( a

    > ), and yth root of x.
    >
    > I'm looking for any helpful or constructive suggestions.
    >
    > Thanks,
    > Derek
    >



    It really depends on your precision and accuracy requirements. For
    arbitrarily high precision, CORDIC is the way to go for sin provided you
    can live with the latency. The other end of the spectrum is a look-up
    table. There are intermediate solutions which are generally a
    combination of angular reductions and interpolation that will get you a
    reasonably high resolution without a huge look-up table. Linear
    interpolation perhaps the easiest, and can be done with relatively
    little hardware. A parabolic fit interpolation will get you
    considerably smaller errors between table entries allowing a finer
    resolution, and can be done with relatively low hardware complexity.

    For X**Y, it is easiest to work with normalized floating point as an
    input, and then using interpolated LUTs. Normalizing limits the range
    of the tables. For a general purpose trancendental function calculator,
    your best bet might be a CORDIC-like iterative engine, as CORDIC and
    CORDIC-like structures can handle trig, hyperbolic trig, logs and
    exponents, and multiply and divide.

    So the point is, that there are many ways to skin this cat, and the
    "best" way depends heavily upon your particular requirements.
     
    Ray Andraka, Oct 3, 2006
    #7
  8. Derek Simmons

    Ray Andraka Guest

    Ray Andraka wrote:

    By the way, I have a paper on CORDIC on my web site that many have found
    ot be quite useful. Http://www.andraka.com/papers see: A survey of
    CORDIC algorithms for FPGA based Computers.

    I also second the reference to Jean Muller's book elementary functions
    book for algorithms, although you may have difficulty translating it
    into hardware.
     
    Ray Andraka, Oct 3, 2006
    #8
  9. Derek Simmons

    Guest

    Ray,

    In case your company uses Synopsys tools, there is a very simple
    solution available in their DesignWare library. They have both hardware
    as well as simulation models for both the above functions, which can be
    simply instantiated in the code. If you are not looking for any
    specific algorithm that implements the functions (and if you have
    access to the library) then this could be the right solution.

    -Sourabh

    Disclaimer: This is not push anyone's marketing agenda; just
    information about a solution for the given problem.
     
    , Oct 3, 2006
    #9
  10. Derek Simmons

    MariuszK Guest

    MariuszK, Oct 3, 2006
    #10
  11. Derek Simmons, Oct 3, 2006
    #11
  12. Andrew FPGA wrote:
    > > >What I'm looking for is a resource like, if it existed, Numerical
    > > >Receipes in HDL (VHDL/Verilog).

    >
    > Elementary Functions, Algorithms and Implementation by Jean-Michel
    > Muller.
    > No HDL code but the algorithms are there.


    I found a couple of people have recommended this book and when I did a
    quick search on Amazon it came highly recommended. I'm looking into
    getting a copy.

    Thanks,
    Derek
     
    Derek Simmons, Oct 3, 2006
    #12
  13. >
    > It really depends on your precision and accuracy requirements. For
    > arbitrarily high precision, CORDIC is the way to go for sin provided you
    > can live with the latency. The other end of the spectrum is a look-up
    > table. There are intermediate solutions which are generally a
    > combination of angular reductions and interpolation that will get you a
    > reasonably high resolution without a huge look-up table. Linear
    > interpolation perhaps the easiest, and can be done with relatively
    > little hardware. A parabolic fit interpolation will get you
    > considerably smaller errors between table entries allowing a finer
    > resolution, and can be done with relatively low hardware complexity.


    I can live with the latency because the math unit I'm designing is
    pipelined. As long as I organize the operations putting the ones with
    longest latency first and at the cost of a multiplier or adder I should
    keep a couple of parallel tracks busy.

    >
    > For X**Y, it is easiest to work with normalized floating point as an
    > input, and then using interpolated LUTs. Normalizing limits the range
    > of the tables. For a general purpose trancendental function calculator,
    > your best bet might be a CORDIC-like iterative engine, as CORDIC and
    > CORDIC-like structures can handle trig, hyperbolic trig, logs and
    > exponents, and multiply and divide.
    >


    I'm comparing the trade off for using a lookup table to using an
    iterative process. I have designed a general purpose rasterizer. I can
    feed it a canned list of triangles in screen coordinates and it can
    render them shaded. I'm working my way backwards up the pipeline to
    design the geometry engine stage. Given the parameters for viewing
    transformations I'm adding the functionality to build the viewing
    transforms, using the object space coordinates calculate the world
    space coordinates and from the worldspace coordinates calculate the
    screen coordinates for the rasterizer.

    Right now I'm doing this with the attitude of a hobby but I would like
    to roll it over into something professional. Much of what I'm doing is
    iterative, it never amazes me when QuartusII finds a flaw in one of my
    state machines and decides to flatten it.

    Thanks,
    Derek
     
    Derek Simmons, Oct 3, 2006
    #13
  14. Derek Simmons

    Guest

    Derek Simmons wrote:
    > Andrew FPGA wrote:
    > > > >What I'm looking for is a resource like, if it existed, Numerical
    > > > >Receipes in HDL (VHDL/Verilog).

    > >
    > > Elementary Functions, Algorithms and Implementation by Jean-Michel
    > > Muller.
    > > No HDL code but the algorithms are there.

    >
    > I found a couple of people have recommended this book and when I did a
    > quick search on Amazon it came highly recommended. I'm looking into
    > getting a copy.
    >
    > Thanks,
    > Derek


    Another book to consider is -

    DIGITAL COMPUTER ARITHMETIC DATAPATH DESIGN USING VERILOG HDL by James
    Stine.

    It has a 25 page chapter on Elementary Functions; the style of the book
    is to sketch the algorithm and then show the verilog code for typically
    a 16 bit implementation at the hierarchic gate level.
     
    , Oct 4, 2006
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    482
    tom_usenet
    Sep 9, 2003
  2. Alexander Stippler

    why do I need ::sin, not std::sin?

    Alexander Stippler, Jun 4, 2004, in forum: C++
    Replies:
    14
    Views:
    859
    Pete Becker
    Jun 5, 2004
  3. reagan
    Replies:
    5
    Views:
    892
    reagan
    Dec 7, 2004
  4. night_bird
    Replies:
    0
    Views:
    672
    night_bird
    Nov 16, 2007
  5. jack
    Replies:
    0
    Views:
    416
Loading...

Share This Page