#define _CL_DS_H
#include "cln/types.h"
-#include "cl_gmpconfig.h"
-#include "cl_D.h"
-#include "cl_DS_endian.h"
-#include "cl_alloca.h"
+#include "base/cl_gmpconfig.h"
+#include "base/digit/cl_D.h"
+#include "base/digitseq/cl_DS_endian.h"
+#include "base/cl_alloca.h"
namespace cln {
#define D4(byte0,byte1,byte2,byte3) (((uintD)(byte0)<<24)|((uintD)(byte1)<<16)|((uintD)(byte2)<<8)|((uintD)(byte3)))
#define D8(byte0,byte1,byte2,byte3,byte4,byte5,byte6,byte7) (((uintD)(byte0)<<56)|((uintD)(byte1)<<48)|((uintD)(byte2)<<40)|((uintD)(byte3)<<32)|((uintD)(byte4)<<24)|((uintD)(byte5)<<16)|((uintD)(byte6)<<8)|((uintD)(byte7)))
+// i386-pc-solaris #defines DS.
+// Grr...
+#undef DS
+
struct DS {
uintD* MSDptr;
- unsigned int len;
+ uintC len;
uintD* LSDptr;
};
// See which functions are defined as external functions.
-#include "cl_asm.h"
+#include "base/digitseq/cl_asm.h"
// Declare the external functions.
#ifdef TEST_LOOPS
-extern cl_boolean test_loop_up (const uintD* ptr, uintC count);
+extern bool test_loop_up (const uintD* ptr, uintC count);
-extern cl_boolean test_loop_down (const uintD* ptr, uintC count);
+extern bool test_loop_down (const uintD* ptr, uintC count);
#endif
#ifdef TEST_LOOPS
-extern cl_boolean and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count);
+extern bool and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count);
extern cl_signean compare_loop_up (const uintD* xptr, const uintD* yptr, uintC count);
#ifdef TEST_LOOPS
-extern cl_boolean and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count);
+extern bool and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count);
extern cl_signean compare_loop_down (const uintD* xptr, const uintD* yptr, uintC count);
} // namespace cln
#include <gmp.h>
+// Argh, gmp.h includes <stddef.h> which erases the definition of offsetof
+// that we have provided in cl_offsetof.h. Restore it.
+#include "base/cl_offsetof.h"
namespace cln {
// Kopierschleife:
// destptr = copy_loop_up(sourceptr,destptr,count);
-// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
+// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
// und liefert das neue destptr.
inline uintD* copy_loop_up (const uintD* sourceptr, uintD* destptr, uintC count)
{ dotimesC(count,count, { *destptr++ = *sourceptr++; } );
// Kopierschleife:
// destptr = copy_loop_down(sourceptr,destptr,count);
-// kopiert count (uintC>=0) Digits abwärts von sourceptr nach destptr
+// kopiert count (uintC>=0) Digits abwärts von sourceptr nach destptr
// und liefert das neue destptr.
inline uintD* copy_loop_down (const uintD* sourceptr, uintD* destptr, uintC count)
{ dotimesC(count,count, { *--destptr = *--sourceptr; } );
#ifndef FILL_LOOPS
-// Füllschleife:
+// Füllschleife:
// destptr = fill_loop_up(destptr,count,filler);
-// kopiert count (uintC>=0) mal das Digit filler aufwärts nach destptr
+// kopiert count (uintC>=0) mal das Digit filler aufwärts nach destptr
// und liefert das neue destptr.
inline uintD* fill_loop_up (uintD* destptr, uintC count, uintD filler)
{ dotimesC(count,count, { *destptr++ = filler; } );
return destptr;
}
-// Füllschleife:
+// Füllschleife:
// destptr = fill_loop_down(destptr,count,filler);
-// kopiert count (uintC>=0) mal das Digit filler abwärts nach destptr
+// kopiert count (uintC>=0) mal das Digit filler abwärts nach destptr
// und liefert das neue destptr.
inline uintD* fill_loop_down (uintD* destptr, uintC count, uintD filler)
{ dotimesC(count,count, { *--destptr = filler; } );
#ifndef CLEAR_LOOPS
-// Lösch-Schleife:
+// Lösch-Schleife:
// destptr = clear_loop_up(destptr,count);
-// löscht count (uintC>=0) Digits aufwärts ab destptr
+// löscht count (uintC>=0) Digits aufwärts ab destptr
// und liefert das neue destptr.
inline uintD* clear_loop_up (uintD* destptr, uintC count)
{ dotimesC(count,count, { *destptr++ = 0; } );
return destptr;
}
-// Lösch-Schleife:
+// Lösch-Schleife:
// destptr = clear_loop_down(destptr,count);
-// löscht count (uintC>=0) Digits abwärts ab destptr
+// löscht count (uintC>=0) Digits abwärts ab destptr
// und liefert das neue destptr.
inline uintD* clear_loop_down (uintD* destptr, uintC count)
{ dotimesC(count,count, { *--destptr = 0; } );
// Test-Schleife:
// test_loop_up(ptr,count)
-// testet count (uintC>=0) Digits aufwärts ab ptr, ob darunter eines /=0 ist.
+// testet count (uintC>=0) Digits aufwärts ab ptr, ob darunter eines /=0 ist.
// Ergebnis /=0, falls ja.
- inline cl_boolean test_loop_up (const uintD* ptr, uintC count)
- { dotimesC(count,count, { if (*ptr++) return cl_true; } );
- return cl_false;
+ inline bool test_loop_up (const uintD* ptr, uintC count)
+ { dotimesC(count,count, { if (*ptr++) return true; } );
+ return false;
}
// Test-Schleife:
// test_loop_down(ptr,count)
-// testet count (uintC>=0) Digits abwärts ab ptr, ob darunter eines /=0 ist.
+// testet count (uintC>=0) Digits abwärts ab ptr, ob darunter eines /=0 ist.
// Ergebnis /=0, falls ja.
- inline cl_boolean test_loop_down (const uintD* ptr, uintC count)
- { dotimesC(count,count, { if (*--ptr) return cl_true; } );
- return cl_false;
+ inline bool test_loop_down (const uintD* ptr, uintC count)
+ { dotimesC(count,count, { if (*--ptr) return true; } );
+ return false;
}
#endif
// OR-Schleife:
// or_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch OR.
inline void or_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *xptr++ |= *yptr++; } ); }
// XOR-Schleife:
// xor_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch XOR.
inline void xor_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *xptr++ ^= *yptr++; } ); }
// AND-Schleife:
// and_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch AND.
inline void and_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *xptr++ &= *yptr++; } ); }
// EQV-Schleife:
// eqv_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch EQV (NOT XOR).
inline void eqv_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count,
// NAND-Schleife:
// nand_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch NAND (NOT AND).
inline void nand_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count,
// NOR-Schleife:
// nor_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch NOR (NOT OR).
inline void nor_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count,
// ANDC2-Schleife:
// andc2_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch ANDC2 (AND NOT).
inline void andc2_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *xptr++ &= ~(*yptr++); } ); }
// ORC2-Schleife:
// orc2_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch ORC2 (OR NOT).
inline void orc2_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *xptr++ |= ~(*yptr++); } ); }
// NOT-Schleife:
// not_loop_up(xptr,count);
-// verknüpft count (uintC>0) Digits aufwärts ab xptr mit Ziel ab xptr
+// verknüpft count (uintC>0) Digits aufwärts ab xptr mit Ziel ab xptr
// durch NOT.
inline void not_loop_up (uintD* xptr, uintC count)
{ dotimespC(count,count,
// AND-Test-Schleife:
// and_test_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr durch AND
-// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis cl_true, falls ja.
- inline cl_boolean and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count)
- { dotimesC(count,count, { if (*xptr++ & *yptr++) return cl_true; } );
- return cl_false;
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr durch AND
+// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis true, falls ja.
+ inline bool and_test_loop_up (const uintD* xptr, const uintD* yptr, uintC count)
+ { dotimesC(count,count, { if (*xptr++ & *yptr++) return true; } );
+ return false;
}
// Vergleichsschleife:
#ifndef ADDSUB_LOOPS
// Additionsschleife:
-// übertrag = add_loop_down(sourceptr1,sourceptr2,destptr,count);
-// addiert count (uintC>=0) Digits abwärts von sourceptr1, von sourceptr2
-// abwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = add_loop_down(sourceptr1,sourceptr2,destptr,count);
+// addiert count (uintC>=0) Digits abwärts von sourceptr1, von sourceptr2
+// abwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
inline uintD add_loop_down (const uintD* sourceptr1, const uintD* sourceptr2, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Additionsschleife:
-// übertrag = addto_loop_down(sourceptr,destptr,count);
-// addiert count (uintC>=0) Digits abwärts von sourceptr, von destptr
-// abwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = addto_loop_down(sourceptr,destptr,count);
+// addiert count (uintC>=0) Digits abwärts von sourceptr, von destptr
+// abwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
inline uintD addto_loop_down (const uintD* sourceptr, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Incrementierschleife:
-// übertrag = inc_loop_down(ptr,count);
-// incrementiert count (uintC>=0) Digits abwärts von ptr, so lange bis kein
-// Übertrag mehr auftritt und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = inc_loop_down(ptr,count);
+// incrementiert count (uintC>=0) Digits abwärts von ptr, so lange bis kein
+// Übertrag mehr auftritt und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
inline uintD inc_loop_down (uintD* ptr, uintC count)
{ dotimesC(count,count,
- { if (!( ++(*--ptr) == 0 )) return 0; } // kein weiterer Übertrag
+ { if (!( ++(*--ptr) == 0 )) return 0; } // kein weiterer Übertrag
);
- return 1; // weiterer Übertrag
+ return 1; // weiterer Übertrag
}
// Subtraktionsschleife:
-// übertrag = sub_loop_down(sourceptr1,sourceptr2,destptr,count);
-// subtrahiert count (uintC>=0) Digits abwärts von sourceptr1, von sourceptr2
-// abwärts nach destptr und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
+// übertrag = sub_loop_down(sourceptr1,sourceptr2,destptr,count);
+// subtrahiert count (uintC>=0) Digits abwärts von sourceptr1, von sourceptr2
+// abwärts nach destptr und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
inline uintD sub_loop_down (const uintD* sourceptr1, const uintD* sourceptr2, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Subtraktionsschleife:
-// übertrag = subx_loop_down(sourceptr1,sourceptr2,destptr,count,carry);
-// subtrahiert count (uintC>=0) Digits abwärts von sourceptr1 und addiert
-// einen Carry (0 oder -1), von sourceptr2 abwärts nach destptr und
-// liefert den Übertrag (0 oder /=0, was -1 bedeutet).
+// übertrag = subx_loop_down(sourceptr1,sourceptr2,destptr,count,carry);
+// subtrahiert count (uintC>=0) Digits abwärts von sourceptr1 und addiert
+// einen Carry (0 oder -1), von sourceptr2 abwärts nach destptr und
+// liefert den Übertrag (0 oder /=0, was -1 bedeutet).
inline uintD subx_loop_down (const uintD* sourceptr1, const uintD* sourceptr2, uintD* destptr, uintC count, uintD carry)
{ var uintD source1;
var uintD source2;
} }
// Subtraktionsschleife:
-// übertrag = subfrom_loop_down(sourceptr,destptr,count);
-// subtrahiert count (uintC>=0) Digits abwärts von sourceptr, von destptr
-// abwärts nach destptr (dest := dest - source)
-// und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
+// übertrag = subfrom_loop_down(sourceptr,destptr,count);
+// subtrahiert count (uintC>=0) Digits abwärts von sourceptr, von destptr
+// abwärts nach destptr (dest := dest - source)
+// und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
inline uintD subfrom_loop_down (const uintD* sourceptr, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Decrementierschleife:
-// übertrag = dec_loop_down(ptr,count);
-// decrementiert count (uintC>=0) Digits abwärts von ptr, so lange bis kein
-// Übertrag mehr auftritt und liefert den Übertrag (0 oder -1).
+// übertrag = dec_loop_down(ptr,count);
+// decrementiert count (uintC>=0) Digits abwärts von ptr, so lange bis kein
+// Übertrag mehr auftritt und liefert den Übertrag (0 oder -1).
inline uintD dec_loop_down (uintD* ptr, uintC count)
{ dotimesC(count,count,
- { if (!( (*--ptr)-- == 0 )) return 0; } // kein weiterer Übertrag
+ { if (!( (*--ptr)-- == 0 )) return 0; } // kein weiterer Übertrag
);
- return (uintD)(-1); // weiterer Übertrag
+ return (uintD)(-1); // weiterer Übertrag
}
// Negierschleife:
-// übertrag = neg_loop_down(ptr,count);
-// negiert count (uintC>=0) Digits abwärts von ptr,
-// und liefert den Übertrag (0 oder -1).
+// übertrag = neg_loop_down(ptr,count);
+// negiert count (uintC>=0) Digits abwärts von ptr,
+// und liefert den Übertrag (0 oder -1).
inline uintD neg_loop_down (uintD* ptr, uintC count)
{ // erstes Digit /=0 suchen:
until (count==0) { if (!(*--ptr == 0)) goto L1; count--; }
#ifndef SHIFT_LOOPS
// Schiebeschleife um 1 Bit nach links:
-// übertrag = shift1left_loop_down(ptr,count);
-// schiebt count (uintC>=0) Digits abwärts von ptr um 1 Bit nach links,
-// und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = shift1left_loop_down(ptr,count);
+// schiebt count (uintC>=0) Digits abwärts von ptr um 1 Bit nach links,
+// und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
#if HAVE_DD
inline uintD shift1left_loop_down (uintD* ptr, uintC count)
{ var uintDD accu = 0;
#endif
// Schiebeschleife um i Bits nach links:
-// übertrag = shiftleft_loop_down(ptr,count,i,übertrag_init);
-// schiebt count (uintC>=0) Digits abwärts von ptr um i Bits (0<i<intDsize)
-// nach links, schiebt dabei die i Bits aus übertrag_init rechts rein,
-// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
+// übertrag = shiftleft_loop_down(ptr,count,i,übertrag_init);
+// schiebt count (uintC>=0) Digits abwärts von ptr um i Bits (0<i<intDsize)
+// nach links, schiebt dabei die i Bits aus übertrag_init rechts rein,
+// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
#if HAVE_DD
inline uintD shiftleft_loop_down (uintD* ptr, uintC count, uintC i, uintD carry)
{ var uintDD accu = (uintDD)carry;
#endif
// Schiebe- und Kopierschleife um i Bits nach links:
-// übertrag = shiftleftcopy_loop_down(sourceptr,destptr,count,i);
-// kopiert count (uintC>=0) Digits abwärts von sourceptr nach destptr
+// übertrag = shiftleftcopy_loop_down(sourceptr,destptr,count,i);
+// kopiert count (uintC>=0) Digits abwärts von sourceptr nach destptr
// und schiebt sie dabei um i Bits (0<i<intDsize) nach links,
-// wobei ganz rechts mit i Nullbits aufgefüllt wird,
-// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
+// wobei ganz rechts mit i Nullbits aufgefüllt wird,
+// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
#if HAVE_DD
inline uintD shiftleftcopy_loop_down (const uintD* sourceptr, uintD* destptr, uintC count, uintC i)
{ var uintDD accu = 0;
#endif
// Schiebeschleife um 1 Bit nach rechts:
-// übertrag = shift1right_loop_up(ptr,count,übertrag_init);
-// schiebt count (uintC>=0) Digits aufwärts von ptr um 1 Bit nach rechts,
-// wobei links das Bit übertrag_init (sollte =0 oder =-1 sein) hineingeschoben
-// wird, und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = shift1right_loop_up(ptr,count,übertrag_init);
+// schiebt count (uintC>=0) Digits aufwärts von ptr um 1 Bit nach rechts,
+// wobei links das Bit übertrag_init (sollte =0 oder =-1 sein) hineingeschoben
+// wird, und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
#if HAVE_DD
inline uintD shift1right_loop_up (uintD* ptr, uintC count, uintD carry)
{ var uintDD accu = (sintDD)(sintD)carry & ((uintDD)1 << (2*intDsize-1)); // 0 oder bit(2*intDsize-1)
#endif
// Schiebeschleife um i Bits nach rechts:
-// übertrag = shiftright_loop_up(ptr,count,i);
-// schiebt count (uintC>=0) Digits aufwärts von ptr um i Bits (0<i<intDsize)
+// übertrag = shiftright_loop_up(ptr,count,i);
+// schiebt count (uintC>=0) Digits aufwärts von ptr um i Bits (0<i<intDsize)
// nach rechts, wobei links Nullen eingeschoben werden,
-// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
+// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
#if HAVE_DD
inline uintD shiftright_loop_up (uintD* ptr, uintC count, uintC i)
{ var uintDD accu = 0;
dotimesC(count,count,
- { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
+ { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
accu = highlowDD_0(lowD(accu));
- // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
+ // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
accu = (highlowDD_0(*ptr)>>i)+accu; *ptr++ = highD(accu);
});
return lowD(accu);
#endif
// Schiebeschleife um i Bits nach rechts:
-// übertrag = shiftrightsigned_loop_up(ptr,count,i);
-// schiebt count (uintC>0) Digits aufwärts von ptr um i Bits (0<i<intDsize)
+// übertrag = shiftrightsigned_loop_up(ptr,count,i);
+// schiebt count (uintC>0) Digits aufwärts von ptr um i Bits (0<i<intDsize)
// nach rechts, wobei links das MSBit ver-i-facht wird,
-// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
+// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
#if HAVE_DD
inline uintD shiftrightsigned_loop_up (uintD* ptr, uintC count, uintC i)
- { var uintDD accu = // Übertrag mit i Vorzeichenbits initialisieren
+ { var uintDD accu = // Übertrag mit i Vorzeichenbits initialisieren
highlowDD_0(sign_of_sintD((sintD)(*ptr)))>>i;
dotimespC(count,count,
- { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
+ { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
accu = highlowDD_0(lowD(accu));
- // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
+ // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
accu = (highlowDD_0(*ptr)>>i)+accu; *ptr++ = highD(accu);
});
return lowD(accu);
#endif
// Schiebe- und Kopier-Schleife um i Bits nach rechts:
-// übertrag = shiftrightcopy_loop_up(sourceptr,destptr,count,i,carry);
-// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
+// übertrag = shiftrightcopy_loop_up(sourceptr,destptr,count,i,carry);
+// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
// und schiebt sie dabei um i Bits (0<i<intDsize) nach rechts, wobei carry
// (sozusagen als sourceptr[-1]) die i Bits ganz links bestimmt,
-// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
+// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
#if HAVE_DD
inline uintD shiftrightcopy_loop_up (const uintD* sourceptr, uintD* destptr, uintC count, uintC i, uintD carry)
- { var uintDD accu = // Übertrag mit carry initialisieren
+ { var uintDD accu = // Übertrag mit carry initialisieren
highlowDD_0(carry)>>i;
dotimesC(count,count,
- { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
+ { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
accu = highlowDD_0(lowD(accu));
- // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
+ // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
accu = (highlowDD_0(*sourceptr++)>>i)+accu; *destptr++ = highD(accu);
});
return lowD(accu);
// Multiplikations-Einfachschleife:
// Multipliziert eine UDS mit einem kleinen Digit und addiert ein kleines Digit.
// mulusmall_loop_down(digit,ptr,len,newdigit)
-// multipliziert die UDS ptr[-len..-1] mit digit (>=2, <=36),
-// addiert dabei newdigit (>=0, <digit) zur letzten Ziffer,
-// und liefert den Carry (>=0, <digit).
+// multipliziert die UDS ptr[-len..-1] mit digit,
+// addiert dabei newdigit zur letzten Ziffer,
+// und liefert den Carry.
#if HAVE_DD
inline uintD mulusmall_loop_down (uintD digit, uintD* ptr, uintC len, uintD newdigit)
{ var uintDD carry = newdigit;
// muluadd_loop_down(digit,sourceptr,destptr,len);
// multipliziert die UDS sourceptr[-len..-1] (len>0)
// mit dem einzelnen digit, legt das Ergebnis in der UDS destptr[-len..-1]
-// ab und liefert den weiteren Übertrag.
+// ab und liefert den weiteren Übertrag.
#if HAVE_DD
inline uintD muluadd_loop_down (uintD digit, const uintD* sourceptr, uintD* destptr, uintC len)
{ var uintDD carry = 0;
// mulusub_loop_down(digit,sourceptr,destptr,len);
// multipliziert die UDS sourceptr[-len..-1] (len>0) mit dem einzelnen
// digit, subtrahiert das Ergebnis von der UDS destptr[-len..-1] und liefert
-// den weiteren Übertrag (>=0, evtl. von destptr[-len-1] zu subtrahieren).
+// den weiteren Übertrag (>=0, evtl. von destptr[-len-1] zu subtrahieren).
#if HAVE_DD
inline uintD mulusub_loop_down (uintD digit, const uintD* sourceptr, uintD* destptr, uintC len)
{ var uintDD carry = 0;
return lowD(carry);
}
else
- return 0; // nichts zu subtrahieren -> kein Übertrag
+ return 0; // nichts zu subtrahieren -> kein Übertrag
}
#else
inline uintD mulusub_loop_down (uintD digit, const uintD* sourceptr, uintD* destptr, uintC len)
return carry;
}
else
- return 0; // nichts zu subtrahieren -> kein Übertrag
+ return 0; // nichts zu subtrahieren -> kein Übertrag
}
#endif
// OR-Schleife:
// or_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch OR.
inline void or_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *--xptr |= *--yptr; } ); }
// XOR-Schleife:
// xor_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch XOR.
inline void xor_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *--xptr ^= *--yptr; } ); }
// AND-Schleife:
// and_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch AND.
inline void and_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *--xptr &= *--yptr; } ); }
// EQV-Schleife:
// eqv_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch EQV (NOT XOR).
inline void eqv_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count,
// NAND-Schleife:
// nand_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch NAND (NOT AND).
inline void nand_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count,
// NOR-Schleife:
// nor_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch NOR (NOT OR).
inline void nor_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count,
// ANDC2-Schleife:
// andc2_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch ANDC2 (AND NOT).
inline void andc2_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *--xptr &= ~(*--yptr); } ); }
// ORC2-Schleife:
// orc2_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr
// mit Ziel ab xptr durch ORC2 (OR NOT).
inline void orc2_loop_down (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *--xptr |= ~(*--yptr); } ); }
// NOT-Schleife:
// not_loop_down(xptr,count);
-// verknüpft count (uintC>0) Digits abwärts ab xptr mit Ziel ab xptr
+// verknüpft count (uintC>0) Digits abwärts ab xptr mit Ziel ab xptr
// durch NOT.
inline void not_loop_down (uintD* xptr, uintC count)
{ dotimespC(count,count,
// AND-Test-Schleife:
// and_test_loop_down(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr durch AND
-// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis cl_true, falls ja.
- inline cl_boolean and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count)
- { dotimesC(count,count, { if (*--xptr & *--yptr) return cl_true; } );
- return cl_false;
+// verknüpft count (uintC>=0) Digits abwärts ab xptr und ab yptr durch AND
+// und testet, ob sich dabei ein Digit /=0 ergibt. Ergebnis true, falls ja.
+ inline bool and_test_loop_down (const uintD* xptr, const uintD* yptr, uintC count)
+ { dotimesC(count,count, { if (*--xptr & *--yptr) return true; } );
+ return false;
}
// Vergleichsschleife:
#ifndef ADDSUB_LOOPS
// Additionsschleife:
-// übertrag = add_loop_up(sourceptr1,sourceptr2,destptr,count);
-// addiert count (uintC>=0) Digits aufwärts von sourceptr1, von sourceptr2
-// aufwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = add_loop_up(sourceptr1,sourceptr2,destptr,count);
+// addiert count (uintC>=0) Digits aufwärts von sourceptr1, von sourceptr2
+// aufwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
inline uintD add_loop_up (const uintD* sourceptr1, const uintD* sourceptr2, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Additionsschleife:
-// übertrag = addto_loop_up(sourceptr,destptr,count);
-// addiert count (uintC>=0) Digits aufwärts von sourceptr, von destptr
-// aufwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = addto_loop_up(sourceptr,destptr,count);
+// addiert count (uintC>=0) Digits aufwärts von sourceptr, von destptr
+// aufwärts nach destptr und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
inline uintD addto_loop_up (const uintD* sourceptr, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Incrementierschleife:
-// übertrag = inc_loop_up(ptr,count);
-// incrementiert count (uintC>=0) Digits aufwärts von ptr, so lange bis kein
-// Übertrag mehr auftritt und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = inc_loop_up(ptr,count);
+// incrementiert count (uintC>=0) Digits aufwärts von ptr, so lange bis kein
+// Übertrag mehr auftritt und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
inline uintD inc_loop_up (uintD* ptr, uintC count)
{ dotimesC(count,count,
- { if (!( ++(*ptr++) == 0 )) return 0; } // kein weiterer Übertrag
+ { if (!( ++(*ptr++) == 0 )) return 0; } // kein weiterer Übertrag
);
- return 1; // weiterer Übertrag
+ return 1; // weiterer Übertrag
}
// Subtraktionsschleife:
-// übertrag = sub_loop_up(sourceptr1,sourceptr2,destptr,count);
-// subtrahiert count (uintC>=0) Digits aufwärts von sourceptr1, von sourceptr2
-// aufwärts nach destptr und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
+// übertrag = sub_loop_up(sourceptr1,sourceptr2,destptr,count);
+// subtrahiert count (uintC>=0) Digits aufwärts von sourceptr1, von sourceptr2
+// aufwärts nach destptr und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
inline uintD sub_loop_up (const uintD* sourceptr1, const uintD* sourceptr2, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Subtraktionsschleife:
-// übertrag = subx_loop_up(sourceptr1,sourceptr2,destptr,count,carry);
-// subtrahiert count (uintC>=0) Digits aufwärts von sourceptr1 und addiert
-// einen Carry (0 oder -1), von sourceptr2 aufwärts nach destptr und
-// liefert den Übertrag (0 oder /=0, was -1 bedeutet).
+// übertrag = subx_loop_up(sourceptr1,sourceptr2,destptr,count,carry);
+// subtrahiert count (uintC>=0) Digits aufwärts von sourceptr1 und addiert
+// einen Carry (0 oder -1), von sourceptr2 aufwärts nach destptr und
+// liefert den Übertrag (0 oder /=0, was -1 bedeutet).
inline uintD subx_loop_up (const uintD* sourceptr1, const uintD* sourceptr2, uintD* destptr, uintC count, uintD carry)
{ var uintD source1;
var uintD source2;
} }
// Subtraktionsschleife:
-// übertrag = subfrom_loop_up(sourceptr,destptr,count);
-// subtrahiert count (uintC>=0) Digits aufwärts von sourceptr, von destptr
-// aufwärts nach destptr (dest := dest - source)
-// und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
+// übertrag = subfrom_loop_up(sourceptr,destptr,count);
+// subtrahiert count (uintC>=0) Digits aufwärts von sourceptr, von destptr
+// aufwärts nach destptr (dest := dest - source)
+// und liefert den Übertrag (0 oder /=0, was -1 bedeutet).
inline uintD subfrom_loop_up (const uintD* sourceptr, uintD* destptr, uintC count)
{ var uintD source1;
var uintD source2;
}
// Decrementierschleife:
-// übertrag = dec_loop_up(ptr,count);
-// decrementiert count (uintC>=0) Digits aufwärts von ptr, so lange bis kein
-// Übertrag mehr auftritt und liefert den Übertrag (0 oder -1).
+// übertrag = dec_loop_up(ptr,count);
+// decrementiert count (uintC>=0) Digits aufwärts von ptr, so lange bis kein
+// Übertrag mehr auftritt und liefert den Übertrag (0 oder -1).
inline uintD dec_loop_up (uintD* ptr, uintC count)
{ dotimesC(count,count,
- { if (!( (*ptr++)-- == 0 )) return 0; } // kein weiterer Übertrag
+ { if (!( (*ptr++)-- == 0 )) return 0; } // kein weiterer Übertrag
);
- return (uintD)(-1); // weiterer Übertrag
+ return (uintD)(-1); // weiterer Übertrag
}
// Negierschleife:
-// übertrag = neg_loop_up(ptr,count);
-// negiert count (uintC>=0) Digits aufwärts von ptr,
-// und liefert den Übertrag (0 oder -1).
+// übertrag = neg_loop_up(ptr,count);
+// negiert count (uintC>=0) Digits aufwärts von ptr,
+// und liefert den Übertrag (0 oder -1).
inline uintD neg_loop_up (uintD* ptr, uintC count)
{ // erstes Digit /=0 suchen:
until (count==0) { if (!(*ptr == 0)) goto L1; ptr++; count--; }
#ifndef SHIFT_LOOPS
// Schiebeschleife um 1 Bit nach links:
-// übertrag = shift1left_loop_up(ptr,count);
-// schiebt count (uintC>=0) Digits aufwärts von ptr um 1 Bit nach links,
-// und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = shift1left_loop_up(ptr,count);
+// schiebt count (uintC>=0) Digits aufwärts von ptr um 1 Bit nach links,
+// und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
#if HAVE_DD
inline uintD shift1left_loop_up (uintD* ptr, uintC count)
{ var uintDD accu = 0;
#endif
// Schiebeschleife um i Bits nach links:
-// übertrag = shiftleft_loop_up(ptr,count,i,übertrag_init);
-// schiebt count (uintC>=0) Digits aufwärts von ptr um i Bits (0<i<intDsize)
-// nach links, schiebt dabei die i Bits aus übertrag_init rechts rein,
-// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
+// übertrag = shiftleft_loop_up(ptr,count,i,übertrag_init);
+// schiebt count (uintC>=0) Digits aufwärts von ptr um i Bits (0<i<intDsize)
+// nach links, schiebt dabei die i Bits aus übertrag_init rechts rein,
+// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
#if HAVE_DD
inline uintD shiftleft_loop_up (uintD* ptr, uintC count, uintC i, uintD carry)
{ var uintDD accu = (uintDD)carry;
#endif
// Schiebe- und Kopierschleife um i Bits nach links:
-// übertrag = shiftleftcopy_loop_up(sourceptr,destptr,count,i);
-// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
+// übertrag = shiftleftcopy_loop_up(sourceptr,destptr,count,i);
+// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
// und schiebt sie dabei um i Bits (0<i<intDsize) nach links,
-// wobei ganz rechts mit i Nullbits aufgefüllt wird,
-// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
+// wobei ganz rechts mit i Nullbits aufgefüllt wird,
+// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
#if HAVE_DD
inline uintD shiftleftcopy_loop_up (const uintD* sourceptr, uintD* destptr, uintC count, uintC i)
{ var uintDD accu = 0;
#endif
// Schiebeschleife um 1 Bit nach rechts:
-// übertrag = shift1right_loop_down(ptr,count,übertrag_init);
-// schiebt count (uintC>=0) Digits abwärts von ptr um 1 Bit nach rechts,
-// wobei links das Bit übertrag_init (sollte =0 oder =-1 sein) hineingeschoben
-// wird, und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
+// übertrag = shift1right_loop_down(ptr,count,übertrag_init);
+// schiebt count (uintC>=0) Digits abwärts von ptr um 1 Bit nach rechts,
+// wobei links das Bit übertrag_init (sollte =0 oder =-1 sein) hineingeschoben
+// wird, und liefert den Übertrag (0 oder /=0, was 1 bedeutet).
#if HAVE_DD
inline uintD shift1right_loop_down (uintD* ptr, uintC count, uintD carry)
{ var uintDD accu = (sintDD)(sintD)carry & ((uintDD)1 << (2*intDsize-1)); // 0 oder bit(2*intDsize-1)
#endif
// Schiebeschleife um i Bits nach rechts:
-// übertrag = shiftright_loop_down(ptr,count,i);
-// schiebt count (uintC>=0) Digits abwärts von ptr um i Bits (0<i<intDsize)
+// übertrag = shiftright_loop_down(ptr,count,i);
+// schiebt count (uintC>=0) Digits abwärts von ptr um i Bits (0<i<intDsize)
// nach rechts, wobei links Nullen eingeschoben werden,
-// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
+// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
#if HAVE_DD
inline uintD shiftright_loop_down (uintD* ptr, uintC count, uintC i)
{ var uintDD accu = 0;
dotimesC(count,count,
- { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
+ { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
accu = highlowDD_0(lowD(accu));
- // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
+ // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
accu = (highlowDD_0(*--ptr)>>i)+accu; *ptr = highD(accu);
});
return lowD(accu);
#endif
// Schiebeschleife um i Bits nach rechts:
-// übertrag = shiftrightsigned_loop_down(ptr,count,i);
-// schiebt count (uintC>0) Digits abwärts von ptr um i Bits (0<i<intDsize)
+// übertrag = shiftrightsigned_loop_down(ptr,count,i);
+// schiebt count (uintC>0) Digits abwärts von ptr um i Bits (0<i<intDsize)
// nach rechts, wobei links das MSBit ver-i-facht wird,
-// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
+// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
#if HAVE_DD
inline uintD shiftrightsigned_loop_down (uintD* ptr, uintC count, uintC i)
- { var uintDD accu = // Übertrag mit i Vorzeichenbits initialisieren
+ { var uintDD accu = // Übertrag mit i Vorzeichenbits initialisieren
highlowDD_0(sign_of_sintD((sintD)(ptr[-1])))>>i;
dotimespC(count,count,
- { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
+ { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
accu = highlowDD_0(lowD(accu));
- // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
+ // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
accu = (highlowDD_0(*--ptr)>>i)+accu; *ptr = highD(accu);
});
return lowD(accu);
#endif
// Schiebe- und Kopier-Schleife um i Bits nach rechts:
-// übertrag = shiftrightcopy_loop_down(sourceptr,destptr,count,i,carry);
-// kopiert count (uintC>=0) Digits abwärts von sourceptr nach destptr
+// übertrag = shiftrightcopy_loop_down(sourceptr,destptr,count,i,carry);
+// kopiert count (uintC>=0) Digits abwärts von sourceptr nach destptr
// und schiebt sie dabei um i Bits (0<i<intDsize) nach rechts, wobei carry
// (sozusagen als sourceptr[0]) die i Bits ganz links bestimmt,
-// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
+// und liefert den Übertrag (was rechts rauskommt, als Bits intDsize-1..intDsize-i).
#if HAVE_DD
inline uintD shiftrightcopy_loop_down (const uintD* sourceptr, uintD* destptr, uintC count, uintC i, uintD carry)
- { var uintDD accu = // Übertrag mit carry initialisieren
+ { var uintDD accu = // Übertrag mit carry initialisieren
highlowDD_0(carry)>>i;
dotimesC(count,count,
- { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
+ { // Die oberen i Bits von (uintD)accu bilden hier den Übertrag.
accu = highlowDD_0(lowD(accu));
- // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
+ // Die oberen i Bits von (uintDD)accu bilden hier den Übertrag.
accu = (highlowDD_0(*--sourceptr)>>i)+accu; *--destptr = highD(accu);
});
return lowD(accu);
// Multiplikations-Einfachschleife:
// Multipliziert eine UDS mit einem kleinen Digit und addiert ein kleines Digit.
// mulusmall_loop_up(digit,ptr,len,newdigit)
-// multipliziert die UDS ptr[0..len-1] mit digit (>=2, <=36),
-// addiert dabei newdigit (>=0, <digit) zur letzten Ziffer,
-// und liefert den Carry (>=0, <digit).
+// multipliziert die UDS ptr[0..len-1] mit digit,
+// addiert dabei newdigit zur letzten Ziffer,
+// und liefert den Carry.
#if HAVE_DD
inline uintD mulusmall_loop_up (uintD digit, uintD* ptr, uintC len, uintD newdigit)
{ var uintDD carry = newdigit;
// muluadd_loop_up(digit,sourceptr,destptr,len);
// multipliziert die UDS sourceptr[0..len-1] (len>0)
// mit dem einzelnen digit, legt das Ergebnis in der UDS destptr[0..len-1]
-// ab und liefert den weiteren Übertrag.
+// ab und liefert den weiteren Übertrag.
#if HAVE_DD
inline uintD muluadd_loop_up (uintD digit, const uintD* sourceptr, uintD* destptr, uintC len)
{ var uintDD carry = 0;
// mulusub_loop_up(digit,sourceptr,destptr,len);
// multipliziert die UDS sourceptr[0..len-1] (len>0) mit dem einzelnen
// digit, subtrahiert das Ergebnis von der UDS destptr[0..len-1] und liefert
-// den weiteren Übertrag (>=0, evtl. von destptr[len] zu subtrahieren).
+// den weiteren Übertrag (>=0, evtl. von destptr[len] zu subtrahieren).
#if HAVE_DD
inline uintD mulusub_loop_up (uintD digit, const uintD* sourceptr, uintD* destptr, uintC len)
{ var uintDD carry = 0;
return lowD(carry);
}
else
- return 0; // nichts zu subtrahieren -> kein Übertrag
+ return 0; // nichts zu subtrahieren -> kein Übertrag
}
#else
inline uintD mulusub_loop_up (uintD digit, const uintD* sourceptr, uintD* destptr, uintC len)
return carry;
}
else
- return 0; // nichts zu subtrahieren -> kein Übertrag
+ return 0; // nichts zu subtrahieren -> kein Übertrag
}
#endif
// XOR-Schleife:
// xor_loop_up(xptr,yptr,count);
-// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
+// verknüpft count (uintC>=0) Digits aufwärts ab xptr und ab yptr
// mit Ziel ab xptr durch XOR.
inline void xor_loop_up (uintD* xptr, const uintD* yptr, uintC count)
{ dotimesC(count,count, { *xptr++ ^= *yptr++; } ); }
#if !defined(SHIFT_LOOPS) && CL_DS_BIG_ENDIAN_P
// Schiebe- und Kopierschleife um i Bits nach links:
-// übertrag = shiftleftcopy_loop_up(sourceptr,destptr,count,i);
-// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
+// übertrag = shiftleftcopy_loop_up(sourceptr,destptr,count,i);
+// kopiert count (uintC>=0) Digits aufwärts von sourceptr nach destptr
// und schiebt sie dabei um i Bits (0<i<intDsize) nach links,
-// wobei ganz rechts mit i Nullbits aufgefüllt wird,
-// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
+// wobei ganz rechts mit i Nullbits aufgefüllt wird,
+// und liefert den Übertrag (was links rauskommt, >=0, <2^i).
#if HAVE_DD
inline uintD shiftleftcopy_loop_up (const uintD* sourceptr, uintD* destptr, uintC count, uintC i)
{ var uintDD accu = 0;
// Schiebe- und XOR-Schleife:
// shiftxor_loop_up(xptr,yptr,count,i);
-// verknüpft count+1 Digits aufwärts ab xptr mit count Digits aufwärts ab yptr,
+// verknüpft count+1 Digits aufwärts ab xptr mit count Digits aufwärts ab yptr,
// um i Bits verschoben, durch XOR. (count uintC>=0, 0<i<intDsize)
#if HAVE_DD
inline void shiftxor_loop_up (uintD* xptr, const uintD* yptr, uintC count, uintC i)
// Umwandlungsroutinen Digit-Sequence-Teil <--> Longword:
// get_32_Dptr(ptr)
-// holt die nächsten 32 Bits aus den 32/intDsize Digits ab ptr.
+// holt die nächsten 32 Bits aus den 32/intDsize Digits ab ptr.
// set_32_Dptr(ptr,wert);
// speichert den Wert wert (32 Bits) in die 32/intDsize Digits ab ptr.
// get_max32_Dptr(count,ptr)
-// holt die nächsten count Bits aus den ceiling(count/intDsize) Digits ab ptr.
+// holt die nächsten count Bits aus den ceiling(count/intDsize) Digits ab ptr.
// set_max32_Dptr(count,ptr,wert)
// speichert wert (count Bits) in die ceiling(count/intDsize) Digits ab ptr.
// Jeweils ptr eine Variable vom Typ uintD*,
#if (cl_word_size==64)
// get_64_Dptr(ptr)
-// holt die nächsten 64 Bits aus den 64/intDsize Digits ab ptr.
+// holt die nächsten 64 Bits aus den 64/intDsize Digits ab ptr.
// set_64_Dptr(ptr,wert);
// speichert den Wert wert (64 Bits) in die 64/intDsize Digits ab ptr.
// get_max64_Dptr(count,ptr)
-// holt die nächsten count Bits aus den ceiling(count/intDsize) Digits ab ptr.
+// holt die nächsten count Bits aus den ceiling(count/intDsize) Digits ab ptr.
// set_max64_Dptr(count,ptr,wert)
// speichert wert (count Bits) in die ceiling(count/intDsize) Digits ab ptr.
// Jeweils ptr eine Variable vom Typ uintD*,
// num_stack_alloc_1(need, MSDptr = , LSDptr = );
// num_stack_small_alloc_1(need, MSDptr = , LSDptr = );
-// wie num_stack_alloc, nur daß unterhalb von MSDptr noch ein Digit Platz
-// zusätzlich belegt wird.
+// wie num_stack_alloc, nur daß unterhalb von MSDptr noch ein Digit Platz
+// zusätzlich belegt wird.
#define num_stack_array(need,low_zuweisung,high_zuweisung) \
- {var uintL __need = (uintL)(need); \
+ {var uintC __need = (uintC)(need); \
var uintD* __array = cl_alloc_array(uintD,__need); \
- unused (low_zuweisung &__array[0]); unused (high_zuweisung &__array[__need]); \
+ cl_unused (low_zuweisung &__array[0]); cl_unused (high_zuweisung &__array[__need]); \
}
#define num_stack_small_array(need,low_zuweisung,high_zuweisung) \
- {var uintL __need = (uintL)(need); \
+ {var uintC __need = (uintC)(need); \
var uintD* __array = cl_small_alloc_array(uintD,__need); \
- unused (low_zuweisung &__array[0]); unused (high_zuweisung &__array[__need]); \
+ cl_unused (low_zuweisung &__array[0]); cl_unused (high_zuweisung &__array[__need]); \
}
#if CL_DS_BIG_ENDIAN_P
#define num_stack_alloc(need,MSDptr_zuweisung,LSDptr_zuweisung) \
#define num_stack_small_alloc(need,MSDptr_zuweisung,LSDptr_zuweisung) \
num_stack_small_array(need,MSDptr_zuweisung,LSDptr_zuweisung)
#define num_stack_alloc_1(need,MSDptr_zuweisung,LSDptr_zuweisung) \
- num_stack_array((uintL)(need)+1,MSDptr_zuweisung 1 + ,LSDptr_zuweisung)
+ num_stack_array((uintC)(need)+1,MSDptr_zuweisung 1 + ,LSDptr_zuweisung)
#define num_stack_small_alloc_1(need,MSDptr_zuweisung,LSDptr_zuweisung) \
- num_stack_small_array((uintL)(need)+1,MSDptr_zuweisung 1 + ,LSDptr_zuweisung)
+ num_stack_small_array((uintC)(need)+1,MSDptr_zuweisung 1 + ,LSDptr_zuweisung)
#else
#define num_stack_alloc(need,MSDptr_zuweisung,LSDptr_zuweisung) \
num_stack_array(need,LSDptr_zuweisung,MSDptr_zuweisung)
#define num_stack_small_alloc(need,MSDptr_zuweisung,LSDptr_zuweisung) \
num_stack_small_array(need,LSDptr_zuweisung,MSDptr_zuweisung)
#define num_stack_alloc_1(need,MSDptr_zuweisung,LSDptr_zuweisung) \
- num_stack_array((uintL)(need)+1,LSDptr_zuweisung,MSDptr_zuweisung -1 + )
+ num_stack_array((uintC)(need)+1,LSDptr_zuweisung,MSDptr_zuweisung -1 + )
#define num_stack_small_alloc_1(need,MSDptr_zuweisung,LSDptr_zuweisung) \
- num_stack_small_array((uintL)(need)+1,LSDptr_zuweisung,MSDptr_zuweisung -1 + )
+ num_stack_small_array((uintC)(need)+1,LSDptr_zuweisung,MSDptr_zuweisung -1 + )
#endif
// Macro: In der DS MSDptr/len/LSDptr wird eine 1 unterhalb des Pointers ptr
-// addiert. Unterhalb von MSDptr muß 1 Digit Platz sein.
+// addiert. Unterhalb von MSDptr muß 1 Digit Platz sein.
// Dabei ist ptr - MSDptr = count und 0 < count <= len .
-// Eventuell wird MSDptr erniedrigt und len erhöht.
+// Eventuell wird MSDptr erniedrigt und len erhöht.
#define DS_1_plus(ptr,count) \
{var uintD* ptr_from_DS_1_plus = (ptr); \
var uintC count_from_DS_1_plus = (count); \
- loop { if (--count_from_DS_1_plus==0) /* Zähler erniedrigen */\
+ loop { if (--count_from_DS_1_plus==0) /* Zähler erniedrigen */\
{ /* Beim Most Significant Digit angelangt */\
lsprefnext(ptr_from_DS_1_plus) += 1; \
/* jetzt ist ptr_from_DS_1_plus = MSDptr */\
if (mspref(ptr_from_DS_1_plus,0) == (uintD)bit(intDsize-1)) \
- { /* 7FFF + 1 muß zu 00008000 werden: */\
+ { /* 7FFF + 1 muß zu 00008000 werden: */\
lsprefnext(MSDptr) = 0; \
len++; \
} \
break; \
} \
if (!((lsprefnext(ptr_from_DS_1_plus) += 1) == 0)) /* weiterincrementieren */\
- break; /* kein weiterer Übertrag -> Schleife abbrechen */\
+ break; /* kein weiterer Übertrag -> Schleife abbrechen */\
} }
// Macro: In der DS MSDptr/len/LSDptr wird eine 1 unterhalb des Pointers ptr
-// subtrahiert. Unterhalb von MSDptr muß 1 Digit Platz sein.
+// subtrahiert. Unterhalb von MSDptr muß 1 Digit Platz sein.
// Dabei ist ptr - MSDptr = count und 0 < count <= len .
-// Eventuell wird MSDptr erniedrigt und len erhöht.
+// Eventuell wird MSDptr erniedrigt und len erhöht.
#define DS_minus1_plus(ptr,count) \
{var uintD* ptr_from_DS_minus1_plus = (ptr); \
var uintC count_from_DS_minus1_plus = (count); \
- loop { if (--count_from_DS_minus1_plus==0) /* Zähler erniedrigen */\
+ loop { if (--count_from_DS_minus1_plus==0) /* Zähler erniedrigen */\
{ /* Beim Most Significant Digit angelangt */\
lsprefnext(ptr_from_DS_minus1_plus) -= 1; \
/* jetzt ist ptr_from_DS_minus1_plus = MSDptr */\
if (mspref(ptr_from_DS_minus1_plus,0) == (uintD)bit(intDsize-1)-1) \
- { /* 8000 - 1 muß zu FFFF7FFF werden: */\
+ { /* 8000 - 1 muß zu FFFF7FFF werden: */\
lsprefnext(MSDptr) = (uintD)(-1); \
len++; \
} \
break; \
} \
if (!((sintD)(lsprefnext(ptr_from_DS_minus1_plus) -= 1) == -1)) /* weiterdecrementieren */\
- break; /* kein weiterer Übertrag -> Schleife abbrechen */\
+ break; /* kein weiterer Übertrag -> Schleife abbrechen */\
} }
// multipliziert die UDS sourceptr1[-len1..-1] (len1>0)
// mit der UDS sourceptr2[-len1..-1] (len2>0)
// und legt das Ergebnis in der UDS destptr[-len..-1] (len=len1+len2) ab.
-// Unterhalb von destptr werden len Digits Platz benötigt.
+// Unterhalb von destptr werden len Digits Platz benötigt.
extern void cl_UDS_mul (const uintD* sourceptr1, uintC len1,
const uintD* sourceptr2, uintC len2,
uintD* destptr);
// Ergebnis ist die UDS MSDptr/len/LSDptr, mit len=len1+len2, im Stack.
// Dabei wird num_stack erniedrigt.
#define UDS_UDS_mul_UDS(len1,LSDptr1,len2,LSDptr2, MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung) \
- var uintL CONCAT(len_from_UDSmul_,__LINE__) = (uintL)(len1) + (uintL)(len2); \
+ var uintC CONCAT(len_from_UDSmul_,__LINE__) = (uintC)(len1) + (uintC)(len2); \
var uintD* CONCAT(LSDptr_from_UDSmul_,__LINE__); \
- unused (len_zuweisung CONCAT(len_from_UDSmul_,__LINE__)); \
+ cl_unused (len_zuweisung CONCAT(len_from_UDSmul_,__LINE__)); \
num_stack_alloc(CONCAT(len_from_UDSmul_,__LINE__),MSDptr_zuweisung,LSDptr_zuweisung CONCAT(LSDptr_from_UDSmul_,__LINE__) =); \
cl_UDS_mul((LSDptr1),(len1),(LSDptr2),(len2),CONCAT(LSDptr_from_UDSmul_,__LINE__));
#define DS_DS_mul_DS(MSDptr1,len1,LSDptr1,MSDptr2,len2,LSDptr2, MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung) \
var uintD* MSDptr0; \
var uintD* LSDptr0; \
- var uintL len_from_DSmal = (uintL)(len1) + (uintL)(len2); \
- unused (len_zuweisung len_from_DSmal); \
+ var uintC len_from_DSmal = (uintC)(len1) + (uintC)(len2); \
+ cl_unused (len_zuweisung len_from_DSmal); \
num_stack_alloc(len_from_DSmal,MSDptr_zuweisung MSDptr0 =,LSDptr_zuweisung LSDptr0 =); \
var uintD MSD1_from_DSmal = mspref(MSDptr1,0); \
var uintD MSD2_from_DSmal = mspref(MSDptr2,0); \
- var uintL len1_from_DSmal = (len1); \
- var uintL len2_from_DSmal = (len2); \
+ var uintC len1_from_DSmal = (len1); \
+ var uintC len2_from_DSmal = (len2); \
if (MSD1_from_DSmal==0) { msprefnext(MSDptr0) = 0; len1_from_DSmal--; } \
if (MSD2_from_DSmal==0) { msprefnext(MSDptr0) = 0; len2_from_DSmal--; } \
cl_UDS_mul((LSDptr1),len1_from_DSmal,(LSDptr2),len2_from_DSmal,LSDptr0); \
if ((sintD)MSD1_from_DSmal < 0) /* n<0 ? */\
- /* muß m bzw. m+b^l subtrahieren, um k Digits verschoben: */\
+ /* muß m bzw. m+b^l subtrahieren, um k Digits verschoben: */\
{ subfrom_loop_lsp(LSDptr2,LSDptr0 lspop len1,len2); } \
if ((sintD)MSD2_from_DSmal < 0) /* m<0 ? */\
- /* muß n bzw. n+b^k subtrahieren, um l Digits verschoben: */\
+ /* muß n bzw. n+b^k subtrahieren, um l Digits verschoben: */\
{ subfrom_loop_lsp(LSDptr1,LSDptr0 lspop len2,len1); }
// q = q_MSDptr/q_len/q_LSDptr, r = r_MSDptr/r_len/r_LSDptr beides
// Normalized Unsigned Digit sequences.
// Vorsicht: q_LSDptr <= r_MSDptr,
-// Vorzeichenerweiterung von r kann q zerstören!
+// Vorzeichenerweiterung von r kann q zerstören!
// Vorzeichenerweiterung von q ist erlaubt.
// a und b werden nicht modifiziert.
// num_stack wird erniedrigt.
#define UDS_divide(a_MSDptr,a_len,a_LSDptr,b_MSDptr,b_len,b_LSDptr,q_,r_) \
- /* Platz fürs Ergebnis machen. Brauche maximal a_len+1 Digits. */\
+ /* Platz fürs Ergebnis machen. Brauche maximal a_len+1 Digits. */\
var uintC _a_len = (a_len); \
var uintD* roomptr; num_stack_alloc_1(_a_len+1,roomptr=,); \
cl_UDS_divide(a_MSDptr,_a_len,a_LSDptr,b_MSDptr,b_len,b_LSDptr,roomptr,q_,r_);
// Bildet zu einer Unsigned Digit sequence a die Wurzel
-// (genauer: Gaußklammer aus Wurzel aus a).
+// (genauer: Gaußklammer aus Wurzel aus a).
// UDS_sqrt(a_MSDptr,a_len,a_LSDptr, &b, squarep=)
// > a_MSDptr/a_len/a_LSDptr: eine UDS
-// < NUDS b: Gaußklammer der Wurzel aus a
-// < squarep: cl_true falls a = b^2, cl_false falls b^2 < a < (b+1)^2.
+// < NUDS b: Gaußklammer der Wurzel aus a
+// < squarep: true falls a = b^2, false falls b^2 < a < (b+1)^2.
// a wird nicht modifiziert.
// Vorzeichenerweiterung von b ist erlaubt.
// num_stack wird erniedrigt.
#define UDS_sqrt(a_MSDptr,a_len,a_LSDptr,b_,squarep_zuweisung) \
- { /* ceiling(a_len,2) Digits Platz fürs Ergebnis machen: */\
+ { /* ceiling(a_len,2) Digits Platz fürs Ergebnis machen: */\
var uintC _a_len = (a_len); \
num_stack_alloc_1(ceiling(_a_len,2),(b_)->MSDptr=,); \
squarep_zuweisung cl_UDS_sqrt(a_MSDptr,_a_len,a_LSDptr,b_); \
}
- extern cl_boolean cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDptr, DS* b_);
+ extern bool cl_UDS_sqrt (const uintD* a_MSDptr, uintC a_len, const uintD* a_LSDptr, DS* b_);
// Auxiliary function for approximately computing 1/x