History

remove unused code

Sigrid Solveig Haflínudóttir committed 1 year ago0.5

Commit 04522871 parent c36900426 files · +2 −1193Browse files

Unified · Split

26 files
  1. Makefile +2 −16
  2. libc/dorfmt.c +0 −46
  3. libc/encodefmt.c +0 −78
  4. libc/fmt.c +0 −7
  5. libc/fmtlock.c +0 −16
  6. libc/fmtquote.c +0 −249
  7. libc/fmtstr.c +0 −12
  8. libc/nan64.c +0 −12
  9. libc/rune.c +0 −22
  10. libc/snprint.c +0 −16
  11. libc/u16.c +0 −44
  12. libmp/cnfield.c +0 −114
  13. libmp/gmfield.c +0 −173
  14. libmp/letomp.c +0 −31
  15. libmp/mpaux.c +0 −40
  16. libmp/mpfield.c +0 −21
  17. libmp/mpinvert.c +0 −17
  18. libmp/mplogic.c +0 −6
  19. libmp/mpmodop.c +0 −61
  20. libmp/mpsel.c +0 −42
  21. libmp/mptole.c +0 −28
  22. libmp/mptolel.c +0 −33
  23. libmp/mptoui.c +0 −13
  24. libmp/mptouv.c +0 −47
  25. libmp/mptov.c +0 −33
  26. libmp/reduce +0 −16
