AdderGraphs.jl 2.25 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

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

Rémi's avatar
Rémi committed
54

Rémi's avatar
Rémi committed
55
56
57

export AdderGraph
export AdderNode
Rémi's avatar
Rémi committed
58
export InputEdge
Rémi's avatar
Rémi committed
59

Rémi's avatar
Rémi committed
60
include("utils.jl")
Rémi's avatar
Rémi committed
61
62
63
64
65
66
67
68
69
70
71
72
include("inputedge.jl")
include("addernode.jl")
include("addergraph.jl")

# Utils
export odd


# InputEdge


# AdderGraph
Rémi's avatar
Rémi committed
73
74
export length
export push_node!
Rémi's avatar
Rémi committed
75
export push_output!
Rémi's avatar
Rémi committed
76
export read_addergraph
Rémi's avatar
Rémi committed
77
78
export write_addergraph
export get_outputs
Rémi's avatar
Rémi committed
79
export are_data_paths_set
Rémi's avatar
Rémi committed
80
81
82
83
84
85
86
export compute_internal_msb_lsb!
export get_error_in
export set_error_in!



# AdderNode
Rémi's avatar
Rémi committed
87
88
89
90
export get_adder_msb
export get_adder_lsb
export get_adder_msbin
export get_adder_lsbin
Rémi's avatar
Rémi committed
91
92
93
94
export set_adder_msb!
export set_adder_msb!
export set_adder_msbin!
export set_adder_msbin!
Rémi's avatar
Rémi committed
95
96
97
98
export get_previous_addernodes_value
export get_addernode_index_by_value
export get_previous_addernodes_index
export get_input_shifts
Rémi's avatar
Rémi committed
99
100
101
export get_subtractions
export produce_addernode

Rémi's avatar
Rémi committed
102
103

end # module