@@ -119,16 +119,26 @@ object Periods {
119
119
object Period {
120
120
121
121
/** The single-phase period consisting of given run id and phase id */
122
- def apply (rid : RunId , pid : PhaseId ): Period =
122
+ def apply (rid : RunId , pid : PhaseId ): Period = {
123
+ assert(rid <= MaxPossibleRunId )
124
+ assert(pid <= MaxPossiblePhaseId )
123
125
new Period (((rid << PhaseWidth ) | pid) << PhaseWidth )
126
+ }
124
127
125
128
/** The period consisting of given run id, and lo/hi phase ids */
126
- def apply (rid : RunId , loPid : PhaseId , hiPid : PhaseId ): Period =
129
+ def apply (rid : RunId , loPid : PhaseId , hiPid : PhaseId ): Period = {
130
+ assert(rid <= MaxPossibleRunId )
131
+ assert(loPid <= MaxPossiblePhaseId )
132
+ assert(hiPid <= MaxPossiblePhaseId )
133
+
127
134
new Period (((rid << PhaseWidth ) | hiPid) << PhaseWidth | (hiPid - loPid))
135
+ }
128
136
129
137
/** The interval consisting of all periods of given run id */
130
- def allInRun (rid : RunId ) =
138
+ def allInRun (rid : RunId ) = {
139
+ assert(rid <= MaxPossibleRunId )
131
140
apply(rid, 0 , PhaseMask )
141
+ }
132
142
}
133
143
134
144
final val Nowhere = new Period (0 )
@@ -141,6 +151,8 @@ object Periods {
141
151
type RunId = Int
142
152
final val NoRunId = 0
143
153
final val InitialRunId = 1
154
+ final val RunWidth = java.lang.Integer .SIZE - PhaseWidth * 2 - 1 /* sign */
155
+ final val MaxPossibleRunId = (1 << RunWidth ) - 1
144
156
145
157
/** An ordinal number for phases. First phase has number 1. */
146
158
type PhaseId = Int
0 commit comments