2 ms·
Another thing you can do is reduce the range of tick counts. Say you have a 32 bit tick count which increments a hundred times a second, but the longest period
by kazinator 12y ago
Another thing you can do is reduce the range of tick counts. Say you have a 32 bit tick count which increments a hundred times a second, but the longest period (biggest delta between any two live time values) you care about in your module (driver or whatever) is well within 30 seconds. That's only 3000 ticks. Then, whenever you sample the counter, you can mask it down into, say, the 13 bit range [0,8192): effectively a tick counter that rolls over every 81.9 seconds (which you treat correctly as a 13 bit value in your calculations like is_before(t0, t1) or add_time(t0, delta)).
- ambrop7 12y agoThere's no need to reduce the range, you can just treat correctly the full counter range (see my other comment).
- kazinator 12y agoWell, it's a tautology that if you treat correctly anything, you don't need any defensive tricks. Treat all the ones and zeros correctly and everything else takes care of itself.
- ambrop7 12y agoYou mentioned correct treatment first :) I'm just saying that masking the clock is unnecessary and doesn't make correct treatment any easier.