Skip to content

Explicitly disable SIMD128/256 support for HACL* on aarch64-linux #135032

@Zheaoli

Description

@Zheaoli
Contributor

Bug report

Bug description:

https://discuss.python.org/t/supporting-simd-on-aarch64-linux/94188/3

SIMD128 on linux arm64 is not good enough(same with the MacOS)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

added
type-bugAn unexpected behavior, bug, or error
on Jun 2, 2025
added a commit that references this issue on Jun 2, 2025
8079caa
added
pendingThe issue will be closed if no feedback is provided
on Jun 2, 2025
picnixz

picnixz commented on Jun 2, 2025

@picnixz
Member

As I said on the PR, please present benchmarks (I'd like to know how worse it is). And please do the same for SIMD-256 as results may be different (don't forget to build it using --enable-optimizations and --with-lto)

Zheaoli

Zheaoli commented on Jun 2, 2025

@Zheaoli
ContributorAuthor

don't forget to build it using --enable-optimizations and --with-lto

Thanks for the remind, I'm working on it(

added
type-featureA feature request or enhancement
buildThe build process and cross-build
and removed
type-bugAn unexpected behavior, bug, or error
pendingThe issue will be closed if no feedback is provided
on Jun 2, 2025
changed the title [-]Disable the SIMD128/SIMD256 for Linux arm64 explictly[/-] [+]Explicitly disable SIMD128/256 support for HACL* on aarch64-linux[/+] on Jun 2, 2025
added
type-bugAn unexpected behavior, bug, or error
and removed
type-featureA feature request or enhancement
on Jun 2, 2025
picnixz

picnixz commented on Jun 2, 2025

@picnixz
Member

Since this is affecting BLAKE-2 and HMAC only, we only need to backport it until 3.14 as BLAKE-2 was not in 3.13 I think.

added
3.14bugs and security fixes
3.15new features, bugs and security fixes
on Jun 2, 2025
Zheaoli

Zheaoli commented on Jun 3, 2025

@Zheaoli
ContributorAuthor

After test, The result is the same

import timeit
import random
from string import ascii_letters
from hashlib import blake2s

tmep_string = "".join([random.choice(ascii_letters) for _ in range(1024)])

def main():
    blake2s_hash = blake2s(tmep_string.encode("utf-8")).hexdigest()

if __name__ == "__main__":
    # print(timeit.timeit(main, number=1000000))
    print(timeit.timeit("blake2s(tmep_string.encode('utf-8')).hexdigest()", globals=globals(), number=1000000))
    # print(timeit.timeit("blake2s(tmep_string.encode('utf-8')).hexdigest()", number=1000000))  # This will fail without globals

This is the result with SIMD

ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.4876955619997716
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.4599792300000445
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.4746942629999467
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.4710460269998293
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.4790154759998586
ubuntu@ip-172-31-6-42:~/cpython$ ./configure --with-builtin-hashlib-hashes=md5,sha1,sha2,sha3,blake2 --enable-optimizations --with-lto^C
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.470140725999954
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.472699333000037
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.456732337000176
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.456266343000152
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.452893915000004
ubuntu@ip-172-31-6-42:~/cpython$ ./python demo.py 
2.458339425000304

And the result without SIMD

ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.4618775650001226
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.419546210000135
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.419580041000245
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.4346035089997713
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.4218126690002464
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.419804486999965
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.410035002999848
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.424998641000002
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.4183685279999736
ubuntu@ip-172-31-6-42:~/cpython-original$ ./python demo.py 
2.4080212740000206
Zheaoli

Zheaoli commented on Jun 3, 2025

@Zheaoli
ContributorAuthor

And please do the same for SIMD-256 as

BTW, here's no SIMD-256 for aarch64 yet

Zheaoli

Zheaoli commented on Jun 3, 2025

@Zheaoli
ContributorAuthor
Zheaoli

Zheaoli commented on Jun 6, 2025

@Zheaoli
ContributorAuthor

ping @picnixz ~

Zheaoli

Zheaoli commented on Jun 12, 2025

@Zheaoli
ContributorAuthor

@picnixz PTAL when you got time

picnixz

picnixz commented on Jun 13, 2025

@picnixz
Member

Please use pyperf instead of manual timeit. Also, keep out the encode call and consider using os.urandom(1024) as the string to hash. As it's a CSHF, the input being ascii or not shouldn't matter.

Zheaoli

Zheaoli commented on Jun 15, 2025

@Zheaoli
ContributorAuthor
+-------------------+----------------+-----------------------+
| Benchmark         | bench-original | bench-simd            |
+===================+================+=======================+
| blake2s_benchmark | 4.74 us        | 4.73 us: 1.00x faster |
+-------------------+----------------+-----------------------+

Seems I got some wrong bench before(lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesbuildThe build process and cross-buildextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Zheaoli@picnixz

      Issue actions

        Explicitly disable SIMD128/256 support for HACL* on aarch64-linux · Issue #135032 · python/cpython