riscv / riscv-aclint

https://jira.riscv.org/browse/RVG-59
Other
39 stars 8 forks source link

Example code does not match comment #11

Open jrahmeh opened 2 years ago

jrahmeh commented 2 years ago

In the sample code for synchronizing MTIME registers, the code sequence for computing T3 does not match the comment. The comment says: "T3 = T1 - ((T0 + T2) / 2)". The code actually computes: "T3 = T1 - (T0/2 + T2/2)". For odd values in T0 and T2, these expressions produce different results. For example if T0 and T2 are both 3, then (T0+T2)/2 is 3, while (T0/2 + T2/2) is 2.

bgrayson-mips commented 1 month ago

Even worse, the code does not actually provide the required guarantee, that after synchronization the two MTIME values are <1 count away from each other. Take this scenario:

I am not sure if "synchronized to within one MTIME tick period" means strictly-less-than-one tick, or just "less than two MTIME tick periods". If the former, the code should be fixed.