Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel LiteX
migen
Commits
314a6c77
Commit
314a6c77
authored
11 years ago
by
Sebastien Bourdeauducq
Browse files
Options
Download
Email Patches
Plain Diff
corelogic: complex arithmetic support
parent
badba896
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
examples/basic/complex.py
examples/basic/complex.py
+16
-0
migen/corelogic/complex.py
migen/corelogic/complex.py
+52
-0
No files found.
examples/basic/complex.py
0 → 100644
View file @
314a6c77
from
migen.corelogic.complex
import
*
from
migen.fhdl
import
verilog
w
=
Complex
(
32
,
42
)
A
=
SignalC
(
16
)
B
=
SignalC
(
16
)
Bw
=
SignalC
(
16
,
variable
=
True
)
C
=
SignalC
(
16
)
D
=
SignalC
(
16
)
sync
=
[
Bw
.
eq
(
B
*
w
),
C
.
eq
(
A
+
Bw
),
D
.
eq
(
A
-
Bw
)
]
print
(
verilog
.
convert
(
Fragment
(
sync
=
sync
)))
This diff is collapsed.
Click to expand it.
migen/corelogic/complex.py
0 → 100644
View file @
314a6c77
from
migen.fhdl.structure
import
*
class
Complex
:
def
__init__
(
self
,
real
,
imag
):
self
.
real
=
real
self
.
imag
=
imag
def
__neg__
(
self
):
return
Complex
(
-
self
.
real
,
-
self
.
imag
)
def
__add__
(
self
,
other
):
if
isinstance
(
other
,
Complex
):
return
Complex
(
self
.
real
+
other
.
real
,
self
.
imag
+
other
.
imag
)
else
:
return
Complex
(
self
.
real
+
other
,
self
.
imag
)
__radd__
=
__add__
def
__sub__
(
self
,
other
):
if
isinstance
(
other
,
Complex
):
return
Complex
(
self
.
real
-
other
.
real
,
self
.
imag
-
other
.
imag
)
else
:
return
Complex
(
self
.
real
-
other
,
self
.
imag
)
def
__rsub__
(
self
,
other
):
if
isinstance
(
other
,
Complex
):
return
Complex
(
other
.
real
-
self
.
real
,
other
.
imag
-
self
.
imag
)
else
:
return
Complex
(
other
-
self
.
real
,
-
self
.
imag
)
def
__mul__
(
self
,
other
):
if
isinstance
(
other
,
Complex
):
return
Complex
(
self
.
real
*
other
.
real
-
self
.
imag
*
other
.
imag
,
self
.
real
*
other
.
imag
+
self
.
imag
*
other
.
real
)
else
:
return
Complex
(
self
.
real
*
other
,
self
.
imag
*
other
)
__rmul__
=
__mul__
def
__lshift__
(
self
,
other
):
return
Complex
(
self
.
real
<<
other
,
self
.
imag
<<
other
)
def
__rshift__
(
self
,
other
):
return
Complex
(
self
.
real
>>
other
,
self
.
imag
>>
other
)
def
__repr__
(
self
):
return
repr
(
self
.
real
)
+
" + "
+
repr
(
self
.
imag
)
+
"j"
def
eq
(
self
,
r
):
if
isinstance
(
r
,
Complex
):
return
self
.
real
.
eq
(
r
.
real
),
self
.
imag
.
eq
(
r
.
imag
)
else
:
return
self
.
real
.
eq
(
r
),
self
.
imag
.
eq
(
0
)
def
SignalC
(
*
args
,
**
kwargs
):
real
=
Signal
(
*
args
,
**
kwargs
)
imag
=
Signal
(
*
args
,
**
kwargs
)
return
Complex
(
real
,
imag
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment