Commit 3ba4b7da authored by Rémi's avatar Rémi
Browse files

Add functions to AdderGraphs.jl

parent a1f644d8
function odd(number::Int)
if number == 0
return 0
end
while mod(number, 2) == 0
number = div(number, 2)
end
return number
end
# function odd(number::Int)
# if number == 0
# return 0
# end
# while mod(number, 2) == 0
# number = div(number, 2)
# end
# return number
# end
function coefs_fit_specs_varepsilon(
b0, b1, b2, a1, a2,
......
name = "AdderGraphs"
uuid = "818587fb-0c22-4279-a2b9-8b16b5360b71"
version = "0.1.0"
version = "0.1.1"
......@@ -18,21 +18,22 @@ mutable struct AdderGraph
constants::Vector{AdderNode}
outputs::Vector{Int}
full_adders_computed::Bool
error_in::Float64
errors_computed::Bool
data_paths::Bool
end
function AdderGraph()
return AdderGraph(Vector{AdderNode}(), Vector{Int}(), false, false, false)
return AdderGraph(Vector{AdderNode}(), Vector{Int}(), 0.0, false, false, false)
end
function AdderGraph(v::Vector{Int})
return AdderGraph(Vector{AdderNode}(), v, false, false, false)
return AdderGraph(Vector{AdderNode}(), v, 0.0, false, false, false)
end
function AdderGraph(c::Vector{AdderNode}, v::Vector{Int})
return AdderGraph(c, v, false, false, false)
return AdderGraph(c, v, 0.0, false, false, false)
end
function AdderGraph(c::Vector{AdderNode})
return AdderGraph(c, Vector{Int}(), false, false, false)
return AdderGraph(c, Vector{Int}(), 0.0, false, false, false)
end
function AdderNode(value::Int, inputs::Vector{Int}, input_shifts::Vector{Int}, subtraction::Vector{Bool})
......@@ -56,5 +57,13 @@ export get_adder_msbin
export get_adder_lsbin
export add_data_msb_lsb!
export add_data_msbin_lsbin!
export get_error_in
export set_error_in!
export odd
export get_previous_addernodes_value
export get_addernode_index_by_value
export get_previous_addernodes_index
export get_previous_addernodes
export get_input_shifts
end # module
......@@ -19,6 +19,15 @@ function push_output!(addergraph::AdderGraph, output_value::Int)
end
function get_error_in(addergraph::AdderGraph)
return addergraph.error_in
end
function set_error_in!(addergraph::AdderGraph, error_in::Float64)
addergraph.error_in = error_in
return addergraph
end
function are_data_paths_set(addergraph::AdderGraph)
return addergraph.data_paths
......@@ -132,6 +141,37 @@ function get_value(addernode::AdderNode)
end
function get_previous_addernodes_value(addernode::AdderNode)
return addernode.inputs
end
function get_input_shifts(addernode::AdderNode)
return addernode.input_shifts
end
function get_addernode_index_by_value(addergraph::AdderGraph, value::Int)
node_index = 0
addernodes = get_nodes(addergraph)
for i in 1:length(addernodes)
addernode = addernodes[i]
if get_value(addernode) == value
node_index = i
break
end
end
return node_index
end
function get_previous_addernodes_index(addergraph::AdderGraph, addernode::AdderNode)
return get_addernode_index_by_value.(addergraph, get_previous_addernodes_value(addernode))
end
function get_previous_addernodes(addergraph::AdderGraph, addernode::AdderNode)
return inputs
end
function read_addergraph(s::String)
addergraph = AdderGraph()
......
......@@ -3,16 +3,15 @@ function num_constraints(model::Model)
return sum(num_constraints(model, F, S) for (F, S) in list_of_constraint_types(model))
end
function odd(number::Int)
if number == 0
return 0
end
while mod(number, 2) == 0
number = div(number, 2)
end
return number
end
# function odd(number::Int)
# if number == 0
# return 0
# end
# while mod(number, 2) == 0
# number = div(number, 2)
# end
# return number
# end
import Base.isempty
function isempty(solution::DesignSolution)
......
function odd(number::Int)
if number == 0
return 0
end
while mod(number, 2) == 0
number = div(number, 2)
end
return number
end
# function odd(number::Int)
# if number == 0
# return 0
# end
# while mod(number, 2) == 0
# number = div(number, 2)
# end
# return number
# end
function get_min_wordlength(number::Int)
return round(Int, max(log2(odd(abs(number))), 1), RoundUp)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment