bn_mul.h
mbedtls/config.h
mbedtls/bignum.h
mbedtls/bignum.h
bn_mul.h
mbedtls/check_config.h
mbedtls/config.h
limits.h
stddef.h
stdint.h
stdio.h
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)
MBEDTLS_BYTES_TO_T_UINT_2
a
b
MBEDTLS_BYTES_TO_T_UINT_4
(a, b, 0, 0)
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)
asm
__asm
MULADDC_INIT
{ \ mbedtls_t_udbl r; \ mbedtls_mpi_uint r0, r1;
MULADDC_CORE
r = *(s++) * (mbedtls_t_udbl) b; \ r0 = (mbedtls_mpi_uint) r; \ r1 = (mbedtls_mpi_uint)( r >> biL ); \ r0 += c; r1 += (r0 < c); \ r0 += *d; r1 += (r0 < *d); \ c = r1; *(d++) = r0;
MULADDC_STOP
}

Multi-precision integer library.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    /*
    *Multiplysourcevector[s]withb,addresult
    *todestinationvector[d]andsetcarryc.
    *
    *Currentlysupports:
    *
    *.IA-32(386+).AMD64/EM64T
    *.IA-32(SSE2).Motorola68000
    *.PowerPC,32-bit.MicroBlaze
    *.PowerPC,64-bit.TriCore
    *.SPARCv8.ARMv3+
    *.Alpha.MIPS32
    *.C,longlong.C,generic
    */
    #ifndefMBEDTLS_BN_MUL_H
    #defineMBEDTLS_BN_MUL_H

    #if!defined(MBEDTLS_CONFIG_FILE)
    #include"mbedtls/config.h"
    #else
    #includeMBEDTLS_CONFIG_FILE
    #endif

    #include"mbedtls/bignum.h"

    /*
    *Conversionmacrosforembeddedconstants:
    *buildlistsofmbedtls_mpi_uint'sfromlistsofunsignedchar'sgroupedby8,4or2
    */
    #ifdefined(MBEDTLS_HAVE_INT32)

    #defineMBEDTLS_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)

    #defineMBEDTLS_BYTES_TO_T_UINT_2(a,b)\
    MBEDTLS_BYTES_TO_T_UINT_4(a,b,0,0)

    #defineMBEDTLS_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)

    #else/*64-bits*/

    #defineMBEDTLS_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)

    #defineMBEDTLS_BYTES_TO_T_UINT_4(a,b,c,d)\
    MBEDTLS_BYTES_TO_T_UINT_8(a,b,c,d,0,0,0,0)

    #defineMBEDTLS_BYTES_TO_T_UINT_2(a,b)\
    MBEDTLS_BYTES_TO_T_UINT_8(a,b,0,0,0,0,0,0)

    #endif/*bitsinmbedtls_mpi_uint*/

    /**INDENT-OFF**/
    #ifdefined(MBEDTLS_HAVE_ASM)

    #ifndefasm
    #defineasm__asm
    #endif

    /*armcc5--gnudefines__GNUC__butdoesn'tsupportGNU'sextendedasm*/
    #ifdefined(__GNUC__)&&\
    (!defined(__ARMCC_VERSION)||__ARMCC_VERSION>=6000000)

    /*
    *GCC<5.0treatedthex86ebx(whichisusedfortheGOT)asa
    *fixedreservedregisterwhenbuildingasPIC,leadingtoerrors
    *like:bn_mul.h:46:13:error:PICregisterclobberedby'ebx'in'asm'
    *
    *ThisisfixedbyanimprovedregisterallocatorinGCC5+.Fromthe
    *releasenotes:
    *Registerallocationimprovements:ReuseofthePIChardregister,
    *insteadofusingafixedregister,wasimplementedonx86/x86-64
    *targets.ThisimprovesgeneratedPICcodeperformanceasmorehard
    *registerscanbeused.
    */
    #ifdefined(__GNUC__)&&__GNUC__<5&&defined(__PIC__)
    #defineMULADDC_CANNOT_USE_EBX
    #endif

    /*
    *Disableuseofthei386assemblycodebelowifoption-O0,todisableall
    *compileroptimisations,ispassed,detectedwith__OPTIMIZE__
    *Thisisdoneasthenumberofregistersusedintheassemblycodedoesn't
    *workwiththe-O0option.
    */
    #ifdefined(__i386__)&&defined(__OPTIMIZE__)&&!defined(MULADDC_CANNOT_USE_EBX)

    #defineMULADDC_INIT\
    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"

    #defineMULADDC_CORE\
    "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"

    #ifdefined(MBEDTLS_HAVE_SSE2)

    #defineMULADDC_HUIT\
    "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"\
    "movd4(%%esi),%%mm4\n\t"\
    "pmuludq%%mm0,%%mm4\n\t"\
    "movd8(%%esi),%%mm6\n\t"\
    "pmuludq%%mm0,%%mm6\n\t"\
    "movd12(%%esi),%%mm7\n\t"\
    "pmuludq%%mm0,%%mm7\n\t"\
    "paddq%%mm2,%%mm1\n\t"\
    "movd4(%%edi),%%mm3\n\t"\
    "paddq%%mm4,%%mm3\n\t"\
    "movd8(%%edi),%%mm5\n\t"\
    "paddq%%mm6,%%mm5\n\t"\
    "movd12(%%edi),%%mm4\n\t"\
    "paddq%%mm4,%%mm7\n\t"\
    "movd%%mm1,(%%edi)\n\t"\
    "movd16(%%esi),%%mm2\n\t"\
    "pmuludq%%mm0,%%mm2\n\t"\
    "psrlq$32,%%mm1\n\t"\
    "movd20(%%esi),%%mm4\n\t"\
    "pmuludq%%mm0,%%mm4\n\t"\
    "paddq%%mm3,%%mm1\n\t"\
    "movd24(%%esi),%%mm6\n\t"\
    "pmuludq%%mm0,%%mm6\n\t"\
    "movd%%mm1,4(%%edi)\n\t"\
    "psrlq$32,%%mm1\n\t"\
    "movd28(%%esi),%%mm3\n\t"\
    "pmuludq%%mm0,%%mm3\n\t"\
    "paddq%%mm5,%%mm1\n\t"\
    "movd16(%%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"\
    "movd20(%%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"\
    "movd24(%%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"\
    "movd28(%%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"

    #defineMULADDC_STOP\
    "emms\n\t"\
    "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"\
    );

    #else

    #defineMULADDC_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"\
    );
    #endif/*SSE2*/
    #endif/*i386*/

    #ifdefined(__amd64__)||defined(__x86_64__)

    #defineMULADDC_INIT\
    asm(\
    "xorq%%r8,%%r8\n"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    :"+c"(c),"+D"(d),"+S"(s),"+m"(*(uint64_t(*)[16])d)\
    :"b"(b),"m"(*(constuint64_t(*)[16])s)\
    :"rax","rdx","r8"\
    );

    #endif/*AMD64*/

    #ifdefined(__aarch64__)

    #defineMULADDC_INIT\
    asm(

    #defineMULADDC_CORE\
    "ldrx4,[%2],#8\n\t"\
    "ldrx5,[%1]\n\t"\
    "mulx6,x4,%4\n\t"\
    "umulhx7,x4,%4\n\t"\
    "addsx5,x5,x6\n\t"\
    "adcx7,x7,xzr\n\t"\
    "addsx5,x5,%0\n\t"\
    "adc%0,x7,xzr\n\t"\
    "strx5,[%1],#8\n\t"

    #defineMULADDC_STOP\
    :"+r"(c),"+r"(d),"+r"(s),"+m"(*(uint64_t(*)[16])d)\
    :"r"(b),"m"(*(constuint64_t(*)[16])s)\
    :"x4","x5","x6","x7","cc"\
    );

    #endif/*Aarch64*/

    #ifdefined(__mc68020__)||defined(__mcpu32__)

    #defineMULADDC_INIT\
    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"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    "movl%%d3,%0\n\t"\
    "movl%%a3,%1\n\t"\
    "movl%%a2,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"d0","d1","d2","d3","d4","a2","a3"\
    );

    #defineMULADDC_HUIT\
    "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"

    #endif/*MC68000*/

    #ifdefined(__powerpc64__)||defined(__ppc64__)

    #ifdefined(__MACH__)&&defined(__APPLE__)

    #defineMULADDC_INIT\
    asm(\
    "ldr3,%3\n\t"\
    "ldr4,%4\n\t"\
    "ldr5,%5\n\t"\
    "ldr6,%6\n\t"\
    "addir3,r3,-8\n\t"\
    "addir4,r4,-8\n\t"\
    "addicr5,r5,0\n\t"

    #defineMULADDC_CORE\
    "ldur7,8(r3)\n\t"\
    "mulldr8,r7,r6\n\t"\
    "mulhdur9,r7,r6\n\t"\
    "adder8,r8,r5\n\t"\
    "ldr7,8(r4)\n\t"\
    "addzer5,r9\n\t"\
    "addcr8,r8,r7\n\t"\
    "stdur8,8(r4)\n\t"

    #defineMULADDC_STOP\
    "addzer5,r5\n\t"\
    "addir4,r4,8\n\t"\
    "addir3,r3,8\n\t"\
    "stdr5,%0\n\t"\
    "stdr4,%1\n\t"\
    "stdr3,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r3","r4","r5","r6","r7","r8","r9"\
    );

    #else/*__MACH__&&__APPLE__*/

    #defineMULADDC_INIT\
    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"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    "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"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r3","r4","r5","r6","r7","r8","r9"\
    );

    #endif/*__MACH__&&__APPLE__*/

    #elifdefined(__powerpc__)||defined(__ppc__)/*endPPC64/beginPPC32*/

    #ifdefined(__MACH__)&&defined(__APPLE__)

    #defineMULADDC_INIT\
    asm(\
    "lwzr3,%3\n\t"\
    "lwzr4,%4\n\t"\
    "lwzr5,%5\n\t"\
    "lwzr6,%6\n\t"\
    "addir3,r3,-4\n\t"\
    "addir4,r4,-4\n\t"\
    "addicr5,r5,0\n\t"

    #defineMULADDC_CORE\
    "lwzur7,4(r3)\n\t"\
    "mullwr8,r7,r6\n\t"\
    "mulhwur9,r7,r6\n\t"\
    "adder8,r8,r5\n\t"\
    "lwzr7,4(r4)\n\t"\
    "addzer5,r9\n\t"\
    "addcr8,r8,r7\n\t"\
    "stwur8,4(r4)\n\t"

    #defineMULADDC_STOP\
    "addzer5,r5\n\t"\
    "addir4,r4,4\n\t"\
    "addir3,r3,4\n\t"\
    "stwr5,%0\n\t"\
    "stwr4,%1\n\t"\
    "stwr3,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r3","r4","r5","r6","r7","r8","r9"\
    );

    #else/*__MACH__&&__APPLE__*/

    #defineMULADDC_INIT\
    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"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    "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"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r3","r4","r5","r6","r7","r8","r9"\
    );

    #endif/*__MACH__&&__APPLE__*/

    #endif/*PPC32*/

    /*
    *TheSparc(64)assemblyisreportedtobebroken.
    *Disableitfornow,untilwe'reabletofixit.
    */
    #if0&&defined(__sparc__)
    #ifdefined(__sparc64__)

    #defineMULADDC_INIT\
    asm(\
    "ldx%3,%%o0\n\t"\
    "ldx%4,%%o1\n\t"\
    "ld%5,%%o2\n\t"\
    "ld%6,%%o3\n\t"

    #defineMULADDC_CORE\
    "ld[%%o0],%%o4\n\t"\
    "inc4,%%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"\
    "inc4,%%o1\n\t"

    #defineMULADDC_STOP\
    "st%%o2,%0\n\t"\
    "stx%%o1,%1\n\t"\
    "stx%%o0,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"g1","o0","o1","o2","o3","o4",\
    "o5"\
    );

    #else/*__sparc64__*/

    #defineMULADDC_INIT\
    asm(\
    "ld%3,%%o0\n\t"\
    "ld%4,%%o1\n\t"\
    "ld%5,%%o2\n\t"\
    "ld%6,%%o3\n\t"

    #defineMULADDC_CORE\
    "ld[%%o0],%%o4\n\t"\
    "inc4,%%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"\
    "inc4,%%o1\n\t"

    #defineMULADDC_STOP\
    "st%%o2,%0\n\t"\
    "st%%o1,%1\n\t"\
    "st%%o0,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"g1","o0","o1","o2","o3","o4",\
    "o5"\
    );

    #endif/*__sparc64__*/
    #endif/*__sparc__*/

    #ifdefined(__microblaze__)||defined(microblaze)

    #defineMULADDC_INIT\
    asm(\
    "lwir3,%3\n\t"\
    "lwir4,%4\n\t"\
    "lwir5,%5\n\t"\
    "lwir6,%6\n\t"\
    "andir7,r6,0xffff\n\t"\
    "bsrlir6,r6,16\n\t"

    #if(__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__)
    #defineMULADDC_LHUI\
    "lhuir9,r3,0\n\t"\
    "addir3,r3,2\n\t"\
    "lhuir8,r3,0\n\t"
    #else
    #defineMULADDC_LHUI\
    "lhuir8,r3,0\n\t"\
    "addir3,r3,2\n\t"\
    "lhuir9,r3,0\n\t"
    #endif

    #defineMULADDC_CORE\
    MULADDC_LHUI\
    "addir3,r3,2\n\t"\
    "mulr10,r9,r6\n\t"\
    "mulr11,r8,r7\n\t"\
    "mulr12,r9,r7\n\t"\
    "mulr13,r8,r6\n\t"\
    "bsrlir8,r10,16\n\t"\
    "bsrlir9,r11,16\n\t"\
    "addr13,r13,r8\n\t"\
    "addr13,r13,r9\n\t"\
    "bsllir10,r10,16\n\t"\
    "bsllir11,r11,16\n\t"\
    "addr12,r12,r10\n\t"\
    "addcr13,r13,r0\n\t"\
    "addr12,r12,r11\n\t"\
    "addcr13,r13,r0\n\t"\
    "lwir10,r4,0\n\t"\
    "addr12,r12,r10\n\t"\
    "addcr13,r13,r0\n\t"\
    "addr12,r12,r5\n\t"\
    "addcr5,r13,r0\n\t"\
    "swir12,r4,0\n\t"\
    "addir4,r4,4\n\t"

    #defineMULADDC_STOP\
    "swir5,%0\n\t"\
    "swir4,%1\n\t"\
    "swir3,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r3","r4","r5","r6","r7","r8",\
    "r9","r10","r11","r12","r13"\
    );

    #endif/*MicroBlaze*/

    #ifdefined(__tricore__)

    #defineMULADDC_INIT\
    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"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    "st.w%0,%%d4\n\t"\
    "st.a%1,%%a3\n\t"\
    "st.a%2,%%a2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"d0","d1","e2","d4","a2","a3"\
    );

    #endif/*TriCore*/

    /*
    *Note,gcc-O0bydefaultusesr7fortheframepointer,soitcomplainsabout
    *ouruseofr7below,unless-fomit-frame-pointerispassed.
    *
    *Ontheotherhand,-fomit-frame-pointerisimpliedbyany-Oxoptionswith
    *x!=0,whichwecandetectusing__OPTIMIZE__(whichisalsodefinedby
    *clangandarmcc5underthesameconditions).
    *
    *So,onlyusetheoptimizedassemblybelowforoptimizedbuild,whichavoids
    *thebuilderrorandisprettyreasonableanyway.
    */
    #ifdefined(__GNUC__)&&!defined(__OPTIMIZE__)
    #defineMULADDC_CANNOT_USE_R7
    #endif

    #ifdefined(__arm__)&&!defined(MULADDC_CANNOT_USE_R7)

    #ifdefined(__thumb__)&&!defined(__thumb2__)
    #if!defined(__ARMCC_VERSION)&&!defined(__clang__)\
    &&!defined(__llvm__)&&!defined(__INTEL_COMPILER)
    /*
    *Thumb1ISA.Thiscodepathhasonlybeentestedsuccessfullyongcc;
    *itdoesnotcompileonclangorarmclang.
    *
    *Othercompilerswhichdefine__GNUC__maynotwork.Theabovemacro
    *attemptstoexcludetheseuntestedcompilers.
    */

    #defineMULADDC_INIT\
    asm(\
    "ldrr0,%3\n\t"\
    "ldrr1,%4\n\t"\
    "ldrr2,%5\n\t"\
    "ldrr3,%6\n\t"\
    "lsrr7,r3,#16\n\t"\
    "movr9,r7\n\t"\
    "lslr7,r3,#16\n\t"\
    "lsrr7,r7,#16\n\t"\
    "movr8,r7\n\t"

    #defineMULADDC_CORE\
    "ldmiar0!,{r6}\n\t"\
    "lsrr7,r6,#16\n\t"\
    "lslr6,r6,#16\n\t"\
    "lsrr6,r6,#16\n\t"\
    "movr4,r8\n\t"\
    "mulr4,r6\n\t"\
    "movr3,r9\n\t"\
    "mulr6,r3\n\t"\
    "movr5,r9\n\t"\
    "mulr5,r7\n\t"\
    "movr3,r8\n\t"\
    "mulr7,r3\n\t"\
    "lsrr3,r6,#16\n\t"\
    "addr5,r5,r3\n\t"\
    "lsrr3,r7,#16\n\t"\
    "addr5,r5,r3\n\t"\
    "addr4,r4,r2\n\t"\
    "movr2,#0\n\t"\
    "adcr5,r2\n\t"\
    "lslr3,r6,#16\n\t"\
    "addr4,r4,r3\n\t"\
    "adcr5,r2\n\t"\
    "lslr3,r7,#16\n\t"\
    "addr4,r4,r3\n\t"\
    "adcr5,r2\n\t"\
    "ldrr3,[r1]\n\t"\
    "addr4,r4,r3\n\t"\
    "adcr2,r5\n\t"\
    "stmiar1!,{r4}\n\t"

    #defineMULADDC_STOP\
    "strr2,%0\n\t"\
    "strr1,%1\n\t"\
    "strr0,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r0","r1","r2","r3","r4","r5",\
    "r6","r7","r8","r9","cc"\
    );

    #endif/*Compilerisgcc*/

    #elif(__ARM_ARCH>=6)&&\
    defined(__ARM_FEATURE_DSP)&&(__ARM_FEATURE_DSP==1)

    #defineMULADDC_INIT\
    asm(

    #defineMULADDC_CORE\
    "ldrr0,[%0],#4\n\t"\
    "ldrr1,[%1]\n\t"\
    "umaalr1,%2,%3,r0\n\t"\
    "strr1,[%1],#4\n\t"

    #defineMULADDC_STOP\
    :"=r"(s),"=r"(d),"=r"(c)\
    :"r"(b),"0"(s),"1"(d),"2"(c)\
    :"r0","r1","memory"\
    );

    #else

    #defineMULADDC_INIT\
    asm(\
    "ldrr0,%3\n\t"\
    "ldrr1,%4\n\t"\
    "ldrr2,%5\n\t"\
    "ldrr3,%6\n\t"

    #defineMULADDC_CORE\
    "ldrr4,[r0],#4\n\t"\
    "movr5,#0\n\t"\
    "ldrr6,[r1]\n\t"\
    "umlalr2,r5,r3,r4\n\t"\
    "addsr7,r6,r2\n\t"\
    "adcr2,r5,#0\n\t"\
    "strr7,[r1],#4\n\t"

    #defineMULADDC_STOP\
    "strr2,%0\n\t"\
    "strr1,%1\n\t"\
    "strr0,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"r0","r1","r2","r3","r4","r5",\
    "r6","r7","cc"\
    );

    #endif/*Thumb*/

    #endif/*ARMv3*/

    #ifdefined(__alpha__)

    #defineMULADDC_INIT\
    asm(\
    "ldq$1,%3\n\t"\
    "ldq$2,%4\n\t"\
    "ldq$3,%5\n\t"\
    "ldq$4,%6\n\t"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    "stq$3,%0\n\t"\
    "stq$2,%1\n\t"\
    "stq$1,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"$1","$2","$3","$4","$5","$6","$7"\
    );
    #endif/*Alpha*/

    #ifdefined(__mips__)&&!defined(__mips64)

    #defineMULADDC_INIT\
    asm(\
    "lw$10,%3\n\t"\
    "lw$11,%4\n\t"\
    "lw$12,%5\n\t"\
    "lw$13,%6\n\t"

    #defineMULADDC_CORE\
    "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"

    #defineMULADDC_STOP\
    "sw$12,%0\n\t"\
    "sw$11,%1\n\t"\
    "sw$10,%2\n\t"\
    :"=m"(c),"=m"(d),"=m"(s)\
    :"m"(s),"m"(d),"m"(c),"m"(b)\
    :"$9","$10","$11","$12","$13","$14","$15","lo","hi"\
    );

    #endif/*MIPS*/
    #endif/*GNUC*/

    #if(defined(_MSC_VER)&&defined(_M_IX86))||defined(__WATCOMC__)

    #defineMULADDC_INIT\
    __asmmovesi,s\
    __asmmovedi,d\
    __asmmovecx,c\
    __asmmovebx,b

    #defineMULADDC_CORE\
    __asmlodsd\
    __asmmulebx\
    __asmaddeax,ecx\
    __asmadcedx,0\
    __asmaddeax,[edi]\
    __asmadcedx,0\
    __asmmovecx,edx\
    __asmstosd

    #ifdefined(MBEDTLS_HAVE_SSE2)

    #defineEMIT__asm_emit

    #defineMULADDC_HUIT\
    EMIT0x0FEMIT0x6EEMIT0xC9\
    EMIT0x0FEMIT0x6EEMIT0xC3\
    EMIT0x0FEMIT0x6EEMIT0x1F\
    EMIT0x0FEMIT0xD4EMIT0xCB\
    EMIT0x0FEMIT0x6EEMIT0x16\
    EMIT0x0FEMIT0xF4EMIT0xD0\
    EMIT0x0FEMIT0x6EEMIT0x66EMIT0x04\
    EMIT0x0FEMIT0xF4EMIT0xE0\
    EMIT0x0FEMIT0x6EEMIT0x76EMIT0x08\
    EMIT0x0FEMIT0xF4EMIT0xF0\
    EMIT0x0FEMIT0x6EEMIT0x7EEMIT0x0C\
    EMIT0x0FEMIT0xF4EMIT0xF8\
    EMIT0x0FEMIT0xD4EMIT0xCA\
    EMIT0x0FEMIT0x6EEMIT0x5FEMIT0x04\
    EMIT0x0FEMIT0xD4EMIT0xDC\
    EMIT0x0FEMIT0x6EEMIT0x6FEMIT0x08\
    EMIT0x0FEMIT0xD4EMIT0xEE\
    EMIT0x0FEMIT0x6EEMIT0x67EMIT0x0C\
    EMIT0x0FEMIT0xD4EMIT0xFC\
    EMIT0x0FEMIT0x7EEMIT0x0F\
    EMIT0x0FEMIT0x6EEMIT0x56EMIT0x10\
    EMIT0x0FEMIT0xF4EMIT0xD0\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0x6EEMIT0x66EMIT0x14\
    EMIT0x0FEMIT0xF4EMIT0xE0\
    EMIT0x0FEMIT0xD4EMIT0xCB\
    EMIT0x0FEMIT0x6EEMIT0x76EMIT0x18\
    EMIT0x0FEMIT0xF4EMIT0xF0\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x04\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0x6EEMIT0x5EEMIT0x1C\
    EMIT0x0FEMIT0xF4EMIT0xD8\
    EMIT0x0FEMIT0xD4EMIT0xCD\
    EMIT0x0FEMIT0x6EEMIT0x6FEMIT0x10\
    EMIT0x0FEMIT0xD4EMIT0xD5\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x08\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0xD4EMIT0xCF\
    EMIT0x0FEMIT0x6EEMIT0x6FEMIT0x14\
    EMIT0x0FEMIT0xD4EMIT0xE5\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x0C\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0xD4EMIT0xCA\
    EMIT0x0FEMIT0x6EEMIT0x6FEMIT0x18\
    EMIT0x0FEMIT0xD4EMIT0xF5\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x10\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0xD4EMIT0xCC\
    EMIT0x0FEMIT0x6EEMIT0x6FEMIT0x1C\
    EMIT0x0FEMIT0xD4EMIT0xDD\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x14\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0xD4EMIT0xCE\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x18\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0xD4EMIT0xCB\
    EMIT0x0FEMIT0x7EEMIT0x4FEMIT0x1C\
    EMIT0x83EMIT0xC7EMIT0x20\
    EMIT0x83EMIT0xC6EMIT0x20\
    EMIT0x0FEMIT0x73EMIT0xD1EMIT0x20\
    EMIT0x0FEMIT0x7EEMIT0xC9

    #defineMULADDC_STOP\
    EMIT0x0FEMIT0x77\
    __asmmovc,ecx\
    __asmmovd,edi\
    __asmmovs,esi\

    #else

    #defineMULADDC_STOP\
    __asmmovc,ecx\
    __asmmovd,edi\
    __asmmovs,esi\

    #endif/*SSE2*/
    #endif/*MSVC*/

    #endif/*MBEDTLS_HAVE_ASM*/

    #if!defined(MULADDC_CORE)
    #ifdefined(MBEDTLS_HAVE_UDBL)

    #defineMULADDC_INIT\
    {\
    mbedtls_t_udblr;\
    mbedtls_mpi_uintr0,r1;

    #defineMULADDC_CORE\
    r=*(s++)*(mbedtls_t_udbl)b;\
    r0=(mbedtls_mpi_uint)r;\
    r1=(mbedtls_mpi_uint)(r>>biL);\
    r0+=c;r1+=(r0<c);\
    r0+=*d;r1+=(r0<*d);\
    c=r1;*(d++)=r0;

    #defineMULADDC_STOP\
    }

    #else
    #defineMULADDC_INIT\
    {\
    mbedtls_mpi_uints0,s1,b0,b1;\
    mbedtls_mpi_uintr0,r1,rx,ry;\
    b0=(b<<biH)>>biH;\
    b1=(b>>biH);

    #defineMULADDC_CORE\
    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;

    #defineMULADDC_STOP\
    }

    #endif/*C(generic)*/
    #endif/*C(longlong)*/

    /**INDENT-ON**/
    #endif/*bn_mul.h*/