AdderGraphs.jl 2.33 KB
Newer Older
Rémi's avatar
Rémi committed
1
2
module AdderGraphs

Rémi's avatar
Rémi committed
3
4
abstract type AbstractInputEdge end

Rémi's avatar
Rémi committed
5
# OriginAdder: AdderNode(1, Vector{InputEdge}(), 0, 0, -1.0, 0)
Rémi's avatar
Rémi committed
6
7
mutable struct AdderNode
    value::Int
Rémi's avatar
Rémi committed
8
    inputs::Vector{AbstractInputEdge}
Rémi's avatar
Rémi committed
9
10
11
    msb_out::Int
    lsb_out::Int
    error_out::Float64
Rémi's avatar
Rémi committed
12
13
14
    nb_full_adders::Int
end

Rémi's avatar
Rémi committed
15
16
17
18
19
20
mutable struct InputEdge <: AbstractInputEdge
    input_adder::AdderNode
    shift::Int
    is_negative::Bool
end

Rémi's avatar
Rémi committed
21
22
23
24
25
26
27
28
29
function origin_addernode()
    return AdderNode(1, Vector{InputEdge}(), 0, 0, -1.0, 0)
end

function AdderNode(value::Int, inputs::Vector{InputEdge})
    return AdderNode(value, inputs, 0, 0, -1.0, 0)
end


Rémi's avatar
Rémi committed
30
mutable struct AdderGraph
Rémi's avatar
Rémi committed
31
    origin::AdderNode
Rémi's avatar
Rémi committed
32
33
34
    constants::Vector{AdderNode}
    outputs::Vector{Int}
    full_adders_computed::Bool
Rémi's avatar
Rémi committed
35
    error_in::Float64
Rémi's avatar
Rémi committed
36
    errors_computed::Bool
Rémi's avatar
Rémi committed
37
    data_paths::Bool
Rémi's avatar
Rémi committed
38
39
end

Rémi's avatar
Rémi committed
40
41
42
function AdderGraph(c::Vector{AdderNode}, v::Vector{Int})
    return AdderGraph(origin_addernode(), c, v, false, 0.0, false, false)
end
Rémi's avatar
Rémi committed
43
function AdderGraph()
Rémi's avatar
Rémi committed
44
    return AdderGraph(Vector{AdderNode}(), Vector{Int}())
Rémi's avatar
Rémi committed
45
46
end
function AdderGraph(v::Vector{Int})
Rémi's avatar
Rémi committed
47
    return AdderGraph(Vector{AdderNode}(), v)
48
49
end
function AdderGraph(c::Vector{AdderNode})
Rémi's avatar
Rémi committed
50
    return AdderGraph(c, Vector{Int}())
51
end
Rémi's avatar
Rémi committed
52

Rémi's avatar
Rémi committed
53

Rémi's avatar
Rémi committed
54
55
export AdderGraph
export AdderNode
Rémi's avatar
Rémi committed
56
export InputEdge
Rémi's avatar
Rémi committed
57

Rémi's avatar
Rémi committed
58
include("utils.jl")
Rémi's avatar
Rémi committed
59
60
61
62
63
64
65
66
67
include("inputedge.jl")
include("addernode.jl")
include("addergraph.jl")

# Utils
export odd


# InputEdge
Rémi's avatar
Rémi committed
68
69
70
71
export get_input_addernode
export get_input_shift
export is_negative_input
export get_input_addernode_value
Rémi's avatar
Rémi committed
72
73
74


# AdderGraph
Rémi's avatar
Rémi committed
75
export length
Rémi's avatar
Rémi committed
76
export get_nodes
Rémi's avatar
Rémi committed
77
export push_node!
Rémi's avatar
Rémi committed
78
export push_output!
Rémi's avatar
Rémi committed
79
export get_outputs
Rémi's avatar
Rémi committed
80
81
export get_error_in
export set_error_in!
Rémi's avatar
Rémi committed
82
export are_data_paths_set
Rémi's avatar
Rémi committed
83
export set_data_paths!
Rémi's avatar
Rémi committed
84
export are_errors_computed
Rémi's avatar
Rémi committed
85
export set_errors_computed!
Rémi's avatar
Rémi committed
86
export are_full_adders_computed
Rémi's avatar
Rémi committed
87
export set_full_adders_computed!
88
export get_origin
Rémi's avatar
Rémi committed
89
export get_total_nb_full_adders
Rémi's avatar
Rémi committed
90
91
92
export get_addernode_by_value
export read_addergraph
export write_addergraph
Rémi's avatar
Rémi committed
93
94
95


# AdderNode
Rémi's avatar
Rémi committed
96
97
export get_value
export get_input_edges
Rémi's avatar
Rémi committed
98
99
export get_adder_msb
export get_adder_lsb
Rémi's avatar
Rémi committed
100
export get_adder_error
Rémi's avatar
Rémi committed
101
export set_adder_msb!
Rémi's avatar
Rémi committed
102
103
104
105
export set_adder_lsb!
export set_adder_error!
export get_input_addernodes
export get_input_addernode_values
Rémi's avatar
Rémi committed
106
export get_input_shifts
Rémi's avatar
Rémi committed
107
108
109
export are_negative_inputs
export get_adder_msb_in
export get_adder_lsb_in
Rémi's avatar
Rémi committed
110
111
export get_nb_full_adders
export set_nb_full_adders!
Rémi's avatar
Rémi committed
112
113
export produce_addernode

Rémi's avatar
Rémi committed
114

Rémi's avatar
Rémi committed
115

Rémi's avatar
Rémi committed
116
end # module