Deleted Added
sdiff udiff text old ( 6026:45c8a91d1174 ) new ( 6128:fdfbd4c6e449 )
full compact
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 147 unchanged lines hidden (view full) ---

156 * This function breaks names up at periods and considers each subname
157 * separately.
158 * @param stat1 The first stat.
159 * @param stat2 The second stat.
160 * @return stat1's name is alphabetically before stat2's
161 */
162 static bool less(Info *stat1, Info *stat2);
163};
164struct StorageParams;
165
166template <class Stat, class Base>
167class InfoProxy : public Base
168{
169 protected:
170 Stat &s;
171
172 public:
173 InfoProxy(Stat &stat) : s(stat) {}
174
175 bool check() const { return s.check(); }
176 void prepare() { s.prepare(); }
177 void reset() { s.reset(); }
178 void
179 visit(Visit &visitor)
180 {
181 visitor.visit(*static_cast<Base *>(this));
182 }
183 bool zero() const { return s.zero(); }
184};
185
186class ScalarInfo : public Info
187{
188 public:
189 virtual Counter value() const = 0;
190 virtual Result result() const = 0;
191 virtual Result total() const = 0;
192};
193
194template <class Stat>
195class ScalarInfoProxy : public InfoProxy<Stat, ScalarInfo>
196{
197 public:
198 ScalarInfoProxy(Stat &stat) : InfoProxy<Stat, ScalarInfo>(stat) {}
199
200 Counter value() const { return this->s.value(); }
201 Result result() const { return this->s.result(); }
202 Result total() const { return this->s.total(); }
203};
204
205class VectorInfo : public Info
206{
207 public:
208 /** Names and descriptions of subfields. */
209 std::vector<std::string> subnames;
210 std::vector<std::string> subdescs;
211
212 public:
213 void enable();
214
215 public:
216 virtual size_type size() const = 0;
217 virtual const VCounter &value() const = 0;
218 virtual const VResult &result() const = 0;
219 virtual Result total() const = 0;
220};
221
222template <class Stat>
223class VectorInfoProxy : public InfoProxy<Stat, VectorInfo>
224{
225 protected:
226 mutable VCounter cvec;
227 mutable VResult rvec;
228
229 public:
230 VectorInfoProxy(Stat &stat) : InfoProxy<Stat, VectorInfo>(stat) {}
231
232 size_type size() const { return this->s.size(); }
233
234 VCounter &
235 value() const
236 {
237 this->s.value(cvec);
238 return cvec;

--- 16 unchanged lines hidden (view full) ---

255 Counter underflow;
256 Counter overflow;
257 VCounter cvec;
258 Counter sum;
259 Counter squares;
260 Counter samples;
261};
262
263class DistInfo : public Info
264{
265 public:
266 /** Local storage for the entry values, used for printing. */
267 DistData data;
268};
269
270template <class Stat>
271class DistInfoProxy : public InfoProxy<Stat, DistInfo>
272{
273 public:
274 DistInfoProxy(Stat &stat) : InfoProxy<Stat, DistInfo>(stat) {}
275};
276
277class VectorDistInfo : public Info
278{
279 public:
280 std::vector<DistData> data;
281
282 /** Names and descriptions of subfields. */
283 std::vector<std::string> subnames;
284 std::vector<std::string> subdescs;
285 void enable();
286
287 protected:
288 /** Local storage for the entry values, used for printing. */
289 mutable VResult rvec;
290
291 public:
292 virtual size_type size() const = 0;
293};
294
295template <class Stat>
296class VectorDistInfoProxy : public InfoProxy<Stat, VectorDistInfo>
297{
298 public:
299 VectorDistInfoProxy(Stat &stat) : InfoProxy<Stat, VectorDistInfo>(stat) {}
300
301 size_type size() const { return this->s.size(); }
302};
303
304class Vector2dInfo : public Info
305{
306 public:
307 /** Names and descriptions of subfields. */
308 std::vector<std::string> subnames;
309 std::vector<std::string> subdescs;
310 std::vector<std::string> y_subnames;
311
312 size_type x;
313 size_type y;
314
315 /** Local storage for the entry values, used for printing. */
316 mutable VCounter cvec;
317
318 void enable();
319};
320
321template <class Stat>
322class Vector2dInfoProxy : public InfoProxy<Stat, Vector2dInfo>
323{
324 public:
325 Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
326};
327
328class InfoAccess
329{
330 protected:
331 /** Set up an info class for this statistic */
332 void setInfo(Info *info);
333 /** Save Storage class parameters if any */

--- 21 unchanged lines hidden (view full) ---

355 /**
356 * Check that this stat has been set up properly and is ready for
357 * use
358 * @return true for success
359 */
360 bool check() const { return true; }
361};
362
363template <class Derived, template <class> class InfoProxyType>
364class DataWrap : public InfoAccess
365{
366 public:
367 typedef InfoProxyType<Derived> Info;
368
369 protected:
370 Derived &self() { return *static_cast<Derived *>(this); }
371
372 protected:
373 Info *
374 info()
375 {

--- 86 unchanged lines hidden (view full) ---

462 Derived &
463 prereq(const Stat &prereq)
464 {
465 this->info()->prereq = prereq.info();
466 return this->self();
467 }
468};
469
470template <class Derived, template <class> class InfoProxyType>
471class DataWrapVec : public DataWrap<Derived, InfoProxyType>
472{
473 public:
474 typedef InfoProxyType<Derived> Info;
475
476 // The following functions are specific to vectors. If you use them
477 // in a non vector context, you will get a nice compiler error!
478
479 /**
480 * Set the subfield name for the given index, and marks this stat to print
481 * at the end of simulation.
482 * @param index The subfield index.

--- 55 unchanged lines hidden (view full) ---

538 Info *info = this->info();
539
540 size_t size = self.size();
541 for (off_type i = 0; i < size; ++i)
542 self.data(i)->reset(info);
543 }
544};
545
546template <class Derived, template <class> class InfoProxyType>
547class DataWrapVec2d : public DataWrapVec<Derived, InfoProxyType>
548{
549 public:
550 typedef InfoProxyType<Derived> Info;
551
552 /**
553 * @warning This makes the assumption that if you're gonna subnames a 2d
554 * vector, you're subnaming across all y
555 */
556 Derived &
557 ysubnames(const char **names)
558 {

--- 183 unchanged lines hidden (view full) ---

742
743};
744
745/**
746 * Implementation of a scalar stat. The type of stat is determined by the
747 * Storage template.
748 */
749template <class Derived, class Stor>
750class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
751{
752 public:
753 typedef Stor Storage;
754 typedef typename Stor::Params Params;
755
756 protected:
757 /** The storage of this stat. */
758 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));

--- 97 unchanged lines hidden (view full) ---

856 Result total() { return result(); }
857
858 bool zero() { return result() == 0.0; }
859
860 void reset() { data()->reset(this->info()); }
861 void prepare() { data()->prepare(this->info()); }
862};
863
864class ProxyInfo : public ScalarInfo
865{
866 public:
867 std::string str() const { return to_string(value()); }
868 size_type size() const { return 1; }
869 bool check() const { return true; }
870 void prepare() { }
871 void reset() { }
872 bool zero() const { return value() == 0; }

--- 23 unchanged lines hidden (view full) ---

896 public:
897 FunctorProxy(T &func) : functor(&func) {}
898 Counter value() const { return (*functor)(); }
899 Result result() const { return (*functor)(); }
900 Result total() const { return (*functor)(); }
901};
902
903template <class Derived>
904class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
905{
906 private:
907 ProxyInfo *proxy;
908
909 public:
910 ValueBase() : proxy(NULL) { }
911 ~ValueBase() { if (proxy) delete proxy; }
912

--- 159 unchanged lines hidden (view full) ---

1072 }
1073};
1074
1075/**
1076 * Implementation of a vector of stats. The type of stat is determined by the
1077 * Storage class. @sa ScalarBase
1078 */
1079template <class Derived, class Stor>
1080class VectorBase : public DataWrapVec<Derived, VectorInfoProxy>
1081{
1082 public:
1083 typedef Stor Storage;
1084 typedef typename Stor::Params Params;
1085
1086 /** Proxy type */
1087 typedef ScalarProxy<Derived> Proxy;
1088 friend class ScalarProxy<Derived>;
1089 friend class DataWrapVec<Derived, VectorInfoProxy>;
1090
1091 protected:
1092 /** The storage of this stat. */
1093 Storage *storage;
1094 size_type _size;
1095
1096 protected:
1097 /**

--- 193 unchanged lines hidden (view full) ---

1291 assert (index >= 0 && index < size());
1292 return ScalarProxy<Stat>(stat, offset + index);
1293 }
1294
1295 size_type size() const { return len; }
1296};
1297
1298template <class Derived, class Stor>
1299class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
1300{
1301 public:
1302 typedef Vector2dInfoProxy<Derived> Info;
1303 typedef Stor Storage;
1304 typedef typename Stor::Params Params;
1305 typedef VectorProxy<Derived> Proxy;
1306 friend class ScalarProxy<Derived>;
1307 friend class VectorProxy<Derived>;
1308 friend class DataWrapVec<Derived, Vector2dInfoProxy>;
1309 friend class DataWrapVec2d<Derived, Vector2dInfoProxy>;
1310
1311 protected:
1312 size_type x;
1313 size_type y;
1314 size_type _size;
1315 Storage *storage;
1316
1317 protected:

--- 411 unchanged lines hidden (view full) ---

1729 }
1730};
1731
1732/**
1733 * Implementation of a distribution stat. The type of distribution is
1734 * determined by the Storage template. @sa ScalarBase
1735 */
1736template <class Derived, class Stor>
1737class DistBase : public DataWrap<Derived, DistInfoProxy>
1738{
1739 public:
1740 typedef DistInfoProxy<Derived> Info;
1741 typedef Stor Storage;
1742 typedef typename Stor::Params Params;
1743
1744 protected:
1745 /** The storage for this stat. */
1746 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
1747
1748 protected:

--- 63 unchanged lines hidden (view full) ---

1812 data()->reset(this->info());
1813 }
1814};
1815
1816template <class Stat>
1817class DistProxy;
1818
1819template <class Derived, class Stor>
1820class VectorDistBase : public DataWrapVec<Derived, VectorDistInfoProxy>
1821{
1822 public:
1823 typedef VectorDistInfoProxy<Derived> Info;
1824 typedef Stor Storage;
1825 typedef typename Stor::Params Params;
1826 typedef DistProxy<Derived> Proxy;
1827 friend class DistProxy<Derived>;
1828 friend class DataWrapVec<Derived, VectorDistInfoProxy>;
1829
1830 protected:
1831 Storage *storage;
1832 size_type _size;
1833
1834 protected:
1835 Storage *
1836 data(off_type index)

--- 186 unchanged lines hidden (view full) ---

2023};
2024
2025/** Reference counting pointer to a function Node. */
2026typedef RefCountingPtr<Node> NodePtr;
2027
2028class ScalarStatNode : public Node
2029{
2030 private:
2031 const ScalarInfo *data;
2032 mutable VResult vresult;
2033
2034 public:
2035 ScalarStatNode(const ScalarInfo *d) : data(d), vresult(1) {}
2036
2037 const VResult &
2038 result() const
2039 {
2040 vresult[0] = data->result();
2041 return vresult;
2042 }
2043

--- 46 unchanged lines hidden (view full) ---

2090 {
2091 return proxy.str();
2092 }
2093};
2094
2095class VectorStatNode : public Node
2096{
2097 private:
2098 const VectorInfo *data;
2099
2100 public:
2101 VectorStatNode(const VectorInfo *d) : data(d) { }
2102 const VResult &result() const { return data->result(); }
2103 Result total() const { return data->total(); };
2104
2105 size_type size() const { return data->size(); }
2106
2107 std::string str() const { return data->name; }
2108};
2109

--- 440 unchanged lines hidden (view full) ---

2550 VectorAverageDeviation &
2551 init(size_type size)
2552 {
2553 this->doInit(size);
2554 return this->self();
2555 }
2556};
2557
2558class FormulaInfo : public VectorInfo
2559{
2560 public:
2561 virtual std::string str() const = 0;
2562};
2563
2564template <class Stat>
2565class FormulaInfoProxy : public InfoProxy<Stat, FormulaInfo>
2566{
2567 protected:
2568 mutable VResult vec;
2569 mutable VCounter cvec;
2570
2571 public:
2572 FormulaInfoProxy(Stat &stat) : InfoProxy<Stat, FormulaInfo>(stat) {}
2573
2574 size_type size() const { return this->s.size(); }
2575
2576 const VResult &
2577 result() const
2578 {
2579 this->s.result(vec);
2580 return vec;

--- 5 unchanged lines hidden (view full) ---

2586};
2587
2588class Temp;
2589/**
2590 * A formula for statistics that is calculated when printed. A formula is
2591 * stored as a tree of Nodes that represent the equation to calculate.
2592 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2593 */
2594class Formula : public DataWrapVec<Formula, FormulaInfoProxy>
2595{
2596 protected:
2597 /** The root of the tree which represents the Formula */
2598 NodePtr root;
2599 friend class Temp;
2600
2601 public:
2602 /**

--- 339 unchanged lines hidden ---