@@ -185,7 +185,14 @@ function generateOp(op: string): string {
185185 }
186186}
187187
188- function generateConditionalStatement ( statement : string , condition : string , op : string ) : string {
188+ const kStatementKinds = [ 'if' , 'for' , 'while' , 'switch' , 'break-if' ] as const ;
189+ type kStatementType = ( typeof kStatementKinds ) [ number ] ;
190+
191+ function generateConditionalStatement (
192+ statement : kStatementType ,
193+ condition : string ,
194+ op : string
195+ ) : string {
189196 const code = `` ;
190197 switch ( statement ) {
191198 case 'if' : {
@@ -215,8 +222,19 @@ function generateConditionalStatement(statement: string, condition: string, op:
215222 }
216223 ` ;
217224 }
218- default : {
219- unreachable ( `Unhandled statement` ) ;
225+ case 'break-if' : {
226+ // The initial 'if' prevents the loop from being infinite. Its condition
227+ // is uniform, to ensure the first iteration of the the body executes
228+ // uniformly. The uniformity of the second iteration depends entirely on
229+ // the uniformity of the break-if condition.
230+ return `loop {
231+ if ${ generateCondition ( 'uniform_storage_ro' ) } { break; }
232+ ${ generateOp ( op ) }
233+ continuing {
234+ break if ${ generateCondition ( condition ) } ;
235+ }
236+ }
237+ ` ;
220238 }
221239 }
222240
@@ -227,7 +245,7 @@ g.test('basics')
227245 . desc ( `Test collective operations in simple uniform or non-uniform control flow.` )
228246 . params ( u =>
229247 u
230- . combine ( 'statement' , [ 'if' , 'for' , 'while' , 'switch' ] as const )
248+ . combine ( 'statement' , kStatementKinds )
231249 . beginSubcases ( )
232250 . combineWithParams ( kConditions )
233251 . combineWithParams ( kCollectiveOps )
@@ -315,7 +333,7 @@ g.test('basics,subgroups')
315333 . desc ( `Test subgroup operations in simple uniform or non-uniform control flow.` )
316334 . params ( u =>
317335 u
318- . combine ( 'statement' , [ 'if' , 'for' , 'while' , 'switch' ] as const )
336+ . combine ( 'statement' , kStatementKinds )
319337 . beginSubcases ( )
320338 . combineWithParams ( kConditions )
321339 . combine ( 'op' , kSubgroupOps )
0 commit comments