Skip to content

Optimization: High-performance AVR SHA1 (~135% hashrate increase)#1909

Open
seilaman2210-rgb wants to merge 3 commits into
duino-coin:masterfrom
seilaman2210-rgb:master
Open

Optimization: High-performance AVR SHA1 (~135% hashrate increase)#1909
seilaman2210-rgb wants to merge 3 commits into
duino-coin:masterfrom
seilaman2210-rgb:master

Conversation

@seilaman2210-rgb
Copy link
Copy Markdown

@seilaman2210-rgb seilaman2210-rgb commented Apr 27, 2026

This request is a major optimization for Arduino_Code with almost 135%+ performance compared with the original version

Highlights:

ASM Implementation: The SHA1 compression loop has been rewritten in Assembly to reduce clock cycles per round
Register Management Optimization: Hand-optimized usage of the 32 available 8-bit registers
This prevents "register spilling" (when the compiler moves data to RAM/Stack due to lack of free registers), significantly reducing ld/st (load/store) cycles
Loop Unrolling: Strategic loop unrolling to maximize execution speed on ATmega328P and similar chips.
Binary Size: Efficient code that fits comfortably within the memory limits of Arduino Nano/Uno/Pro Mini.
Lower Dynamic memory (-2/3%) and flash (-8%) use compared to the original code (40% flash, 21% memory)
Architecture-Safe: The implementation is wrapped in #if defined(AVR) guards, ensuring it only compiles for 8-bit AVR
boards and maintains zero impact/full compatibility with ESP8266, ESP32, and other architectures.

Benchmarks (Arduino UNO)

Hashrate: stable 785-779 hs (the original was 333hs)
Shares: no rejected shares or other code related bugs until now
Performance gain: 135%+
Temperature: Same as the original file
Assigned diff: 128 (ARM) original was 10 (AVR)

image

Stability:

Tested for some hours straight with zero rejected shares or calculation errors.
Completely compatible with the official Duino-Coin AVR Miner Python script.
The server successfully recognizes the performance boost, upgrading the difficulty from 10 to 128.

one of my tests:

582987446-d56b8b18-e8c8-4ef8-9fe5-8b60f0a882fe

IDE output:
Sketch: 10,550 bytes (32%) of program storage space.
Dynamic Memory: 394 bytes (19%) of RAM.
Leaves 1,654 bytes for local variables.

Notes:
This is my first time making a PR on GitHub. If I made any mistakes regarding the commit structure or formatting, please let me know and I will fix them as soon as possible. If you find any errors or instability in the code, I am ready to provide fixes
i just forgot to add, but this script was inspired by JK Rolling's code (the max 721hs one), thanks to them!

@seilaman2210-rgb seilaman2210-rgb marked this pull request as draft April 27, 2026 04:54
@seilaman2210-rgb seilaman2210-rgb marked this pull request as ready for review April 27, 2026 04:59
@seilaman2210-rgb seilaman2210-rgb marked this pull request as draft April 27, 2026 05:25
@seilaman2210-rgb seilaman2210-rgb changed the title Optimization: High-performance AVR Assembly SHA1 (~135% hashrate increase) Optimization: High-performance AVR SHA1 (~135% hashrate increase) Apr 27, 2026
Added information about memory usage and optimization in comments.
@seilaman2210-rgb seilaman2210-rgb marked this pull request as ready for review April 27, 2026 18:55
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