2009-01-03 22:22:43 +01:00
|
|
|
/**
|
|
|
|
* \file bn_mul.h
|
2009-01-04 17:27:10 +01:00
|
|
|
*
|
2018-01-05 16:33:17 +01:00
|
|
|
* \brief Multi-precision integer library
|
|
|
|
*/
|
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2015-09-04 14:21:07 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-01-04 17:27:10 +01:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-01-03 22:22:43 +01:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Multiply source vector [s] with b, add result
|
|
|
|
* to destination vector [d] and set carry c.
|
|
|
|
*
|
|
|
|
* Currently supports:
|
|
|
|
*
|
|
|
|
* . IA-32 (386+) . AMD64 / EM64T
|
|
|
|
* . IA-32 (SSE2) . Motorola 68000
|
|
|
|
* . PowerPC, 32-bit . MicroBlaze
|
|
|
|
* . PowerPC, 64-bit . TriCore
|
|
|
|
* . SPARC v8 . ARM v3+
|
|
|
|
* . Alpha . MIPS32
|
|
|
|
* . C, longlong . C, generic
|
|
|
|
*/
|
2015-04-08 12:49:31 +02:00
|
|
|
#ifndef MBEDTLS_BN_MUL_H
|
|
|
|
#define MBEDTLS_BN_MUL_H
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2021-05-27 11:25:03 +02:00
|
|
|
#include "mbedtls/build_info.h"
|
2018-02-14 15:02:41 +01:00
|
|
|
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/bignum.h"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2021-06-24 15:48:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Conversion macros for embedded constants:
|
|
|
|
* build lists of mbedtls_mpi_uint's from lists of unsigned char's grouped by 8, 4 or 2
|
|
|
|
*/
|
|
|
|
#if defined(MBEDTLS_HAVE_INT32)
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_BYTES_TO_T_UINT_4(a, b, c, d) \
|
|
|
|
((mbedtls_mpi_uint) (a) << 0) | \
|
|
|
|
((mbedtls_mpi_uint) (b) << 8) | \
|
|
|
|
((mbedtls_mpi_uint) (c) << 16) | \
|
|
|
|
((mbedtls_mpi_uint) (d) << 24)
|
2021-06-24 15:48:38 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_BYTES_TO_T_UINT_2(a, b) \
|
|
|
|
MBEDTLS_BYTES_TO_T_UINT_4(a, b, 0, 0)
|
2021-06-24 15:48:38 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, e, f, g, h) \
|
|
|
|
MBEDTLS_BYTES_TO_T_UINT_4(a, b, c, d), \
|
|
|
|
MBEDTLS_BYTES_TO_T_UINT_4(e, f, g, h)
|
2021-06-24 15:48:38 +02:00
|
|
|
|
|
|
|
#else /* 64-bits */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, e, f, g, h) \
|
|
|
|
((mbedtls_mpi_uint) (a) << 0) | \
|
|
|
|
((mbedtls_mpi_uint) (b) << 8) | \
|
|
|
|
((mbedtls_mpi_uint) (c) << 16) | \
|
|
|
|
((mbedtls_mpi_uint) (d) << 24) | \
|
|
|
|
((mbedtls_mpi_uint) (e) << 32) | \
|
|
|
|
((mbedtls_mpi_uint) (f) << 40) | \
|
|
|
|
((mbedtls_mpi_uint) (g) << 48) | \
|
|
|
|
((mbedtls_mpi_uint) (h) << 56)
|
|
|
|
|
|
|
|
#define MBEDTLS_BYTES_TO_T_UINT_4(a, b, c, d) \
|
|
|
|
MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
#define MBEDTLS_BYTES_TO_T_UINT_2(a, b) \
|
|
|
|
MBEDTLS_BYTES_TO_T_UINT_8(a, b, 0, 0, 0, 0, 0, 0)
|
2021-06-24 15:48:38 +02:00
|
|
|
|
|
|
|
#endif /* bits in mbedtls_mpi_uint */
|
|
|
|
|
2023-01-04 18:50:08 +01:00
|
|
|
/* *INDENT-OFF* */
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_HAVE_ASM)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2015-08-10 12:08:34 +02:00
|
|
|
/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
|
|
|
|
#if defined(__GNUC__) && \
|
|
|
|
( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
|
2018-07-10 21:18:29 +02:00
|
|
|
|
2018-08-27 22:50:57 +02:00
|
|
|
/*
|
|
|
|
* GCC < 5.0 treated the x86 ebx (which is used for the GOT) as a
|
|
|
|
* fixed reserved register when building as PIC, leading to errors
|
|
|
|
* like: bn_mul.h:46:13: error: PIC register clobbered by 'ebx' in 'asm'
|
|
|
|
*
|
|
|
|
* This is fixed by an improved register allocator in GCC 5+. From the
|
|
|
|
* release notes:
|
|
|
|
* Register allocation improvements: Reuse of the PIC hard register,
|
|
|
|
* instead of using a fixed register, was implemented on x86/x86-64
|
|
|
|
* targets. This improves generated PIC code performance as more hard
|
|
|
|
* registers can be used.
|
|
|
|
*/
|
|
|
|
#if defined(__GNUC__) && __GNUC__ < 5 && defined(__PIC__)
|
|
|
|
#define MULADDC_CANNOT_USE_EBX
|
|
|
|
#endif
|
|
|
|
|
2018-07-10 21:18:29 +02:00
|
|
|
/*
|
|
|
|
* Disable use of the i386 assembly code below if option -O0, to disable all
|
|
|
|
* compiler optimisations, is passed, detected with __OPTIMIZE__
|
|
|
|
* This is done as the number of registers used in the assembly code doesn't
|
|
|
|
* work with the -O0 option.
|
|
|
|
*/
|
2018-08-27 22:50:57 +02:00
|
|
|
#if defined(__i386__) && defined(__OPTIMIZE__) && !defined(MULADDC_CANNOT_USE_EBX)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2022-04-11 11:44:02 +02:00
|
|
|
{ mbedtls_mpi_uint t; \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"movl %%ebx, %0 \n\t" \
|
|
|
|
"movl %5, %%esi \n\t" \
|
|
|
|
"movl %6, %%edi \n\t" \
|
|
|
|
"movl %7, %%ecx \n\t" \
|
|
|
|
"movl %8, %%ebx \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lodsl \n\t" \
|
|
|
|
"mull %%ebx \n\t" \
|
|
|
|
"addl %%ecx, %%eax \n\t" \
|
|
|
|
"adcl $0, %%edx \n\t" \
|
|
|
|
"addl (%%edi), %%eax \n\t" \
|
|
|
|
"adcl $0, %%edx \n\t" \
|
|
|
|
"movl %%edx, %%ecx \n\t" \
|
|
|
|
"stosl \n\t"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
|
|
|
"movl %4, %%ebx \n\t" \
|
|
|
|
"movl %%ecx, %1 \n\t" \
|
|
|
|
"movl %%edi, %2 \n\t" \
|
|
|
|
"movl %%esi, %3 \n\t" \
|
|
|
|
: "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "eax", "ebx", "ecx", "edx", "esi", "edi" \
|
|
|
|
); }
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_HAVE_SSE2)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X8_INIT MULADDC_X1_INIT
|
|
|
|
|
|
|
|
#define MULADDC_X8_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"movd %%ecx, %%mm1 \n\t" \
|
|
|
|
"movd %%ebx, %%mm0 \n\t" \
|
|
|
|
"movd (%%edi), %%mm3 \n\t" \
|
|
|
|
"paddq %%mm3, %%mm1 \n\t" \
|
|
|
|
"movd (%%esi), %%mm2 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm2 \n\t" \
|
|
|
|
"movd 4(%%esi), %%mm4 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm4 \n\t" \
|
|
|
|
"movd 8(%%esi), %%mm6 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm6 \n\t" \
|
|
|
|
"movd 12(%%esi), %%mm7 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm7 \n\t" \
|
|
|
|
"paddq %%mm2, %%mm1 \n\t" \
|
|
|
|
"movd 4(%%edi), %%mm3 \n\t" \
|
|
|
|
"paddq %%mm4, %%mm3 \n\t" \
|
|
|
|
"movd 8(%%edi), %%mm5 \n\t" \
|
|
|
|
"paddq %%mm6, %%mm5 \n\t" \
|
|
|
|
"movd 12(%%edi), %%mm4 \n\t" \
|
|
|
|
"paddq %%mm4, %%mm7 \n\t" \
|
|
|
|
"movd %%mm1, (%%edi) \n\t" \
|
|
|
|
"movd 16(%%esi), %%mm2 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm2 \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"movd 20(%%esi), %%mm4 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm4 \n\t" \
|
|
|
|
"paddq %%mm3, %%mm1 \n\t" \
|
|
|
|
"movd 24(%%esi), %%mm6 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm6 \n\t" \
|
|
|
|
"movd %%mm1, 4(%%edi) \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"movd 28(%%esi), %%mm3 \n\t" \
|
|
|
|
"pmuludq %%mm0, %%mm3 \n\t" \
|
|
|
|
"paddq %%mm5, %%mm1 \n\t" \
|
|
|
|
"movd 16(%%edi), %%mm5 \n\t" \
|
|
|
|
"paddq %%mm5, %%mm2 \n\t" \
|
|
|
|
"movd %%mm1, 8(%%edi) \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"paddq %%mm7, %%mm1 \n\t" \
|
|
|
|
"movd 20(%%edi), %%mm5 \n\t" \
|
|
|
|
"paddq %%mm5, %%mm4 \n\t" \
|
|
|
|
"movd %%mm1, 12(%%edi) \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"paddq %%mm2, %%mm1 \n\t" \
|
|
|
|
"movd 24(%%edi), %%mm5 \n\t" \
|
|
|
|
"paddq %%mm5, %%mm6 \n\t" \
|
|
|
|
"movd %%mm1, 16(%%edi) \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"paddq %%mm4, %%mm1 \n\t" \
|
|
|
|
"movd 28(%%edi), %%mm5 \n\t" \
|
|
|
|
"paddq %%mm5, %%mm3 \n\t" \
|
|
|
|
"movd %%mm1, 20(%%edi) \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"paddq %%mm6, %%mm1 \n\t" \
|
|
|
|
"movd %%mm1, 24(%%edi) \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"paddq %%mm3, %%mm1 \n\t" \
|
|
|
|
"movd %%mm1, 28(%%edi) \n\t" \
|
|
|
|
"addl $32, %%edi \n\t" \
|
|
|
|
"addl $32, %%esi \n\t" \
|
|
|
|
"psrlq $32, %%mm1 \n\t" \
|
|
|
|
"movd %%mm1, %%ecx \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X8_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"emms \n\t" \
|
|
|
|
"movl %4, %%ebx \n\t" \
|
|
|
|
"movl %%ecx, %1 \n\t" \
|
|
|
|
"movl %%edi, %2 \n\t" \
|
|
|
|
"movl %%esi, %3 \n\t" \
|
2009-07-19 23:37:39 +02:00
|
|
|
: "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
|
2018-06-24 13:58:31 +02:00
|
|
|
: "eax", "ebx", "ecx", "edx", "esi", "edi" \
|
2022-04-11 11:44:02 +02:00
|
|
|
); } \
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif /* SSE2 */
|
2022-04-06 12:25:22 +02:00
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif /* i386 */
|
|
|
|
|
|
|
|
#if defined(__amd64__) || defined (__x86_64__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
2018-09-30 13:09:47 +02:00
|
|
|
"xorq %%r8, %%r8\n"
|
2014-06-19 17:20:43 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2018-09-30 13:09:47 +02:00
|
|
|
"movq (%%rsi), %%rax\n" \
|
|
|
|
"mulq %%rbx\n" \
|
|
|
|
"addq $8, %%rsi\n" \
|
|
|
|
"addq %%rcx, %%rax\n" \
|
|
|
|
"movq %%r8, %%rcx\n" \
|
|
|
|
"adcq $0, %%rdx\n" \
|
|
|
|
"nop \n" \
|
|
|
|
"addq %%rax, (%%rdi)\n" \
|
|
|
|
"adcq %%rdx, %%rcx\n" \
|
|
|
|
"addq $8, %%rdi\n"
|
2014-06-19 17:20:43 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2021-09-14 00:13:05 +02:00
|
|
|
: "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \
|
|
|
|
: "b" (b), "m" (*(const uint64_t (*)[16]) s) \
|
|
|
|
: "rax", "rdx", "r8" \
|
2014-01-07 17:50:46 +01:00
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#endif /* AMD64 */
|
|
|
|
|
2023-06-23 16:17:37 +02:00
|
|
|
// The following assembly code assumes that a pointer will fit in a 64-bit register
|
|
|
|
// (including ILP32 __aarch64__ ABIs such as on watchOS, hence the 2^32 - 1)
|
2023-06-21 22:16:23 +02:00
|
|
|
#if defined(__aarch64__) && (UINTPTR_MAX == 0xfffffffful || UINTPTR_MAX == 0xfffffffffffffffful)
|
2018-08-16 11:01:57 +02:00
|
|
|
|
2023-06-27 10:43:55 +02:00
|
|
|
/*
|
|
|
|
* There are some issues around different compilers requiring different constraint
|
|
|
|
* syntax for updating pointers from assembly code (see notes for
|
|
|
|
* MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT in common.h), especially on aarch64_32 (aka ILP32).
|
|
|
|
*
|
|
|
|
* For this reason we cast the pointers to/from uintptr_t here.
|
|
|
|
*/
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2023-06-21 22:16:23 +02:00
|
|
|
do { uintptr_t muladdc_d = (uintptr_t) d, muladdc_s = (uintptr_t) s; asm(
|
2018-08-16 11:01:57 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2023-06-27 10:27:27 +02:00
|
|
|
"ldr x4, [%x2], #8 \n\t" \
|
|
|
|
"ldr x5, [%x1] \n\t" \
|
2021-09-22 19:15:51 +02:00
|
|
|
"mul x6, x4, %4 \n\t" \
|
|
|
|
"umulh x7, x4, %4 \n\t" \
|
2018-08-16 11:01:57 +02:00
|
|
|
"adds x5, x5, x6 \n\t" \
|
|
|
|
"adc x7, x7, xzr \n\t" \
|
2018-08-20 14:59:53 +02:00
|
|
|
"adds x5, x5, %0 \n\t" \
|
2018-08-16 11:01:57 +02:00
|
|
|
"adc %0, x7, xzr \n\t" \
|
2023-06-27 10:27:27 +02:00
|
|
|
"str x5, [%x1], #8 \n\t"
|
2018-08-16 11:01:57 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2023-06-21 17:14:46 +02:00
|
|
|
: "+r" (c), \
|
2023-06-21 22:16:23 +02:00
|
|
|
"+r" (muladdc_d), \
|
|
|
|
"+r" (muladdc_s), \
|
2023-06-21 17:14:46 +02:00
|
|
|
"+m" (*(uint64_t (*)[16]) d) \
|
2021-09-22 19:15:51 +02:00
|
|
|
: "r" (b), "m" (*(const uint64_t (*)[16]) s) \
|
|
|
|
: "x4", "x5", "x6", "x7", "cc" \
|
2023-06-21 22:16:23 +02:00
|
|
|
); d = (mbedtls_mpi_uint *)muladdc_d; s = (mbedtls_mpi_uint *)muladdc_s; } while (0);
|
2018-08-16 11:01:57 +02:00
|
|
|
|
|
|
|
#endif /* Aarch64 */
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
#if defined(__mc68020__) || defined(__mcpu32__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"movl %3, %%a2 \n\t" \
|
|
|
|
"movl %4, %%a3 \n\t" \
|
|
|
|
"movl %5, %%d3 \n\t" \
|
|
|
|
"movl %6, %%d2 \n\t" \
|
|
|
|
"moveq #0, %%d0 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d4:%%d1 \n\t" \
|
|
|
|
"addl %%d3, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d4 \n\t" \
|
|
|
|
"moveq #0, %%d3 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"addxl %%d4, %%d3 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"movl %%d3, %0 \n\t" \
|
|
|
|
"movl %%a3, %1 \n\t" \
|
|
|
|
"movl %%a2, %2 \n\t" \
|
2014-01-10 15:30:23 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X8_INIT MULADDC_X1_INIT
|
|
|
|
|
|
|
|
#define MULADDC_X8_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d4:%%d1 \n\t" \
|
|
|
|
"addxl %%d3, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d4 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d3:%%d1 \n\t" \
|
|
|
|
"addxl %%d4, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d3 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d4:%%d1 \n\t" \
|
|
|
|
"addxl %%d3, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d4 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d3:%%d1 \n\t" \
|
|
|
|
"addxl %%d4, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d3 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d4:%%d1 \n\t" \
|
|
|
|
"addxl %%d3, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d4 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d3:%%d1 \n\t" \
|
|
|
|
"addxl %%d4, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d3 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d4:%%d1 \n\t" \
|
|
|
|
"addxl %%d3, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d4 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"movel %%a2@+, %%d1 \n\t" \
|
|
|
|
"mulul %%d2, %%d3:%%d1 \n\t" \
|
|
|
|
"addxl %%d4, %%d1 \n\t" \
|
|
|
|
"addxl %%d0, %%d3 \n\t" \
|
|
|
|
"addl %%d1, %%a3@+ \n\t" \
|
|
|
|
"addxl %%d0, %%d3 \n\t"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X8_STOP MULADDC_X1_STOP
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif /* MC68000 */
|
|
|
|
|
|
|
|
#if defined(__powerpc64__) || defined(__ppc64__)
|
|
|
|
|
|
|
|
#if defined(__MACH__) && defined(__APPLE__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ld r3, %3 \n\t" \
|
|
|
|
"ld r4, %4 \n\t" \
|
|
|
|
"ld r5, %5 \n\t" \
|
|
|
|
"ld r6, %6 \n\t" \
|
|
|
|
"addi r3, r3, -8 \n\t" \
|
|
|
|
"addi r4, r4, -8 \n\t" \
|
|
|
|
"addic r5, r5, 0 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldu r7, 8(r3) \n\t" \
|
|
|
|
"mulld r8, r7, r6 \n\t" \
|
|
|
|
"mulhdu r9, r7, r6 \n\t" \
|
|
|
|
"adde r8, r8, r5 \n\t" \
|
|
|
|
"ld r7, 8(r4) \n\t" \
|
|
|
|
"addze r5, r9 \n\t" \
|
|
|
|
"addc r8, r8, r7 \n\t" \
|
|
|
|
"stdu r8, 8(r4) \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"addze r5, r5 \n\t" \
|
|
|
|
"addi r4, r4, 8 \n\t" \
|
|
|
|
"addi r3, r3, 8 \n\t" \
|
|
|
|
"std r5, %0 \n\t" \
|
|
|
|
"std r4, %1 \n\t" \
|
|
|
|
"std r3, %2 \n\t" \
|
2014-01-07 19:16:48 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
|
2014-05-01 13:03:14 +02:00
|
|
|
#else /* __MACH__ && __APPLE__ */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ld %%r3, %3 \n\t" \
|
|
|
|
"ld %%r4, %4 \n\t" \
|
|
|
|
"ld %%r5, %5 \n\t" \
|
|
|
|
"ld %%r6, %6 \n\t" \
|
|
|
|
"addi %%r3, %%r3, -8 \n\t" \
|
|
|
|
"addi %%r4, %%r4, -8 \n\t" \
|
|
|
|
"addic %%r5, %%r5, 0 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldu %%r7, 8(%%r3) \n\t" \
|
|
|
|
"mulld %%r8, %%r7, %%r6 \n\t" \
|
|
|
|
"mulhdu %%r9, %%r7, %%r6 \n\t" \
|
|
|
|
"adde %%r8, %%r8, %%r5 \n\t" \
|
|
|
|
"ld %%r7, 8(%%r4) \n\t" \
|
|
|
|
"addze %%r5, %%r9 \n\t" \
|
|
|
|
"addc %%r8, %%r8, %%r7 \n\t" \
|
|
|
|
"stdu %%r8, 8(%%r4) \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"addze %%r5, %%r5 \n\t" \
|
|
|
|
"addi %%r4, %%r4, 8 \n\t" \
|
|
|
|
"addi %%r3, %%r3, 8 \n\t" \
|
|
|
|
"std %%r5, %0 \n\t" \
|
|
|
|
"std %%r4, %1 \n\t" \
|
|
|
|
"std %%r3, %2 \n\t" \
|
2014-01-07 19:16:48 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2014-05-01 13:03:14 +02:00
|
|
|
#endif /* __MACH__ && __APPLE__ */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2014-05-06 08:26:13 +02:00
|
|
|
#elif defined(__powerpc__) || defined(__ppc__) /* end PPC64/begin PPC32 */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#if defined(__MACH__) && defined(__APPLE__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"lwz r3, %3 \n\t" \
|
|
|
|
"lwz r4, %4 \n\t" \
|
|
|
|
"lwz r5, %5 \n\t" \
|
|
|
|
"lwz r6, %6 \n\t" \
|
|
|
|
"addi r3, r3, -4 \n\t" \
|
|
|
|
"addi r4, r4, -4 \n\t" \
|
|
|
|
"addic r5, r5, 0 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lwzu r7, 4(r3) \n\t" \
|
|
|
|
"mullw r8, r7, r6 \n\t" \
|
|
|
|
"mulhwu r9, r7, r6 \n\t" \
|
|
|
|
"adde r8, r8, r5 \n\t" \
|
|
|
|
"lwz r7, 4(r4) \n\t" \
|
|
|
|
"addze r5, r9 \n\t" \
|
|
|
|
"addc r8, r8, r7 \n\t" \
|
|
|
|
"stwu r8, 4(r4) \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"addze r5, r5 \n\t" \
|
|
|
|
"addi r4, r4, 4 \n\t" \
|
|
|
|
"addi r3, r3, 4 \n\t" \
|
|
|
|
"stw r5, %0 \n\t" \
|
|
|
|
"stw r4, %1 \n\t" \
|
|
|
|
"stw r3, %2 \n\t" \
|
2014-01-07 19:16:48 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2014-05-01 13:03:14 +02:00
|
|
|
#else /* __MACH__ && __APPLE__ */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"lwz %%r3, %3 \n\t" \
|
|
|
|
"lwz %%r4, %4 \n\t" \
|
|
|
|
"lwz %%r5, %5 \n\t" \
|
|
|
|
"lwz %%r6, %6 \n\t" \
|
|
|
|
"addi %%r3, %%r3, -4 \n\t" \
|
|
|
|
"addi %%r4, %%r4, -4 \n\t" \
|
|
|
|
"addic %%r5, %%r5, 0 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lwzu %%r7, 4(%%r3) \n\t" \
|
|
|
|
"mullw %%r8, %%r7, %%r6 \n\t" \
|
|
|
|
"mulhwu %%r9, %%r7, %%r6 \n\t" \
|
|
|
|
"adde %%r8, %%r8, %%r5 \n\t" \
|
|
|
|
"lwz %%r7, 4(%%r4) \n\t" \
|
|
|
|
"addze %%r5, %%r9 \n\t" \
|
|
|
|
"addc %%r8, %%r8, %%r7 \n\t" \
|
|
|
|
"stwu %%r8, 4(%%r4) \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"addze %%r5, %%r5 \n\t" \
|
|
|
|
"addi %%r4, %%r4, 4 \n\t" \
|
|
|
|
"addi %%r3, %%r3, 4 \n\t" \
|
|
|
|
"stw %%r5, %0 \n\t" \
|
|
|
|
"stw %%r4, %1 \n\t" \
|
|
|
|
"stw %%r3, %2 \n\t" \
|
2014-01-07 19:16:48 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2014-05-01 13:03:14 +02:00
|
|
|
#endif /* __MACH__ && __APPLE__ */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#endif /* PPC32 */
|
|
|
|
|
2014-06-24 17:57:57 +02:00
|
|
|
/*
|
2015-10-21 14:52:24 +02:00
|
|
|
* The Sparc(64) assembly is reported to be broken.
|
2014-06-24 17:57:57 +02:00
|
|
|
* Disable it for now, until we're able to fix it.
|
|
|
|
*/
|
2015-10-21 14:52:24 +02:00
|
|
|
#if 0 && defined(__sparc__)
|
|
|
|
#if defined(__sparc64__)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ldx %3, %%o0 \n\t" \
|
|
|
|
"ldx %4, %%o1 \n\t" \
|
|
|
|
"ld %5, %%o2 \n\t" \
|
|
|
|
"ld %6, %%o3 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ld [%%o0], %%o4 \n\t" \
|
|
|
|
"inc 4, %%o0 \n\t" \
|
|
|
|
"ld [%%o1], %%o5 \n\t" \
|
|
|
|
"umul %%o3, %%o4, %%o4 \n\t" \
|
|
|
|
"addcc %%o4, %%o2, %%o4 \n\t" \
|
|
|
|
"rd %%y, %%g1 \n\t" \
|
|
|
|
"addx %%g1, 0, %%g1 \n\t" \
|
|
|
|
"addcc %%o4, %%o5, %%o4 \n\t" \
|
|
|
|
"st %%o4, [%%o1] \n\t" \
|
|
|
|
"addx %%g1, 0, %%o2 \n\t" \
|
|
|
|
"inc 4, %%o1 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"st %%o2, %0 \n\t" \
|
|
|
|
"stx %%o1, %1 \n\t" \
|
|
|
|
"stx %%o0, %2 \n\t" \
|
2012-10-30 08:29:57 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "g1", "o0", "o1", "o2", "o3", "o4", \
|
|
|
|
"o5" \
|
|
|
|
);
|
|
|
|
|
2015-10-21 14:52:24 +02:00
|
|
|
#else /* __sparc64__ */
|
2012-10-30 08:29:57 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ld %3, %%o0 \n\t" \
|
|
|
|
"ld %4, %%o1 \n\t" \
|
|
|
|
"ld %5, %%o2 \n\t" \
|
|
|
|
"ld %6, %%o3 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ld [%%o0], %%o4 \n\t" \
|
|
|
|
"inc 4, %%o0 \n\t" \
|
|
|
|
"ld [%%o1], %%o5 \n\t" \
|
|
|
|
"umul %%o3, %%o4, %%o4 \n\t" \
|
|
|
|
"addcc %%o4, %%o2, %%o4 \n\t" \
|
|
|
|
"rd %%y, %%g1 \n\t" \
|
|
|
|
"addx %%g1, 0, %%g1 \n\t" \
|
|
|
|
"addcc %%o4, %%o5, %%o4 \n\t" \
|
|
|
|
"st %%o4, [%%o1] \n\t" \
|
|
|
|
"addx %%g1, 0, %%o2 \n\t" \
|
|
|
|
"inc 4, %%o1 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"st %%o2, %0 \n\t" \
|
|
|
|
"st %%o1, %1 \n\t" \
|
|
|
|
"st %%o0, %2 \n\t" \
|
2012-10-30 08:29:57 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "g1", "o0", "o1", "o2", "o3", "o4", \
|
|
|
|
"o5" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2015-10-21 14:52:24 +02:00
|
|
|
#endif /* __sparc64__ */
|
|
|
|
#endif /* __sparc__ */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#if defined(__microblaze__) || defined(microblaze)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"lwi r3, %3 \n\t" \
|
|
|
|
"lwi r4, %4 \n\t" \
|
|
|
|
"lwi r5, %5 \n\t" \
|
|
|
|
"lwi r6, %6 \n\t" \
|
|
|
|
"andi r7, r6, 0xffff \n\t" \
|
|
|
|
"bsrli r6, r6, 16 \n\t"
|
|
|
|
|
2021-05-31 10:07:28 +02:00
|
|
|
#if(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
|
|
|
#define MULADDC_LHUI \
|
|
|
|
"lhui r9, r3, 0 \n\t" \
|
|
|
|
"addi r3, r3, 2 \n\t" \
|
|
|
|
"lhui r8, r3, 0 \n\t"
|
|
|
|
#else
|
|
|
|
#define MULADDC_LHUI \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lhui r8, r3, 0 \n\t" \
|
|
|
|
"addi r3, r3, 2 \n\t" \
|
2021-05-31 10:07:28 +02:00
|
|
|
"lhui r9, r3, 0 \n\t"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MULADDC_X1_CORE \
|
|
|
|
MULADDC_LHUI \
|
2014-06-19 17:20:43 +02:00
|
|
|
"addi r3, r3, 2 \n\t" \
|
|
|
|
"mul r10, r9, r6 \n\t" \
|
|
|
|
"mul r11, r8, r7 \n\t" \
|
|
|
|
"mul r12, r9, r7 \n\t" \
|
|
|
|
"mul r13, r8, r6 \n\t" \
|
|
|
|
"bsrli r8, r10, 16 \n\t" \
|
|
|
|
"bsrli r9, r11, 16 \n\t" \
|
|
|
|
"add r13, r13, r8 \n\t" \
|
|
|
|
"add r13, r13, r9 \n\t" \
|
|
|
|
"bslli r10, r10, 16 \n\t" \
|
|
|
|
"bslli r11, r11, 16 \n\t" \
|
|
|
|
"add r12, r12, r10 \n\t" \
|
|
|
|
"addc r13, r13, r0 \n\t" \
|
|
|
|
"add r12, r12, r11 \n\t" \
|
|
|
|
"addc r13, r13, r0 \n\t" \
|
|
|
|
"lwi r10, r4, 0 \n\t" \
|
|
|
|
"add r12, r12, r10 \n\t" \
|
|
|
|
"addc r13, r13, r0 \n\t" \
|
|
|
|
"add r12, r12, r5 \n\t" \
|
|
|
|
"addc r5, r13, r0 \n\t" \
|
|
|
|
"swi r12, r4, 0 \n\t" \
|
|
|
|
"addi r4, r4, 4 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"swi r5, %0 \n\t" \
|
|
|
|
"swi r4, %1 \n\t" \
|
|
|
|
"swi r3, %2 \n\t" \
|
2014-01-10 15:35:41 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
2018-05-21 16:52:34 +02:00
|
|
|
: "r3", "r4", "r5", "r6", "r7", "r8", \
|
2014-01-10 15:35:41 +01:00
|
|
|
"r9", "r10", "r11", "r12", "r13" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#endif /* MicroBlaze */
|
|
|
|
|
|
|
|
#if defined(__tricore__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ld.a %%a2, %3 \n\t" \
|
|
|
|
"ld.a %%a3, %4 \n\t" \
|
|
|
|
"ld.w %%d4, %5 \n\t" \
|
|
|
|
"ld.w %%d1, %6 \n\t" \
|
|
|
|
"xor %%d5, %%d5 \n\t"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ld.w %%d0, [%%a2+] \n\t" \
|
|
|
|
"madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
|
|
|
|
"ld.w %%d0, [%%a3] \n\t" \
|
|
|
|
"addx %%d2, %%d2, %%d0 \n\t" \
|
|
|
|
"addc %%d3, %%d3, 0 \n\t" \
|
|
|
|
"mov %%d4, %%d3 \n\t" \
|
|
|
|
"st.w [%%a3+], %%d2 \n\t"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"st.w %0, %%d4 \n\t" \
|
|
|
|
"st.a %1, %%a3 \n\t" \
|
|
|
|
"st.a %2, %%a2 \n\t" \
|
2014-01-10 15:47:50 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "d0", "d1", "e2", "d4", "a2", "a3" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#endif /* TriCore */
|
|
|
|
|
2023-05-25 13:53:41 +02:00
|
|
|
#if defined(__arm__)
|
|
|
|
|
2023-05-25 19:53:57 +02:00
|
|
|
#if defined(__thumb__) && !defined(__thumb2__)
|
2023-06-15 19:42:25 +02:00
|
|
|
#if defined(MBEDTLS_COMPILER_IS_GCC)
|
2016-01-08 14:29:11 +01:00
|
|
|
/*
|
2023-06-05 02:41:52 +02:00
|
|
|
* Thumb 1 ISA. This code path has only been tested successfully on gcc;
|
|
|
|
* it does not compile on clang or armclang.
|
2016-01-08 14:29:11 +01:00
|
|
|
*/
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2023-05-25 13:53:41 +02:00
|
|
|
#if !defined(__OPTIMIZE__) && defined(__GNUC__)
|
2023-05-25 12:01:41 +02:00
|
|
|
/*
|
|
|
|
* Note, gcc -O0 by default uses r7 for the frame pointer, so it complains about
|
|
|
|
* our use of r7 below, unless -fomit-frame-pointer is passed.
|
|
|
|
*
|
|
|
|
* On the other hand, -fomit-frame-pointer is implied by any -Ox options with
|
|
|
|
* x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
|
|
|
|
* clang and armcc5 under the same conditions).
|
|
|
|
*
|
|
|
|
* If gcc needs to use r7, we use r1 as a scratch register and have a few extra
|
|
|
|
* instructions to preserve/restore it; otherwise, we can use r7 and avoid
|
|
|
|
* the preserve/restore overhead.
|
|
|
|
*/
|
2023-06-05 02:42:17 +02:00
|
|
|
#define MULADDC_SCRATCH "RS .req r1 \n\t"
|
|
|
|
#define MULADDC_PRESERVE_SCRATCH "mov r10, r1 \n\t"
|
|
|
|
#define MULADDC_RESTORE_SCRATCH "mov r1, r10 \n\t"
|
|
|
|
#define MULADDC_SCRATCH_CLOBBER "r10"
|
2023-05-25 13:53:41 +02:00
|
|
|
#else /* !defined(__OPTIMIZE__) && defined(__GNUC__) */
|
2023-06-05 02:42:17 +02:00
|
|
|
#define MULADDC_SCRATCH "RS .req r7 \n\t"
|
|
|
|
#define MULADDC_PRESERVE_SCRATCH ""
|
|
|
|
#define MULADDC_RESTORE_SCRATCH ""
|
|
|
|
#define MULADDC_SCRATCH_CLOBBER "r7"
|
2023-05-25 13:53:41 +02:00
|
|
|
#endif /* !defined(__OPTIMIZE__) && defined(__GNUC__) */
|
2023-05-25 12:01:41 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
2023-05-25 12:01:41 +02:00
|
|
|
MULADDC_SCRATCH \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldr r0, %3 \n\t" \
|
|
|
|
"ldr r1, %4 \n\t" \
|
|
|
|
"ldr r2, %5 \n\t" \
|
|
|
|
"ldr r3, %6 \n\t" \
|
2023-05-25 12:01:41 +02:00
|
|
|
"lsr r4, r3, #16 \n\t" \
|
|
|
|
"mov r9, r4 \n\t" \
|
|
|
|
"lsl r4, r3, #16 \n\t" \
|
|
|
|
"lsr r4, r4, #16 \n\t" \
|
|
|
|
"mov r8, r4 \n\t" \
|
|
|
|
|
2014-06-19 17:20:43 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2023-06-05 02:42:28 +02:00
|
|
|
MULADDC_PRESERVE_SCRATCH \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldmia r0!, {r6} \n\t" \
|
2023-05-25 12:01:41 +02:00
|
|
|
"lsr RS, r6, #16 \n\t" \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lsl r6, r6, #16 \n\t" \
|
|
|
|
"lsr r6, r6, #16 \n\t" \
|
|
|
|
"mov r4, r8 \n\t" \
|
|
|
|
"mul r4, r6 \n\t" \
|
|
|
|
"mov r3, r9 \n\t" \
|
|
|
|
"mul r6, r3 \n\t" \
|
|
|
|
"mov r5, r9 \n\t" \
|
2023-05-25 12:01:41 +02:00
|
|
|
"mul r5, RS \n\t" \
|
2014-06-19 17:20:43 +02:00
|
|
|
"mov r3, r8 \n\t" \
|
2023-05-25 12:01:41 +02:00
|
|
|
"mul RS, r3 \n\t" \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lsr r3, r6, #16 \n\t" \
|
|
|
|
"add r5, r5, r3 \n\t" \
|
2023-05-25 12:01:41 +02:00
|
|
|
"lsr r3, RS, #16 \n\t" \
|
2014-06-19 17:20:43 +02:00
|
|
|
"add r5, r5, r3 \n\t" \
|
|
|
|
"add r4, r4, r2 \n\t" \
|
|
|
|
"mov r2, #0 \n\t" \
|
|
|
|
"adc r5, r2 \n\t" \
|
|
|
|
"lsl r3, r6, #16 \n\t" \
|
|
|
|
"add r4, r4, r3 \n\t" \
|
|
|
|
"adc r5, r2 \n\t" \
|
2023-05-25 12:01:41 +02:00
|
|
|
"lsl r3, RS, #16 \n\t" \
|
2014-06-19 17:20:43 +02:00
|
|
|
"add r4, r4, r3 \n\t" \
|
|
|
|
"adc r5, r2 \n\t" \
|
2023-06-05 02:42:28 +02:00
|
|
|
MULADDC_RESTORE_SCRATCH \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldr r3, [r1] \n\t" \
|
|
|
|
"add r4, r4, r3 \n\t" \
|
|
|
|
"adc r2, r5 \n\t" \
|
|
|
|
"stmia r1!, {r4} \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"str r2, %0 \n\t" \
|
|
|
|
"str r1, %1 \n\t" \
|
|
|
|
"str r0, %2 \n\t" \
|
2013-03-06 18:14:52 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "r0", "r1", "r2", "r3", "r4", "r5", \
|
2023-05-25 12:01:41 +02:00
|
|
|
"r6", MULADDC_SCRATCH_CLOBBER, "r8", "r9", "cc" \
|
2013-03-06 18:14:52 +01:00
|
|
|
);
|
2023-06-02 16:27:13 +02:00
|
|
|
#endif /* !defined(__ARMCC_VERSION) && !defined(__clang__) */
|
2012-07-02 10:36:36 +02:00
|
|
|
|
2023-05-25 13:53:41 +02:00
|
|
|
#elif (__ARM_ARCH >= 6) && \
|
|
|
|
defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)
|
2023-05-25 19:53:57 +02:00
|
|
|
/* Armv6-M (or later) with DSP Instruction Set Extensions.
|
|
|
|
* Requires support for either Thumb 2 or Arm ISA.
|
|
|
|
*/
|
2018-05-21 22:01:21 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2022-04-06 12:38:48 +02:00
|
|
|
{ \
|
|
|
|
mbedtls_mpi_uint tmp_a, tmp_b; \
|
|
|
|
asm volatile (
|
|
|
|
|
|
|
|
#define MULADDC_X1_CORE \
|
|
|
|
".p2align 2 \n\t" \
|
Remove explicit width suffixes from Arm bignum assembly
Within the M-profile of the Arm architecture, some instructions
admit both a 16-bit and a 32-bit encoding. For those instructions,
some assemblers support the use of the .n (narrow) and .w (wide)
suffixes to force a choice of instruction encoding width.
Forcing the size of encodings may be useful to ensure alignment
of code, which can have a significant performance impact on some
microarchitectures.
It is for this reason that a previous commit introduced explicit
.w suffixes into what was believed to be M-profile only assembly
in library/bn_mul.h.
This change, however, introduced two issues:
- First, the assembly block in question is used also for Armv7-A
systems, on which the .n/.w distinction is not meaningful
(all instructions are 32-bit).
- Second, compiler support for .n/.w suffixes appears patchy,
leading to compilation failures even when building for M-profile
targets.
This commit removes the .w annotations in order to restore working
code, deferring controlled re-introduction for the sake of performance.
Fixes #6089.
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-07-15 13:00:58 +02:00
|
|
|
"ldr %[a], [%[in]], #4 \n\t" \
|
|
|
|
"ldr %[b], [%[acc]] \n\t" \
|
2022-04-06 12:38:48 +02:00
|
|
|
"umaal %[b], %[carry], %[scalar], %[a] \n\t" \
|
Remove explicit width suffixes from Arm bignum assembly
Within the M-profile of the Arm architecture, some instructions
admit both a 16-bit and a 32-bit encoding. For those instructions,
some assemblers support the use of the .n (narrow) and .w (wide)
suffixes to force a choice of instruction encoding width.
Forcing the size of encodings may be useful to ensure alignment
of code, which can have a significant performance impact on some
microarchitectures.
It is for this reason that a previous commit introduced explicit
.w suffixes into what was believed to be M-profile only assembly
in library/bn_mul.h.
This change, however, introduced two issues:
- First, the assembly block in question is used also for Armv7-A
systems, on which the .n/.w distinction is not meaningful
(all instructions are 32-bit).
- Second, compiler support for .n/.w suffixes appears patchy,
leading to compilation failures even when building for M-profile
targets.
This commit removes the .w annotations in order to restore working
code, deferring controlled re-introduction for the sake of performance.
Fixes #6089.
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-07-15 13:00:58 +02:00
|
|
|
"str %[b], [%[acc]], #4 \n\t"
|
2022-04-06 12:38:48 +02:00
|
|
|
|
|
|
|
#define MULADDC_X1_STOP \
|
|
|
|
: [a] "=&r" (tmp_a), \
|
|
|
|
[b] "=&r" (tmp_b), \
|
|
|
|
[in] "+r" (s), \
|
|
|
|
[acc] "+r" (d), \
|
|
|
|
[carry] "+l" (c) \
|
|
|
|
: [scalar] "r" (b) \
|
|
|
|
: "memory" \
|
|
|
|
); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MULADDC_X2_INIT \
|
|
|
|
{ \
|
|
|
|
mbedtls_mpi_uint tmp_a0, tmp_b0; \
|
|
|
|
mbedtls_mpi_uint tmp_a1, tmp_b1; \
|
|
|
|
asm volatile (
|
|
|
|
|
2022-04-17 07:57:34 +02:00
|
|
|
/* - Make sure loop is 4-byte aligned to avoid stalls
|
|
|
|
* upon repeated non-word aligned instructions in
|
|
|
|
* some microarchitectures.
|
|
|
|
* - Don't use ldm with post-increment or back-to-back
|
|
|
|
* loads with post-increment and same address register
|
|
|
|
* to avoid stalls on some microarchitectures.
|
|
|
|
* - Bunch loads and stores to reduce latency on some
|
|
|
|
* microarchitectures. E.g., on Cortex-M4, the first
|
|
|
|
* in a series of load/store operations has latency
|
|
|
|
* 2 cycles, while subsequent loads/stores are single-cycle. */
|
2022-04-06 12:38:48 +02:00
|
|
|
#define MULADDC_X2_CORE \
|
|
|
|
".p2align 2 \n\t" \
|
Remove explicit width suffixes from Arm bignum assembly
Within the M-profile of the Arm architecture, some instructions
admit both a 16-bit and a 32-bit encoding. For those instructions,
some assemblers support the use of the .n (narrow) and .w (wide)
suffixes to force a choice of instruction encoding width.
Forcing the size of encodings may be useful to ensure alignment
of code, which can have a significant performance impact on some
microarchitectures.
It is for this reason that a previous commit introduced explicit
.w suffixes into what was believed to be M-profile only assembly
in library/bn_mul.h.
This change, however, introduced two issues:
- First, the assembly block in question is used also for Armv7-A
systems, on which the .n/.w distinction is not meaningful
(all instructions are 32-bit).
- Second, compiler support for .n/.w suffixes appears patchy,
leading to compilation failures even when building for M-profile
targets.
This commit removes the .w annotations in order to restore working
code, deferring controlled re-introduction for the sake of performance.
Fixes #6089.
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-07-15 13:00:58 +02:00
|
|
|
"ldr %[a0], [%[in]], #+8 \n\t" \
|
|
|
|
"ldr %[b0], [%[acc]], #+8 \n\t" \
|
|
|
|
"ldr %[a1], [%[in], #-4] \n\t" \
|
|
|
|
"ldr %[b1], [%[acc], #-4] \n\t" \
|
2022-04-06 12:38:48 +02:00
|
|
|
"umaal %[b0], %[carry], %[scalar], %[a0] \n\t" \
|
|
|
|
"umaal %[b1], %[carry], %[scalar], %[a1] \n\t" \
|
Remove explicit width suffixes from Arm bignum assembly
Within the M-profile of the Arm architecture, some instructions
admit both a 16-bit and a 32-bit encoding. For those instructions,
some assemblers support the use of the .n (narrow) and .w (wide)
suffixes to force a choice of instruction encoding width.
Forcing the size of encodings may be useful to ensure alignment
of code, which can have a significant performance impact on some
microarchitectures.
It is for this reason that a previous commit introduced explicit
.w suffixes into what was believed to be M-profile only assembly
in library/bn_mul.h.
This change, however, introduced two issues:
- First, the assembly block in question is used also for Armv7-A
systems, on which the .n/.w distinction is not meaningful
(all instructions are 32-bit).
- Second, compiler support for .n/.w suffixes appears patchy,
leading to compilation failures even when building for M-profile
targets.
This commit removes the .w annotations in order to restore working
code, deferring controlled re-introduction for the sake of performance.
Fixes #6089.
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
2022-07-15 13:00:58 +02:00
|
|
|
"str %[b0], [%[acc], #-8] \n\t" \
|
|
|
|
"str %[b1], [%[acc], #-4] \n\t"
|
2022-04-06 12:38:48 +02:00
|
|
|
|
|
|
|
#define MULADDC_X2_STOP \
|
|
|
|
: [a0] "=&r" (tmp_a0), \
|
|
|
|
[b0] "=&r" (tmp_b0), \
|
|
|
|
[a1] "=&r" (tmp_a1), \
|
|
|
|
[b1] "=&r" (tmp_b1), \
|
|
|
|
[in] "+r" (s), \
|
|
|
|
[acc] "+r" (d), \
|
|
|
|
[carry] "+l" (c) \
|
|
|
|
: [scalar] "r" (b) \
|
|
|
|
: "memory" \
|
|
|
|
); \
|
|
|
|
}
|
2018-05-21 22:01:21 +02:00
|
|
|
|
2023-06-05 02:42:28 +02:00
|
|
|
#else /* Thumb 2 or Arm ISA, without DSP extensions */
|
2011-11-18 13:47:23 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ldr r0, %3 \n\t" \
|
|
|
|
"ldr r1, %4 \n\t" \
|
|
|
|
"ldr r2, %5 \n\t" \
|
|
|
|
"ldr r3, %6 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldr r4, [r0], #4 \n\t" \
|
|
|
|
"mov r5, #0 \n\t" \
|
|
|
|
"ldr r6, [r1] \n\t" \
|
|
|
|
"umlal r2, r5, r3, r4 \n\t" \
|
2023-05-25 12:00:05 +02:00
|
|
|
"adds r4, r6, r2 \n\t" \
|
2014-06-19 17:20:43 +02:00
|
|
|
"adc r2, r5, #0 \n\t" \
|
2023-05-25 12:00:05 +02:00
|
|
|
"str r4, [r1], #4 \n\t"
|
2014-06-19 17:20:43 +02:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"str r2, %0 \n\t" \
|
|
|
|
"str r1, %1 \n\t" \
|
|
|
|
"str r0, %2 \n\t" \
|
2013-03-06 18:14:52 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "r0", "r1", "r2", "r3", "r4", "r5", \
|
2023-05-25 12:00:05 +02:00
|
|
|
"r6", "cc" \
|
2013-03-06 18:14:52 +01:00
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2023-05-25 13:53:41 +02:00
|
|
|
#endif /* ISA codepath selection */
|
|
|
|
|
|
|
|
#endif /* defined(__arm__) */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#if defined(__alpha__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"ldq $1, %3 \n\t" \
|
|
|
|
"ldq $2, %4 \n\t" \
|
|
|
|
"ldq $3, %5 \n\t" \
|
|
|
|
"ldq $4, %6 \n\t"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"ldq $6, 0($1) \n\t" \
|
|
|
|
"addq $1, 8, $1 \n\t" \
|
|
|
|
"mulq $6, $4, $7 \n\t" \
|
|
|
|
"umulh $6, $4, $6 \n\t" \
|
|
|
|
"addq $7, $3, $7 \n\t" \
|
|
|
|
"cmpult $7, $3, $3 \n\t" \
|
|
|
|
"ldq $5, 0($2) \n\t" \
|
|
|
|
"addq $7, $5, $7 \n\t" \
|
|
|
|
"cmpult $7, $5, $5 \n\t" \
|
|
|
|
"stq $7, 0($2) \n\t" \
|
|
|
|
"addq $2, 8, $2 \n\t" \
|
|
|
|
"addq $6, $3, $3 \n\t" \
|
|
|
|
"addq $5, $3, $3 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"stq $3, %0 \n\t" \
|
|
|
|
"stq $2, %1 \n\t" \
|
|
|
|
"stq $1, %2 \n\t" \
|
2014-01-10 15:53:41 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
|
|
|
: "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
|
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif /* Alpha */
|
|
|
|
|
2014-12-16 16:24:06 +01:00
|
|
|
#if defined(__mips__) && !defined(__mips64)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2014-06-19 17:20:43 +02:00
|
|
|
asm( \
|
|
|
|
"lw $10, %3 \n\t" \
|
|
|
|
"lw $11, %4 \n\t" \
|
|
|
|
"lw $12, %5 \n\t" \
|
|
|
|
"lw $13, %6 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2014-06-19 17:20:43 +02:00
|
|
|
"lw $14, 0($10) \n\t" \
|
|
|
|
"multu $13, $14 \n\t" \
|
|
|
|
"addi $10, $10, 4 \n\t" \
|
|
|
|
"mflo $14 \n\t" \
|
|
|
|
"mfhi $9 \n\t" \
|
|
|
|
"addu $14, $12, $14 \n\t" \
|
|
|
|
"lw $15, 0($11) \n\t" \
|
|
|
|
"sltu $12, $14, $12 \n\t" \
|
|
|
|
"addu $15, $14, $15 \n\t" \
|
|
|
|
"sltu $14, $15, $14 \n\t" \
|
|
|
|
"addu $12, $12, $9 \n\t" \
|
|
|
|
"sw $15, 0($11) \n\t" \
|
|
|
|
"addu $12, $12, $14 \n\t" \
|
|
|
|
"addi $11, $11, 4 \n\t"
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2014-06-19 17:20:43 +02:00
|
|
|
"sw $12, %0 \n\t" \
|
|
|
|
"sw $11, %1 \n\t" \
|
|
|
|
"sw $10, %2 \n\t" \
|
2014-01-07 18:31:06 +01:00
|
|
|
: "=m" (c), "=m" (d), "=m" (s) \
|
|
|
|
: "m" (s), "m" (d), "m" (c), "m" (b) \
|
2019-01-15 01:01:40 +01:00
|
|
|
: "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \
|
2014-01-07 18:31:06 +01:00
|
|
|
);
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#endif /* MIPS */
|
|
|
|
#endif /* GNUC */
|
|
|
|
|
|
|
|
#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2009-01-03 22:22:43 +01:00
|
|
|
__asm mov esi, s \
|
|
|
|
__asm mov edi, d \
|
|
|
|
__asm mov ecx, c \
|
|
|
|
__asm mov ebx, b
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2009-01-03 22:22:43 +01:00
|
|
|
__asm lodsd \
|
|
|
|
__asm mul ebx \
|
|
|
|
__asm add eax, ecx \
|
|
|
|
__asm adc edx, 0 \
|
|
|
|
__asm add eax, [edi] \
|
|
|
|
__asm adc edx, 0 \
|
|
|
|
__asm mov ecx, edx \
|
|
|
|
__asm stosd
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
|
|
|
__asm mov c, ecx \
|
|
|
|
__asm mov d, edi \
|
|
|
|
__asm mov s, esi
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_HAVE_SSE2)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#define EMIT __asm _emit
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X8_INIT MULADDC_X1_INIT
|
|
|
|
|
|
|
|
#define MULADDC_X8_CORE \
|
2009-01-03 22:22:43 +01:00
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x1F \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x16 \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x0F \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
|
|
|
|
EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
|
|
|
|
EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
|
|
|
|
EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
|
|
|
|
EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
|
|
|
|
EMIT 0x0F EMIT 0x7E EMIT 0xC9
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X8_STOP \
|
2009-01-03 22:22:43 +01:00
|
|
|
EMIT 0x0F EMIT 0x77 \
|
|
|
|
__asm mov c, ecx \
|
|
|
|
__asm mov d, edi \
|
2022-04-06 12:25:22 +02:00
|
|
|
__asm mov s, esi
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
#endif /* SSE2 */
|
|
|
|
#endif /* MSVC */
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_HAVE_ASM */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#if !defined(MULADDC_X1_CORE)
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_HAVE_UDBL)
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_INIT \
|
2009-01-03 22:22:43 +01:00
|
|
|
{ \
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_t_udbl r; \
|
|
|
|
mbedtls_mpi_uint r0, r1;
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2015-04-08 12:49:31 +02:00
|
|
|
r = *(s++) * (mbedtls_t_udbl) b; \
|
|
|
|
r0 = (mbedtls_mpi_uint) r; \
|
|
|
|
r1 = (mbedtls_mpi_uint)( r >> biL ); \
|
2009-01-03 22:22:43 +01:00
|
|
|
r0 += c; r1 += (r0 < c); \
|
|
|
|
r0 += *d; r1 += (r0 < *d); \
|
|
|
|
c = r1; *(d++) = r0;
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#else /* MBEDTLS_HAVE_UDBL */
|
|
|
|
|
|
|
|
#define MULADDC_X1_INIT \
|
2009-01-03 22:22:43 +01:00
|
|
|
{ \
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_mpi_uint s0, s1, b0, b1; \
|
|
|
|
mbedtls_mpi_uint r0, r1, rx, ry; \
|
2009-01-03 22:22:43 +01:00
|
|
|
b0 = ( b << biH ) >> biH; \
|
|
|
|
b1 = ( b >> biH );
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_CORE \
|
2009-01-03 22:22:43 +01:00
|
|
|
s0 = ( *s << biH ) >> biH; \
|
|
|
|
s1 = ( *s >> biH ); s++; \
|
|
|
|
rx = s0 * b1; r0 = s0 * b0; \
|
|
|
|
ry = s1 * b0; r1 = s1 * b1; \
|
|
|
|
r1 += ( rx >> biH ); \
|
|
|
|
r1 += ( ry >> biH ); \
|
|
|
|
rx <<= biH; ry <<= biH; \
|
|
|
|
r0 += rx; r1 += (r0 < rx); \
|
|
|
|
r0 += ry; r1 += (r0 < ry); \
|
|
|
|
r0 += c; r1 += (r0 < c); \
|
|
|
|
r0 += *d; r1 += (r0 < *d); \
|
|
|
|
c = r1; *(d++) = r0;
|
|
|
|
|
2022-04-06 12:25:22 +02:00
|
|
|
#define MULADDC_X1_STOP \
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* C (longlong) */
|
2022-04-06 12:25:22 +02:00
|
|
|
#endif /* C (generic) */
|
|
|
|
|
|
|
|
#if !defined(MULADDC_X2_CORE)
|
|
|
|
#define MULADDC_X2_INIT MULADDC_X1_INIT
|
|
|
|
#define MULADDC_X2_STOP MULADDC_X1_STOP
|
|
|
|
#define MULADDC_X2_CORE MULADDC_X1_CORE MULADDC_X1_CORE
|
|
|
|
#endif /* MULADDC_X2_CORE */
|
|
|
|
|
|
|
|
#if !defined(MULADDC_X4_CORE)
|
|
|
|
#define MULADDC_X4_INIT MULADDC_X2_INIT
|
|
|
|
#define MULADDC_X4_STOP MULADDC_X2_STOP
|
|
|
|
#define MULADDC_X4_CORE MULADDC_X2_CORE MULADDC_X2_CORE
|
|
|
|
#endif /* MULADDC_X4_CORE */
|
|
|
|
|
|
|
|
#if !defined(MULADDC_X8_CORE)
|
|
|
|
#define MULADDC_X8_INIT MULADDC_X4_INIT
|
|
|
|
#define MULADDC_X8_STOP MULADDC_X4_STOP
|
|
|
|
#define MULADDC_X8_CORE MULADDC_X4_CORE MULADDC_X4_CORE
|
|
|
|
#endif /* MULADDC_X8_CORE */
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2023-01-05 10:50:47 +01:00
|
|
|
/* *INDENT-ON* */
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif /* bn_mul.h */
|