Posts: Add AoCO 2025 Day 07 Study Notes - #49
Conversation
There was a problem hiding this comment.
This PR adds study notes for Day 7 of the Advent of Compiler Optimisations 2025 series, focusing on division by a constant optimization. The content is well-structured with clear mathematical explanations and practical examples.
Issues Found:
- Two typos in the markdown content that need correction
- Inconsistent hexadecimal notation (missing "0x" prefixes in some locations)
All issues have been marked with suggested fixes that can be applied with one click.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| $$ | ||
| \begin{aligned} | ||
| RHS &= \lfloor \frac{N \cdot M}{2^k} \rfloor \\ | ||
| &= \lfloor \frac{100 \cdot 19999999A}{2^36} \rfloor \\ |
There was a problem hiding this comment.
Add "0x" prefix to hexadecimal value for consistency
| &= \lfloor \frac{100 \cdot 19999999A}{2^36} \rfloor \\ | |
| &= \\lfloor \\frac{100 \\cdot 0x19999999A}{2^36} \\rfloor \\\\ |
| \lfloor \frac{N}{D} \rfloor = \lfloor \frac{N \cdot M}{2^k} \rfloor | ||
| $$ | ||
|
|
||
| The compiler's goal is to find a fixed-point approxmiation such that : |
There was a problem hiding this comment.
Fix typo: "approxmiation" should be "approximation"
| The compiler's goal is to find a fixed-point approxmiation such that : | |
| The compiler's goal is to find a fixed-point approximation such that : |
| &= \lceil \frac{68719476736}{10} \rceil \\ | ||
| &= \lceil 6871947673.6 \rceil \\ | ||
| &= 6871947674 \\ | ||
| &= 19999999A |
There was a problem hiding this comment.
Add "0x" prefix to hexadecimal value for consistency with line 136 where "0xCCCCCCCD" is used
| &= 19999999A | |
| &= 0x19999999A |
|
|
||
| ## Example : Division by 10 | ||
|
|
||
| In this example, we analyze how the compile handles unsigned division by 10. |
There was a problem hiding this comment.
Fix typo: "compile" should be "compiler"
| In this example, we analyze how the compile handles unsigned division by 10. | |
| In this example, we analyze how the compiler handles unsigned division by 10. |
| Similarly the magic number $M$ used by the compiler is `0xCCCCCCCD` | ||
| instead of our calculation result `19999999A`. | ||
|
|
||
| Since we know $35 < 36$ and $0xCCCCCCCD < 19999999A$, |
There was a problem hiding this comment.
Add "0x" prefix to hexadecimal value for consistent notation in the comparison
| Since we know $35 < 36$ and $0xCCCCCCCD < 19999999A$, | |
| Since we know $35 < 36$ and $0xCCCCCCCD < 0x19999999A$, |
There was a problem hiding this comment.
Code Review
This pull request introduces a new blog post containing study notes on compiler optimizations for division by a constant, specifically focusing on the use of magic numbers and bit shifts. Additionally, it updates the CSS for the Markdown renderer to hide vertical overflow in KaTeX display elements. I have no feedback to provide.
These notes are based on the post Multiplying our way out of division and the YouTube video [AoCO 7/25] Division by a Constant which are Day 7 of the Advent of Compiler Optimisations 2025 Series by Matt Godbolt.