是否可以不用uadk_memcpy (主要是解决大包memcpy_large) 如果是大包,直接用指针, 如果是小包(< DIGEST_BLOCK_SIZE),copy到临时buffer priv->data,下次用 如果上次有剩余尾巴(priv->last_update_bufflen > 0),则继续填满上次的priv->data,
diff: 简单测试,没测到digest_update_inner diff --git a/src/uadk_digest.c b/src/uadk_digest.c index ecc0ce6..013ff07 100644 --- a/src/uadk_digest.c +++ b/src/uadk_digest.c @@ -537,21 +537,27 @@ static int digest_update_inner(EVP_MD_CTX *ctx, const void *data, size_t data_le { struct digest_priv_ctx *priv = (struct digest_priv_ctx *) EVP_MD_CTX_md_data(ctx); - const unsigned char *tmpdata = (const unsigned char *)data; + unsigned char *tmpdata = (unsigned char *)data; size_t left_len = data_len; int copy_to_bufflen; int ret;
+ printf("%s\n", __func__); + priv->req.has_next = DIGEST_DOING;
while (priv->last_update_bufflen + left_len > DIGEST_BLOCK_SIZE) { - copy_to_bufflen = DIGEST_BLOCK_SIZE - priv->last_update_bufflen; - uadk_memcpy(priv->data + priv->last_update_bufflen, tmpdata, - copy_to_bufflen); + if (priv->last_update_bufflen > 0) { + copy_to_bufflen = DIGEST_BLOCK_SIZE - priv->last_update_bufflen; + memcpy(priv->data + priv->last_update_bufflen, tmpdata, + copy_to_bufflen); + priv->req.in = priv->data; + } else { + copy_to_bufflen = DIGEST_BLOCK_SIZE; + priv->req.in = tmpdata; + }
- priv->last_update_bufflen = DIGEST_BLOCK_SIZE; priv->req.in_bytes = DIGEST_BLOCK_SIZE; - priv->req.in = priv->data; priv->req.out = priv->out; left_len -= copy_to_bufflen; tmpdata += copy_to_bufflen; @@ -570,7 +576,7 @@ static int digest_update_inner(EVP_MD_CTX *ctx, const void *data, size_t data_le priv->last_update_bufflen = 0; if (left_len <= DIGEST_BLOCK_SIZE) { priv->last_update_bufflen = left_len; - uadk_memcpy(priv->data, tmpdata, priv->last_update_bufflen); + memcpy(priv->data, tmpdata, priv->last_update_bufflen); break; } } @@ -602,9 +608,9 @@ static int uadk_e_digest_update(EVP_MD_CTX *ctx, const void *data, size_t data_l
if (unlikely(priv->switch_flag == UADK_DO_SOFT)) goto soft_update; - + printf(" %s\n", __func__); if (priv->last_update_bufflen + data_len <= DIGEST_BLOCK_SIZE) { - uadk_memcpy(priv->data + priv->last_update_bufflen, data, data_len); + memcpy(priv->data + priv->last_update_bufflen, data, data_len); priv->last_update_bufflen += data_len; return 1; } ~
On 2022/3/31 下午7:28, Kai Ye wrote:
No assembly language is required as glibc version >= 2.32. This is because the later glibc version has updated this optimization.
Signed-off-by: Kai Ye yekai13@huawei.com
src/uadk_utils.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/uadk_utils.c b/src/uadk_utils.c index 2b34b3a..6e91ba2 100644 --- a/src/uadk_utils.c +++ b/src/uadk_utils.c @@ -14,9 +14,20 @@
- limitations under the License.
*/ +#include <gnu/libc-version.h> #include "uadk_utils.h"
-#define UADK_MEM_IMPROVE_THRESHOLD 1024 +#define GLIBC_MAIN 2U +#define GLIBC_MINOR 32U +#define UADK_MEM_IMPROVE_THRESHOLD 1024U
+#if __ARM_NEON && defined(__GLIBC__) && defined(__GLIBC_MINOR__) +#define LIBC_VERSION_PREREQ(major, minor) \
- ((__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100) < \
- (major * 10000 + minor * 100))
+#else +#define LIBC_VERSION_PREREQ(major, minor) 0 +#endif
static void *memcpy_large(void *dstpp, const void *srcpp, size_t len) { @@ -56,7 +67,9 @@ static void *memcpy_large(void *dstpp, const void *srcpp, size_t len)
void *uadk_memcpy(void *dstpp, const void *srcpp, size_t len) {
- if (len >= UADK_MEM_IMPROVE_THRESHOLD)
- /* No assembly language is required as glibc version >= 2.32 */
- if (len >= UADK_MEM_IMPROVE_THRESHOLD &&
return memcpy_large(dstpp, srcpp, len); else return memcpy(dstpp, srcpp, len);LIBC_VERSION_PREREQ(GLIBC_MAIN, GLIBC_MINOR))