X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=src%2Finteger%2Fcl_I.h;h=52c137d0ecc1d0ca92694f2b354097eed9c85c74;hb=c84c6db5d56829d69083c819688a973867694a2a;hp=843cd301488ddc0830987d731ea8160520e9df33;hpb=850abfde7f0d985ba01526c346bcd0d733562943;p=cln.git diff --git a/src/integer/cl_I.h b/src/integer/cl_I.h index 843cd30..52c137d 100644 --- a/src/integer/cl_I.h +++ b/src/integer/cl_I.h @@ -42,7 +42,7 @@ inline cl_uint cl_FN_word (const cl_I& x) // Bignums. struct cl_heap_bignum : cl_heap { - unsigned int length; // length (in digits) + uintC length; // length (in digits) uintD data[1]; // number in two's complement representation }; @@ -51,7 +51,7 @@ inline cl_heap_bignum* TheBignum (cl_heap_bignum* p) inline cl_heap_bignum* TheBignum (const cl_number& obj) { return (cl_heap_bignum*)(obj.pointer); } -inline cl_heap_bignum* allocate_bignum (unsigned int length) +inline cl_heap_bignum* allocate_bignum (uintC length) { cl_heap_bignum* p = (cl_heap_bignum*) malloc_hook(offsetofa(cl_heap_bignum,data)+sizeof(uintD)*length); p->refcount = 1; @@ -112,32 +112,32 @@ inline cl_boolean eq (const cl_I& x, sint32 y) // Umwandlungsroutinen Integer <--> Longword: // Wandelt Fixnum >=0 in Unsigned Longword um. -// FN_to_UL(obj) +// FN_to_UV(obj) // > obj: ein Fixnum >=0 -// < ergebnis: der Wert des Fixnum als 32-Bit-Zahl. -inline uint32 FN_to_UL (const cl_I& x) +// < ergebnis: der Wert des Fixnum als intVsize-Bit-Zahl. +inline uintV FN_to_UV (const cl_I& x) { // This assumes cl_value_shift + cl_value_len == cl_pointer_size. return (cl_uint)(x.word) >> cl_value_shift; } // Wandelt Fixnum in Longword um. -// FN_to_L(obj) +// FN_to_V(obj) // > obj: ein Fixnum -// < ergebnis: der Wert des Fixnum als 32-Bit-Zahl. -inline sint32 FN_to_L (const cl_I& x) +// < ergebnis: der Wert des Fixnum als intVsize-Bit-Zahl. +inline sintV FN_to_V (const cl_I& x) { // This assumes cl_value_shift + cl_value_len == cl_pointer_size. return (cl_sint)(x.word) >> cl_value_shift; } -// FN_L_zerop(x,x_) stellt fest, ob x = 0 ist. -// Dabei ist x ein Fixnum und x_ = FN_to_L(x). - #define FN_L_zerop(x,x_) (x_==0) +// FN_V_zerop(x,x_) stellt fest, ob x = 0 ist. +// Dabei ist x ein Fixnum und x_ = FN_to_V(x). + #define FN_V_zerop(x,x_) (x_==0) -// FN_L_minusp(x,x_) stellt fest, ob x < 0 ist. -// Dabei ist x ein Fixnum und x_ = FN_to_L(x). - #define FN_L_minusp(x,x_) (x_<0) +// FN_V_minusp(x,x_) stellt fest, ob x < 0 ist. +// Dabei ist x ein Fixnum und x_ = FN_to_V(x). + #define FN_V_minusp(x,x_) (x_<0) #ifdef intQsize @@ -212,11 +212,42 @@ inline sint64 FN_to_Q (const cl_I& x) } #endif +#ifdef intQsize + +// Wandelt Quadword in Integer um. +// Q_to_I(wert) +// > wert: Wert des Integers, ein signed 64-Bit-Integer. +// < ergebnis: Integer mit diesem Wert. + extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); + inline const cl_I Q_to_I (sint64 wert) + { + return cl_I(cl_I_constructor_from_Q(wert)); + } + +// Wandelt Unsigned Quadword in Integer >=0 um. +// UQ_to_I(wert) +// > wert: Wert des Integers, ein unsigned 64-Bit-Integer. +// < ergebnis: Integer mit diesem Wert. + extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); + inline const cl_I UQ_to_I (uint64 wert) + { + return cl_I(cl_I_constructor_from_UQ(wert)); + } + +#endif + // Wandelt Doppel-Longword in Integer um. // L2_to_I(wert_hi,wert_lo) // > wert_hi|wert_lo: Wert des Integers, ein signed 64-Bit-Integer. // < ergebnis: Integer mit diesem Wert. +#if (cl_word_size==64) + inline cl_private_thing cl_I_constructor_from_L2 (sint32 wert_hi, uint32 wert_lo) + { + return cl_I_constructor_from_Q(((sint64)wert_hi<<32) | (sint64)wert_lo); + } +#else extern cl_private_thing cl_I_constructor_from_L2 (sint32 wert_hi, uint32 wert_lo); +#endif inline const cl_I L2_to_I (sint32 wert_hi, uint32 wert_lo) { return cl_I(cl_I_constructor_from_L2(wert_hi,wert_lo)); @@ -226,34 +257,37 @@ inline sint64 FN_to_Q (const cl_I& x) // UL2_to_I(wert_hi,wert_lo) // > wert_hi|wert_lo: Wert des Integers, ein unsigned 64-Bit-Integer. // < ergebnis: Integer mit diesem Wert. +#if (cl_word_size==64) + inline cl_private_thing cl_I_constructor_from_UL2 (uint32 wert_hi, uint32 wert_lo) + { + return cl_I_constructor_from_UQ(((uint64)wert_hi<<32) | (uint64)wert_lo); + } +#else extern cl_private_thing cl_I_constructor_from_UL2 (uint32 wert_hi, uint32 wert_lo); +#endif inline const cl_I UL2_to_I (uint32 wert_hi, uint32 wert_lo) { return cl_I(cl_I_constructor_from_UL2(wert_hi,wert_lo)); } -#ifdef intQsize - -// Wandelt Quadword in Integer um. -// Q_to_I(wert) -// > wert: Wert des Integers, ein signed 64-Bit-Integer. +// Wandelt sintV in Integer um. +// V_to_I(wert) +// > wert: Wert des Integers, ein sintV. // < ergebnis: Integer mit diesem Wert. - extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); - inline const cl_I Q_to_I (sint64 wert) - { - return cl_I(cl_I_constructor_from_Q(wert)); - } +#if (intVsize<=32) + #define V_to_I(wert) L_to_I(wert) +#else + #define V_to_I(wert) Q_to_I(wert) +#endif -// Wandelt Unsigned Quadword in Integer >=0 um. -// UQ_to_I(wert) -// > wert: Wert des Integers, ein unsigned 64-Bit-Integer. +// Wandelt uintV in Integer >=0 um. +// UV_to_I(wert) +// > wert: Wert des Integers, ein uintV. // < ergebnis: Integer mit diesem Wert. - extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); - inline const cl_I UQ_to_I (uint64 wert) - { - return cl_I(cl_I_constructor_from_UQ(wert)); - } - +#if (intVsize<=32) + #define UV_to_I(wert) UL_to_I(wert) +#else + #define UV_to_I(wert) UQ_to_I(wert) #endif // Wandelt uintD in Integer >=0 um. @@ -284,22 +318,30 @@ inline const cl_I minus (uintL x, uintL y) #if (intDsize<=32) -// Holt die nächsten pFN_maxlength Digits in ein uint32. -inline uint32 pFN_maxlength_digits_at (const uintD* ptr) +// Holt die nächsten pFN_maxlength Digits in ein uintV. +inline uintV pFN_maxlength_digits_at (const uintD* ptr) { #if (pFN_maxlength==1) - return (uint32)lspref(ptr,0); + return (uintV)lspref(ptr,0); #elif (pFN_maxlength==2) - return ((uint32)lspref(ptr,1)<>(2*intDsize)); lspref(ptr,1) = (uintD)(wert>>intDsize); lspref(ptr,0) = (uintD)(wert); +#elif (pFN_maxlength==5) + lspref(ptr,4) = (uintD)(wert>>(4*intDsize)); + lspref(ptr,3) = (uintD)(wert>>(3*intDsize)); + lspref(ptr,2) = (uintD)(wert>>(2*intDsize)); + lspref(ptr,1) = (uintD)(wert>>intDsize); + lspref(ptr,0) = (uintD)(wert); +#elif (pFN_maxlength==6) + lspref(ptr,5) = (uintD)(wert>>(5*intDsize)); + lspref(ptr,4) = (uintD)(wert>>(4*intDsize)); + lspref(ptr,3) = (uintD)(wert>>(3*intDsize)); + lspref(ptr,2) = (uintD)(wert>>(2*intDsize)); + lspref(ptr,1) = (uintD)(wert>>intDsize); + lspref(ptr,0) = (uintD)(wert); +#elif (pFN_maxlength==7) + lspref(ptr,6) = (uintD)(wert>>(6*intDsize)); + lspref(ptr,5) = (uintD)(wert>>(5*intDsize)); + lspref(ptr,4) = (uintD)(wert>>(4*intDsize)); + lspref(ptr,3) = (uintD)(wert>>(3*intDsize)); + lspref(ptr,2) = (uintD)(wert>>(2*intDsize)); + lspref(ptr,1) = (uintD)(wert>>intDsize); + lspref(ptr,0) = (uintD)(wert); +#elif (pFN_maxlength==8) + lspref(ptr,7) = (uintD)(wert>>(7*intDsize)); + lspref(ptr,6) = (uintD)(wert>>(6*intDsize)); + lspref(ptr,5) = (uintD)(wert>>(5*intDsize)); + lspref(ptr,4) = (uintD)(wert>>(4*intDsize)); + lspref(ptr,3) = (uintD)(wert>>(3*intDsize)); + lspref(ptr,2) = (uintD)(wert>>(2*intDsize)); + lspref(ptr,1) = (uintD)(wert>>intDsize); + lspref(ptr,0) = (uintD)(wert); #endif } @@ -590,14 +662,14 @@ inline sintD FN_MSD (cl_uint word) // > MSBptr/len/..: Ziffernfolge, bestehend aus Punkten (werden überlesen) // und Ziffern/Buchstaben mit Wert < base. // < ergebnis: der dargestellte Integer >=0 - extern const cl_I digits_to_I (const char * MSBptr, uintL len, uintD base); + extern const cl_I digits_to_I (const char * MSBptr, uintC len, uintD base); // Hilfsfunktion zur Ausgabe von Integers // cl_digits_need(len,base) liefert eine obere Abschätzung für die Anzahl der // Ziffern im Stellenwertsystem der Basis base, die x >= 0 braucht. - extern uintL cl_digits_need (const cl_I& x, uintL base); + extern uintC cl_digits_need (const cl_I& x, uintL base); // Wandelt ein Integer in ein Stellensystem um. // I_to_digits(x,base, &ergebnis); @@ -605,7 +677,7 @@ inline sintD FN_MSD (cl_uint word) // > base: Stellensystem-Basis, 2 <= base <= 36. // > ergebnis.LSBptr: darunter ist mindestens digits_need(len) Bytes Platz // < ergebnis: fertige Folge MSBptr/len/LSBptr von Ziffern - typedef struct { uintB* MSBptr; uintL len; uintB* LSBptr; } cl_digits; + typedef struct { uintB* MSBptr; uintC len; uintB* LSBptr; } cl_digits; extern void I_to_digits (const cl_I& x, uintD base, cl_digits* erg);