Makefile+2−16
@@ -5,20 +5,16 @@ BIN=${DESTDIR}${PREFIX}/bin · 4 unmodified lines
55 MAN=${DESTDIR}${PREFIX}/share/man/man1
66 CFLAGS?=-g -O2
77 CFLAGS+=-Iinclude -Wall -Wno-missing-braces -Wno-parentheses -Wno-incompatible-pointer-types
8+LDFLAGS?=
89
910 OBJS=\
1011 libc/dofmt.o\
11− libc/dorfmt.o\
12− libc/encodefmt.o\
1312 libc/fltfmt.o\
1413 libc/fmt.o\
1514 libc/fmtfd.o\
1615 libc/fmtfdflush.o\
17− libc/fmtlock.o\
1816 libc/fmtprint.o\
19− libc/fmtquote.o\
2017 libc/fmtrune.o\
21− libc/fmtstr.o\
2218 libc/fmtvprint.o\
2319 libc/fprint.o\
2420 libc/genrandom.o\
@@ -26,7 +22,6 @@ OBJS=\ · 1 unmodified line
2622 libc/nan64.o\
2723 libc/print.o\
2824 libc/rune.o\
29− libc/snprint.o\
3025 libc/sprint.o\
3126 libc/strtod.o\
3227 libc/sysfatal.o\
@@ -37,9 +32,6 @@ OBJS=\ · 4 unmodified lines
3732 libc/vfprint.o\
3833 libc/vsnprint.o\
3934 libmp/betomp.o\
40− libmp/cnfield.o\
41− libmp/gmfield.o\
42− libmp/letomp.o\
4335 libmp/mpadd.o\
4436 libmp/mpaux.o\
4537 libmp/mpcmp.o\
@@ -47,9 +39,7 @@ OBJS=\ · 1 unmodified line
4739 libmp/mpdiv.o\
4840 libmp/mpexp.o\
4941 libmp/mpextendedgcd.o\
50− libmp/mpfield.o\
5142 libmp/mpfmt.o\
52− libmp/mpinvert.o\
5343 libmp/mpleft.o\
5444 libmp/mplogic.o\
5545 libmp/mpmod.o\
@@ -58,15 +48,11 @@ OBJS=\ · 2 unmodified lines
5848 libmp/mpnrand.o\
5949 libmp/mprand.o\
6050 libmp/mpright.o\
61− libmp/mpsel.o\
6251 libmp/mpsub.o\
6352 libmp/mptobe.o\
6453 libmp/mptober.o\
6554 libmp/mptoi.o\
66− libmp/mptole.o\
67− libmp/mptolel.o\
6855 libmp/mptoui.o\
69− libmp/mptouv.o\
7056 libmp/mptov.o\
7157 libmp/mpvecadd.o\
7258 libmp/mpveccmp.o\
@@ -95,7 +81,7 @@ clean: · 22 unmodified lines
9581 rm -f ${TARGET} ${OBJS} ${TARGET}.c
9682
9783 ${TARGET}: ${OBJS}
98− ${CC} -o $@ ${OBJS}
84+ ${CC} -o $@ ${OBJS} ${LDFLAGS}
9985
10086 pc.c: pc.y
10187 yacc -o $@ $<
libc/dorfmt.c+0−46
@@ -1,46 +0,0 @@
1−#include <u.h>
2−#include <libc.h>
3−#include "fmtdef.h"
4−
5−/* format the output into f->to and return the number of characters fmted */
6−
7−int
8−dorfmt(Fmt *f, const Rune *fmt)
9−{
10− Rune *rt, *rs;
11− int r;
12− char *t, *s;
13− int nfmt;
14−
15− nfmt = f->nfmt;
16− for(;;){
17− if(f->runes){
18− rt = f->to;
19− rs = f->stop;
20− while((r = *fmt++) && r != '%'){
21− FMTRCHAR(f, rt, rs, r);
22− }
23− f->nfmt += rt - (Rune *)f->to;
24− f->to = rt;
25− if(!r)
26− return f->nfmt - nfmt;
27− f->stop = rs;
28− }else{
29− t = f->to;
30− s = f->stop;
31− while((r = *fmt++) && r != '%'){
32− FMTRUNE(f, t, f->stop, r);
33− }
34− f->nfmt += t - (char *)f->to;
35− f->to = t;
36− if(!r)
37− return f->nfmt - nfmt;
38− f->stop = s;
39− }
40−
41− fmt = __fmtdispatch(f, (Rune*)fmt, 1);
42− if(fmt == nil)
43− return -1;
44− }
45− return 0; /* not reached */
46−}
libc/encodefmt.c+0−78
@@ -1,78 +0,0 @@
1−#include <u.h>
2−#include <libc.h>
3−#include <ctype.h>
4−
5−int
6−encodefmt(Fmt *f)
7−{
8− char *out;
9− char *buf;
10− int len;
11− int ilen;
12− int rv;
13− uchar *b;
14− char *p;
15− char obuf[64]; // rsc optimization
16−
17− if(!(f->flags&FmtPrec) || f->prec < 1)
18− goto error;
19−
20− b = va_arg(f->args, uchar*);
21− if(b == 0)
22− return fmtstrcpy(f, "<nil>");
23−
24− ilen = f->prec;
25− f->prec = 0;
26− f->flags &= ~FmtPrec;
27− switch(f->r){
28− case '<':
29− len = (8*ilen+4)/5 + 3;
30− break;
31− case '[':
32− len = (8*ilen+5)/6 + 4;
33− break;
34− case 'H':
35− len = 2*ilen + 1;
36− break;
37− default:
38− goto error;
39− }
40−
41− if(len > sizeof(obuf)){
42− buf = malloc(len);
43− if(buf == nil)
44− goto error;
45− } else
46− buf = obuf;
47−
48− // convert
49− out = buf;
50− switch(f->r){
51− case '[':
52− rv = enc64(out, len, b, ilen);
53− break;
54− case '<':
55− rv = enc32(out, len, b, ilen);
56− break;
57− case 'H':
58− rv = enc16(out, len, b, ilen);
59− break;
60− default:
61− rv = -1;
62− break;
63− }
64− if(rv < 0)
65− goto error;
66−
67− if((f->flags & FmtLong) != 0 && f->r != '[')
68− for(p = buf; *p; p++)
69− *p = tolower(*p);
70−
71− fmtstrcpy(f, buf);
72− if(buf != obuf)
73− free(buf);
74− return 0;
75−
76−error:
77− return fmtstrcpy(f, "<encodefmt>");
78−}
libc/fmt.c+0−7
@@ -65,8 +65,6 @@ static Convfmt knownfmt[] = { · 64 unmodified lines
6565 };
6666
6767
68−int (*fmtdoquote)(int);
69−
7068 /*
7169 * __fmtlock() must be set
7270 */
@@ -102,9 +100,7 @@ fmtinstall(int c, int (*f)(Fmt*)) · 29 unmodified lines
102100 {
103101 int ret;
104102
105− __fmtlock();
106103 ret = __fmtinstall(c, f);
107− __fmtunlock();
108104 return ret;
109105 }
110106
@@ -122,14 +118,11 @@ fmtfmt(int c) · 11 unmodified lines
122118 }
123119
124120 /* is this a predefined format char? */
125− __fmtlock();
126121 for(p=knownfmt; p->c; p++)
127122 if(p->c == c){
128123 __fmtinstall(p->c, p->fmt);
129− __fmtunlock();
130124 return p->fmt;
131125 }
132− __fmtunlock();
133126
134127 return __badfmt;
135128 }
libc/fmtlock.c+0−16
@@ -1,16 +0,0 @@
1−#include <u.h>
2−#include <libc.h>
3−
4−static Lock fmtl;
5−
6−void
7−__fmtlock(void)
8−{
9− lock(&fmtl);
10−}
11−
12−void
13−__fmtunlock(void)
14−{
15− unlock(&fmtl);
16−}
libc/fmtquote.c+0−249
@@ -1,249 +0,0 @@
1−#include <u.h>
2−#include <libc.h>
3−#include "fmtdef.h"
4−
5−/*
6− * How many bytes of output UTF will be produced by quoting (if necessary) this string?
7− * How many runes? How much of the input will be consumed?
8− * The parameter q is filled in by __quotesetup.
9− * The string may be UTF or Runes (s or r).
10− * Return count does not include NUL.
11− * Terminate the scan at the first of:
12− * NUL in input
13− * count exceeded in input
14− * count exceeded on output
15− * *ninp is set to number of input bytes accepted.
16− * nin may be <0 initially, to avoid checking input by count.
17− */
18−void
19−__quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout)
20−{
21− int w;
22− Rune c;
23−
24− q->quoted = 0;
25− q->nbytesout = 0;
26− q->nrunesout = 0;
27− q->nbytesin = 0;
28− q->nrunesin = 0;
29− if(sharp || nin==0 || (s && *s=='\0') || (r && *r=='\0')){
30− if(nout < 2)
31− return;
32− q->quoted = 1;
33− q->nbytesout = 2;
34− q->nrunesout = 2;
35− }
36− for(; nin!=0; nin--){
37− if(s)
38− w = chartorune(&c, s);
39− else{
40− c = *r;
41− w = runelen(c);
42− }
43−
44− if(c == '\0')
45− break;
46− if(runesout){
47− if(q->nrunesout+1 > nout)
48− break;
49− }else{
50− if(q->nbytesout+w > nout)
51− break;
52− }
53−
54− if((c <= L' ') || (c == L'\'') || (fmtdoquote!=0 && fmtdoquote(c))){
55− if(!q->quoted){
56− if(runesout){
57− if(1+q->nrunesout+1+1 > nout) /* no room for quotes */
58− break;
59− }else{
60− if(1+q->nbytesout+w+1 > nout) /* no room for quotes */
61− break;
62− }
63− q->nrunesout += 2; /* include quotes */
64− q->nbytesout += 2; /* include quotes */
65− q->quoted = 1;
66− }
67− if(c == '\'') {
68− if(runesout){
69− if(1+q->nrunesout+1 > nout) /* no room for quotes */
70− break;
71− }else{
72− if(1+q->nbytesout+w > nout) /* no room for quotes */
73− break;
74− }
75− q->nbytesout++;
76− q->nrunesout++; /* quotes reproduce as two characters */
77− }
78− }
79−
80− /* advance input */
81− if(s)
82− s += w;
83− else
84− r++;
85− q->nbytesin += w;
86− q->nrunesin++;
87−
88− /* advance output */
89− q->nbytesout += w;
90− q->nrunesout++;
91− }
92−}
93−
94−static int
95−qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f)
96−{
97− Rune r, *rm, *rme;
98− char *t, *s, *m, *me;
99− Rune *rt, *rs;
100− ulong fl;
101− int nc, w;
102−
103− m = sin;
104− me = m + q->nbytesin;
105− rm = rin;
106− rme = rm + q->nrunesin;
107−
108− w = f->width;
109− fl = f->flags;
110− if(f->runes){
111− if(!(fl & FmtLeft) && __rfmtpad(f, w - q->nrunesout) < 0)
112− return -1;
113− }else{
114− if(!(fl & FmtLeft) && __fmtpad(f, w - q->nbytesout) < 0)
115− return -1;
116− }
117− t = (char*)f->to;
118− s = (char*)f->stop;
119− rt = (Rune*)f->to;
120− rs = (Rune*)f->stop;
121− if(f->runes)
122− FMTRCHAR(f, rt, rs, '\'');
123− else
124− FMTRUNE(f, t, s, '\'');
125− for(nc = q->nrunesin; nc > 0; nc--){
126− if(sin){
127− r = *(uchar*)m;
128− if(r < Runeself)
129− m++;
130− else if((me - m) >= UTFmax || fullrune(m, me-m))
131− m += chartorune(&r, m);
132− else
133− break;
134− }else{
135− if(rm >= rme)
136− break;
137− r = *(uchar*)rm++;
138− }
139− if(f->runes){
140− FMTRCHAR(f, rt, rs, r);
141− if(r == '\'')
142− FMTRCHAR(f, rt, rs, r);
143− }else{
144− FMTRUNE(f, t, s, r);
145− if(r == '\'')
146− FMTRUNE(f, t, s, r);
147− }
148− }
149−
150− if(f->runes){
151− FMTRCHAR(f, rt, rs, '\'');
152− USED(rs);
153− f->nfmt += rt - (Rune *)f->to;
154− f->to = rt;
155− if(fl & FmtLeft && __rfmtpad(f, w - q->nrunesout) < 0)
156− return -1;
157− }else{
158− FMTRUNE(f, t, s, '\'');
159− USED(s);
160− f->nfmt += t - (char *)f->to;
161− f->to = t;
162− if(fl & FmtLeft && __fmtpad(f, w - q->nbytesout) < 0)
163− return -1;
164− }
165− return 0;
166−}
167−
168−int
169−__quotestrfmt(int runesin, Fmt *f)
170−{
171− int nin, outlen;
172− Rune *r;
173− char *s;
174− Quoteinfo q;
175−
176− nin = -1;
177− if(f->flags&FmtPrec)
178− nin = f->prec;
179− if(runesin){
180− r = va_arg(f->args, Rune *);
181− s = nil;
182− }else{
183− s = va_arg(f->args, char *);
184− r = nil;
185− }
186− if(!s && !r)
187− return __fmtcpy(f, (void*)"<nil>", 5, 5);
188−
189− if(f->flush)
190− outlen = 0x7FFFFFFF; /* if we can flush, no output limit */
191− else if(f->runes)
192− outlen = (Rune*)f->stop - (Rune*)f->to;
193− else
194− outlen = (char*)f->stop - (char*)f->to;
195−
196− __quotesetup(s, r, nin, outlen, &q, f->flags&FmtSharp, f->runes);
197−//print("bytes in %d bytes out %d runes in %d runesout %d\n", q.nbytesin, q.nbytesout, q.nrunesin, q.nrunesout);
198−
199− if(runesin){
200− if(!q.quoted)
201− return __fmtrcpy(f, r, q.nrunesin);
202− return qstrfmt(nil, r, &q, f);
203− }
204−
205− if(!q.quoted)
206− return __fmtcpy(f, s, q.nrunesin, q.nbytesin);
207− return qstrfmt(s, nil, &q, f);
208−}
209−
210−int
211−quotestrfmt(Fmt *f)
212−{
213− return __quotestrfmt(0, f);
214−}
215−
216−int
217−quoterunestrfmt(Fmt *f)
218−{
219− return __quotestrfmt(1, f);
220−}
221−
222−void
223−quotefmtinstall(void)
224−{
225− fmtinstall('q', quotestrfmt);
226− fmtinstall('Q', quoterunestrfmt);
227−}
228−
229−int
230−__needsquotes(char *s, int *quotelenp)
231−{
232− Quoteinfo q;
233−
234− __quotesetup(s, nil, -1, 0x7FFFFFFF, &q, 0, 0);
235− *quotelenp = q.nbytesout;
236−
237− return q.quoted;
238−}
239−
240−int
241−__runeneedsquotes(Rune *r, int *quotelenp)
242−{
243− Quoteinfo q;
244−
245− __quotesetup(nil, r, -1, 0x7FFFFFFF, &q, 0, 0);
246− *quotelenp = q.nrunesout;
247−
248− return q.quoted;
249−}
libc/fmtstr.c+0−12
@@ -1,12 +0,0 @@
1−#include <u.h>
2−#include <libc.h>
3−#include "fmtdef.h"
4−
5−char*
6−fmtstrflush(Fmt *f)
7−{
8− if(f->start == nil)
9− return nil;
10− *(char*)f->to = '\0';
11− return (char*)f->start;
12−}
libc/nan64.c+0−12
@@ -38,18 +38,6 @@ __isNaN(double d) · 37 unmodified lines
3838 return (ulong)(x>>32)==0x7FF00000 && !__isInf(d, 0);
3939 }
4040
41−double
42−__Inf(int sign)
43−{
44− uvlong *p;
45−
46− if(sign < 0)
47− p = &uvinf;
48− else
49− p = &uvneginf;
50− return *(double*)p;
51−}
52−
5341 int
5442 __isInf(double d, int sign)
5543 {
libc/rune.c+0−22
@@ -163,28 +163,6 @@ runelen(long c) · 162 unmodified lines
163163 return runetochar(str, &rune);
164164 }
165165
166−int
167−runenlen(Rune *r, int nrune)
168−{
169− int nb, c;
170−
171− nb = 0;
172− while(nrune--) {
173− c = *r++;
174− if(c <= Rune1)
175− nb++;
176− else
177− if(c <= Rune2)
178− nb += 2;
179− else
180− if(c <= Rune3 || c > Runemax)
181− nb += 3;
182− else
183− nb += 4;
184− }
185− return nb;
186−}
187−
188166 int
189167 fullrune(char *str, int n)
190168 {
libc/snprint.c+0−16
@@ -1,16 +0,0 @@
1−#include <u.h>
2−#include <libc.h>
3−#include "fmtdef.h"
4−
5−int
6−snprint(char *buf, int len, char *fmt, ...)
7−{
8− int n;
9− va_list args;
10−
11− va_start(args, fmt);
12− n = vsnprint(buf, len, fmt, args);
13− va_end(args);
14− return n;
15−}
16−
libc/u16.c+0−44
@@ -23,47 +23,3 @@ dec16chr(int c) · 22 unmodified lines
2323 o |= between(c, 'a', 'f') & (1+10+(c-'a'));
2424 return o-1;
2525 }
26−
27−int
28−dec16(uchar *out, int lim, char *in, int n)
29−{
30− int c, w = 0, i = 0;
31− uchar *start = out;
32− uchar *eout = out + lim;
33−
34− while(n-- > 0){
35− c = dec16chr(*in++);
36− if(c < 0)
37− continue;
38− w = (w<<4) + c;
39− i++;
40− if(i == 2){
41− if(out + 1 > eout)
42− goto exhausted;
43− *out++ = w;
44− w = 0;
45− i = 0;
46− }
47− }
48−exhausted:
49− return out - start;
50−}
51−
52−int
53−enc16(char *out, int lim, uchar *in, int n)
54−{
55− uint c;
56− char *eout = out + lim;
57− char *start = out;
58−
59− while(n-- > 0){
60− c = *in++;
61− if(out + 2 >= eout)
62− goto exhausted;
63− *out++ = enc16chr(c>>4);
64− *out++ = enc16chr(c&15);
65− }
66−exhausted:
67− *out = 0;
68− return out - start;
69−}
libmp/cnfield.c+0−114
@@ -1,114 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−/*
6− * fast reduction for crandall numbers of the form: 2^n - c
7− */
8−
9−enum {
10− MAXDIG = 1024 / Dbits,
11−};
12−
13−typedef struct CNfield CNfield;
14−struct CNfield
15−{
16− Mfield f;
17−
18− mpint m[1];
19−
20− int s;
21− mpdigit c;
22−};
23−
24−static int
25−cnreduce(Mfield *m, mpint *a, mpint *r)
26−{
27− mpdigit q[MAXDIG-1], t[MAXDIG], d;
28− CNfield *f = (CNfield*)m;
29− int qn, tn, k;
30−
31− k = f->f.m.top;
32− if((a->top - k) >= MAXDIG)
33− return -1;
34−
35− mpleft(a, f->s, r);
36− if(r->top <= k)
37− mpbits(r, (k+1)*Dbits);
38−
39− /* q = hi(r) */
40− qn = r->top - k;
41− memmove(q, r->p+k, qn*Dbytes);
42−
43− /* r = lo(r) */
44− r->top = k;
45− r->sign = 1;
46−
47− do {
48− /* t = q*c */
49− tn = qn+1;
50− memset(t, 0, tn*Dbytes);
51− mpvecdigmuladd(q, qn, f->c, t);
52−
53− /* q = hi(t) */
54− qn = tn - k;
55− if(qn <= 0) qn = 0;
56− else memmove(q, t+k, qn*Dbytes);
57−
58− /* r += lo(t) */
59− if(tn > k)
60− tn = k;
61− mpvecadd(r->p, k, t, tn, r->p);
62−
63− /* if(r >= m) r -= m */
64− mpvecsub(r->p, k+1, f->m->p, k, t);
65− d = t[k];
66− for(tn = 0; tn < k; tn++)
67− r->p[tn] = (r->p[tn] & d) | (t[tn] & ~d);
68− } while(qn > 0);
69−
70− if(f->s != 0)
71− mpright(r, f->s, r);
72− mpnorm(r);
73−
74− return 0;
75−}
76−
77−Mfield*
78−cnfield(mpint *N)
79−{
80− mpint *M, *C;
81− CNfield *f;
82− mpdigit d;
83− int s;
84−
85− if(N->top <= 2 || N->top >= MAXDIG)
86− return nil;
87− f = nil;
88− d = N->p[N->top-1];
89− for(s = 0; (d & (mpdigit)1<<Dbits-1) == 0; s++)
90− d <<= 1;
91− C = mpnew(0);
92− M = mpcopy(N);
93− mpleft(N, s, M);
94− mpleft(mpone, M->top*Dbits, C);
95− mpsub(C, M, C);
96− if(C->top != 1)
97− goto out;
98− f = mallocz(sizeof(CNfield) + M->top*sizeof(mpdigit), 1);
99− if(f == nil)
100− goto out;
101− f->s = s;
102− f->c = C->p[0];
103− f->m->size = M->top;
104− f->m->p = (mpdigit*)&f[1];
105− mpassign(M, f->m);
106− mpassign(N, (mpint*)f);
107− f->f.reduce = cnreduce;
108− f->f.m.flags |= MPfield;
109−out:
110− mpfree(M);
111− mpfree(C);
112−
113− return (Mfield*)f;
114−}
libmp/gmfield.c+0−173
@@ -1,173 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−/*
6− * fast reduction for generalized mersenne numbers (GM)
7− * using a series of additions and subtractions.
8− */
9−
10−enum {
11− MAXDIG = 1024/Dbits,
12−};
13−
14−typedef struct GMfield GMfield;
15−struct GMfield
16−{
17− Mfield f;
18−
19− mpint m2[1];
20−
21− int nadd;
22− int nsub;
23− int indx[256];
24−};
25−
26−static int
27−gmreduce(Mfield *m, mpint *a, mpint *r)
28−{
29− GMfield *g = (GMfield*)m;
30− mpdigit d0, t[MAXDIG];
31− int i, j, d, *x;
32−
33− if(mpmagcmp(a, g->m2) >= 0)
34− return -1;
35−
36− if(a != r)
37− mpassign(a, r);
38−
39− d = g->f.m.top;
40− mpbits(r, (d+1)*Dbits*2);
41− memmove(t+d, r->p+d, d*Dbytes);
42−
43− r->sign = 1;
44− r->top = d;
45− r->p[d] = 0;
46−
47− if(g->nsub > 0)
48− mpvecdigmuladd(g->f.m.p, d, g->nsub, r->p);
49−
50− x = g->indx;
51− for(i=0; i<g->nadd; i++){
52− t[0] = 0;
53− d0 = t[*x++];
54− for(j=1; j<d; j++)
55− t[j] = t[*x++];
56− t[0] = d0;
57−
58− mpvecadd(r->p, d+1, t, d, r->p);
59− }
60−
61− for(i=0; i<g->nsub; i++){
62− t[0] = 0;
63− d0 = t[*x++];
64− for(j=1; j<d; j++)
65− t[j] = t[*x++];
66− t[0] = d0;
67−
68− mpvecsub(r->p, d+1, t, d, r->p);
69− }
70−
71− mpvecdigmulsub(g->f.m.p, d, r->p[d], r->p);
72− r->p[d] = 0;
73−
74− mpvecsub(r->p, d+1, g->f.m.p, d, r->p+d+1);
75− d0 = r->p[2*d+1];
76− for(j=0; j<d; j++)
77− r->p[j] = (r->p[j] & d0) | (r->p[j+d+1] & ~d0);
78−
79− mpnorm(r);
80−
81− return 0;
82−}
83−
84−Mfield*
85−gmfield(mpint *N)
86−{
87− int i,j,d, s, *C, *X, *x, *e;
88− mpint *M, *T;
89− GMfield *g;
90−
91− d = N->top;
92− if(d <= 2 || d > MAXDIG/2 || (mpsignif(N) % Dbits) != 0)
93− return nil;
94− g = nil;
95− T = mpnew(0);
96− M = mpcopy(N);
97− C = malloc(sizeof(int)*(d+1));
98− X = malloc(sizeof(int)*(d*d));
99− if(C == nil || X == nil)
100− goto out;
101−
102− for(i=0; i<=d; i++){
103− if((M->p[i]>>8) != 0 && (~M->p[i]>>8) != 0)
104− goto out;
105− j = M->p[i];
106− C[d - i] = -j;
107− itomp(j, T);
108− mpleft(T, i*Dbits, T);
109− mpsub(M, T, M);
110− }
111− for(j=0; j<d; j++)
112− X[j] = C[d-j];
113− for(i=1; i<d; i++){
114− X[d*i] = X[d*(i-1) + d-1]*C[d];
115− for(j=1; j<d; j++)
116− X[d*i + j] = X[d*(i-1) + j-1] + X[d*(i-1) + d-1]*C[d-j];
117− }
118− g = mallocz(sizeof(GMfield) + (d+1)*sizeof(mpdigit)*2, 1);
119− if(g == nil)
120− goto out;
121−
122− g->m2->p = (mpdigit*)&g[1];
123− g->m2->size = d*2+1;
124− mpmul(N, N, g->m2);
125− mpassign(N, (mpint*)g);
126− g->f.reduce = gmreduce;
127− g->f.m.flags |= MPfield;
128−
129− s = 0;
130− x = g->indx;
131− e = x + nelem(g->indx) - d;
132− for(g->nadd=0; x <= e; x += d, g->nadd++){
133− s = 0;
134− for(i=0; i<d; i++){
135− for(j=0; j<d; j++){
136− if(X[d*i+j] > 0 && x[j] == 0){
137− X[d*i+j]--;
138− x[j] = d+i;
139− s = 1;
140− break;
141− }
142− }
143− }
144− if(s == 0)
145− break;
146− }
147− for(g->nsub=0; x <= e; x += d, g->nsub++){
148− s = 0;
149− for(i=0; i<d; i++){
150− for(j=0; j<d; j++){
151− if(X[d*i+j] < 0 && x[j] == 0){
152− X[d*i+j]++;
153− x[j] = d+i;
154− s = 1;
155− break;
156− }
157− }
158− }
159− if(s == 0)
160− break;
161− }
162− if(s != 0){
163− mpfree((mpint*)g);
164− g = nil;
165− }
166−out:
167− free(C);
168− free(X);
169− mpfree(M);
170− mpfree(T);
171− return (Mfield*)g;
172−}
173−
libmp/letomp.c+0−31
@@ -1,31 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−// convert a little endian byte array (least significant byte first) to an mpint
6−mpint*
7−letomp(uchar *s, uint n, mpint *b)
8−{
9− int i=0, m = 0;
10− mpdigit x=0;
11−
12− if(b == nil){
13− b = mpnew(0);
14− setmalloctag(b, getcallerpc(&s));
15− }
16− mpbits(b, 8*n);
17− for(; n > 0; n--){
18− x |= ((mpdigit)(*s++)) << i;
19− i += 8;
20− if(i == Dbits){
21− b->p[m++] = x;
22− i = 0;
23− x = 0;
24− }
25− }
26− if(i > 0)
27− b->p[m++] = x;
28− b->top = m;
29− b->sign = 1;
30− return mpnorm(b);
31−}
libmp/mpaux.c+0−40
@@ -31,17 +31,6 @@ mpint *mpzero = &_mpzero; · 30 unmodified lines
3131
3232 static int mpmindigits = 33;
3333
34−// set minimum digit allocation
35−void
36−mpsetminbits(int n)
37−{
38− if(n < 0)
39− sysfatal("mpsetminbits: n < 0");
40− if(n == 0)
41− n = 1;
42− mpmindigits = DIGITS(n);
43−}
44−
4534 // allocate an n bit 0'd number
4635 mpint*
4736 mpnew(int n)
@@ -174,32 +163,3 @@ mpsignif(mpint *n) · 126 unmodified lines
174163 }
175164 return 0;
176165 }
177−
178−// k, where n = 2**k * q for odd q
179−int
180−mplowbits0(mpint *n)
181−{
182− int k, bit, digit;
183− mpdigit d;
184−
185− assert(n->flags & MPnorm);
186− if(n->top==0)
187− return 0;
188− k = 0;
189− bit = 0;
190− digit = 0;
191− d = n->p[0];
192− for(;;){
193− if(d & (1<<bit))
194− break;
195− k++;
196− bit++;
197− if(bit==Dbits){
198− if(++digit >= n->top)
199− return 0;
200− d = n->p[digit];
201− bit = 0;
202− }
203− }
204− return k;
205−}
libmp/mpfield.c+0−21
@@ -1,21 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−mpint*
6−mpfield(mpint *N)
7−{
8− Mfield *f;
9−
10− if(N == nil || N->flags & (MPfield|MPstatic))
11− return N;
12− if((f = cnfield(N)) != nil)
13− goto Exchange;
14− if((f = gmfield(N)) != nil)
15− goto Exchange;
16− return N;
17−Exchange:
18− setmalloctag(f, getcallerpc(&N));
19− mpfree(N);
20− return (mpint*)f;
21−}
libmp/mpinvert.c+0−17
@@ -1,17 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−
4−// use extended gcd to find the multiplicative inverse
5−// res = b**-1 mod m
6−void
7−mpinvert(mpint *b, mpint *m, mpint *res)
8−{
9− mpint *v;
10−
11− v = mpnew(0);
12− mpextendedgcd(b, m, v, res, nil);
13− if(mpcmp(v, mpone) != 0)
14− abort();
15− mpfree(v);
16− mpmod(res, m, res);
17−}
libmp/mplogic.c+0−6
@@ -77,12 +77,6 @@ mpand(mpint *b1, mpint *b2, mpint *sum) · 76 unmodified lines
7777 mplogic(b1, b2, sum, 0x2a);
7878 }
7979
80−void
81−mpbic(mpint *b1, mpint *b2, mpint *sum)
82−{
83− mplogic(b1, b2, sum, 0x22);
84−}
85−
8680 void
8781 mpnot(mpint *b, mpint *r)
8882 {
libmp/mpmodop.c+0−61
@@ -16,67 +16,6 @@ modarg(mpint *a, mpint *m) · 15 unmodified lines
1616 return a;
1717 }
1818
19−void
20−mpmodadd(mpint *b1, mpint *b2, mpint *m, mpint *sum)
21−{
22− mpint *a, *b;
23− mpdigit d;
24− int i, j;
25−
26− a = modarg(b1, m);
27− b = modarg(b2, m);
28−
29− sum->flags |= (a->flags | b->flags) & MPtimesafe;
30− mpbits(sum, Dbits*2*(m->top+1));
31−
32− mpvecadd(a->p, m->top, b->p, m->top, sum->p);
33− mpvecsub(sum->p, m->top+1, m->p, m->top, sum->p+m->top+1);
34−
35− d = sum->p[2*m->top+1];
36− for(i = 0, j = m->top+1; i < m->top; i++, j++)
37− sum->p[i] = (sum->p[i] & d) | (sum->p[j] & ~d);
38−
39− sum->top = m->top;
40− sum->sign = 1;
41− mpnorm(sum);
42−
43− if(a != b1)
44− mpfree(a);
45− if(b != b2)
46− mpfree(b);
47−}
48−
49−void
50−mpmodsub(mpint *b1, mpint *b2, mpint *m, mpint *diff)
51−{
52− mpint *a, *b;
53− mpdigit d;
54− int i, j;
55−
56− a = modarg(b1, m);
57− b = modarg(b2, m);
58−
59− diff->flags |= (a->flags | b->flags) & MPtimesafe;
60− mpbits(diff, Dbits*2*(m->top+1));
61−
62− a->p[m->top] = 0;
63− mpvecsub(a->p, m->top+1, b->p, m->top, diff->p);
64− mpvecadd(diff->p, m->top, m->p, m->top, diff->p+m->top+1);
65−
66− d = ~diff->p[m->top];
67− for(i = 0, j = m->top+1; i < m->top; i++, j++)
68− diff->p[i] = (diff->p[i] & d) | (diff->p[j] & ~d);
69−
70− diff->top = m->top;
71− diff->sign = 1;
72− mpnorm(diff);
73−
74− if(a != b1)
75− mpfree(a);
76− if(b != b2)
77− mpfree(b);
78−}
79−
8019 void
8120 mpmodmul(mpint *b1, mpint *b2, mpint *m, mpint *prod)
8221 {
libmp/mpsel.c+0−42
@@ -1,42 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−// res = s != 0 ? b1 : b2
6−void
7−mpsel(int s, mpint *b1, mpint *b2, mpint *res)
8−{
9− mpdigit d;
10− int n, m, i;
11−
12− res->flags |= (b1->flags | b2->flags) & MPtimesafe;
13− if((res->flags & MPtimesafe) == 0){
14− mpassign(s ? b1 : b2, res);
15− return;
16− }
17− res->flags &= ~MPnorm;
18−
19− n = b1->top;
20− m = b2->top;
21− mpbits(res, Dbits*(n >= m ? n : m));
22− res->top = n >= m ? n : m;
23−
24− s = (-s^s|s)>>(sizeof(s)*8-1);
25− res->sign = (b1->sign & s) | (b2->sign & ~s);
26−
27− d = -((mpdigit)s & 1);
28−
29− i = 0;
30− while(i < n && i < m){
31− res->p[i] = (b1->p[i] & d) | (b2->p[i] & ~d);
32− i++;
33− }
34− while(i < n){
35− res->p[i] = b1->p[i] & d;
36− i++;
37− }
38− while(i < m){
39− res->p[i] = b2->p[i] & ~d;
40− i++;
41− }
42−}
libmp/mptole.c+0−28
@@ -1,28 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−// convert an mpint into a little endian byte array (least significant byte first)
6−// return number of bytes converted
7−// if p == nil, allocate and result array
8−int
9−mptole(mpint *b, uchar *p, uint n, uchar **pp)
10−{
11− int m;
12−
13− m = (mpsignif(b)+7)/8;
14− if(m == 0)
15− m++;
16− if(p == nil){
17− n = m;
18− p = malloc(n);
19− if(p == nil)
20− sysfatal("mptole: %r");
21− setmalloctag(p, getcallerpc(&b));
22− } else if(n < m)
23− return -1;
24− if(pp != nil)
25− *pp = p;
26− mptolel(b, p, n);
27− return m;
28−}
libmp/mptolel.c+0−33
@@ -1,33 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−void
6−mptolel(mpint *b, uchar *p, int n)
7−{
8− int i, j, m;
9− mpdigit x;
10−
11− memset(p, 0, n);
12−
13− m = b->top*Dbytes;
14− if(m < n)
15− n = m;
16−
17− i = 0;
18− while(n >= Dbytes){
19− n -= Dbytes;
20− x = b->p[i++];
21− for(j = 0; j < Dbytes; j++){
22− *p++ = x;
23− x >>= 8;
24− }
25− }
26− if(n > 0){
27− x = b->p[i];
28− for(j = 0; j < n; j++){
29− *p++ = x;
30− x >>= 8;
31− }
32− }
33−}
libmp/mptoui.c+0−13
@@ -19,16 +19,3 @@ uitomp(uint i, mpint *b) · 18 unmodified lines
1919 b->sign = 1;
2020 return mpnorm(b);
2121 }
22−
23−uint
24−mptoui(mpint *b)
25−{
26− uint x;
27−
28− x = *b->p;
29− if(b->sign < 0)
30− x = 0;
31− else if(b->top > 1 || (sizeof(mpdigit) > sizeof(uint) && x > MAXUINT))
32− x = MAXUINT;
33− return x;
34−}
libmp/mptouv.c+0−47
@@ -1,47 +0,0 @@
1−#include "os.h"
2−#include <mp.h>
3−#include "dat.h"
4−
5−#define VLDIGITS (sizeof(vlong)/sizeof(mpdigit))
6−
7−/*
8− * this code assumes that a vlong is an integral number of
9− * mpdigits long.
10− */
11−mpint*
12−uvtomp(uvlong v, mpint *b)
13−{
14− int s;
15−
16− if(b == nil){
17− b = mpnew(VLDIGITS*Dbits);
18− setmalloctag(b, getcallerpc(&v));
19− }else
20− mpbits(b, VLDIGITS*Dbits);
21− b->sign = 1;
22− for(s = 0; s < VLDIGITS; s++){
23− b->p[s] = v;
24− v >>= sizeof(mpdigit)*8;
25− }
26− b->top = s;
27− return mpnorm(b);
28−}
29−
30−uvlong
31−mptouv(mpint *b)
32−{
33− uvlong v;
34− int s;
35−
36− if(b->top == 0 || b->sign < 0)
37− return 0LL;
38−
39− if(b->top > VLDIGITS)
40− return -1LL;
41−
42− v = 0ULL;
43− for(s = 0; s < b->top; s++)
44− v |= (uvlong)b->p[s]<<(s*sizeof(mpdigit)*8);
45−
46− return v;
47−}
libmp/mptov.c+0−33
@@ -28,36 +28,3 @@ vtomp(vlong v, mpint *b) · 27 unmodified lines
2828 b->top = s;
2929 return mpnorm(b);
3030 }
31−
32−vlong
33−mptov(mpint *b)
34−{
35− uvlong v;
36− int s;
37−
38− if(b->top == 0)
39− return 0LL;
40−
41− if(b->top > VLDIGITS){
42− if(b->sign > 0)
43− return (vlong)MAXVLONG;
44− else
45− return (vlong)MINVLONG;
46− }
47−
48− v = 0ULL;
49− for(s = 0; s < b->top; s++)
50− v |= (uvlong)b->p[s]<<(s*sizeof(mpdigit)*8);
51−
52− if(b->sign > 0){
53− if(v > MAXVLONG)
54− v = MAXVLONG;
55− } else {
56− if(v > MINVLONG)
57− v = MINVLONG;
58− else
59− v = -(vlong)v;
60− }
61−
62− return (vlong)v;
63−}
libmp/reduce+0−16
@@ -1,16 +0,0 @@
1−O=$1
2−shift
3−objtype=$1
4−shift
5−
6−ls -p ../$objtype/*.[cs] >[2]/dev/null | sed 's/..$//' > /tmp/reduce.$pid
7−#
8−# if empty directory, just return the input files
9−#
10−if (! ~ $status '|') {
11− echo $*
12− rm /tmp/reduce.$pid
13− exit 0
14−}
15−echo $* | tr ' ' \012 | grep -v -f /tmp/reduce.$pid | tr \012 ' '
16−rm /tmp/reduce.$pid

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t