From b7005116df8957e576a7a2401366c357b7dcc0a9 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 6 Apr 2024 17:28:33 -0400 Subject: Use inline assembly Signed-off-by: Ian Moffett --- src/main.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index fddef12..dd4db27 100644 --- a/src/main.c +++ b/src/main.c @@ -34,9 +34,6 @@ #include #include #include -#if defined(__x86_64__) -#include -#endif /* defined(__x86_64__) */ #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ #error "Big endian machines not supported yet" @@ -176,12 +173,30 @@ encrypt(const struct cpu_info *info, char *buf, size_t buf_size) step >>= 1; switch (step) { +#if defined(__x86_64__) case 32: - accel_invert256((uintptr_t)buf + current_pos); + __asm__ __volatile__( + "vmovdqu (%0), %%ymm1\n" /* Load data into %YMM1 */ + "vpcmpeqb %%ymm0, %%ymm0, %%ymm0\n" /* Set %YMM0 to 1s */ + "vpxor %%ymm1, %%ymm0, %%ymm0\n" /* NOT %YMM1 -> %YMM0 */ + "vmovdqu %%ymm0, (%1)\n" /* Writeback result */ + : + : "r" ((uintptr_t)buf + current_pos), + "r" ((uintptr_t)buf + current_pos) + ); break; case 16: - accel_invert128((uintptr_t)buf + current_pos); + __asm__ __volatile__( + "movdqu (%0), %%xmm0\n" /* Read 128 bits -> %XMM0 */ + "pcmpeqb %%xmm1, %%xmm1\n" /* Set %XMM1 to all 1s */ + "pxor %%xmm0, %%xmm1\n" /* NOT %XMM0 -> %XMM1 */ + "movdqu %%xmm1, (%0)\n" + : + : "r" ((uintptr_t)buf + current_pos), + "r" ((uintptr_t)buf + current_pos) + ); break; +#endif case 8: flip_block(tmp, uint64_t, buf, current_pos); break; -- cgit v1.2.3