/* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. ChibiOS/RT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. ChibiOS/RT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /** * @file chmempools.c * @brief Memory Pools code. * * @addtogroup pools * @details Memory Pools related APIs and services. *

Operation mode

* The Memory Pools APIs allow to allocate/free fixed size objects in * constant time and reliably without memory fragmentation * problems.
* Memory Pools do not enforce any alignment constraint on the * contained object however the objects must be properly aligned * to contain a pointer to void. * @pre In order to use the memory pools APIs the @p CH_USE_MEMPOOLS option * must be enabled in @p chconf.h. * @{ */ #include "ch.h" #if CH_USE_MEMPOOLS || defined(__DOXYGEN__) /** * @brief Initializes an empty memory pool. * * @param[out] mp pointer to a @p MemoryPool structure * @param[in] size the size of the objects contained in this memory pool, * the minimum accepted size is the size of a pointer to * void. * @param[in] provider memory provider function for the memory pool or * @p NULL if the pool is not allowed to grow * automatically * * @init */ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) { chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit"); mp->mp_next = NULL; mp->mp_object_size = size; mp->mp_provider = provider; } /** * @brief Loads a memory pool with an array of static objects. * @pre The memory pool must be already been initialized. * @pre The array elements must be of the right size for the specified * memory pool. * @post The memory pool contains the elements of the input array. * * @param[in] mp pointer to a @p MemoryPool structure * @param[in] p pointer to the array first element * @param[in] n number of elements in the array * * @api */ void chPoolLoadArray(MemoryPool *mp, void *p, size_t n) { chDbgCheck((mp != NULL) && (n != 0), "chPoolLoadArray"); while (n) { chPoolAdd(mp, p); p = (void *)(((uint8_t *)p) + mp->mp_object_size); n--; } } /** * @brief Allocates an object from a memory pool. * @pre The memory pool must be already been initialized. * * @param[in] mp pointer to a @p MemoryPool structure * @return The pointer to the allocated object. * @retval NULL if pool is empty. * * @iclass */ void *chPoolAllocI(MemoryPool *mp) { void *objp; chDbgCheckClassI(); chDbgCheck(mp != NULL, "chPoolAllocI"); if ((objp = mp->mp_next) != NULL) mp->mp_next = mp->mp_next->ph_next; else if (mp->mp_provider != NULL) objp = mp->mp_provider(mp->mp_object_size); return objp; } /** * @brief Allocates an object from a memory pool. * @pre The memory pool must be already been initialized. * * @param[in] mp pointer to a @p MemoryPool structure * @return The pointer to the allocated object. * @retval NULL if pool is empty. * * @api */ void *chPoolAlloc(MemoryPool *mp) { void *objp; chSysLock(); objp = chPoolAllocI(mp); chSysUnlock(); return objp; } /** * @brief Releases an object into a memory pool. * @pre The memory pool must be already been initialized. * @pre The freed object must be of the right size for the specified * memory pool. * @pre The object must be properly aligned to contain a pointer to void. * * @param[in] mp pointer to a @p MemoryPool structure * @param[in] objp the pointer to the object to be released * * @iclass */ void chPoolFreeI(MemoryPool *mp, void *objp) { struct pool_header *php = objp; chDbgCheckClassI(); chDbgCheck((mp != NULL) && (objp != NULL), "chPoolFreeI"); php->ph_next = mp->mp_next; mp->mp_next = php; } /** * @brief Releases an object into a memory pool. * @pre The memory pool must be already been initialized. * @pre The freed object must be of the right size for the specified * memory pool. * @pre The object must be properly aligned to contain a pointer to void. * * @param[in] mp pointer to a @p MemoryPool structure * @param[in] objp the pointer to the object to be released * * @api */ void chPoolFree(MemoryPool *mp, void *objp) { chSysLock(); chPoolFreeI(mp, objp); chSysUnlock(); } #endif /* CH_USE_MEMPOOLS */ /** @} */ 'n74' href='#n74'>74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2012  Claire Xenia Wolf <claire@yosyshq.com>
 *
 *  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 "kernel/register.h"
#include "kernel/celltypes.h"
#include "kernel/rtlil.h"
#include "kernel/log.h"

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN

struct SynthAchronixPass : public ScriptPass {
  SynthAchronixPass() : ScriptPass("synth_achronix", "synthesis for Acrhonix Speedster22i FPGAs.") { }

  void help() override
  {
    //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
    log("\n");
    log("    synth_achronix [options]\n");
    log("\n");
    log("This command runs synthesis for Achronix Speedster eFPGAs. This work is still experimental.\n");
    log("\n");
    log("    -top <module>\n");
    log("        use the specified module as top module (default='top')\n");
    log("\n");
    log("    -vout <file>\n");
    log("        write the design to the specified Verilog netlist file. writing of an\n");
    log("        output file is omitted if this parameter is not specified.\n");
    log("\n");
    log("    -run <from_label>:<to_label>\n");
    log("        only run the commands between the labels (see below). an empty\n");
    log("        from label is synonymous to 'begin', and empty to label is\n");
    log("        synonymous to the end of the command list.\n");
    log("\n");
    log("    -noflatten\n");
    log("        do not flatten design before synthesis\n");
    log("\n");
    log("    -retime\n");
    log("        run 'abc' with '-dff -D 1' options\n");
    log("\n");
    log("\n");
    log("The following commands are executed by this synthesis command:\n");
    help_script();
    log("\n");
  }

  string top_opt, family_opt, vout_file;
  bool retime, flatten;

  void clear_flags() override
  {
    top_opt = "-auto-top";
    vout_file = "";
    retime = false;
    flatten = true;
  }

  void execute(std::vector<std::string> args, RTLIL::Design *design) override
  {
    string run_from, run_to;
    clear_flags();

    size_t argidx;
    for (argidx = 1; argidx < args.size(); argidx++)
      {
        if (args[argidx] == "-top" && argidx+1 < args.size()) {
          top_opt = "-top " + args[++argidx];
          continue;
        }
        if (args[argidx] == "-vout" && argidx+1 < args.size()) {
          vout_file = args[++argidx];
          continue;
        }
        if (args[argidx] == "-run" && argidx+1 < args.size()) {
          size_t pos = args[argidx+1].find(':');
          if (pos == std::string::npos)
            break;
          run_from = args[++argidx].substr(0, pos);
          run_to = args[argidx].substr(pos+1);
          continue;
        }
        if (args[argidx] == "-noflatten") {
          flatten = false;
          continue;
        }
        if (args[argidx] == "-retime") {
          retime = true;
          continue;
        }
        break;
      }
    extra_args(args, argidx, design);

    if (!design->full_selection())
      log_cmd_error("This command only operates on fully selected designs!\n");

    log_header(design, "Executing SYNTH_ACHRONIX pass.\n");
    log_push();

    run_script(design, run_from, run_to);

    log_pop();
  }

  void script() override
  {
    if (check_label("begin"))
      {
        run("read_verilog -sv -lib +/achronix/speedster22i/cells_sim.v");
        run(stringf("hierarchy -check %s", help_mode ? "-top <top>" : top_opt.c_str()));
      }

    if (flatten && check_label("flatten", "(unless -noflatten)"))
      {
        run("proc");
        run("flatten");
        run("tribuf -logic");
        run("deminout");
      }

    if (check_label("coarse"))
      {
        run("synth -run coarse");
      }

    if (check_label("fine"))
      {
        run("opt -fast -mux_undef -undriven -fine -full");
        run("memory_map");
        run("opt -undriven -fine");
        run("opt -fine");
        run("techmap -map +/techmap.v");
        run("opt -full");
        run("clean -purge");
        run("setundef -undriven -zero");
        run("dfflegalize -cell $_DFF_P_ x");
        if (retime || help_mode)
          run("abc -markgroups -dff -D 1", "(only if -retime)");
      }

    if (check_label("map_luts"))
      {
        run("abc -lut 4" + string(retime ? " -dff -D 1" : ""));
        run("clean");
      }

    if (check_label("map_cells"))
      {
        run("iopadmap -bits -outpad $__outpad I:O -inpad $__inpad O:I");
        run("techmap -map +/achronix/speedster22i/cells_map.v");
        // VT: not done yet run("dffinit -highlow -ff DFF q power_up");
        run("clean -purge");
      }

    if (check_label("check"))
      {
        run("hierarchy -check");
        run("stat");
        run("check -noinit");
        run("blackbox =A:whitebox");
      }

    if (check_label("vout"))
      {
        if (!vout_file.empty() || help_mode)
          run(stringf("write_verilog -nodec -attr2comment -defparam -renameprefix syn_ %s",
                      help_mode ? "<file-name>" : vout_file.c_str()));
      }
  }
} SynthAchronixPass;

PRIVATE_NAMESPACE_END