@@ -368,12 +368,19 @@ public void fixClockRollover() {
368368 for (int i =this .scalers .size ()-1 ; i >0 ; --i ) {
369369 Dsc2Scaler previous = this .scalers .get (i -1 ).dsc2 ;
370370 Dsc2Scaler next = this .scalers .get (i ).dsc2 ;
371- if (previous .clock > next .clock ) {
372- var corr = previous .clock - next .clock + 1 ;
371+ long corr = previous .clock - next .clock + 1 ;
372+ boolean is_rollover = previous .clock > next .clock ;
373+ boolean is_gap = corr <= -2 *(long )Integer .MAX_VALUE ;
374+ if (is_rollover || is_gap ) {
375+ if (is_gap ) corr = -corr ;
373376 for (int j =i ; j <this .scalers .size (); ++j ) {
374377 if (j ==i ) System .out .print ( String .format ("FIXING UNGATED CLOCK ROLLOVER: %d -> " ,this .scalers .get (j ).dsc2 .clock ));
375378 this .scalers .get (j ).dsc2 .clock += corr ;
376- if (j ==i ) System .out .println (String .format ("%d" ,this .scalers .get (j ).dsc2 .clock ));
379+ if (j ==i ) {
380+ System .out .println (String .format ("%d" ,this .scalers .get (j ).dsc2 .clock ));
381+ System .out .println ((double )corr /(2 *(long )Integer .MAX_VALUE ));
382+ if (is_gap ) System .out .println ("GAP!" );
383+ }
377384 }
378385 modified = true ;
379386 break ;
@@ -387,12 +394,19 @@ public void fixClockRollover() {
387394 for (int i =this .scalers .size ()-1 ; i >0 ; --i ) {
388395 Dsc2Scaler previous = this .scalers .get (i -1 ).dsc2 ;
389396 Dsc2Scaler next = this .scalers .get (i ).dsc2 ;
390- if (previous .gatedClock > next .gatedClock ) {
391- var corr = previous .gatedClock - next .gatedClock + 1 ;
397+ long corr = previous .gatedClock - next .gatedClock + 1 ;
398+ boolean is_rollover = previous .gatedClock > next .gatedClock ;
399+ boolean is_gap = corr <= -2 *(long )Integer .MAX_VALUE ;
400+ if (is_rollover || is_gap ) {
401+ if (is_gap ) corr = -corr ;
392402 for (int j =i ; j <this .scalers .size (); ++j ) {
393403 if (j ==i ) System .out .print ( String .format ("FIXING GATED CLOCK ROLLOVER: %d -> " ,this .scalers .get (j ).dsc2 .gatedClock ));
394404 this .scalers .get (j ).dsc2 .gatedClock += corr ;
395- if (j ==i ) System .out .println (String .format ("%d" ,this .scalers .get (j ).dsc2 .gatedClock ));
405+ if (j ==i ) {
406+ System .out .println (String .format ("%d" ,this .scalers .get (j ).dsc2 .gatedClock ));
407+ System .out .println ((double )corr /(2 *(long )Integer .MAX_VALUE ));
408+ if (is_gap ) System .out .println ("GAP!" );
409+ }
396410 }
397411 modified = true ;
398412 break ;
0 commit comments