Skip to content

Posts: Add AoCO 2025 Day 07 Study Notes - #49

Merged
gapry merged 2 commits into
mainfrom
AoCO-2025-Day07
Mar 31, 2026
Merged

gapry merged 2 commits into
mainfrom
AoCO-2025-Day07

Conversation

@gapry

@gapry gapry commented Mar 31, 2026 •

Copy link
Copy Markdown
Owner

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.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 \\

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "0x" prefix to hexadecimal value for consistency

Suggested change
&= \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 :

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo: "approxmiation" should be "approximation"

Suggested change
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "0x" prefix to hexadecimal value for consistency with line 136 where "0xCCCCCCCD" is used

Suggested change
&= 19999999A
&= 0x19999999A


## Example : Division by 10

In this example, we analyze how the compile handles unsigned division by 10.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo: "compile" should be "compiler"

Suggested change
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$,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "0x" prefix to hexadecimal value for consistent notation in the comparison

Suggested change
Since we know $35 < 36$ and $0xCCCCCCCD < 19999999A$,
Since we know $35 < 36$ and $0xCCCCCCCD < 0x19999999A$,

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gapry
gapry merged commit 2ee94c9 into main Mar 31, 2026
1 check passed
@gapry
gapry deleted the AoCO-2025-Day07 branch March 31, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant