Re: how to square convert to verilog.
- From: Jonathan Bromley <jonathan.bromley@xxxxxxxxxxxxx>
- Date: Mon, 06 Jul 2009 21:22:19 +0100
On Sat, 4 Jul 2009 00:44:45 -0700 (PDT), Jack wrote:
this is my c term.[snip code]
i wnat to conver to verilog.
That is a VERY expensive way to draw a circular blob,
of 100 pixels radius, in the centre of the screen.
(You did know that was what it does, I assume?
It would have been nice had you told us - my
geometry is not as slick it used to be; I had
to think about it for a minute or two.)
Instead, try looking-up Bresenham's circle drawing
algorithm. It's cheap, and maps easily to raster-
scan hardware scanning the image pixels in the
same order that your C code does. The usual form
of the algorithm draws a circular outline, but it's
easy to rework it to draw a filled circle like yours.
If you really, really want to do Pythagoras for
every pixel, then consider these useful facts:
1)
Much of the arithmetic can be pre-calculated.
For example, the term (j-768)*(j-768) remains
constant for an entire scan line and needs only
to be calculated once per 2048 points (something
the original C programmer has missed, and has
left to his compiler to optimize).
2)
For an 11-bit number 'i' in the range 0..2047,
the calculation (i-1024) is rather simple.
(j-768) is a little trickier, but still leaves
an awful lot of bits of j unchanged.
Alternatively, instead of running a loop from
0 to 1535 and subtracting 768 from every point,
how about running the loop from -768 to +767?
3)
As you move from one point to the next, you could
keep the previous value of i*i and use it to
compute (i+1)*(i+1) rather easily...
(i+1)*(i+1)
= i*i + 2*i + 1
= i*i + (2*i + 1)
Oooh, look, if I remember i*i I can get the next
value (i+1)*(i+1) just by adding something that's
quite easy to calculate....
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@xxxxxxxxxxxxx
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
.
- References:
- how to square convert to verilog.
- From: Jack
- how to square convert to verilog.
- Prev by Date: Re: how to square convert to verilog.
- Next by Date: module ports vs parameters
- Previous by thread: Re: how to square convert to verilog.
- Next by thread: module ports vs parameters
- Index(es):
Relevant Pages
|
Loading