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

Subversion Repositories myblaze

[/] [myblaze/] [trunk/] [rtl/] [functions.py] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rockee
# -*- coding: utf-8 -*-
2
"""
3
    functions.py
4
    ============
5
 
6
    Functions
7
 
8 5 rockee
    :copyright: Copyright (c) 2010 Jian Luo
9
    :author-email: jian.luo.cn(at_)gmail.com
10
    :license: LGPL, see LICENSE for details
11 2 rockee
    :revision: $Id: functions.py 5 2010-11-21 10:59:30Z rockee $
12
"""
13
 
14
from myhdl import *
15
from defines import *
16
 
17
def align_mem_load(data, size, address):
18
    """
19
    Aligns the memory load operation (Big endian decoding)
20
    """
21
    result = intbv(0)[32:]
22
 
23
    if size == transfer_size_type.BYTE:
24
        if address[1] == 0:
25
            if address[0] == 0:
26
                result[:] = data[32:24]
27
            else:
28
                result[:] = data[24:16]
29
        else:
30
            if address[0] == 0:
31
                result[:] = data[16:8]
32
            else:
33
                result[:] = data[8:]
34
    elif size == transfer_size_type.HALFWORD:
35
        if address[1] == 0:
36
            result[:] = data[32:16]
37
        else:
38
            result[:] = data[16:]
39
    else:
40
        result[:] = data
41
 
42
    return result
43
 
44
def decode_mem_store(address, size):
45
    result = intbv(0)[4:]
46
 
47
    if size == transfer_size_type.BYTE:
48
        if address[1] == 0:
49
            if address[0] == 0:
50
                result[:] = 0b1000
51
            else:
52
                result[:] = 0b0100
53
        else:
54
            if address[0] == 0:
55
                result[:] = 0b0010
56
            else:
57
                result[:] = 0b0001
58
    elif size == transfer_size_type.HALFWORD:
59
        if address[1] == 0:
60
            result[:] = 0b1100
61
        else:
62
            result[:] = 0b0011
63
    else:
64
        result[:] = 0b1111
65
 
66
    #if size == transfer_size_type.BYTE:
67
        #if address[1] == 0:
68
            #if address[0] == 0:
69
                #result[:] = 0b0001
70
            #else:
71
                #result[:] = 0b0010
72
        #else:
73
            #if address[0] == 0:
74
                #result[:] = 0b0100
75
            #else:
76
                #result[:] = 0b1000
77
    #elif size == transfer_size_type.HALFWORD:
78
        #if address[1] == 0:
79
            #result[:] = 0b0011
80
        #else:
81
            #result[:] = 0b1100
82
    #else:
83
        #result[:] = 0b1111
84
 
85
    return result
86
 
87
def align_mem_store(data, size):
88
    result = intbv(0)[32:]
89
    if size == transfer_size_type.BYTE:
90
        result[:] = concat(data[8:], data[8:], data[8:], data[8:])
91
    elif size == transfer_size_type.HALFWORD:
92
        result[:] = concat(data[16:], data[16:])
93
    else:
94
        result[:] = data
95
    return result
96
 
97
 
98
def forward_condition(reg_write, reg_a, reg_d):
99
    result = reg_write and (reg_a == reg_d)
100
    return result
101
 
102
def select_register_data(reg_dat, reg_x, wb_dat, write):
103
    tmp = intbv(0)[CFG_DMEM_WIDTH:]
104
    if reg_x == 0:
105
        tmp[:] = 0
106
    elif write:
107
        tmp[:] = wb_dat
108
    else:
109
        tmp[:] = reg_dat
110
    return tmp
111
 
112
def add(a, b, ci):
113
    aa = intbv(0)[CFG_DMEM_WIDTH+2:]
114
    bb = intbv(0)[CFG_DMEM_WIDTH+2:]
115
    cc = intbv(0)[CFG_DMEM_WIDTH+2:]
116
    result = intbv(0)[CFG_DMEM_WIDTH+1:]
117
 
118
    aa[:] = concat(False, a, True)
119
    bb[:] = concat(False, b, ci)
120
    cc[:] = aa.signed() + bb.signed()
121
 
122
    result[:] = cc[CFG_DMEM_WIDTH+2:1]
123
    return result
124
 
125
def repeat(input, times):
126
    result = intbv(0)[times:]
127
    for i in range(times):
128
        result[i] = input
129
    return result
130
 
131
def bit_reverse(input, width):
132
    result = intbv(0)[width:]
133
    for i in range(width):
134
        result[width-1-i] = input[i]
135
    return result
136
 
137
# XXX: Verilog don't allow veriable in slice,
138
#      the workaround is to write 2 function instead, but that's ugly :-(
139
def sign_extend(value, fill, from_size=16, to_size=32):
140
    tmp = intbv(0)[to_size:]
141
    size = to_size-from_size
142
    for i in range(size):
143
        tmp[to_size-1-i] = fill
144
    tmp[from_size:] = value[from_size:]
145
    return tmp
146
 
147
def sign_extend8(value, fill):
148
    tmp = intbv(0)[CFG_DMEM_WIDTH:]
149
    size = CFG_DMEM_WIDTH-8
150
    for i in range(size):
151
        tmp[CFG_DMEM_WIDTH-1-i] = fill
152
    tmp[8:] = value[8:]
153
    return tmp
154
 
155
def sign_extend16(value, fill):
156
    tmp = intbv(0)[CFG_DMEM_WIDTH:]
157
    size = CFG_DMEM_WIDTH-16
158
    for i in range(size):
159
        tmp[CFG_DMEM_WIDTH-1-i] = fill
160
    tmp[16:] = value[16:]
161
    return tmp
162
 
163
#def select_register_data(reg_dat, reg, wb_dat, write)
164
 
165
### EOF ###
166
# vim:smarttab:sts=4:ts=4:sw=4:et:ai:tw=80:
167
 

powered by: WebSVN 2.1.0

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