From 13e6cd30991ebccf549ec932805c847416668765 Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Tue, 25 Nov 2014 18:07:30 +0100 Subject: partial implementation of gen_demultiplexer diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..022e5a0 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +CXX=g++ -std=c++11 -ggdb -Wall -Wextra +LDFLAGS=-lgecodedriver -lgecodesearch -lgecodeminimodel -lgecodeint -lgecodekernel -lgecodesupport -lgecodegist + +all: gen_demultiplexer diff --git a/gen_demultiplexer.cpp b/gen_demultiplexer.cpp new file mode 100644 index 0000000..edf4acd --- /dev/null +++ b/gen_demultiplexer.cpp @@ -0,0 +1,156 @@ +#include +#include +#include + + +#include +#include +#include +#include + +using namespace std; +using namespace Gecode; + +string S() { + return ""; +} + +template +string S(T v, Ts... vs) { + stringstream ss; + ss << v << S(vs...); + return ss.str(); +} + +struct Op { + string inst; + IntVar *v; + int delay; +}; + +struct Demultiplexer : public Space { + + IntVarArray op_times; + array ops; + uint opCount; + + Demultiplexer(vector bits) + : op_times(*this, 17, 0, 16) + { + /// post the problem (the instructions and their temporal + /// dependencies) + + // only one op per time slice + distinct(*this, op_times); + + // the final jump + auto &jump = op(2, " ijmp"); + at(jump, 15); + + // rising flanks + for (uint i=0; i 1) { + auto nextOp = op(delay - 1, "; 1 clock cycle delay"); + rel(*this, *(o.v) + 1 == *(nextOp.v)); + } + + return o; + } + + /// helper for constraint formulation + + void after(Op& pre, Op& post, int delay_min=0, int delay_max=-1) { + rel(*this, *(pre.v) + pre.delay + delay_min <= *(post.v)); + if (delay_max >= 0) + rel(*this, *(pre.v) + pre.delay + delay_max >= *(post.v)); + } + + void at(Op& op, int time_min, int time_max=-1) { + if (time_max == -1) + time_max = time_min; + rel(*this, *(op.v) >= time_min); + rel(*this, *(op.v) <= time_max); + } + + /// return resulting instruction stream + + string print() { + stringstream ss; + print(ss, false); + return ss.str(); + } + + /// gecode boilerplate + Demultiplexer(bool share, Demultiplexer &o) + : Space(share, o), + ops(o.ops), + opCount(o.opCount) + { + op_times.update(*this, share, o.op_times); + } + + virtual Space* copy(bool share) { + return new Demultiplexer(share, *this); + } + + void print(ostream &o, bool printTimes=true) const { + multimap timedOps; + for (uint i=0; i gp("print solution"); + // Gist::Options go; + // go.inspect.click(&gp); + // Gist::dfs(d, go); + + DFS e(d); + delete d; + d = e.next(); + if (d) { + cout << d->print(); + delete d; + }else{ + cerr << "no instruction sequence found"; + } +} -- cgit v0.10.1