diff -r 641f389e9157 -r a71299154b21 crypto/weakcrypto/source/bigint/gcchelp.cpp --- a/crypto/weakcrypto/source/bigint/gcchelp.cpp Tue Aug 31 17:00:08 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,395 +0,0 @@ -/* -* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of the License "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* -*/ - - -/** - @file -*/ - - -#include // need this for __NAKED__, __JUMP and __POPRET - -extern "C" { -#ifdef __GCC32__ -__NAKED__ long long __divdi3(long long /*dividend*/, long long /*divisor*/) -// -// Dividend in r1:r0, divisor in r3:r2, Return quotient in r1:r0 -// - { - asm("stmfd sp!, {r4-r8,lr} "); - asm("eor r8, r1, r3 "); // sign of result into r8 - asm("movs r1, r1 "); - asm("bpl 1f "); - asm("rsbs r0, r0, #0 "); // ABS(dividend) - asm("rsc r1, r1, #0 "); - asm("1: "); - asm("movs r3, r3 "); - asm("bpl 2f "); - asm("rsbs r2, r2, #0 "); // ABS(divisor) - asm("rsc r3, r3, #0 "); - asm("2: "); - asm("bl UDiv01 "); // do the division, result in r4,r5 - asm("eors r0, r4, r8, asr #32 "); // quotient into r1:r0, inverted if quotient -ve - asm("eors r1, r5, r8, asr #32 "); - asm("adcs r0, r0, #0 "); // if quotient -ve, add 1 - asm("adcs r1, r1, #0 "); - __POPRET("r4-r8,"); - } - -__NAKED__ long long __moddi3(long long /*dividend*/, long long /*divisor*/) /* signed */ - { - asm("stmfd sp!, {r4-r8,lr} "); - asm("movs r8, r1 "); // sign of remainder (=sign of dividend) into r8 - asm("bpl 1f "); - asm("rsbs r0, r0, #0 "); // ABS(dividend) - asm("rsc r1, r1, #0 "); - asm("1: "); - asm("movs r3, r3 "); - asm("bpl 2f "); - asm("rsbs r2, r2, #0 "); // ABS(divisor) - asm("rsc r3, r3, #0 "); - asm("2: "); - asm("bl UDiv01 "); // do the division, remainder in r3,r6 - asm("eors r0, r3, r8, asr #32 "); // remainder into r1:r0, inverted if dividend -ve - asm("eors r1, r6, r8, asr #32 "); - asm("adcs r0, r0, #0 "); // if dividend -ve, add 1 - asm("adcs r1, r1, #0 "); - __POPRET("r4-r8,"); - } - -__NAKED__ long long __umoddi3(unsigned long long /*dividend*/, unsigned long long /*divisor*/) /* unsigned */ - { - asm("stmfd sp!, {r4-r7,lr} "); - asm("bl UDiv01 "); // do the division, remainder in r6:r3 - asm("mov r0, r3 "); - asm("mov r1, r6 "); - __POPRET("r4-r7,"); - } - -__NAKED__ long long __ashrdi3(long long /*value*/, unsigned int /*count*/) - { - asm("cmp r2, #63 "); - asm("movhi r2, #63 "); // count>63 same as count=63 - asm("cmp r2, #32 "); - asm("bcs Asr01 "); // jump if shift count >=32 - asm("rsb r12, r2, #32 "); // r12=32-shift count - asm("mov r0, r0, lsr r2 "); // shift ls word right - asm("orr r0, r0, r1, lsl r12 "); // or in bits shifted out of ms word - asm("mov r1, r1, asr r2 "); // shift ms word right - __JUMP(,lr); - asm("Asr01: "); - asm("sub r2, r2, #32 "); // r2=shift count-32 - asm("mov r0, r1, asr r2 "); // ls word = ms word >> (count-32) - asm("mov r1, r1, asr #32 "); // ms word of result=sign extension of r1 - __JUMP(,lr); - } - -__NAKED__ long long __ashldi3(long long /*value*/, unsigned int /*count*/) - { - asm("cmp r2, #63 "); - asm("movhi r2, #64 "); // count>63 same as count=64 - asm("cmp r2, #32 "); - asm("bcs Asl01 "); // jump if shift count >=32 - asm("rsb r12, r2, #32 "); // r12=32-shift count - asm("mov r1, r1, asl r2 "); // shift ms word left - asm("orr r1, r1, r0, lsr r12 "); // or in bits shifted out of ls word - asm("mov r0, r0, asl r2 "); // shift ls word left - __JUMP(,lr); - asm("Asl01: "); - asm("sub r2, r2, #32 "); // r2=shift count-32 - asm("mov r1, r0, asl r2 "); // result ms word = ls word << (count-32) - asm("mov r0, #0 "); // ls word of result is zero - __JUMP(,lr); - } - -__NAKED__ unsigned long long __lshrdi3(unsigned long long /*value*/, unsigned int /*count*/) - { - asm("cmp r2, #63 "); - asm("movhi r2, #64 "); // count>63 same as count=64 - asm("cmp r2, #32 "); - asm("bcs Lsr01 "); // jump if shift count >=32 - asm("rsb r12, r2, #32 "); // r12=32-shift count - asm("mov r0, r0, lsr r2 "); // shift ls word right - asm("orr r0, r0, r1, lsl r12 "); // or in bits shifted out of ms word - asm("mov r1, r1, lsr r2 "); // shift ms word right - __JUMP(,lr); - asm("Lsr01: "); - asm("sub r2, r2, #32 "); // r2=shift count-32 - asm("mov r0, r1, lsr r2 "); // ls word = ms word >> (count-32) - asm("mov r1, #0 "); // ms word of result = 0 - __JUMP(,lr); - } - -__NAKED__ long long __muldi3(long long /*multiplicand*/, long long /*multiplier*/) - { - asm("mul r1, r2, r1 "); // r1=low2*high1 - asm("mov ip, r0 "); // ip=low1 - asm("mla r1, r0, r3, r1 "); // r1+=low1*high2 - asm("mov r0, #0 "); - asm("umlal r0, r1, r2, ip "); // r1:r0 += high1*low1 - __JUMP(,lr); - } - -__NAKED__ long long __negdi2(long long /*argument*/) - { - asm("rsbs r0, r0, #0 "); // r0=0-r0, set carry - asm("rscs r1, r1, #0 "); // r1=0-r1-(1-C) - __JUMP(,lr); - } - -__NAKED__ unsigned long long __udivmoddi4 (unsigned long long /*dividend*/, - unsigned long long /*divisor*/, - unsigned long long* /*p_remainder*/) - { - asm("stmfd sp!, {r4-r7,lr} "); - asm("bl UDiv01 "); // do the division, quotient in r5:r4 remainder in r6:r3 - asm("ldr r7, [sp, #20] "); // r7=p_remainder - asm("mov r0, r4 "); // r0=quotient low - asm("stmia r7, {r3,r6} "); // store remainder - asm("mov r1, r5 "); // r0=quotient high - __POPRET("r4-r7,"); - } - -__NAKED__ int __cmpdi2(long long /*a*/, long long /*b*/) - { - // return 0 if ab - asm("subs r0, r2, r0 "); - asm("sbcs r1, r3, r1 "); // r1:r0 = b-a, set flags - asm("movlt r0, #2 "); // if bb - asm("cmp r1, r3 "); - asm("cmpeq r0, r2 "); // compare r1:r0 - r3:r2 - asm("movhi r0, #2 "); // r0=2 if a>b - asm("moveq r0, #1 "); // r0=1 if a=b - asm("movlo r0, #0 "); // r0=0 if a= 2^32, so quotient < 2^32 - // Use 64 bit accumulator, 32 bit quotient - asm("udiv64a: "); - asm("mov r4, #0 "); // quotient in r4, use r1, r6 as accumulator - asm("mov r6, #0 "); - asm("mov r5, #8 "); // do 32 iterations - asm("udiv64d: "); - asm("adds r0, r0, r0 "); // shift dividend left into acc - asm("adcs r1, r1, r1 "); - asm("adcs r6, r6, r6 "); - asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 - asm("sbcs r12, r6, r3 "); - asm("adc r4, r4, r4 "); // shift result bit left into quotient - asm("movcs r1, r7 "); // if no borrow, update acc - asm("movcs r6, r12 "); - asm("adds r0, r0, r0 "); // shift dividend left into acc - asm("adcs r1, r1, r1 "); - asm("adcs r6, r6, r6 "); - asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 - asm("sbcs r12, r6, r3 "); - asm("adc r4, r4, r4 "); // shift result bit left into quotient - asm("movcs r1, r7 "); // if no borrow, update acc - asm("movcs r6, r12 "); - asm("adds r0, r0, r0 "); // shift dividend left into acc - asm("adcs r1, r1, r1 "); - asm("adcs r6, r6, r6 "); - asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 - asm("sbcs r12, r6, r3 "); - asm("adc r4, r4, r4 "); // shift result bit left into quotient - asm("movcs r1, r7 "); // if no borrow, update acc - asm("movcs r6, r12 "); - asm("adds r0, r0, r0 "); // shift dividend left into acc - asm("adcs r1, r1, r1 "); - asm("adcs r6, r6, r6 "); - asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 - asm("sbcs r12, r6, r3 "); - asm("adc r4, r4, r4 "); // shift result bit left into quotient - asm("movcs r1, r7 "); // if no borrow, update acc - asm("movcs r6, r12 "); - asm("subs r5, r5, #1 "); // loop - asm("bne udiv64d "); - asm("mov r3, r1 "); // remainder in r3,r6 - __JUMP(,lr); - - asm("udiv64_divby0: "); - asm("str lr, [sp, #-4]! "); - asm("bl " DIV_BY_ZERO); - __POPRET(""); - } - -} -