Libre RISC-V Mailing list Archives (accessible via public-inbox)
 help / color / Atom feed
From: bugzilla-daemon@libre-soc.org
To: libre-riscv-dev@lists.libre-riscv.org
Subject: [libre-riscv-dev] [Bug 208] implement CORDIC in a general way sufficient to do transcendentals
Date: Mon, 13 Apr 2020 17:23:10 +0000
Message-ID: <bug-208-13-nkfOcnZQGf@https.bugs.libre-soc.org/> (raw)
In-Reply-To: <bug-208-13@https.bugs.libre-soc.org/>

https://bugs.libre-soc.org/show_bug.cgi?id=208

--- Comment #4 from Luke Kenneth Casson Leighton <lkcl@lkcl.net> ---
(In reply to Michael Nolan from comment #3)
> I was able to translate the linked myhdl code to nmigen and implement both a
> state machine based and pipelined cordic here:
> https://git.libre-soc.org/?p=ieee754fpu.git;a=tree;f=src/ieee754/cordic;
> h=3f06900baa42651410d661739fb616e4b3020c52;
> hb=77f150cff440bed025e2487b6f0fcda9f529290b

cool!  well that was easy :)

> You can configure the width, as well as the number of cordic rounds per
> pipeline stage. There are some accuracy issues with it though - it exactly
> matches the behavior of the myhdl one, but the results it gives can be off
> by 1% or so from that obtained using sin() or cos() on 16 bit numbers.

yes.  i believe it's well-known that to get 16-bit accuracy you need
32-bit registers.

i made a couple of corrections btw - frickin well done for working out
the pipeline API with zero assistance - that's deeply impressive given
that, other than the docstring comments, there's no "documentation" on
it.

CordicInitialData needed to "yield self.z0" (not self.z)

"yield from" is reserved for a way to yield *from* something that is
itself iteratable (such as another function).  self.z0 is in fact
iterable, so what would be returned by "yield from" would be first
self.z0[0], then on the next iteration self.z0[1] and so on which
would be very painful.

"yield" just returns "that object".

however... we have a bit of a problem back in nmutil.iocontrol NextControl
and PrevControl iteration, in that it can't actually properly work out
if the *object* that you are iterating should be yielded or yielded *from*.
so i added a hack "check if data has a ports function".

however i've just right now worked out that we could detect if the object
is iterable with isinstance(self.data_o, Iterable).
so that's just been committed.

i also added an rtlil test because i was fascinated to see what the
graphviz looks like.


--- a/src/ieee754/cordic/pipe_data.py
+++ b/src/ieee754/cordic/pipe_data.py
@@ -10,11 +10,14 @@ class CordicInitialData:
         self.z0 = Signal(range(-ZMAX, ZMAX), name="z")     # denormed result

     def __iter__(self):
-        yield from self.z
+        yield self.z0

     def eq(self, i):
         return [self.z0.eq(i.z0)]

 class CordicData:

@@ -27,9 +30,12 @@ class CordicData:
         self.z = Signal(range(-ZMAX, ZMAX), name="z")     # denormed result

     def __iter__(self):
-        yield from self.x
-        yield from self.y
-        yield from self.z
+        yield self.x
+        yield self.y
+        yield self.z

     def eq(self, i):
         ret = [self.z.eq(i.z), self.x.eq(i.x), self.y.eq(i.y)]
diff --git a/src/ieee754/cordic/test/test_pipe.py
b/src/ieee754/cordic/test/test_pipe.py
index 880351a..b7eaf8a 100644
--- a/src/ieee754/cordic/test/test_pipe.py
+++ b/src/ieee754/cordic/test/test_pipe.py
@@ -1,6 +1,7 @@
 from nmigen import Module, Signal
 from nmigen.back.pysim import Simulator, Passive
 from nmigen.test.utils import FHDLTestCase
+from nmigen.cli import rtlil

 from ieee754.cordic.sin_cos_pipeline import CordicBasePipe
 from ieee754.cordic.pipe_data import CordicPipeSpec
@@ -16,6 +17,13 @@ class SinCosTestCase(FHDLTestCase):
         pspec = CordicPipeSpec(fracbits=fracbits, rounds_per_stage=4)
         m.submodules.dut = dut = CordicBasePipe(pspec)

