SST 16.0.0
Structural Simulation Toolkit
sst_types.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_SST_TYPES_H
13#define SST_CORE_SST_TYPES_H
14
15#include "sst/core/util/bit_util.h"
16
17#include <cstddef>
18#include <cstdint>
19#include <iosfwd>
20#include <limits>
21#include <ostream>
22#include <utility>
23
24namespace SST {
25
26/**********************************************************************
27 * Common types used by SST
28 **********************************************************************/
29using ComponentId_t = uint64_t;
30using StatisticId_t = uint64_t;
31using LinkId_t = uint64_t;
32using HandlerId_t = uint64_t;
33using Cycle_t = uint64_t;
34using SimTime_t = uint64_t;
35using Time_t = double;
36
37/* PorModuleId_t is a <port name,index> pair*/
38using PortModuleId_t = std::pair<std::string, size_t>;
39
40// Macro to use when printing SimTime_t in printf or Output
41#define PRI_SIMTIME PRIu64
42
43// Flag used to indicate that a version of *EnableAll* was used to enable stats in an object
44static constexpr StatisticId_t STATALL_ID = std::numeric_limits<StatisticId_t>::max();
45
46constexpr SimTime_t MAX_SIMTIME_T = SST::bit_util::type_max<ComponentId_t>;
47
48/**********************************************************************
49 * constexpr variable and inline functions used to build ID for
50 * generating the various IDs for elements
51 *
52 * The Component and Statistic IDs use subfields in the following way:
53 * 31:0 - Bottom 30 bits are the ID of the parent Component
54 * 47:32 - The next 16 bits is the ID of a SubComponent with that
55 * component
56 * 63:48 - The top 16 bits are unused for Component IDs, but they are
57 * used to uniquely identify a statistic with a (Sub)Component
58 **********************************************************************/
59
60/** Value used to indicate a Component's ID has not yet been set */
61constexpr ComponentId_t UNSET_COMPONENT_ID = SST::bit_util::type_max<ComponentId_t>;
62
63/** Value used to indicate a Statistic's ID has not yet been set */
64constexpr StatisticId_t UNSET_STATISTIC_ID = SST::bit_util::type_max<StatisticId_t>;
65
66/** Number of bits used for the parent component base ID */
67constexpr size_t COMPONENT_ID_BITS = 32;
68
69/**
70 Gets the parent Component base ID from a general (i.e. either Component or SubComponent) ID
71
72 @param complete_id The complete Component ID, including any SubComponent ID
73
74 @return Parent Component base ID
75*/
76inline ComponentId_t
77COMPONENT_ID_MASK(ComponentId_t complete_id)
78{
79 return complete_id & SST::bit_util::lower_mask<ComponentId_t, COMPONENT_ID_BITS>;
80}
81
82/** Number of bits used to store the ID of a SubComponent and part of the complete ID */
83constexpr size_t SUBCOMPONENT_ID_BITS = 16;
84
85/**
86 Get the SubComponent portion of the Component ID
87
88 @param complete_id The complete Component ID, including any SubComponent ID
89
90 @return SubComponent portion of the Component ID
91*/
92inline ComponentId_t
93SUBCOMPONENT_ID_MASK(ComponentId_t complete_id)
94{
95 return (complete_id >> COMPONENT_ID_BITS) & SST::bit_util::lower_mask<ComponentId_t, SUBCOMPONENT_ID_BITS>;
96}
97
98/**
99 Create a component ID from the specified base Component ID and SubComponent ID
100
101 @param comp_id Base ID of the parent Component
102
103 @param sub_comp_id ID of the SubComponent with the Component
104
105 @return Complete ID of the SubComponent
106*/
107inline ComponentId_t
108SUBCOMPONENT_ID_CREATE(ComponentId_t comp_id, ComponentId_t sub_comp_id)
109{
110 return (sub_comp_id << COMPONENT_ID_BITS) | comp_id;
111}
112
113/** Number of bits in the complete Component ID */
114constexpr size_t CONFIG_COMPONENT_ID_BITS = (COMPONENT_ID_BITS + SUBCOMPONENT_ID_BITS);
115
116/**
117 Gets the Complete Component ID (Component + SubComponent portions), masking out any Statistic ID that may be in the
118 upper bits
119
120 @param complete_id Complete ID (including any Statistic ID)
121
122 @return Component portion of the ID with any Statistic ID masked out
123*/
124inline ComponentId_t
125CONFIG_COMPONENT_ID_MASK(ComponentId_t complete_id)
126{
127 return complete_id & SST::bit_util::lower_mask<ComponentId_t, COMPONENT_ID_BITS + SUBCOMPONENT_ID_BITS>;
128}
129
130/**
131 Create a Statistic ID from the complete ComponentID and ID of the Statistic within that Component
132
133 @param comp_id Complete ID of the Component + SubComponent
134
135 @param stat_id Statistic ID
136
137 @return Combined ID for the Statistic
138*/
139inline StatisticId_t
140STATISTIC_ID_CREATE(ComponentId_t comp_id, StatisticId_t stat_id)
141{
142 return (stat_id << CONFIG_COMPONENT_ID_BITS) | comp_id;
143}
144
145/**
146 Determine whether a SubComponent is Component Defined (i.e. anonymous) or not
147
148 @param complete_id Component Component ID for the SubComponent
149
150 @return True if SubComponent is Anonymous, false otherwise
151*/
152inline bool
153COMPDEFINED_SUBCOMPONENT_ID_MASK(ComponentId_t complete_id)
154{
155 return complete_id >> (sizeof(ComponentId_t) * 8 - 1);
156}
157
158/**
159 Create a component ID from the specified base Component ID and SubComponent ID, with the component defined
160 (i.e. anonymous) bit set.
161
162 @param comp_id Base ID of the parent Component
163
164 @param sub_comp_id ID of the SubComponent
165
166 @return Complete ID for the SubComponent with the component defined bit set
167*/
168inline ComponentId_t
169COMPDEFINED_SUBCOMPONENT_ID_CREATE(ComponentId_t comp_id, ComponentId_t sub_comp_id)
170{
171 return (sub_comp_id << COMPONENT_ID_BITS) | comp_id | SST::bit_util::upper_mask<ComponentId_t, 1>;
172}
173
174using watts [[deprecated("watts will be removed in SST 17")]] = double;
175using joules [[deprecated("joules will be removed in SST 17")]] = double;
176using farads [[deprecated("farads will be removed in SST 17")]] = double;
177using volts [[deprecated("volts will be removed in SST 17")]] = double;
178
179#ifndef LIKELY
180#define LIKELY(x) __builtin_expect((int)(x), 1)
181#define UNLIKELY(x) __builtin_expect((int)(x), 0)
182#endif
183
184enum class SimulationRunMode {
185 UNKNOWN, /*!< Unknown mode - Invalid for running */
186 INIT, /*!< Initialize-only. Useful for debugging initialization and graph generation */
187 RUN, /*!< Run-only. Useful when restoring from a checkpoint (not currently supported) */
188 BOTH /*!< Default. Both initialize and Run the simulation */
189};
190
191// Overload the << operator for SimulationRunMode
192std::ostream& operator<<(std::ostream& os, const SimulationRunMode& mode);
193
194/**
195 Struct used as a base class for all AttachPoint metadata passed to
196 registration functions. Needed so that dynamic cast can be used
197 since different tools may pass different metadata through the
198 AttachPoints.
199 */
200struct AttachPointMetaData
201{
202 AttachPointMetaData() {}
203 virtual ~AttachPointMetaData() {}
204};
205
206} // namespace SST
207
208#endif // SST_CORE_SST_TYPES_H