Beispiel #1
0
 def last_condition(self):
     cond = self._make_cond(self.last_cond)
     if cond is not None:
         cond = vtypes.AndList(self.state == self.state_count, cond)
     else:
         cond = self.state == self.state_count
     return cond
Beispiel #2
0
    def make_output(self):
        data, valid, ready = self.output_vars
        
        # Inserting delayed registers
        ovar = self
        if self.stage_id is not None:
            for i in range(self.stage_id, self.df.max_stage_id):
                ovar = self.df.stage(ovar, preg=ovar)
        
        if not isinstance(data, (vtypes.Wire, vtypes.Output)):
            raise TypeError('Data signal must be Wire, not %s' % str(type(data)))
        else:
            ovar.df.m.Assign( data(ovar.data) )

        my_valid = vtypes.Int(1) if ovar.valid is None else ovar.valid 
        if valid is None:
            pass
        elif not isinstance(valid, (vtypes.Wire, vtypes.Output)):
            raise TypeError('Valid signal must be Wire, not %s' % str(type(valid)))
        else:
            ovar.df.m.Assign( valid(my_valid) )

        if ready is None:
            ready = vtypes.Int(1)

        if ovar.ready is not None:
            prev_subst = ovar.ready._get_subst()
            if len(prev_subst) == 0:
                ovar.df.m.Assign( ovar.ready(ready) )
            elif isinstance(prev_subst[0].right, vtypes.Int) and (prev_subst[0].right.value==1):
                ovar.ready.subst[0].overwrite_right( ready )
            else:
                ovar.ready.subst[0].overwrite_right( vtypes.AndList(prev_subst[0].right, ready) )

        ovar.dst_data = _PipelineInterface(data, valid, ready, output=True)
Beispiel #3
0
 def current_condition(self):
     cond = self.next_kwargs['cond'] if 'cond' in self.next_kwargs else None
     if cond is not None:
         cond = vtypes.AndList(self.state == self.state_count, cond)
     else:
         cond = self.state == self.state_count
     return cond
Beispiel #4
0
 def make_valid(self, valid, ready):
     if ready is not None and valid is not None:
         next_valid = vtypes.AndList(valid, ready)
     elif ready is not None:
         next_valid = ready
     elif valid is not None:
         next_valid = valid
     else:
         next_valid = None
     return next_valid
Beispiel #5
0
 def pack_valid(self, lvalid, rvalid):
     if rvalid is not None and lvalid is not None:
         return vtypes.AndList(lvalid, rvalid)
     elif rvalid is None and lvalid is None:
         return None
     elif rvalid is None:
         return lvalid
     elif lvalid is None:
         return rvalid
     return None
Beispiel #6
0
def _and_vars(*vars):
    if not vars:
        return vtypes.Int(1)
    ret = None
    for var in vars:
        if var is None:
            continue
        if ret is None:
            ret = var
        else:
            ret = vtypes.AndList(ret, var)
    if ret is None:
        return vtypes.Int(1)
    return ret
Beispiel #7
0
    def _make_prev(self, data, valid, ready, width=None, initval=0):
        tmp_data = self._add_reg('data', self.tmp_count, width=width, initval=initval)
        tmp_valid = valid
        tmp_ready = ready
        
        self.tmp_count += 1

        if valid is not None and ready is not None:
            data_cond = vtypes.AndList(valid, ready)
        elif valid is not None:
            data_cond = valid
        elif ready is not None:
            data_cond = ready
        else:
            data_cond = None
        
        self.seq.add( tmp_data(data), cond=data_cond )

        return tmp_data, tmp_valid, tmp_ready
Beispiel #8
0
    def _make_tmp(self, data, valid, ready, width=None, initval=0, acc_ops=()):
        tmp_data = self._add_reg(
            'data', self.tmp_count, width=width, initval=initval)

        if valid is not None:
            tmp_valid = self._add_reg('valid', self.tmp_count, initval=0)
        else:
            tmp_valid = None

        if ready:
            tmp_ready = self._add_wire('ready', self.tmp_count)
        else:
            tmp_ready = None

        self.tmp_count += 1

        # all ready
        all_ready = None
        for r in ready:
            if r is None:
                continue
            if all_ready is None:
                all_ready = r
            else:
                all_ready = vtypes.AndList(all_ready, r)

        # data
        data_cond_vars = []
        if valid is not None:
            data_cond_vars.append(valid)
        if tmp_ready is not None:
            data_cond_vars.append(all_ready)
            if tmp_valid is not None:
                data_cond_vars.append(vtypes.OrList(
                    tmp_ready, vtypes.Not(tmp_valid)))
            else:
                data_cond_vars.append(tmp_ready)

        if len(data_cond_vars) == 0:
            data_cond = None
        elif len(data_cond_vars) == 1:
            data_cond = data_cond_vars[0]
        else:
            data_cond = vtypes.AndList(*data_cond_vars)

        # Accumulator
        for op in acc_ops:
            if not isinstance(op, type):
                data = op(tmp_data, data)
            elif issubclass(op, vtypes._BinaryOperator):
                data = op(tmp_data, data)
            elif issubclass(op, vtypes._UnaryOperator):
                data = op(data)

            if not isinstance(data, vtypes._Numeric):
                raise TypeError("Operator '%s' returns unsupported object type '%s'."
                                % (str(op), str(type(data))))

        self.seq.add(tmp_data(data), cond=data_cond)

        # valid
        valid_cond_vars = []
        if tmp_ready is not None:
            valid_cond_vars.append(all_ready)
            ordy = vtypes.OrList(tmp_ready, vtypes.Not(tmp_valid))
            valid_cond_vars.append(ordy)

        if len(valid_cond_vars) == 0:
            valid_cond = None
        elif len(valid_cond_vars) == 1:
            valid_cond = valid_cond_vars[0]
        else:
            valid_cond = vtypes.AndList(*valid_cond_vars)

        if tmp_valid is not None:
            if tmp_ready is not None:
                self.seq.add(tmp_valid(0), cond=vtypes.AndList(
                    tmp_valid, tmp_ready))
            self.seq.add(tmp_valid(valid), cond=valid_cond)

        # ready
        if tmp_ready is not None:
            ordy = vtypes.AndList(vtypes.OrList(
                tmp_ready, vtypes.Not(tmp_valid)), valid)
            for r in ready:
                _connect_ready(self.m, r, ordy)

        return tmp_data, tmp_valid, tmp_ready