/* * nextpnr -- Next Generation Place and Route * * Copyright (C) 2021 gatecat * * 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. * */ #include "log.h" #include "nextpnr.h" #include "util.h" #include NEXTPNR_NAMESPACE_BEGIN namespace { struct GlobalVist { PipId downhill = PipId(); int total_hops = 0; int global_hops = 0; bool operator<(const GlobalVist &other) const { return (total_hops < other.total_hops) || ((total_hops == other.total_hops) && (global_hops > other.global_hops)); } }; // This is our main global routing implementation. It is used both to actually route globals; and also to discover if // global buffers have available short routes from their source for auto-placement static int route_global_arc(Context *ctx, NetInfo *net, size_t usr_idx, size_t phys_port_idx, int max_hops, bool dry_run) { auto &usr = net->users.at(usr_idx); WireId src = ctx->getNetinfoSourceWire(net); WireId dest = ctx->getNetinfoSinkWire(net, usr, phys_port_idx); if (dest == WireId()) { if (dry_run) return -1; else log_error("Arc %d.%d (%s.%s) of net %s has no sink wire!\n", int(usr_idx), int(phys_port_idx), ctx->nameOf(usr.cell), ctx->nameOf(usr.port), ctx->nameOf(net)); } // Consider any existing routing put in place by the site router, etc int start_hops = 0; while (net->wires.count(dest) && dest != src) { dest = ctx->getPipSrcWire(net->wires.at(dest).pip); ++start_hops; } // The main BFS implementation // Currently this is a backwards-BFS from sink to source (or pre-existing routing) that avoids general routing. It // currently aims for minimum hops as a primary goal and maximum global resource usage as a secondary goal. More // advanced heuristics will likely be needed for more complex situation WireId startpoint; GlobalVist best_visit; std::queue visit_queue; dict visits; visit_queue.push(dest); visits[dest].downhill = PipId(); visits[dest].total_hops = start_hops; while (!visit_queue.empty()) { WireId cursor = visit_queue.front(); visit_queue.pop(); auto &curr_visit = visits.at(cursor); // We're now at least one layer deeper than a valid visit, any further exploration is futile if (startpoint != WireId() && curr_visit.total_hops > best_visit.total_hops) break; // Valid end of routing if ((cursor == src) || (ctx->getBoundWireNet(cursor) == net)) { if (startpoint == WireId() || curr_visit < best_visit) { startpoint = cursor; best_visit = curr_visit; } } // Explore uphill for (auto pip : ctx->getPipsUphill(cursor)) { if (!dry_run && !ctx->checkPipAvailForNet(pip, net)) continue; WireId pip_src = ctx->getPipSrcWire(pip); if (!dry_run && !ctx->checkWireAvail(pip_src) && ctx->getBoundWireNet(pip_src) != net) continue; auto cat = ctx->get_wire_category(pip_src); if (!ctx->is_site_wire(pip_src) && cat == WIRE_CAT_GENERAL) continue; // never allow general routing GlobalVist next_visit; next_visit.downhill = pip; next_visit.total_hops = curr_visit.total_hops + 1; if (max_hops != -1 && next_visit.total_hops > max_hops) continue; next_visit.global_hops = curr
// dear imgui: Renderer + Platform Binding for Allegro 5
// (Info: Allegro 5 is a cross-platform general purpose library for handling windows, inputs, graphics, etc.)

// Implemented features:
//  [X] Renderer: User texture binding. Use 'ALLEGRO_BITMAP*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
//  [X] Platform: Clipboard support (from Allegro 5.1.12)
//  [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// Issues:
//  [ ] Renderer: The renderer is suboptimal as we need to unindex our buffers and convert vertices manually.
//  [ ] Platform: Missing gamepad support.

// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
// https://github.com/ocornut/imgui, Original Allegro 5 code by @birthggd

#pragma once

struct ALLEGRO_DISPLAY;
union ALLEGRO_EVENT;

IMGUI_IMPL_API bool     ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display);
IMGUI_IMPL_API void     ImGui_ImplAllegro5_Shutdown();
IMGUI_IMPL_API void     ImGui_ImplAllegro5_NewFrame();
IMGUI_IMPL_API void     ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data);
IMGUI_IMPL_API bool     ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT* event);

// Use if you want to reset your rendering device without losing ImGui state.
IMGUI_IMPL_API bool     ImGui_ImplAllegro5_CreateDeviceObjects();
IMGUI_IMPL_API void     ImGui_ImplAllegro5_InvalidateDeviceObjects();