Movatterモバイル変換


[0]ホーム

URL:


Next:, Up:The GCC low-level runtime library   [Contents][Index]


3.1 Routines for integer arithmetic

The integer arithmetic routines are used on platforms that don’t providehardware support for arithmetic operations on some modes.

3.1.1 Arithmetic functions

Runtime Function:int__ashlsi3(inta, intb)
Runtime Function:long__ashldi3(longa, intb)
Runtime Function:long long__ashlti3(long longa, intb)

These functions return the result of shiftinga left byb bits.

Runtime Function:int__ashrsi3(inta, intb)
Runtime Function:long__ashrdi3(longa, intb)
Runtime Function:long long__ashrti3(long longa, intb)

These functions return the result of arithmetically shiftinga rightbyb bits.

Runtime Function:int__divsi3(inta, intb)
Runtime Function:long__divdi3(longa, longb)
Runtime Function:long long__divti3(long longa, long longb)

These functions return the quotient of the signed division ofa andb.

Runtime Function:int__lshrsi3(inta, intb)
Runtime Function:long__lshrdi3(longa, intb)
Runtime Function:long long__lshrti3(long longa, intb)

These functions return the result of logically shiftinga right byb bits.

Runtime Function:int__modsi3(inta, intb)
Runtime Function:long__moddi3(longa, longb)
Runtime Function:long long__modti3(long longa, long longb)

These functions return the remainder of the signed division ofaandb.

Runtime Function:int__mulsi3(inta, intb)
Runtime Function:long__muldi3(longa, longb)
Runtime Function:long long__multi3(long longa, long longb)

These functions return the product ofa andb.

Runtime Function:long__negdi2(longa)
Runtime Function:long long__negti2(long longa)

These functions return the negation ofa.

Runtime Function:unsigned int__udivsi3(unsigned inta, unsigned intb)
Runtime Function:unsigned long__udivdi3(unsigned longa, unsigned longb)
Runtime Function:unsigned long long__udivti3(unsigned long longa, unsigned long longb)

These functions return the quotient of the unsigned division ofaandb.

Runtime Function:unsigned long__udivmoddi4(unsigned longa, unsigned longb, unsigned long *c)
Runtime Function:unsigned long long__udivmodti4(unsigned long longa, unsigned long longb, unsigned long long *c)

These functions calculate both the quotient and remainder of the unsigneddivision ofa andb. The return value is the quotient, andthe remainder is placed in variable pointed to byc.

Runtime Function:unsigned int__umodsi3(unsigned inta, unsigned intb)
Runtime Function:unsigned long__umoddi3(unsigned longa, unsigned longb)
Runtime Function:unsigned long long__umodti3(unsigned long longa, unsigned long longb)

These functions return the remainder of the unsigned division ofaandb.

3.1.2 Comparison functions

The following functions implement integral comparisons. These functionsimplement a low-level compare, upon which the higher level comparisonoperators (such as less than and greater than or equal to) can beconstructed. The returned values lie in the range zero to two, to allowthe high-level operators to be implemented by testing the returnedresult using either signed or unsigned comparison.

Runtime Function:int__cmpdi2(longa, longb)
Runtime Function:int__cmpti2(long longa, long longb)

These functions perform a signed comparison ofa andb. Ifa is less thanb, they return 0; ifa is greater thanb, they return 2; and ifa andb are equal they return 1.

Runtime Function:int__ucmpdi2(unsigned longa, unsigned longb)
Runtime Function:int__ucmpti2(unsigned long longa, unsigned long longb)

These functions perform an unsigned comparison ofa andb.Ifa is less thanb, they return 0; ifa is greater thanb, they return 2; and ifa andb are equal they return 1.

3.1.3 Trapping arithmetic functions

The following functions implement trapping arithmetic. These functionscall the libc functionabort upon signed arithmetic overflow.

Runtime Function:int__absvsi2(inta)
Runtime Function:long__absvdi2(longa)

These functions return the absolute value ofa.

Runtime Function:int__addvsi3(inta, intb)
Runtime Function:long__addvdi3(longa, longb)

These functions return the sum ofa andb; that isa +b.

Runtime Function:int__mulvsi3(inta, intb)
Runtime Function:long__mulvdi3(longa, longb)

The functions return the product ofa andb; that isa *b.

