mirror of
https://github.com/aaru-dps/Aaru.Checksums.Native.git
synced 2025-12-16 19:24:29 +00:00
Refactor code.
This commit is contained in:
@@ -112,14 +112,14 @@ TARGET_WITH_SIMD void adler32_neon(uint16_t* sum1, uint16_t* sum2, const uint8_t
|
|||||||
* Multiply-add bytes by [ 32, 31, 30, ... ] for s2.
|
* Multiply-add bytes by [ 32, 31, 30, ... ] for s2.
|
||||||
*/
|
*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_1), neon_ld1m_16((uint16_t[]) {32, 31, 30, 29}));
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_1), neon_ld1m_16((uint16_t[]){32, 31, 30, 29}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1), neon_ld1m_16((uint16_t[]){28, 27, 26, 25}));
|
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1), neon_ld1m_16((uint16_t[]){28, 27, 26, 25}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_2), neon_ld1m_16((uint16_t[]) {24, 23, 22, 21}));
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_2), neon_ld1m_16((uint16_t[]){24, 23, 22, 21}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_2), neon_ld1m_16((uint16_t[]) {20, 19, 18, 17}));
|
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_2), neon_ld1m_16((uint16_t[]){20, 19, 18, 17}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_3), neon_ld1m_16((uint16_t[]) {16, 15, 14, 13}));
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_3), neon_ld1m_16((uint16_t[]){16, 15, 14, 13}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_3), neon_ld1m_16((uint16_t[]) {12, 11, 10, 9}));
|
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_3), neon_ld1m_16((uint16_t[]){12, 11, 10, 9}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_4), neon_ld1m_16((uint16_t[]) {8, 7, 6, 5}));
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_4), neon_ld1m_16((uint16_t[]){8, 7, 6, 5}));
|
||||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_4), neon_ld1m_16((uint16_t[]) {4, 3, 2, 1}));
|
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_4), neon_ld1m_16((uint16_t[]){4, 3, 2, 1}));
|
||||||
#else
|
#else
|
||||||
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_1), (uint16x4_t){32, 31, 30, 29});
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_column_sum_1), (uint16x4_t){32, 31, 30, 29});
|
||||||
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1), (uint16x4_t){28, 27, 26, 25});
|
v_s2 = vmlal_u16(v_s2, vget_high_u16(v_column_sum_1), (uint16x4_t){28, 27, 26, 25});
|
||||||
|
|||||||
@@ -26,13 +26,13 @@
|
|||||||
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
|
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
|
||||||
|
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
#include "arm_vmull.h"
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "crc32_simd.h"
|
#include "crc32_simd.h"
|
||||||
#include "arm_vmull.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* somewhat surprisingly the "naive" way of doing this, ie. with a flag and a cond. branch,
|
* somewhat surprisingly the "naive" way of doing this, ie. with a flag and a cond. branch,
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the Aaru Data Preservation Suite.
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
* Copyright (c) 2019-2021 Natalia Portillo.
|
* Copyright (c) 2019-2021 Natalia Portillo.
|
||||||
*
|
*
|
||||||
* This file is under the public domain:
|
* This file is under the public domain:
|
||||||
* https://github.com/rawrunprotected/crc
|
* https://github.com/rawrunprotected/crc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
|
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
|
||||||
|
|
||||||
#include <arm_neon.h>
|
#include <arm_neon.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
#include "arm_vmull.h"
|
#include "arm_vmull.h"
|
||||||
|
|||||||
32
library.h
32
library.h
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the Aaru Data Preservation Suite.
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
* Copyright (c) 2019-2021 Natalia Portillo.
|
* Copyright (c) 2019-2021 Natalia Portillo.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
* published by the Free Software Foundation; either version 2.1 of the
|
* published by the Free Software Foundation; either version 2.1 of the
|
||||||
* License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful, but
|
* This library is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef AARU_CHECKSUMS_NATIVE_LIBRARY_H
|
#ifndef AARU_CHECKSUMS_NATIVE_LIBRARY_H
|
||||||
#define AARU_CHECKSUMS_NATIVE_LIBRARY_H
|
#define AARU_CHECKSUMS_NATIVE_LIBRARY_H
|
||||||
|
|||||||
47
simd.c
47
simd.c
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the Aaru Data Preservation Suite.
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
* Copyright (c) 2019-2021 Natalia Portillo.
|
* Copyright (c) 2019-2021 Natalia Portillo.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
* published by the Free Software Foundation; either version 2.1 of the
|
* published by the Free Software Foundation; either version 2.1 of the
|
||||||
* License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful, but
|
* This library is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
#include "simd.h"
|
#include "simd.h"
|
||||||
@@ -112,6 +112,7 @@ int have_avx2(void)
|
|||||||
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
|
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <processthreadsapi.h>
|
#include <processthreadsapi.h>
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
@@ -120,16 +121,14 @@ int have_avx2(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)) && defined(__APPLE__)
|
#if(defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)) && defined(__APPLE__)
|
||||||
int have_neon_apple()
|
int have_neon_apple()
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
size_t len = sizeof(int);
|
size_t len = sizeof(int);
|
||||||
int ret=
|
int ret = sysctlbyname("hw.optional.neon", &value, &len, NULL, 0);
|
||||||
sysctlbyname("hw.optional.neon", &value, &len, NULL, 0);
|
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
return value == 1;
|
return value == 1;
|
||||||
}
|
}
|
||||||
@@ -138,11 +137,9 @@ int have_crc32_apple()
|
|||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
size_t len = sizeof(int);
|
size_t len = sizeof(int);
|
||||||
int ret=
|
int ret = sysctlbyname("hw.optional.crc32", &value, &len, NULL, 0);
|
||||||
sysctlbyname("hw.optional.crc32", &value, &len, NULL, 0);
|
|
||||||
|
|
||||||
if(ret != 0)
|
if(ret != 0) return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
return value == 1;
|
return value == 1;
|
||||||
}
|
}
|
||||||
|
|||||||
32
simd.h
32
simd.h
@@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the Aaru Data Preservation Suite.
|
* This file is part of the Aaru Data Preservation Suite.
|
||||||
* Copyright (c) 2019-2021 Natalia Portillo.
|
* Copyright (c) 2019-2021 Natalia Portillo.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
* it under the terms of the GNU Lesser General Public License as
|
||||||
* published by the Free Software Foundation; either version 2.1 of the
|
* published by the Free Software Foundation; either version 2.1 of the
|
||||||
* License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful, but
|
* This library is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef AARU_CHECKSUMS_NATIVE_SIMD_H
|
#ifndef AARU_CHECKSUMS_NATIVE_SIMD_H
|
||||||
#define AARU_CHECKSUMS_NATIVE_SIMD_H
|
#define AARU_CHECKSUMS_NATIVE_SIMD_H
|
||||||
|
|||||||
26
spamsum.c
26
spamsum.c
@@ -141,7 +141,7 @@ AARU_LOCAL inline void roll_hash(spamsum_ctx* ctx, uint8_t c)
|
|||||||
|
|
||||||
AARU_LOCAL inline void fuzzy_try_reduce_blockhash(spamsum_ctx* ctx)
|
AARU_LOCAL inline void fuzzy_try_reduce_blockhash(spamsum_ctx* ctx)
|
||||||
{
|
{
|
||||||
//assert(ctx->bh_start < ctx->bh_end);
|
// assert(ctx->bh_start < ctx->bh_end);
|
||||||
|
|
||||||
if(ctx->bh_end - ctx->bh_start < 2) /* Need at least two working hashes. */
|
if(ctx->bh_end - ctx->bh_start < 2) /* Need at least two working hashes. */
|
||||||
return;
|
return;
|
||||||
@@ -163,7 +163,7 @@ AARU_LOCAL inline void fuzzy_try_fork_blockhash(spamsum_ctx* ctx)
|
|||||||
{
|
{
|
||||||
if(ctx->bh_end >= NUM_BLOCKHASHES) return;
|
if(ctx->bh_end >= NUM_BLOCKHASHES) return;
|
||||||
|
|
||||||
//assert(ctx->bh_end != 0);
|
// assert(ctx->bh_end != 0);
|
||||||
|
|
||||||
uint32_t obh = ctx->bh_end - 1;
|
uint32_t obh = ctx->bh_end - 1;
|
||||||
uint32_t nbh = ctx->bh_end;
|
uint32_t nbh = ctx->bh_end;
|
||||||
@@ -184,7 +184,7 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
if(!result) return -1;
|
if(!result) return -1;
|
||||||
|
|
||||||
/* Verify that our elimination was not overeager. */
|
/* Verify that our elimination was not overeager. */
|
||||||
//assert(bi == 0 || (uint64_t)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < ctx->total_size);
|
// assert(bi == 0 || (uint64_t)SSDEEP_BS(bi) / 2 * SPAMSUM_LENGTH < ctx->total_size);
|
||||||
|
|
||||||
/* Initial blocksize guess. */
|
/* Initial blocksize guess. */
|
||||||
while((uint64_t)SSDEEP_BS(bi) * SPAMSUM_LENGTH < ctx->total_size)
|
while((uint64_t)SSDEEP_BS(bi) * SPAMSUM_LENGTH < ctx->total_size)
|
||||||
@@ -203,21 +203,21 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
|
|
||||||
while(bi > ctx->bh_start && ctx->bh[bi].d_len < SPAMSUM_LENGTH / 2) --bi;
|
while(bi > ctx->bh_start && ctx->bh[bi].d_len < SPAMSUM_LENGTH / 2) --bi;
|
||||||
|
|
||||||
//assert(!(bi > 0 && ctx->bh[bi].d_len < SPAMSUM_LENGTH / 2));
|
// assert(!(bi > 0 && ctx->bh[bi].d_len < SPAMSUM_LENGTH / 2));
|
||||||
|
|
||||||
int i = snprintf((char*)result, (size_t)remain, "%lu:", (unsigned long)SSDEEP_BS(bi));
|
int i = snprintf((char*)result, (size_t)remain, "%lu:", (unsigned long)SSDEEP_BS(bi));
|
||||||
|
|
||||||
if(i <= 0) /* Maybe snprintf has set errno here? */
|
if(i <= 0) /* Maybe snprintf has set errno here? */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
//assert(i < remain);
|
// assert(i < remain);
|
||||||
|
|
||||||
remain -= i;
|
remain -= i;
|
||||||
result += i;
|
result += i;
|
||||||
|
|
||||||
i = (int)ctx->bh[bi].d_len;
|
i = (int)ctx->bh[bi].d_len;
|
||||||
|
|
||||||
//assert(i <= remain);
|
// assert(i <= remain);
|
||||||
|
|
||||||
memcpy(result, ctx->bh[bi].digest, (size_t)i);
|
memcpy(result, ctx->bh[bi].digest, (size_t)i);
|
||||||
result += i;
|
result += i;
|
||||||
@@ -225,7 +225,7 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
|
|
||||||
if(h != 0)
|
if(h != 0)
|
||||||
{
|
{
|
||||||
//assert(remain > 0);
|
// assert(remain > 0);
|
||||||
|
|
||||||
*result = b64[ctx->bh[bi].h % 64];
|
*result = b64[ctx->bh[bi].h % 64];
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
}
|
}
|
||||||
else if(ctx->bh[bi].digest[i] != 0)
|
else if(ctx->bh[bi].digest[i] != 0)
|
||||||
{
|
{
|
||||||
//assert(remain > 0);
|
// assert(remain > 0);
|
||||||
|
|
||||||
*result = ctx->bh[bi].digest[i];
|
*result = ctx->bh[bi].digest[i];
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//assert(remain > 0);
|
// assert(remain > 0);
|
||||||
|
|
||||||
*result++ = ':';
|
*result++ = ':';
|
||||||
--remain;
|
--remain;
|
||||||
@@ -267,7 +267,7 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
|
|
||||||
if(h != 0)
|
if(h != 0)
|
||||||
{
|
{
|
||||||
//assert(remain > 0);
|
// assert(remain > 0);
|
||||||
|
|
||||||
h = ctx->bh[bi].half_h;
|
h = ctx->bh[bi].half_h;
|
||||||
*result = b64[h % 64];
|
*result = b64[h % 64];
|
||||||
@@ -284,7 +284,7 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
|
|
||||||
if(i != 0)
|
if(i != 0)
|
||||||
{
|
{
|
||||||
//assert(remain > 0);
|
// assert(remain > 0);
|
||||||
|
|
||||||
*result = (uint8_t)i;
|
*result = (uint8_t)i;
|
||||||
|
|
||||||
@@ -298,9 +298,9 @@ AARU_EXPORT int AARU_CALL spamsum_final(spamsum_ctx* ctx, uint8_t* result)
|
|||||||
}
|
}
|
||||||
else if(h != 0)
|
else if(h != 0)
|
||||||
{
|
{
|
||||||
//assert(ctx->bh[bi].d_len == 0);
|
// assert(ctx->bh[bi].d_len == 0);
|
||||||
|
|
||||||
//assert(remain > 0);
|
// assert(remain > 0);
|
||||||
|
|
||||||
*result++ = b64[ctx->bh[bi].h % 64];
|
*result++ = b64[ctx->bh[bi].h % 64];
|
||||||
/* No need to bother with FUZZY_FLAG_ELIMSEQ, because this
|
/* No need to bother with FUZZY_FLAG_ELIMSEQ, because this
|
||||||
|
|||||||
Reference in New Issue
Block a user