Skip to content

Commit 214b56a

Browse files
committed
Reinstate INLINE
1 parent 8ed4e81 commit 214b56a

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

jsrc/xdic.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/* Dictionary support */
55

66
#include "j.h"
7-
#define scafINLINE
87
// Dictionary support
98
#ifndef CRC32
109
#define HASH4(crc,x) ((UI4)(crc)*0x85249421+(UI4)(x))
@@ -24,7 +23,7 @@
2423
#endif
2524

2625
// CRC32 of n floats.
27-
static scafINLINE UI4 crcfloats(UI8 *v, I n){
26+
static INLINE UI4 crcfloats(UI8 *v, I n){
2827
// Do 3 CRCs in parallel because the latency of the CRC instruction is 3 clocks.
2928
// This is executed repeatedly so we expect all the branches to predict correctly
3029
UI4 crc0=-1; // convert bytecount to words
@@ -36,7 +35,7 @@ static scafINLINE UI4 crcfloats(UI8 *v, I n){
3635
}
3736

3837
// CRC32 of n Is
39-
static scafINLINE UI4 crcwords(UI *v, I n){
38+
static INLINE UI4 crcwords(UI *v, I n){
4039
// Do 3 CRCs in parallel because the latency of the CRC instruction is 3 clocks.
4140
// This is executed repeatedly so we expect all the branches to predict correctly
4241
UI4 crc0=-1; // convert bytecount to words
@@ -48,18 +47,18 @@ static scafINLINE UI4 crcwords(UI *v, I n){
4847
}
4948

5049
// CRC32 of n bytes
51-
static scafINLINE UI4 crcbytes(C *v, I n){
50+
static INLINE UI4 crcbytes(C *v, I n){
5251
UI4 wdcrc=n&-SZI?crcwords((UI*)v,n>>LGSZI):~0; // take CRC of the fullword part, if any
5352
if(n&(SZI-1)){wdcrc=HASHI(wdcrc,((UI*)v)[n>>LGSZI]<<((SZI-(n&(SZI-1)))<<LGSZI));} // if there are bytes, take their CRC after discarding garb. Avoid overfetch
5453
R wdcrc; // return composite CRC
5554
}
5655

5756
// CRC32 of n boxes
5857
static UI4 jtcrcy(J jt,A y);
59-
static scafINLINE UI4 crcboxes(A *v, I n, J jt){UI4 crc=0; A cur=v[0]; DO(n, A nxt=v[i+1]; crc=HASH4(crc,jtcrcy(jt,C(cur))); cur=nxt;) R crc;} // overfetch OK
58+
static INLINE UI4 crcboxes(A *v, I n, J jt){UI4 crc=0; A cur=v[0]; DO(n, A nxt=v[i+1]; crc=HASH4(crc,jtcrcy(jt,C(cur))); cur=nxt;) R crc;} // overfetch OK
6059

6160
// CRC32 of n Xs
62-
static scafINLINE UI4 crcxnums(X *v, I n){UI4 crc=0; X cur=v[0]; DO(n, X nxt=v[i+1]; crc=HASH4(crc,likely(XLIMBLEN(v[i])!=0)?crcwords(UIAV(v[i]),XLIMBLEN(v[i])):~0); cur=nxt;) R crc;}
61+
static INLINE UI4 crcxnums(X *v, I n){UI4 crc=0; X cur=v[0]; DO(n, X nxt=v[i+1]; crc=HASH4(crc,likely(XLIMBLEN(v[i])!=0)?crcwords(UIAV(v[i]),XLIMBLEN(v[i])):~0); cur=nxt;) R crc;}
6362

6463
// CRC32 of y. Floats must observe -0.
6564
static UI4 jtcrcy(J jt,A y){
@@ -490,7 +489,7 @@ A self; //
490489
// k is A for keys, n is #keys, s is place for slot#s. Hash each key, store, prefetch (possibly using wrong hash)
491490
// if s is 0, we are using a user hash; use uits return area as s
492491
// result is 0 on error
493-
static scafINLINE I8* jtkeyprep(DIC *dic, void *k, I n, I8 *s,J jt,A ka){I i;
492+
static INLINE I8* jtkeyprep(DIC *dic, void *k, I n, I8 *s,J jt,A ka){I i;
494493
UI8 hsz=dic->bloc.hashsiz; UI8 kib=dic->bloc.klens; UI4 (*hf)(void*,I,J)=dic->bloc.hashfn; C *hashtbl=CAV1(dic->bloc.hash); // elesiz/hashsiz kbytelen/kitemlen
495494
if(likely(s!=0)) {
496495
// internal hash
@@ -512,7 +511,7 @@ static scafINLINE I8* jtkeyprep(DIC *dic, void *k, I n, I8 *s,J jt,A ka){I i;
512511
// ********************************** get/has **********************************
513512

514513
// Do the work for just 1 get. z is 0 for has
515-
static scafINLINE A jtget1(DIC *dic,void *k,A z,J jt,A adyad){
514+
static INLINE A jtget1(DIC *dic,void *k,A z,J jt,A adyad){
516515
UI8 hsz=dic->bloc.hashsiz; UI8 kib=dic->bloc.klens; UI4 (*hf)(void*,I,J)=dic->bloc.hashfn; // elesiz/hashsiz kbytelen/kitemlen hash function
517516
UI4 hsh=(*hf)(k,(UI4)kib,jt); PREFETCH(&CAV1(dic->bloc.hash)[(((UI8)hsh*(UI4)hsz)>>32)*(hsz>>56)]);
518517
UI lv; DICLKRDRQ(dic,lv,dic->bloc.flags&DICFSINGLETHREADED); // request read lock
@@ -557,7 +556,7 @@ exiterr:; z=0; goto retz;
557556
// resolve each key in the hash and copy the value (or default) to the result
558557
// a is default if given, 0 if not; or 1 if has
559558
// We take a read lock on the table and return with it
560-
static scafINLINE B jtgetslots(DIC *dic,void *k,I n,I8 *s,void *zv,J jt,A a, VIRT virt){I i;
559+
static INLINE B jtgetslots(DIC *dic,void *k,I n,I8 *s,void *zv,J jt,A a, VIRT virt){I i;
561560
UI lv; DICLKRDRQ(dic,lv,dic->bloc.flags&DICFSINGLETHREADED); // request read lock
562561
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
563562
UI8 kib=dic->bloc.klens; I (*cf)(I,void*,void*)=dic->bloc.compfn; I vn=dic->bloc.vbytelen; // more nonresizable: kbytelen/kitemlen compare fn size of a value in bytes
@@ -654,7 +653,7 @@ static DF2(jtdicget){F12IP;A z;
654653

655654
// put fast case: one key, no user hash or compare function. We enter having requested a pre-write lock.
656655
// Result is 0 on error, otherwise is the current lv with DICLMSKOKRET set and DICLMSKRESIZEREQ set if resize is needed
657-
static scafINLINE UI8 jtput1(DIC *dic,void *k,void *v,UI8 lv,J jt){
656+
static INLINE UI8 jtput1(DIC *dic,void *k,void *v,UI8 lv,J jt){
658657
UI8 hsz=dic->bloc.hashsiz; UI8 kib=dic->bloc.klens; UI4 (*hf)(void*,I,J)=dic->bloc.hashfn; C *hashtbl=CAV1(dic->bloc.hash); // elesiz/hashsiz kbytelen/kitemlen
659658
UI4 hsh=(*hf)(k,(UI4)kib,jt); PREFETCH(&hashtbl[(((UI8)hsh*(UI4)hsz)>>32)*(hsz>>56)]);
660659
// hash the key and prefetch from the hashtable
@@ -709,7 +708,7 @@ resize:; // resize required. We already have a write lock
709708
// resolve each key in the hash and copy new kvs
710709
// We have requested a prewrite lock; we may even have a full write lock on the keys and value
711710
// return holding a write lock on this dic; return value of lv (to make release faster in caller), with RET bits set to indicate error or resize request
712-
static scafINLINE UI8 jtputslots(DIC *dic,void *k,I n,void *v,I vn,I8 *s,J jt,UI lv,VIRT virt){I i;
711+
static INLINE UI8 jtputslots(DIC *dic,void *k,I n,void *v,I vn,I8 *s,J jt,UI lv,VIRT virt){I i;
713712
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
714713
UI8 kib=dic->bloc.klens; I (*cf)(I,void*,void*)=dic->bloc.compfn; // kbytelen/kitemlen compare func unchanged by resize
715714
DICLKRWWT(dic,lv) // wait for pre-write lock to be granted (NOP if we already have a write lock). The DIC may have been resized during the wait, so pointers and limits must be refreshed after the lock
@@ -900,7 +899,7 @@ abortexit:;
900899
// resolve each key in the hash and copy new kvs
901900
// We have requested a prewrite lock; we may even have a full write lock on the keys and value
902901
// return holding a write lock on this dic; rc=0 if error, rc=-1 to request a resize
903-
static scafINLINE UI8 jtdelslots(DIC *dic,void *k,I n,I8 *s,J jt,UI lv,VIRT virt){I i;
902+
static INLINE UI8 jtdelslots(DIC *dic,void *k,I n,I8 *s,J jt,UI lv,VIRT virt){I i;
904903
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
905904
UI8 kib=dic->bloc.klens; I (*cf)(I,void*,void*)=dic->bloc.compfn; // more nonresizable
906905
DICLKRWWT(dic,lv) // wait for pre-write lock to be granted (NOP if we already have a write lock). The DIC may have been resized during the wait, so pointers and limits must be refreshed after the lock
@@ -1106,7 +1105,7 @@ DF2(jtdisprbdic){F12IP;
11061105
// resolve each key in the hash and copy the value (or default) to the result
11071106
// a is default if given, 0 if not; or 1 if has
11081107
// We take a read lock on the table and release it
1109-
static scafINLINE B jtgetslotso(DIC *dic,void *k,I n,I8 *s,void *zv,J jt,A a, VIRT virt){I i;
1108+
static INLINE B jtgetslotso(DIC *dic,void *k,I n,I8 *s,void *zv,J jt,A a, VIRT virt){I i;
11101109
UI lv; DICLKRDRQ(dic,lv,dic->bloc.flags&DICFSINGLETHREADED); // request read lock
11111110
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
11121111
UI8 kib=dic->bloc.klens; I (*cf)(I,void*,void*)=dic->bloc.compfn; I vb=dic->bloc.vbytelen; // more nonresizable: kbytelen/kitemlen compare fn prototype required to get arg converted to I
@@ -1198,7 +1197,7 @@ static DF2(jtdicgeto){F12IP;A z;
11981197
// k is A for key0,:key1, flags is (return k, return v, include key-0, include k-end)
11991198
// We take a read lock on the table and release it
12001199
// virt is used as virtuals for compare, and then repurposed to hold indexes of kvs to be copied
1201-
static scafINLINE A jtgetkvslotso(DIC *dic,void *k,I flags,J jt,VIRT virt){I i;
1200+
static INLINE A jtgetkvslotso(DIC *dic,void *k,I flags,J jt,VIRT virt){I i;
12021201
PROLOG(000);
12031202
UI lv; DICLKRDRQ(dic,lv,dic->bloc.flags&DICFSINGLETHREADED); // request read lock
12041203
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
@@ -1390,7 +1389,7 @@ static DF2(jtdicgetkvo){F12IP;A z;
13901389
// resolve each key in the hash and copy new kvs
13911390
// We have requested a prewrite lock; we may even have a full write lock on the keys and value
13921391
// return holding a write lock on this dic; rc=0 if error, otherwise current lv (which gives lock status), with OKRET set to be non0 and RESIZEREQ is a resize is needed
1393-
static scafINLINE UI8 jtputslotso(DIC *dic,void *k,I n,void *v,I vn,J jt,UI lv,VIRT virt){I i;
1392+
static INLINE UI8 jtputslotso(DIC *dic,void *k,I n,void *v,I vn,J jt,UI lv,VIRT virt){I i;
13941393
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
13951394
UI8 kib=dic->bloc.klens; I (*cf)(I,void*,void*)=dic->bloc.compfn; // more nonresizable: kbytelen/kitemlen compare fn prototype required to get arg converted to I
13961395
I nodeb=dic->bloc.hashelesiz*(0x1000000+SZI)+(dic->bloc.emptysiz<<19)+(dic->bloc.flags<<8); // (#bytes in node index)\(#bits in empty-chain field\(flags)\(number of bits in a node index)
@@ -1530,7 +1529,7 @@ static DF2(jtdicputo){F12IP;
15301529
// resolve each key in the hash and delete them
15311530
// We have requested a prewrite lock; we may even have a full write lock on the keys and value
15321531
// return holding a write lock on this dic; rc=0 if error, otherwise current lv (which gives lock status), with OKRET set to be non0 and RESIZEREQ is a resize is needed
1533-
static scafINLINE UI8 jtdelslotso(DIC *dic,void *k,I n,J jt,UI lv,VIRT virt){I i;
1532+
static INLINE UI8 jtdelslotso(DIC *dic,void *k,I n,J jt,UI lv,VIRT virt){I i;
15341533
if(unlikely(!(dic->bloc.flags&DICFICF))){initvirt((A)virt.u,dic); initvirt((A)virt.h,dic); virt.self=dic->bloc.hashcompself; } // fill in nonresizable info
15351534
UI8 kib=dic->bloc.klens; I (*cf)(I,void*,void*)=dic->bloc.compfn; // more nonresizable: kbytelen/kitemlen compare fn prototype required to get arg converted to I
15361535
I nodeb=dic->bloc.hashelesiz*(0x1000000+SZI)+(dic->bloc.emptysiz<<19)+(dic->bloc.flags<<8); // (#bytes in node index)\(#bits in empty-chain field\(flags)\(number of bits in a node index)

0 commit comments

Comments
 (0)