]> www.ginac.de Git - cln.git/blob - src/integer/conv/cl_I_from_L2.cc
Replace unused macro with cl_unused.
[cln.git] / src / integer / conv / cl_I_from_L2.cc
1 // L2_to_I() helper.
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "integer/cl_I.h"
8
9
10 // Implementation.
11
12 #include "cln/number.h"
13
14 #if (cl_word_size < 64)
15
16 #include "base/digitseq/cl_DS.h"
17
18 namespace cln {
19
20 cl_private_thing cl_I_constructor_from_L2 (sint32 wert_hi, uint32 wert_lo)
21 {
22         if (wert_hi == 0) {
23                 if ((wert_lo & minus_bit(cl_value_len-1)) == 0)
24                         return (cl_private_thing)(cl_combine(cl_FN_tag,wert_lo));
25         }
26         elif (wert_hi == ~(sint32)0) {
27                 if ((~wert_lo & minus_bit(cl_value_len-1)) == 0)
28                         return (cl_private_thing)(cl_combine(cl_FN_tag,(sint32)wert_lo));
29         }
30         // Bignum erzeugen:
31         // (dessen Länge  bn_minlength <= n <= ceiling(64/intDsize)  erfüllt)
32         #define FILL_1_DIGIT(l,i,from) \
33                 arrayLSref(ptr->data,l,i) = (uintD)from;
34         #define FILL_2_DIGIT(l,i,from) \
35                 arrayLSref(ptr->data,l,i) = (uintD)from; \
36                 arrayLSref(ptr->data,l,i+1) = (uintD)(from>>intDsize);
37         #define FILL_3_DIGIT(l,i,from) \
38                 arrayLSref(ptr->data,l,i) = (uintD)from; from>>=intDsize; \
39                 arrayLSref(ptr->data,l,i+1) = (uintD)from; \
40                 arrayLSref(ptr->data,l,i+2) = (uintD)(from>>intDsize);
41         #define FILL_4_DIGIT(l,i,from) \
42                 arrayLSref(ptr->data,l,i) = (uintD)from; from>>=intDsize; \
43                 arrayLSref(ptr->data,l,i+1) = (uintD)from; from>>=intDsize; \
44                 arrayLSref(ptr->data,l,i+2) = (uintD)from; \
45                 arrayLSref(ptr->data,l,i+3) = (uintD)(from>>intDsize);
46         #if (intDsize==64)
47         #define FILL_1  FILL_1_DIGIT(1,0,highlow64(wert_hi,wert_lo));
48         #endif
49         #if (32/intDsize==1)
50         #define FILL_1  FILL_1_DIGIT(1,0,wert_lo);
51         #define FILL_2  FILL_1_DIGIT(2,1,wert_hi); FILL_1_DIGIT(2,0,wert_lo);
52         #endif
53         #if (32/intDsize==2)
54         #define FILL_1  FILL_1_DIGIT(1,0,wert_lo);
55         #define FILL_2  FILL_2_DIGIT(2,0,wert_lo);
56         #define FILL_3  FILL_1_DIGIT(3,2,wert_hi); FILL_2_DIGIT(3,0,wert_lo);
57         #define FILL_4  FILL_2_DIGIT(4,2,wert_hi); FILL_2_DIGIT(4,0,wert_lo);
58         #endif
59         #if (32/intDsize==4)
60         #define FILL_1  FILL_1_DIGIT(1,0,wert_lo);
61         #define FILL_2  FILL_2_DIGIT(2,0,wert_lo);
62         #define FILL_3  FILL_3_DIGIT(3,0,wert_lo);
63         #define FILL_4  FILL_4_DIGIT(4,0,wert_lo);
64         #define FILL_5  FILL_1_DIGIT(5,4,wert_hi); FILL_4_DIGIT(5,0,wert_lo);
65         #define FILL_6  FILL_2_DIGIT(6,4,wert_hi); FILL_4_DIGIT(6,0,wert_lo);
66         #define FILL_7  FILL_3_DIGIT(7,4,wert_hi); FILL_4_DIGIT(7,0,wert_lo);
67         #define FILL_8  FILL_4_DIGIT(8,4,wert_hi); FILL_4_DIGIT(8,0,wert_lo);
68         #endif
69         if (wert_hi >= 0) {
70                 #define IF_LENGTH(i)  \
71                   if ((bn_minlength <= i) && (i*intDsize <= 64)         \
72                     && (!((i+1)*intDsize <= 64)                         \
73                         || (i*intDsize-1 < 32                           \
74                             ? ((wert_hi == 0) && (wert_lo < (uint32)bitc(i*intDsize-1))) \
75                             : ((uint32)wert_hi < (uint32)bitc(i*intDsize-1-32)) \
76                      ) )   )
77                 #define ALLOC(i)  \
78                   var cl_heap_bignum* ptr = allocate_bignum(i);
79                 #define OK  \
80                   return (cl_private_thing)(ptr);
81                 IF_LENGTH(1)
82                         bignum1: { ALLOC(1); FILL_1; OK; }
83                 #if (intDsize <= 32)
84                 IF_LENGTH(2)
85                         bignum2: { ALLOC(2); FILL_2; OK; }
86                 #if (intDsize <= 16)
87                 IF_LENGTH(3)
88                         bignum3: { ALLOC(3); FILL_3; OK; }
89                 IF_LENGTH(4)
90                         bignum4: { ALLOC(4); FILL_4; OK; }
91                 #if (intDsize <= 8)
92                 IF_LENGTH(5)
93                         bignum5: { ALLOC(5); FILL_5; OK; }
94                 IF_LENGTH(6)
95                         bignum6: { ALLOC(6); FILL_6; OK; }
96                 IF_LENGTH(7)
97                         bignum7: { ALLOC(7); FILL_7; OK; }
98                 IF_LENGTH(8)
99                         bignum8: { ALLOC(8); FILL_8; OK; }
100                 #endif
101                 #endif
102                 #endif
103                 #undef IF_LENGTH
104         } else {
105                 #define IF_LENGTH(i)  \
106                   if ((bn_minlength <= i) && (i*intDsize <= 64)         \
107                     && (!((i+1)*intDsize <= 64)                         \
108                         || (i*intDsize-1 < 32                           \
109                             ? ((wert_hi == ~(sint32)0) && (wert_lo >= (uint32)(-bitc(i*intDsize-1)))) \
110                             : ((uint32)wert_hi >= (uint32)(-bitc(i*intDsize-1-32))) \
111                      ) )   )
112                 IF_LENGTH(1)
113                         goto bignum1;
114                 #if (intDsize <= 32)
115                 IF_LENGTH(2)
116                         goto bignum2;
117                 #if (intDsize <= 16)
118                 IF_LENGTH(3)
119                         goto bignum3;
120                 IF_LENGTH(4)
121                         goto bignum4;
122                 #if (intDsize <= 8)
123                 IF_LENGTH(5)
124                         goto bignum5;
125                 IF_LENGTH(6)
126                         goto bignum6;
127                 IF_LENGTH(7)
128                         goto bignum7;
129                 IF_LENGTH(8)
130                         goto bignum8;
131                 #endif
132                 #endif
133                 #endif
134                 #undef IF_LENGTH
135         }
136 }
137
138 }  // namespace cln
139
140 #endif