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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [rtl/] [flipSign.py] - Blame information for rev 27

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 dannori
 
2
from myhdl import *
3
 
4
 
5
def flipSign(in_data, out_data, overflow, width):
6
  '''Flip the sign of the input value.
7
  The min value will cause an overflow and will be saturated to the max
8
  value when flipping its sign
9
 
10
  I/O Signals
11
  ===========
12
  in_data   : signal with the input data
13
  out_data  : signal having input data with flipped sign
14
  overflow  : signal whether an overflow occured. That only happens for
15
              min value, as the max value = abs(min) - 1
16
 
17
  Parameter
18
  =========
19
  width     : input width
20
  '''
21
 
22
  min = -2**(width-1)
23
  max = 2**(width-1)-1
24
 
25
  @always_comb
26
  def rtl():
27
 
28
    if in_data == min:
29
      out_data.next = max
30
      overflow.next = True
31
    else:
32
      out_data.next = -in_data
33
      overflow.next = False
34
 
35
  return instances()
36
 

powered by: WebSVN 2.1.0

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