From cc0f077163017fccdbaacdf2e185246d9bf7103d Mon Sep 17 00:00:00 2001 From: AlanSong Date: Thu, 5 Mar 2026 06:04:42 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!2=20:?= =?UTF-8?q?=20Enable=20x86-64=20SM3=20optimizations=20with=20CCS=20ISA=20e?= =?UTF-8?q?xtension'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto/sm3/asm/sm3-x86-ccs.pl | 53 ------------------------- crypto/sm3/asm/sm3-x86_64-ccs.pl | 68 -------------------------------- crypto/sm3/build.info | 9 ----- crypto/sm3/sm3_local.h | 7 ---- 4 files changed, 137 deletions(-) delete mode 100644 crypto/sm3/asm/sm3-x86-ccs.pl delete mode 100644 crypto/sm3/asm/sm3-x86_64-ccs.pl diff --git a/crypto/sm3/asm/sm3-x86-ccs.pl b/crypto/sm3/asm/sm3-x86-ccs.pl deleted file mode 100644 index f1afadb9ac2..00000000000 --- a/crypto/sm3/asm/sm3-x86-ccs.pl +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env perl -# Copyright 2021-2024 The OpenSSL Project Authors. All Rights Reserved. -# -# Licensed under the Apache License 2.0 (the "License"). You may not use -# this file except in compliance with the License. You can obtain a copy -# in the file LICENSE in the source distribution or at -# https://www.openssl.org/source/license.html -# -# This module implements support for Zhaoxin SM3 instructions - -$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; -push(@INC,"${dir}","${dir}../../perlasm"); -require "x86asm.pl"; - -$output = pop and open STDOUT,">$output"; - -&asm_init($ARGV[0]); - - -# void ossl_hwsm3_block_data_order(SM3_CTX *c, const void *p, size_t num); -&function_begin("ossl_hwsm3_block_data_order"); - &mov ("edx",&wparam(0)); - &mov ("ecx",8); -&set_label("bswap_loop_before"); - &mov ("eax",&DWP(0,"edx")); - &bswap ("eax"); - &mov (&DWP(0,"edx"),"eax"); - &lea ("edx",&DWP(4,"edx")); - &sub ("ecx",1); - &jnz (&label("bswap_loop_before")); - - &mov ("ebx",0x20); - &mov ("eax",-1); - &mov ("edi",&wparam(0)); - &mov ("esi",&wparam(1)); - &mov ("ecx",&wparam(2)); - &data_byte(0xf3,0x0f,0xa6,0xe8); - - &mov ("edx",&wparam(0)); - &mov ("ecx",8); -&set_label("bswap_loop_after"); - &mov ("eax",&DWP(0,"edx")); - &bswap ("eax"); - &mov (&DWP(0,"edx"),"eax"); - &lea ("edx",&DWP(4,"edx")); - &sub ("ecx",1); - &jnz (&label("bswap_loop_after")); -&function_end("ossl_hwsm3_block_data_order"); - - -&asm_finish(); - -close STDOUT or die "error closing STDOUT: $!"; diff --git a/crypto/sm3/asm/sm3-x86_64-ccs.pl b/crypto/sm3/asm/sm3-x86_64-ccs.pl deleted file mode 100644 index 8a991c4a55e..00000000000 --- a/crypto/sm3/asm/sm3-x86_64-ccs.pl +++ /dev/null @@ -1,68 +0,0 @@ -#! /usr/bin/env perl -# Copyright 2021-2024 The OpenSSL Project Authors. All Rights Reserved. -# -# Licensed under the Apache License 2.0 (the "License"). You may not use -# this file except in compliance with the License. You can obtain a copy -# in the file LICENSE in the source distribution or at -# https://www.openssl.org/source/license.html -# -# This module implements support for Zhaoxin SM3 instructions - -$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef; -$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef; - -$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; -( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or -( $xlate="${dir}../../../crypto/perlasm/x86_64-xlate.pl" and -f $xlate) or -die "can't locate x86_64-xlate.pl"; - -open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""; -*STDOUT=*OUT; - -$code=".text\n"; - -# void ossl_hwsm3_block_data_order(SM3_CTX *c, const void *p, size_t num); -# c = %rdi, p=%rsi, num=%rdx -{ -$code .= <<___; -.align 16 -.globl ossl_hwsm3_block_data_order -.type ossl_hwsm3_block_data_order,\@function -ossl_hwsm3_block_data_order: - push %rbx # save rbx - - mov \$8,%r8 - mov %rdi,%r9 -.Lbswap_loop_before: - mov (%r9),%eax - bswap %eax - mov %eax,(%r9) - lea 4(%r9),%r9 - sub \$1,%r8 - jnz .Lbswap_loop_before - - mov \$0x20,%rbx - mov \$-1,%rax - mov %rdx,%rcx - - .byte 0xf3,0x0f,0xa6,0xe8 - - mov \$8,%r8 - mov %rdi,%r9 -.Lbswap_loop_after: - mov (%r9),%eax - bswap %eax - mov %eax,(%r9) - lea 4(%r9),%r9 - sub \$1,%r8 - jnz .Lbswap_loop_after - - pop %rbx #restore rbx - ret - -.size ossl_hwsm3_block_data_order,.-ossl_hwsm3_block_data_order -___ -} - -print $code; -close STDOUT or die "error closing STDOUT: $!"; diff --git a/crypto/sm3/build.info b/crypto/sm3/build.info index 4dbc492147f..2fa54a4a8bc 100644 --- a/crypto/sm3/build.info +++ b/crypto/sm3/build.info @@ -5,12 +5,6 @@ IF[{- !$disabled{sm3} -}] $SM3ASM_aarch64=sm3-armv8.S $SM3DEF_aarch64=OPENSSL_SM3_ASM - $SM3ASM_x86_64=sm3-x86_64-ccs.s - $SM3DEF_x86_64=OPENSSL_SM3_ASM - - $SM3ASM_x86=sm3-x86-ccs.s - $SM3DEF_x86=OPENSSL_SM3_ASM - # Now that we have defined all the arch specific variables, use the # appropriate ones, and define the appropriate macros IF[$SM3ASM_{- $target{asm_arch} -}] @@ -24,8 +18,5 @@ IF[{- !$disabled{sm3} -}] GENERATE[sm3-armv8.S]=asm/sm3-armv8.pl INCLUDE[sm3-armv8.o]=.. - - GENERATE[sm3-x86_64-ccs.s]=asm/sm3-x86_64-ccs.pl - GENERATE[sm3-x86-ccs.s]=asm/sm3-x86-ccs.pl ENDIF diff --git a/crypto/sm3/sm3_local.h b/crypto/sm3/sm3_local.h index ffd673f56c0..ac8a2bf768e 100644 --- a/crypto/sm3/sm3_local.h +++ b/crypto/sm3/sm3_local.h @@ -39,13 +39,6 @@ # define HWSM3_CAPABLE (OPENSSL_armcap_P & ARMV8_SM3) void ossl_hwsm3_block_data_order(SM3_CTX *c, const void *p, size_t num); # endif -# if !defined(I386_ONLY) && (\ - defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ - defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) ) -#include "internal/cryptlib.h" -# define HWSM3_CAPABLE ( (OPENSSL_ia32cap_P[4] & 0x20) && (OPENSSL_ia32cap_P[4] & 0x30) ) -void ossl_hwsm3_block_data_order(SM3_CTX *c, const void *p, size_t num); -#endif /* CCS */ #endif #if defined(HWSM3_CAPABLE) -- Gitee