diff --git a/atpg b/atpg index 6c33244..fcca67d 100755 Binary files a/atpg and b/atpg differ diff --git a/circuit.cpp b/circuit.cpp index aa9ef8b..8dea274 100644 --- a/circuit.cpp +++ b/circuit.cpp @@ -27,4 +27,57 @@ void Circuit::cal_topo_index() { } } } +} + +int Circuit::cal_gate_value(const Gate* &gate) { + int res; + + switch(gate->type) { + case Gate::NOT: + res = !gate->inputs[0]->value; + break; + case Gate::BUF: + res = gate->inputs[0]->value; + break; + case Gate::AND: + res = gate->inputs[0]->value; + for(int i=1; iinputs.size(); i++) { + res &= gate->inputs[i]->value; + } + break; + case Gate::NAND: + res = gate->inputs[0]->value; + for(int i=1; iinputs.size(); i++) { + res &= gate->inputs[i]->value; + } + res = !res; + break; + case Gate::OR: + res = gate->inputs[0]->value; + for(int i=1; iinputs.size(); i++) { + res |= gate->inputs[i]->value; + } + break; + case Gate::NOR: + res = gate->inputs[0]->value; + for(int i=1; iinputs.size(); i++) { + res |= gate->inputs[i]->value; + } + res = !res; + break; + case Gate::XOR: + res = gate->inputs[0]->value; + for(int i=1; iinputs.size(); i++) { + res ^= gate->inputs[i]->value; + } + break; + case Gate::XNOR: + res = gate->inputs[0]->value; + for(int i=1; iinputs.size(); i++) { + res ^= gate->inputs[i]->value; + } + res = !res; + break; + } + return res; } \ No newline at end of file diff --git a/circuit.h b/circuit.h index a893714..64d4ff7 100644 --- a/circuit.h +++ b/circuit.h @@ -1,3 +1,5 @@ +#pragma once + #include #include #include @@ -6,8 +8,8 @@ class Gate { public: int topo; std::string name; - enum { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT, OUTPUT } type; - enum { VAL_ZERO, VAL_ONE, VAL_X } value; + enum Type { AND, NAND, OR, NOR, XOR, XNOR, NOT, BUF, INPUT, OUTPUT } type; + int value; std::vector outputs; std::vector inputs; }; @@ -19,6 +21,7 @@ std::vector POs; std::vector gates; std::unordered_map name2gate; void parse_from_file(const char *filename); +int cal_gate_value(const Gate* &gate); void cal_topo_index(); -void cal_headlines(); + }; \ No newline at end of file diff --git a/ls.cpp b/ls.cpp new file mode 100644 index 0000000..0471d53 --- /dev/null +++ b/ls.cpp @@ -0,0 +1,35 @@ +#include "ls.h" + + +std::vector local_search(Circuit* circuit) { + + // local search vector + std::vector vec; + + init_vector(circuit, &vec); + + init_circuit(circuit); + + printf("local search!\n"); + + return std::vector(); +} + + +void init_circuit(Circuit* circuit) { + for(auto pi : circuit->PIs) { + pi->value = rand() % 2; + } +} + +void init_vector(Circuit* circuit, std::vector *vec) { + for(auto pi : circuit->PIs) { + vec->push_back(pi); + } + for(auto gate : circuit->gates) { + // fanout stem + if(gate->outputs.size() >= 2) { + vec->push_back(gate); + } + } +} \ No newline at end of file diff --git a/ls.h b/ls.h new file mode 100644 index 0000000..270c45c --- /dev/null +++ b/ls.h @@ -0,0 +1,9 @@ +#pragma once + +#include "circuit.h" + +std::vector local_search(Circuit* circuit); + +// private +void init_circuit(Circuit* circuit); +void init_vector(Circuit* circuit, std::vector *vec); \ No newline at end of file diff --git a/main.cpp b/main.cpp index e1c8ad7..9954451 100644 --- a/main.cpp +++ b/main.cpp @@ -2,8 +2,8 @@ #include #include - #include "circuit.h" +#include "ls.h" int main(int args, char* argv[]) { @@ -21,11 +21,22 @@ int main(int args, char* argv[]) { printf("PO:\t%ld\n", circuit.POs.size()); printf("Gates:\t%ld\n", circuit.name2gate.size()); + int cnt = 0; + for(auto& gate: circuit.gates) { + if(gate->outputs.size() > 2) { + cnt++; + } + } + printf("Stem:\t%d\n", cnt); + printf("cal topo index ...\n"); circuit.cal_topo_index(); for(Gate* gate : circuit.gates) { assert(gate->topo > 0); } + srand(19260817); + local_search(&circuit); + return 0; } \ No newline at end of file diff --git a/parser.cpp b/parser.cpp index fe276e7..83f8f89 100644 --- a/parser.cpp +++ b/parser.cpp @@ -73,7 +73,6 @@ void Circuit::parse_from_file(const char *filename) { Gate* gate = new Gate(); gate->name = tokens[0]; - gate->value = Gate::VAL_X; for(auto &in : ins) { if(!name2gate.count(in)) { @@ -109,10 +108,9 @@ void Circuit::parse_from_file(const char *filename) { Gate* gate = new Gate(); gate->name = tokens[2]; gate->type = Gate::INPUT; - gate->value = Gate::VAL_X; name2gate.insert(std::make_pair(gate->name, gate)); - gates.push_back(gate); + // gates.push_back(gate); PIs.push_back(gate); } // gate