OpenCores
URL https://opencores.org/ocsvn/dmt_tx/dmt_tx/trunk

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [rtl/] [cmath.py] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 dannori
 
2
from myhdl import *
3
 
4
def cadd(a_re, a_im, b_re, b_im, y_re, y_im, overflow, width=8):
5
  '''Complex add
6
 
7
  I/O pins:
8
  =========
9
  a         : input a
10
  b         : input b
11
  y         : output a + b
12
  overflow  : signal overflow
13
 
14
  parameter:
15
  ==========
16
  width : data width for input and output
17
  '''
18
  @always_comb
19
  def logic():
20
    m = 2**(width-1)
21
 
22
    #
23
    # Real value calculation
24
    if (a_re + b_re) >= m:
25
      y_re.next = m-1
26
      ovfl_re = True
27
 
28
    elif (a_re + b_re) < -m:
29
      y_re.next = -m
30
      ovfl_re = True
31
 
32
    else:
33
      y_re.next = a_re + b_re
34
      ovfl_re = False
35
 
36
    #
37
    # Imaginary add
38
    if (a_im + b_im) >= m:
39
      y_im.next = m-1
40
      ovfl_im = True
41
 
42
    elif (a_im + b_im) < -m:
43
      y_im.next = -m
44
      ovfl_im = True
45
 
46
    else:
47
      y_im.next = a_im + b_im
48
      ovfl_im = False
49
 
50
    overflow.next = ovfl_re or ovfl_im
51
 
52
  return instances()
53
 
54
 
55
def csub(a_re, a_im, b_re, b_im, y_re, y_im, overflow, width=8):
56
 
57
  @always_comb
58
  def logic():
59
    m = 2**(width-1)
60
 
61
    #
62
    # Real value calculation
63
    if (a_re - b_re) >= m:
64
      y_re.next = m-1
65
      ovfl_re = True
66
 
67
    elif (a_re - b_re) < -m:
68
      y_re.next = -m
69
      ovfl_re = True
70
 
71
    else:
72
      y_re.next = a_re - b_re
73
      ovfl_re = False
74
 
75
    #
76
    # Imaginary add
77
    if (a_im - b_im) >= m:
78
      y_im.next = m-1
79
      ovfl_im = True
80
 
81
    elif (a_im - b_im) < -m:
82
      y_im.next = -m
83
      ovfl_im = True
84
 
85
    else:
86
      y_im.next = a_im - b_im
87
      ovfl_im = False
88
 
89
    overflow.next = ovfl_re or ovfl_im
90
 
91
  return instances()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.