Skip to content

Commit c1218e1

Browse files
committed
jtintersect only for 64-bit, & support cct
1 parent e97536d commit c1218e1

5 files changed

Lines changed: 24 additions & 7 deletions

File tree

jsrc/cf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ A jtfolk(J jtfg,A f,A g,A h){F12IP;A p,q,x,y;AF f1=0,f2=0;B b;C c,fi,gi,hi;I fla
191191
f2=fork2tbl[fline][hcol]; f2=(I)jtfg&JTFOLKNOHFN?jtfolk2:f2; // NOHFN means the caller is going to fool with the result fork, so the EP is unreliable
192192
}else{hcol=-1;} // select the value we will put into localuse: hcol=-1 means cct, other hcol=routine address of h or h@]
193193

194-
fdeffillall(z,flag2,CFORK,VERB, f1,f2, f,g,h, flag, RMAX,RMAX,RMAX,fffv->localuse.lu0.cachedloc=0,if(hcol<0)FAV(z)->localuse.lu1.cct=cct;else FAV(z)->localuse.lu1.fork2hfn=hcol<=2?hv->valencefns[1]:FAV(hv->fgh[0])->valencefns[0]);
194+
fdeffillall(z,flag2,CFORK,VERB, f1,f2, f,g,h, flag, RMAX,RMAX,RMAX,fffv->localuse.lu0.cct=cct,if(hcol<0)FAV(z)->localuse.lu1.cct=cct;else FAV(z)->localuse.lu1.fork2hfn=hcol<=2?hv->valencefns[1]:FAV(hv->fgh[0])->valencefns[0]);
195195
// set localuse: for intersect or comparison combination, cct; for echt fork, the h routine to call
196196
R z;
197197
}

jsrc/cp.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ DF2(jtpowop){F12IP;B b;V*v;
319319
A z; fdefallo(z) // allocate normal result area
320320
AF f1,f2; I flag; // derived-verb handlers; flags for the verb we build
321321
A h; // A block for the power list converted to integer (initially, remaining for jtply12 only); u^:_1 (for jtinv[12]); 0 for others
322-
I encn; // the encoded form of the integer power to be passed to pow12n
322+
I encn; D cct=0.0; // the encoded form of the integer power to be passed to pow12n; cct for setintersect (default to none)
323323
if(AT(w)&VERB){
324324
// u^:v. Create derived verb to handle it. The action routines are inplaceable; take NOLOCCHG from u and v, inplaceability from u
325325
f1=f2=jtpowv12cell; h=0; flag=(FAV(a)->flag&FAV(w)->flag&VNOLOCCHG+VNONAME+VNOSELF);
@@ -368,13 +368,23 @@ DF2(jtpowop){F12IP;B b;V*v;
368368
f2=jtinv2; f1=jtinv1; if(nameless(a)){WITHMSGSOFF(if(h=inv(a)){f1=jtinvh1;flag=FAV(h)->flag&VNOLOCCHG+VNONAME+VNOSELF;}else{f1=jtinverr;})} // h must be valid A block for free. If no names in w, take the inverse. If it doesn't exist, fail the monad but keep the dyad going
369369
}else flag=FAV(a)->flag&VNONAME+VNOSELF; // if u^:_, never allow inplace assignment since we are converging
370370
// Note: negative powers other than _1 are resolved in the action routine
371-
}else if(n==2&&a==ds(CLESS)){f2=jtintersect;} // -.^:2, set intersection, which allows inplacing
371+
}
372+
#if C_CRC32C && SY_64 && (C_AVX2 || EMU_AVX2)
373+
else if(unlikely(n==2)){
374+
I aid=FAV(a)->id; if(unlikely(aid==CFIT)){cct=FAV(a)->localuse.lu1.cct; aid=FAV(FAV(a)->fgh[0])->id;}
375+
if(aid==CLESS){ // -.^:2 and -.!.f^:2
376+
f2=jtintersect; // treat the compound as a primitive of its own
377+
flag|=(7+(((IINTER-II0EPS)&0xf)<<3)); // flag it like -.
378+
// if tolerance given on second -., it is now in cct
379+
}
380+
}
381+
#endif
372382
encn=(ABS(n)<<POWERABSX)+(n<0?POWERANEG:0); encn=n==IMIN?((I)-1*POWERABS)+POWERADOWHILE:encn; // save the power, in flagged form, for powatom12
373383
}else{f1=f2=jtply12; flag=FAV(a)->flag&VNONAME+VNOSELF;} // non-atomic power: handle general case, which does not support inplacing (since it might converge)
374384
// fall through to create result
375385
} // end of 'u^:numeric'
376386
} // end of 'u^:n'
377387
fdeffill(z,0,CPOWOP,VERB, f1,f2, a,w,h,flag, RMAX,RMAX,RMAX); // Create derived verb: pass in integer powers or inverse as h
378-
FAV(z)->localuse.lu1.poweratom=encn; // pass power info for powatom12, garbage for others
388+
FAV(z)->localuse.lu1.poweratom=encn; FAV(z)->localuse.lu0.cct=cct; // pass power info for powatom12, garbage for others
379389
RETF(z);
380390
}

