# AI-generated ARM assembly optimization reduces instruction count eightfold in a C++ string-counting test

DevFeed: [AI-generated ARM assembly optimization reduces instruction count eightfold in a C++ string-counting test](<https://devfeed.tech/articles/can-your-ai-rewrite-your-code-in-assembly-29399.md>)

Original publisher: [Read original article](<https://lemire.me/blog/2026/04/05/can-your-ai-rewrite-your-code-in-assembly/>)

Author: Daniel Lemire

Published: 2026-04-05T21:16:14Z

Content type: opinion

Language: en

Sources: [Daniel Lemire](<https://devfeed.tech/sources/daniel-lemire.md>)

Topics: [Assembly](<https://devfeed.tech/topics/assembly.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Artificial Intelligence](<https://devfeed.tech/topics/ai.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [assembly](<https://devfeed.tech/tags/assembly.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [claude](<https://devfeed.tech/tags/claude.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance](<https://devfeed.tech/tags/performance.md>), [prompting](<https://devfeed.tech/tags/prompting.md>)

## AI overview

The article describes an experiment using Grok and Claude to repeatedly optimize an ARM assembly function that counts a character across strings. On random strings of up to 1 kilobyte, the optimized versions reduced instructions by a factor of eight and achieved similar running-time reductions, though the author notes that the code was not closely examined for mistakes. The best version could be rewritten in C using SIMD intrinsics, so assembly provided no benefit in this case.

## Source excerpt

Suppose you have several strings and you want to count the number of instances of the character ! in your strings. In C++, you might solve the problem as follows if you are an old-school programmer. size_t c = 0; for (const auto &str : strings) { c += std::count(str.begin(), str.end(), '!'); } You can ... Continue reading Can your AI rewrite your code in assembly?