Skip to content

Posts: Add AoCO 2025 Day 10 Study Notes #58

Merged
gapry merged 6 commits into
mainfrom
AoCO-2025-Day10-Unrolling-Loops
Apr 30, 2026
Merged

Posts: Add AoCO 2025 Day 10 Study Notes #58
gapry merged 6 commits into
mainfrom
AoCO-2025-Day10-Unrolling-Loops

Conversation

@gapry
Copy link
Copy Markdown
Owner

@gapry gapry commented Apr 30, 2026

No description provided.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

This PR adds educational study notes about loop unrolling in compiler optimizations. The content includes well-structured examples demonstrating standard loops, manual unrolling, and compiler-based unrolling with corresponding assembly code analysis. No blocking issues identified - the code examples are demonstration-only and the documentation is ready for merge.


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.

@gapry gapry merged commit b69ef4f into main Apr 30, 2026
2 checks passed
@gapry gapry deleted the AoCO-2025-Day10-Unrolling-Loops branch April 30, 2026 15:05
Copy link
Copy Markdown

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

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 adds study notes on loop unrolling, demonstrating the differences between manual and compiler-driven optimizations using std::span. Feedback focuses on a technical issue where using forwarding references with std::span could lead to compilation errors for rvalue containers, as well as several improvements to the text's clarity and grammar.


My notes focus on reproducing and verifying [Matt Godbolt](https://xania.org/MattGodbolt)'s teaching within a local development environment using `LLVM toolchain` on `Ubuntu`.

Written by me and assisted by AI, proofread by me and assisted by AI.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This sentence is quite repetitive. A more concise version would improve the flow of the introduction.

Suggested change
Written by me and assisted by AI, proofread by me and assisted by AI.
Written and proofread by me, with AI assistance.

#include <iostream>

template<typename T>
auto sum(T&& dataset) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The sum function template uses a forwarding reference (T&&), but std::span cannot be safely constructed from rvalue containers (like a temporary std::vector) because they are not 'borrowed ranges'. This will cause a compilation error if sum is called with a temporary container. Using const T& is safer for a generic sum function that uses std::span internally.

Suggested change
auto sum(T&& dataset) {
auto sum(const T& dataset) {


Loop unrolling can reduce the overhead by decreasing the number of iterations and branch instructions.

To force on loop unrolling, we will disable the SIMD by `-fno-vectorize -mno-sse -mno-avx` in the following example.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The phrase "To force on loop unrolling" is slightly confusing. If the intention is to isolate the effect of loop unrolling by disabling vectorization, "To focus on loop unrolling" or "To observe loop unrolling" would be clearer. Alternatively, if you meant to force the optimization, "To force loop unrolling" (without "on") is more idiomatic.

Suggested change
To force on loop unrolling, we will disable the SIMD by `-fno-vectorize -mno-sse -mno-avx` in the following example.
To focus on loop unrolling, we will disable the SIMD by -fno-vectorize -mno-sse -mno-avx in the following example.


In previous examples, we use `-fno-unroll-loops` to disable the compiler from doing the loop unrolling.

For now, we enable it and see the output assembly is as same as the part02, which manually unrolled in C code.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

There are a couple of grammatical issues in this sentence: "is as same as" should be "is the same as", and "which manually unrolled" should be "which was manually unrolled". Also, "part02" should be capitalized to match the section header.

Suggested change
For now, we enable it and see the output assembly is as same as the part02, which manually unrolled in C code.
For now, we enable it and see the output assembly is the same as Part 02, which was manually unrolled in C code.

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