Files
OpenSTA/include/sta/Clock.hh
T

293 lines
9.5 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2026-03-10 13:21:17 -07:00
// Copyright (c) 2026, Parallax Software, Inc.
2018-09-28 08:54:21 -07:00
//
// This program 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2022-01-04 10:17:08 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 08:54:21 -07:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
2022-01-04 10:17:08 -07:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2025-01-21 18:54:33 -07:00
//
// The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software.
//
// Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// This notice may not be removed or altered from any source distribution.
2018-09-28 08:54:21 -07:00
2020-02-15 17:13:16 -07:00
#pragma once
2018-09-28 08:54:21 -07:00
2026-01-03 16:59:35 -08:00
#include <map>
2026-03-15 14:35:24 -07:00
#include <string>
2026-01-03 16:59:35 -08:00
2026-04-15 09:38:10 -07:00
#include "GraphClass.hh"
2020-04-05 14:53:44 -07:00
#include "MinMax.hh"
#include "RiseFallMinMax.hh"
#include "SdcClass.hh"
#include "SdcCmdComment.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
2026-01-03 16:59:35 -08:00
using ClkHpinEdgeMap = std::map<Pin*, PinSet*>;
2018-09-28 08:54:21 -07:00
class Clock : public SdcCmdComment
{
public:
~Clock();
2026-03-28 19:13:35 -07:00
const std::string &name() const { return name_; }
2018-09-28 08:54:21 -07:00
float period() const { return period_; }
// Virtual clocks have no pins.
bool isVirtual() const;
2019-10-25 08:51:59 -07:00
const PinSet &pins() const { return pins_; }
// The clock source pin's leaf pins.
// If the source pin is hierarchical, the leaf pins are:
// hierarchical input - load pins inside the hierarchical instance
// hierarchical output - load pins outside the hierarchical instance
PinSet &leafPins() { return leaf_pins_; }
const PinSet &leafPins() const { return leaf_pins_; }
2018-09-28 08:54:21 -07:00
// Clock pin used by input/output delay for propagated generated
// clock insertion delay.
2023-01-19 11:23:45 -07:00
const Pin *defaultPin() const;
2018-09-28 08:54:21 -07:00
bool addToPins() const { return add_to_pins_; }
void setAddToPins(bool add_to_pins);
2026-04-16 18:42:26 -07:00
const FloatSeq &waveform() const { return waveform_; }
2019-11-11 15:30:19 -07:00
ClockEdge *edge(const RiseFall *rf) const;
2018-09-28 08:54:21 -07:00
int index() const { return index_; }
bool isPropagated() const { return is_propagated_; }
void setIsPropagated(bool propagated);
bool isIdeal() const { return !is_propagated_; }
2018-09-28 08:54:21 -07:00
// Ideal clock slew.
2019-11-11 15:30:19 -07:00
void slew(const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const MinMax *min_max,
// Return values.
float &slew,
bool &exists) const;
2018-09-28 08:54:21 -07:00
// Return zero (default) if no slew exists.
2019-11-11 15:30:19 -07:00
float slew(const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const MinMax *min_max) const;
2019-11-11 15:30:19 -07:00
void setSlew(const RiseFall *rf,
2026-01-03 16:59:35 -08:00
const MinMax *min_max,
float slew);
2019-11-11 15:30:19 -07:00
void setSlew(const RiseFallBoth *rf,
2026-01-03 16:59:35 -08:00
const MinMaxAll *min_max,
float slew);
2018-09-28 08:54:21 -07:00
void removeSlew();
2023-01-19 11:23:45 -07:00
const RiseFallMinMax &slews() const { return slews_; }
2019-11-11 15:30:19 -07:00
void setSlewLimit(const RiseFallBoth *rf,
2026-04-13 14:58:16 -07:00
PathClkOrData clk_data,
2026-01-03 16:59:35 -08:00
const MinMax *min_max,
float slew);
2019-11-11 15:30:19 -07:00
void slewLimit(const RiseFall *rf,
2026-04-13 14:58:16 -07:00
PathClkOrData clk_data,
2026-01-03 16:59:35 -08:00
const MinMax *min_max,
// Return values.
float &slew,
bool &exists) const;
2026-04-25 10:35:42 -07:00
const ClockUncertainties &uncertainties() const { return uncertainties_; }
2018-09-28 08:54:21 -07:00
void uncertainty(const SetupHold *setup_hold,
2026-01-03 16:59:35 -08:00
// Return values.
float &uncertainty,
bool &exists) const;
2018-09-28 08:54:21 -07:00
void setUncertainty(const SetupHoldAll *setup_hold,
2026-01-03 16:59:35 -08:00
float uncertainty);
2018-09-28 08:54:21 -07:00
void setUncertainty(const SetupHold *setup_hold,
2026-01-03 16:59:35 -08:00
float uncertainty);
2018-09-28 08:54:21 -07:00
void removeUncertainty(const SetupHoldAll *setup_hold);
void setPeriod(float period);
void setWaveform(FloatSeq *waveform);
2023-01-19 11:23:45 -07:00
void addPin(const Pin *pin);
void deletePin(const Pin *pin);
2019-10-25 08:51:59 -07:00
void makeLeafPins(const Network *network);
2018-09-28 08:54:21 -07:00
bool isGenerated() const;
bool isGeneratedWithPropagatedMaster() const;
void generate(const Clock *src_clk);
Pin *srcPin() const { return src_pin_; }
Clock *masterClk() const { return master_clk_; }
bool masterClkInfered() const { return master_clk_infered_; }
void setInferedMasterClk(Clock *master_clk);
int divideBy() const { return divide_by_; }
int multiplyBy() const { return multiply_by_; }
float dutyCycle() const { return duty_cycle_; }
bool invert() const { return invert_; }
2026-04-16 18:42:26 -07:00
const IntSeq &edges() const { return edges_; }
const FloatSeq &edgeShifts() const { return edge_shifts_; }
2019-11-11 15:30:19 -07:00
const RiseFall *masterClkEdgeTr(const RiseFall *rf) const;
2018-09-28 08:54:21 -07:00
bool combinational() const { return combinational_; }
bool isDivideByOneCombinational() const;
bool generatedUpToDate() const;
void srcPinVertices(VertexSet &src_vertices,
2026-01-03 16:59:35 -08:00
const Network *network,
Graph *graph);
2018-09-28 08:54:21 -07:00
// True if the generated clock waveform is up to date.
bool waveformValid() const { return waveform_valid_; }
void waveformInvalid();
protected:
2023-01-19 11:23:45 -07:00
// Private to Sdc::makeClock.
2026-03-28 19:13:35 -07:00
Clock(std::string_view name,
2026-01-03 16:59:35 -08:00
int index,
2023-01-19 11:23:45 -07:00
const Network *network);
2026-04-16 18:42:26 -07:00
void initClk(const PinSet &pins,
2026-01-03 16:59:35 -08:00
bool add_to_pins,
float period,
2026-04-16 18:42:26 -07:00
const FloatSeq &waveform,
2026-03-28 19:13:35 -07:00
std::string_view comment,
2026-01-03 16:59:35 -08:00
const Network *network);
2026-04-16 18:42:26 -07:00
void initGeneratedClk(const PinSet &pins,
2026-01-03 16:59:35 -08:00
bool add_to_pins,
Pin *src_pin,
Clock *master_clk,
int divide_by,
int multiply_by,
float duty_cycle,
bool invert,
bool combinational,
2026-04-16 18:42:26 -07:00
const IntSeq &edges,
const FloatSeq &edge_shifts,
2026-01-03 16:59:35 -08:00
bool is_propagated,
2026-03-28 19:13:35 -07:00
std::string_view comment,
2026-01-03 16:59:35 -08:00
const Network *network);
2026-04-16 18:42:26 -07:00
void setPins(const PinSet &pins,
2026-01-03 16:59:35 -08:00
const Network *network);
2018-09-28 08:54:21 -07:00
void setMasterClk(Clock *master);
void makeClkEdges();
void setClkEdgeTimes();
2019-11-11 15:30:19 -07:00
void setClkEdgeTime(const RiseFall *rf);
2018-09-28 08:54:21 -07:00
void generateScaledClk(const Clock *src_clk,
2026-01-03 16:59:35 -08:00
float scale);
2018-09-28 08:54:21 -07:00
void generateEdgesClk(const Clock *src_clk);
2026-03-28 19:13:35 -07:00
std::string name_;
2019-10-25 08:51:59 -07:00
PinSet pins_;
2026-04-15 09:38:10 -07:00
bool add_to_pins_{false};
2018-09-28 08:54:21 -07:00
// Hierarchical pins in pins_ become driver pins through the pin.
2019-10-25 08:51:59 -07:00
PinSet leaf_pins_;
2026-04-15 09:38:10 -07:00
float period_{0.0};
2026-04-16 18:42:26 -07:00
FloatSeq waveform_;
2026-04-15 09:38:10 -07:00
bool waveform_valid_{false};
2018-09-28 08:54:21 -07:00
const int index_;
2026-04-16 18:42:26 -07:00
std::array<ClockEdge*, RiseFall::index_count> clk_edges_;
2026-04-15 09:38:10 -07:00
bool is_propagated_{false};
2018-09-28 08:54:21 -07:00
RiseFallMinMax slews_;
RiseFallMinMax slew_limits_[path_clk_or_data_count];
2026-04-25 10:35:42 -07:00
ClockUncertainties uncertainties_;
2026-04-15 09:38:10 -07:00
bool is_generated_{false};
2018-09-28 08:54:21 -07:00
// Generated clock variables.
2026-04-15 09:38:10 -07:00
Pin *src_pin_{nullptr};
Clock *master_clk_{nullptr};
2018-09-28 08:54:21 -07:00
// True if the master clock is infered rather than specified by command.
2026-04-15 09:38:10 -07:00
bool master_clk_infered_{false};
int divide_by_{0};
int multiply_by_{0};
float duty_cycle_{0};
bool invert_{false};
bool combinational_{false};
2026-04-16 18:42:26 -07:00
IntSeq edges_;
FloatSeq edge_shifts_;
2018-09-28 08:54:21 -07:00
private:
friend class Sdc;
};
// A single rise/fall edge of a clock
class ClockEdge
{
public:
Clock *clock() const { return clock_; }
2025-03-30 15:27:53 -07:00
const RiseFall *transition() const { return rf_; }
2018-09-28 08:54:21 -07:00
float time() const { return time_; }
2026-03-15 14:35:24 -07:00
const std::string &name() const { return name_; }
2018-09-28 08:54:21 -07:00
int index() const { return index_; }
ClockEdge *opposite() const;
// Pulse width if this is the leading edge of the pulse.
float pulseWidth() const;
friend class Clock; // builder
private:
2025-03-30 15:27:53 -07:00
ClockEdge(Clock *clock,
const RiseFall *rf);
2018-09-28 08:54:21 -07:00
void setTime(float time);
Clock *clock_;
2025-03-30 15:27:53 -07:00
const RiseFall *rf_;
2026-03-15 14:35:24 -07:00
std::string name_;
2026-04-15 09:38:10 -07:00
float time_{0.0};
2018-09-28 08:54:21 -07:00
int index_;
};
int
clkCmp(const Clock *clk1,
const Clock *clk2);
int
2023-01-19 11:23:45 -07:00
clkEdgeCmp(const ClockEdge *clk_edge1,
2026-01-03 16:59:35 -08:00
const ClockEdge *clk_edge2);
2018-09-28 08:54:21 -07:00
bool
2023-01-19 11:23:45 -07:00
clkEdgeLess(const ClockEdge *clk_edge1,
2026-01-03 16:59:35 -08:00
const ClockEdge *clk_edge2);
2018-09-28 08:54:21 -07:00
class ClockNameLess
{
public:
2023-01-19 11:23:45 -07:00
bool operator()(const Clock *clk1,
2026-03-28 19:13:35 -07:00
const Clock *clk2) const
{
return clk1->name() < clk2->name();
}
2018-09-28 08:54:21 -07:00
};
////////////////////////////////////////////////////////////////
class InterClockUncertainty
{
public:
InterClockUncertainty(const Clock *src,
2026-01-03 16:59:35 -08:00
const Clock *target);
2018-09-28 08:54:21 -07:00
const Clock *src() const { return src_; }
const Clock *target() const { return target_; }
2019-11-11 15:30:19 -07:00
void uncertainty(const RiseFall *src_rf,
2026-01-03 16:59:35 -08:00
const RiseFall *tgt_rf,
const SetupHold *setup_hold,
// Return values.
float &uncertainty,
bool &exists) const;
2019-11-11 15:30:19 -07:00
void setUncertainty(const RiseFallBoth *src_rf,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *tgt_rf,
const SetupHoldAll *setup_hold,
float uncertainty);
2019-11-11 15:30:19 -07:00
void removeUncertainty(const RiseFallBoth *src_rf,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *tgt_rf,
const SetupHoldAll *setup_hold);
2025-03-30 15:27:53 -07:00
const RiseFallMinMax *uncertainties(const RiseFall *src_rf) const;
2026-01-03 16:59:35 -08:00
[[nodiscard]] bool empty() const;
2018-09-28 08:54:21 -07:00
private:
const Clock *src_;
const Clock *target_;
2019-11-11 15:30:19 -07:00
RiseFallMinMax uncertainties_[RiseFall::index_count];
2018-09-28 08:54:21 -07:00
};
class InterClockUncertaintyLess
{
public:
bool operator()(const InterClockUncertainty *inter1,
2026-01-03 16:59:35 -08:00
const InterClockUncertainty *inter2) const;
2018-09-28 08:54:21 -07:00
};
2023-01-19 11:23:45 -07:00
ClockSeq
sortByName(ClockSet *set);
int
compare(const ClockSet *set1,
const ClockSet *set2);
2018-09-28 08:54:21 -07:00
2026-04-13 14:58:16 -07:00
} // namespace sta