Runtime Function:int__negvsi2(inta)
Runtime Function:long__negvdi2(longa)

These functions return the negation ofa; that is-a.

Runtime Function:int__subvsi3(inta, intb)
Runtime Function:long__subvdi3(longa, longb)

These functions return the difference betweenb anda;that isa -b.

3.1.4 Bit operations

Runtime Function:int__clzsi2(unsigned inta)
Runtime Function:int__clzdi2(unsigned longa)
Runtime Function:int__clzti2(unsigned long longa)

These functions return the number of leading 0-bits ina, startingat the most significant bit position. Ifa is zero, the result isundefined.

Runtime Function:int__ctzsi2(unsigned inta)
Runtime Function:int__ctzdi2(unsigned longa)
Runtime Function:int__ctzti2(unsigned long longa)

These functions return the number of trailing 0-bits ina, startingat the least significant bit position. Ifa is zero, the result isundefined.

Runtime Function:int__ffsdi2(unsigned longa)
Runtime Function:int__ffsti2(unsigned long longa)

These functions return the index of the least significant 1-bit ina,or the value zero ifa is zero. The least significant bit is indexone.

Runtime Function:int__paritysi2(unsigned inta)
Runtime Function:int__paritydi2(unsigned longa)
Runtime Function:int__parityti2(unsigned long longa)

These functions return the value zero if the number of bits set ina is even, and the value one otherwise.

Runtime Function:int__popcountsi2(unsigned inta)
Runtime Function:int__popcountdi2(unsigned longa)
Runtime Function:int__popcountti2(unsigned long longa)

These functions return the number of bits set ina.

Runtime Function:int32_t__bswapsi2(int32_ta)
Runtime Function:int64_t__bswapdi2(int64_ta)

These functions return thea byteswapped.

3.1.5 Bit-precise integer arithmetic functions

_BitInt(n) library functions operate on arrays of limbs, whereeach limb has__LIBGCC_BITINT_LIMB_WIDTH__ bits and the limbs areordered according to__LIBGCC_BITINT_ORDER__ ordering. The mostsignificant limb ifn is not divisible by__LIBGCC_BITINT_LIMB_WIDTH__ contains padding bits which should beignored on read (sign or zero extended), but extended on write. For thelibrary functions, all bit-precise integers regardless ofn arerepresented like that, even when the target ABI says that for some smalln they should be represented differently in memory. A pointerto the array of limbs argument is always accompanied with a bit sizeargument. If that argument is positive, it is number of bits and thenumber is assumed to be zero-extended to infinite precision, if thatargument is negative, it is negated number of bits above which all bitsare assumed to be sign-extended to infinite precision. These number of bitsarguments don’t need to match actualn for the operation used in thesource, they could be lowered because of sign or zero extensions on theinput or because value-range optimization figures value will need certainlower number of bits. For big-endian ordering of limbs, when loweringthe bit size argument the pointer argument needs to be adjusted as well.Negative bit size argument should be always smaller or equal to-2,becausesigned _BitInt(1) is not valid.For output arguments, either the corresponding bit size argument shouldbe always positive (for multiplication and division), or is negative whenthe output of conversion from floating-point value is signed and positivewhen unsigned. The arrays of limbs output arguments point to should notoverlap any inputs, while input arrays of limbs can overlap.UBILtype below stands for unsigned integer type with__LIBGCC_BITINT_LIMB_WIDTH__ bit precision.

Runtime Function:void__mulbitint3(UBILtype *ret, int32_tretprec, constUBILtype *u, int32_tuprec, constUBILtype *v, int32_tvprec)

This function multiplies bit-precise integer operandsu andv and storesresult intoretprec precision bit-precise integer resultret.

Runtime Function:void__divmodbitint4(UBILtype *q, int32_tqprec,UBILtype *r, int32_trprec, constUBILtype *u, int32_tuprec, constUBILtype *v, int32_tvprec)

This function divides bit-precise integer operandsu andv and storesquotient intoqprec precision bit-precise integer resultq(unlessq isNULL andqprec is 0, in that case quotientis not stored anywhere) and remainder intorprec precision bit-preciseinteger resultr (similarly, unlessr isNULL andrprecis 0).


Next:Routines for floating point emulation, Up:The GCC low-level runtime library   [Contents][Index]


[8]ページ先頭

©2009-2026 Movatter.jp