31 lines
3.0 KiB
Plaintext
31 lines
3.0 KiB
Plaintext
|
[video member=miotatsu stream_platform=twitch project=riscy title="Fun with Fixed Point Math" vod_platform=youtube id=eXpOx3cd9KA annotator=Miblo]
|
||
|
[0:09][Recap and set the stage for the day]
|
||
|
[1:03][Don the thinking cap]
|
||
|
[1:38][Working through the cycles-per-second formula for measure_cpu_freq()][:blackboard :mathematics :timing]
|
||
|
[16:12][Check our formula with the one in measure_cpu_freq()][:blackboard :mathematics :timing]
|
||
|
[18:46][Reverse engineer the cycles-per-second formula][:blackboard :mathematics :timing]
|
||
|
[20:22][@riskyfive][They are basically doing fixed point math][:mathematics]
|
||
|
[21:02][Computing the decimal portion of a real number in fixed point :mathematics][:blackboard :timing]
|
||
|
[21:58][@riskyfive][Instead of doing float x = 3.14, you do int x = 314 and the point is implicit][:mathematics]
|
||
|
[23:22][@riskyfive][Notice that in one part you have / and then you have another part that is nearly equal but uses %][:mathematics]
|
||
|
[25:37][Determine to work through an example on the whiteboard]
|
||
|
[26:34][@riskyfive][Use a spreadsheet or C program, to make it easier to compute other values]
|
||
|
[27:06][Plug some example values into our cycles-per-second formula][:blackboard :mathematics :timing]
|
||
|
[41:04][Summarise how this fixed point calculation works][:blackboard :mathematics]
|
||
|
[42:47][@riskyfive][I can explain it another way]
|
||
|
[43:49][@riskyfive][Just forget everything after the + to start with]
|
||
|
[45:56][@riskyfive][Say we have 200 cycles (delta_mcycle). We divide by the ticks (delta_mtime). So now we have number of cycles per tick. We multiply by the number of ticks per second (mtime_freq) so now we have cycles per second][:mathematics]
|
||
|
[47:57][Pose the question: How does n % m / m give the decimal part of the number?][:blackboard :mathematics]
|
||
|
[49:29][@riskyfive][So 201 cycles / 10 ticks = floor(20.1) cycles per tick. We take the 20 and multiply by, say, 100 ticks per second so we have 2000 cycles per second][:mathematics]
|
||
|
[50:06][@riskyfive][201 % 10 = 1. Multiply by 100 and divide by 10 we get 2010 cycles per second, and we recover the part we lost in the division][:mathematics]
|
||
|
[50:22][The relationship between a remainder and a decimal][:blackboard :mathematics]
|
||
|
[53:56][Read about reciprocal[ref
|
||
|
site=Wikipedia
|
||
|
page="Multiplicative inverse"
|
||
|
url=https://en.wikipedia.org/wiki/Multiplicative_inverse]][:mathematics :research]
|
||
|
[56:31][@riskyfive][delta_mtime is what determines what the conceptual decimal point is. Say delta_mtime = 100, if you do x % delta_mtime and get 33, then the 33 means you don't have a whole delta_mtime unit. But after you multiply it by something you might get >= 100, so when you divide by delta_mtime again you get >= 1][:mathematics]
|
||
|
[57:41][Is it true that n % m / m = 1 / m % m][:blackboard :mathematics]
|
||
|
[1:00:05][@riskyfive][Think of delta_mtime as being a percentage. If you get 0.33 that's 33%. You will only get an integer again if you cross the 100% line][:mathematics]
|
||
|
[1:01:21][Determine to sleep on this to fully understand it]
|
||
|
[/video]
|