aboutsummaryrefslogtreecommitdiffstats
path: root/fpga_interchange/type_wire.h
diff options
context:
space:
mode:
authorKeith Rothman <537074+litghost@users.noreply.github.com>2021-03-22 17:46:00 -0700
committerKeith Rothman <537074+litghost@users.noreply.github.com>2021-03-23 08:16:50 -0700
commit8d1eb0a1950816d4dcaae40fb230acff0d1afeef (patch)
tree4c0fac8969789f144c2296e4a3208565a57597f7 /fpga_interchange/type_wire.h
parent9ef412c2cc623ef84d8fb866734f3892fc6f127c (diff)
downloadnextpnr-8d1eb0a1950816d4dcaae40fb230acff0d1afeef.tar.gz
nextpnr-8d1eb0a1950816d4dcaae40fb230acff0d1afeef.tar.bz2
nextpnr-8d1eb0a1950816d4dcaae40fb230acff0d1afeef.zip
Initial lookahead for FPGA interchange.
Currently the lookahead is disabled by default because of the time to compute and RAM usage. However it does appear to work reasonably well in testing. Further effort is required to lower RAM usage after initial computation, and explore trade-off for cheaper time to compute. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
Diffstat (limited to 'fpga_interchange/type_wire.h')
-rw-r--r--fpga_interchange/type_wire.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/fpga_interchange/type_wire.h b/fpga_interchange/type_wire.h
new file mode 100644
index 00000000..f2a675ef
--- /dev/null
+++ b/fpga_interchange/type_wire.h
@@ -0,0 +1,111 @@
+/*
+ * nextpnr -- Next Generation Place and Route
+ *
+ * Copyright (C) 2021 Symbiflow Authors
+ *
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+#ifndef TYPE_WIRE_H
+#define TYPE_WIRE_H
+
+#include <algorithm>
+#include <vector>
+
+#include "nextpnr_namespaces.h"
+#include "nextpnr_types.h"
+
+#include "lookahead.capnp.h"
+
+NEXTPNR_NAMESPACE_BEGIN
+
+struct Context;
+
+struct TypeWireId
+{
+ TypeWireId() : type(-1), index(-1) {}
+ TypeWireId(const Context *ctx, WireId wire_inst);
+
+ explicit TypeWireId(lookahead_storage::TypeWireId::Reader reader);
+ void to_builder(lookahead_storage::TypeWireId::Builder builder) const;
+
+ bool operator==(const TypeWireId &other) const { return type == other.type && index == other.index; }
+ bool operator!=(const TypeWireId &other) const { return type != other.type || index != other.index; }
+ bool operator<(const TypeWireId &other) const
+ {
+ return type < other.type || (type == other.type && index < other.index);
+ }
+
+ int32_t type;
+ int32_t index;
+};
+
+struct TypeWirePair
+{
+ TypeWireId src;
+ TypeWireId dst;
+
+ TypeWirePair() = default;
+ explicit TypeWirePair(lookahead_storage::TypeWirePair::Reader reader);
+ void to_builder(lookahead_storage::TypeWirePair::Builder builder) const;
+
+ bool operator==(const TypeWirePair &other) const { return src == other.src && dst == other.dst; }
+ bool operator!=(const TypeWirePair &other) const { return src != other.src || dst != other.dst; }
+};
+
+struct TypeWireSet
+{
+ public:
+ TypeWireSet(const Context *ctx, WireId wire);
+ std::size_t hash() const { return hash_; }
+
+ bool operator==(const TypeWireSet &other) const { return wire_types_ == other.wire_types_; }
+ bool operator!=(const TypeWireSet &other) const { return wire_types_ != other.wire_types_; }
+
+ private:
+ std::size_t hash_;
+ std::vector<TypeWireId> wire_types_;
+};
+
+NEXTPNR_NAMESPACE_END
+
+template <> struct std::hash<NEXTPNR_NAMESPACE_PREFIX TypeWireId>
+{
+ std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX TypeWireId &wire) const noexcept
+ {
+ std::size_t seed = 0;
+ boost::hash_combine(seed, std::hash<int>()(wire.type));
+ boost::hash_combine(seed, std::hash<int>()(wire.index));
+ return seed;
+ }
+};
+
+template <> struct std::hash<NEXTPNR_NAMESPACE_PREFIX TypeWirePair>
+{
+ std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX TypeWirePair &pair) const noexcept
+ {
+ std::size_t seed = 0;
+ boost::hash_combine(seed, std::hash<NEXTPNR_NAMESPACE_PREFIX TypeWireId>()(pair.src));
+ boost::hash_combine(seed, std::hash<NEXTPNR_NAMESPACE_PREFIX TypeWireId>()(pair.dst));
+ return seed;
+ }
+};
+
+template <> struct std::hash<NEXTPNR_NAMESPACE_PREFIX TypeWireSet>
+{
+ std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX TypeWireSet &set) const noexcept { return set.hash(); }
+};
+
+#endif /* TYPE_WIRE_H */