jsrc/jtype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ typedef struct{
11471147
I n; /* maximum number of records */
11481148
I i; /* index of next record to be written */
11491149
I s; /* initial bytesmax value */
1150-
I pmlvl; // sampling level, set > 0 to start sampling
1150+
I pmlvl; // counter, set > 0 to start sampling
11511151
B rec; /* what to record (0 entry & exit; 1 all) */
11521152
B trunc; /* what to do on overflow (0 wrap; 1 truncate) */
11531153
B wrapped; /* 1 iff wrapping has happened */
@@ -1199,6 +1199,7 @@ typedef struct {
11991199
A cachedloc; // for namerefs ('name'~), the locale address if the name is a direct named lookup (after the first reference)
12001200
A gerundself; // in gerund iterators, the address of the self block for m@.v, for diagnostic purposes
12011201
AF modatomfn; // in u m. n, the verb to process atoms of u
1202+
D cct; // cct if given for setintersect -.^:2 [-.-. [e.#
12021203
} lu0;
12031204
// end of first cacheline, which is not used much during execution
12041205
// the rest do not require both cachelines in 64-bit

jsrc/viavx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ F2(jtless){F12IP;A x=w;I ar,at,k,r,*s,wr,*ws;
12681268
EPILOG(x);
12691269
} /* a-.w */
12701270

1271+
#if C_CRC32C && SY_64 && (C_AVX2 || EMU_AVX2)
12711272
// x ([ -. -.[!.f]) y. does not have IRS, supports inplacing on a (the unhashed argument)
12721273
DF2(jtintersect){F12IP;A x=w;I ar,at,k,r,*s,wr,*ws;
12731274
ARGCHK2(a,w);
@@ -1277,14 +1278,14 @@ DF2(jtintersect){F12IP;A x=w;I ar,at,k,r,*s,wr,*ws;
12771278
if(unlikely(ar>1+wr))R take(zeroionei(0),a); // if w's rank is smaller than that of a cell of a, nothing can be common, return no items
12781279
if(unlikely(MIN(ai,wi)==0))R take(zeroionei(0),a); // if either arg is empty, nothing can be common, return no items
12791280
jtfg=MOVEIP0A(jtfg); // only our a argument can be inplaced, and it moves to y in all uses
1280-
PUSHCCTIF(FAV(self)->localuse.lu1.cct,FAV(self)->localuse.lu1.cct!=0) // if there is a CT, use it *** no errors till cct restored ***
1281+
PUSHCCTIF(FAV(self)->localuse.lu0.cct,FAV(self)->localuse.lu0.cct!=0) // if there is a CT, use it *** no errors till cct restored ***
12811282
if(unlikely(ar==wr+1)){ // is just 1 cell of y, with x a list of such cells?
12821283
if(wr==0)x=eq(a,w); else IRS2(a,w,0,wr,wr,jtmatch,x); RZGOTO(x,errexit) x=jtrepeat(jtfg,x,a); // y has rank 1 less than x, execute as ((x = y) # x) (y atomic) or ((x -:"yr) # x) if (y array). Inplace x on the #. Use IRS and leave comparison tolerance as set
12831284
}else{
12841285
// if w's rank is larger than that of a cell of a, reheader w to look like a list of such cells
12851286
if(unlikely((-wr&-(r^wr))<0)){RZGOTO(x=virtual(w,0,r),errexit); AN(x)=wn; s=AS(x); ws=AS(w); k=ar>wr?0:1+wr-r; I s0; PRODX(s0,k,ws,1) s[0]=s0; MCISH(1+s,k+ws,r-1);} // use fauxvirtual here
12861287
// comparison tolerance may be encoded in h - apply it if so
1287-
D savcct = jt->cct;
1288+
// obsolete D savcct = jt->cct;
12881289
// if nothing special (like sparse, or incompatible types, or x requires conversion) do the fast way; otherwise (x e. y) # x
12891290
// because LESS allocates a large array to hold all the values, we use the slower, less memory-intensive, version if a is mapped
12901291
// Don't revert to fork! localuse.lu1.fork2hfn is not set
@@ -1296,6 +1297,7 @@ errexit:;
12961297
if(unlikely(at&BOX)){jtfg=MOVEIPA0(jtfg); PRISTXFERAF(x,a)} // the boxes in w cannot get to the result, even though their values participate; so pristinity depends entirely on original a
12971298
EPILOG(x);
12981299
}
1300+
#endif
12991301

13001302
// x e. y
13011303
F2(jteps){F12IP;I l,r;

test/g121.ijs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ s f&>/ t
452452
NB. comparison tolerance
453453
10 = # (1 + 1e_15 * i. 10) ([ -. -.) 1
454454
1 = # (1 + 1e_15 * i. 10) ([ -.!.0 -.!.0) 1
455+
10 = # (1 + 1e_15 * i. 10) (e. # [) 1
456+
1 = # (1 + 1e_15 * i. 10) (e.!.0 # [) 1
457+
10 = # (1 + 1e_15 * i. 10) (-.^:2) 1
458+
1 = # (1 + 1e_15 * i. 10) (-.!.0^:2) 1
455459

456460
NB. Verify -.!.0 in the middle is treated like -.
457461
yy =: 1e6 $ 1. 2.

0 commit comments

Comments
 (0)