+        for port in dut.ports():
+            print ("port", port)
+
+        vl = rtlil.convert(dut, ports=dut.ports())
+        with open("test_cordic_pipe_sin_cos.il", "w") as f:
+            f.write(vl)
+
         z = Signal(dut.p.data_i.z0.shape())
         z_valid = Signal()
         ready = Signal()
(END)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
libre-riscv-dev mailing list
libre-riscv-dev@lists.libre-riscv.org
http://lists.libre-riscv.org/mailman/listinfo/libre-riscv-dev

  parent reply index

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-208-13@https.bugs.libre-soc.org/>
2020-04-13 14:35 ` bugzilla-daemon
2020-04-13 17:23 ` bugzilla-daemon [this message]
2020-04-13 17:34 ` bugzilla-daemon
2020-04-15 17:54 ` bugzilla-daemon
2020-04-15 18:04   ` Cole Poirier
2020-04-15 19:14 ` bugzilla-daemon
2020-04-15 19:16 ` bugzilla-daemon
2020-04-15 19:17 ` bugzilla-daemon
2020-04-15 19:19 ` bugzilla-daemon
2020-04-15 19:21   ` Cole Poirier
2020-04-15 19:25     ` Luke Kenneth Casson Leighton
2020-04-15 19:29       ` Cole Poirier
2020-04-15 19:34 ` bugzilla-daemon
2020-04-15 19:54 ` bugzilla-daemon
2020-04-15 21:30 ` bugzilla-daemon
2020-04-16  7:53 ` bugzilla-daemon
2020-04-16  8:53 ` bugzilla-daemon
2020-04-16  9:48 ` bugzilla-daemon
2020-04-16 15:36 ` bugzilla-daemon
2020-04-16 16:22 ` bugzilla-daemon
2020-04-16 16:46 ` bugzilla-daemon
2020-04-16 16:59 ` bugzilla-daemon
2020-04-16 17:16 ` bugzilla-daemon
2020-04-17 12:29 ` bugzilla-daemon
2020-04-17 17:19 ` bugzilla-daemon
2020-04-17 17:28 ` bugzilla-daemon
2020-04-17 17:31 ` bugzilla-daemon
2020-04-17 18:02 ` bugzilla-daemon
2020-04-17 18:37 ` bugzilla-daemon
2020-04-17 18:38 ` bugzilla-daemon
2020-04-17 18:42 ` bugzilla-daemon
2020-04-17 19:36 ` bugzilla-daemon
2020-04-17 19:56 ` bugzilla-daemon
2020-04-17 19:59 ` bugzilla-daemon
2020-04-18 21:52 ` bugzilla-daemon
2020-04-20 21:51 ` bugzilla-daemon
2020-04-20 22:43   ` Jacob Lifshay
2020-05-05 13:17 ` bugzilla-daemon
2020-05-05 14:04 ` bugzilla-daemon
2020-05-05 14:06 ` bugzilla-daemon
2020-05-05 14:29 ` bugzilla-daemon
2020-05-05 14:42 ` bugzilla-daemon
2020-05-05 14:52 ` bugzilla-daemon
2020-05-05 14:53 ` bugzilla-daemon
2020-05-05 14:55 ` bugzilla-daemon
2020-05-05 14:58 ` bugzilla-daemon
2020-05-05 15:00 ` bugzilla-daemon
2020-05-05 15:00 ` bugzilla-daemon
2020-05-05 15:10 ` bugzilla-daemon
2020-05-05 15:10 ` bugzilla-daemon
2020-05-05 15:13 ` bugzilla-daemon
2020-05-05 16:03 ` bugzilla-daemon
2020-05-05 16:12 ` bugzilla-daemon
2020-05-05 16:16 ` bugzilla-daemon
2020-05-05 16:28 ` bugzilla-daemon
2020-05-05 17:02 ` bugzilla-daemon
2020-05-05 17:30 ` bugzilla-daemon
2020-05-06  9:53 ` bugzilla-daemon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-208-13-nkfOcnZQGf@https.bugs.libre-soc.org/ \
    --to=bugzilla-daemon@libre-soc.org \
    --cc=libre-riscv-dev@lists.libre-riscv.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Libre RISC-V Mailing list Archives (accessible via public-inbox)

Archives are clonable: git clone --mirror https://inbox.libre-soc.org/libre-riscv-dev

Example config snippet for mirrors


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git