a.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #define _s(o) i(l0-2,a=o##i(a,s(4<<i,a))) //a=o##i(a,s(4,a));a=o##i(a,s(8,a));a=o##i(a,s(16,a));a=o##i(a,s(32,a))
  2. #define s_(t,o) a(t##0,i(nN(Nx),a=o##i(a,O))_s(o)a)[b(l0-2)]
  3. #define S_(t,o) e(V##t b=t##0;N(V##t a=O;_s(o)b=a+b[b(l0-2)]))
  4. #define A() (_&&23<j?_+j-24:D+j)
  5. #define B3(b,c,d,e,f,g) _N(bl(127<O,b,bl(c,d,bl(e,f,g))))
  6. #define l0 5
  7. #define ZU static U//abc.efg.ij.lmno..r.t...x..
  8. #define ZV static V//..C..FG......NOPQR.TUVW...
  9. #define AV(n) __attribute((vector_size(1<<n),aligned(1)))
  10. typedef char V AV(l0);typedef unsigned u,vu AV(l0-1),Vu AV(l0);typedef unsigned long(*_)(),U,U4 AV(4),VU AV(l0),UU AV(l0+1);typedef int Vi AV(l0);typedef float Ve AV(l0);
  11. ZU w_(U,...),prr(),b_(),T(),_r(),r_(),a2(),ys(),pz(),wx(),_p(),z_(),W,M[30],D[32],S[1<<10],*c=S+(1<<10);static Ve e0;static VU U0;static Vu u0,I2={0,1,2,3,4,5,6,7}; //,8,9,10,11,12,13,14,15};
  12. ZV I0={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};//,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63};
  13. #define D(g,z) U(g,z,_ $,Ua,Ux)
  14. #define o(f) bu(ia32_##f##256)
  15. #define n0 (1L<<l0)
  16. #define nN(z) (n0-1+(z)>>l0)
  17. #define bI(z) R(1,nx,i(nN(Nx),rc=b2(e(z))))
  18. #define bC(z) R(1,nx,i(nN(Nx),ru=b_(e(z))))
  19. #define K(n,z) R(0,n,i(x(r,nx),rU=e(z)))
  20. #define L(t,n,z) R(t,n,i(x(r,nN(Nx)),rV=e(z)))
  21. #define _(z) r(e(z),_r(x))
  22. #define __(z) r(e(z),_r(x);_r(a))
  23. #define a(z,y) e(typeof(z)a=z;y)
  24. #define b(z) ((1l<<(z))-1)
  25. #define e(_) ({_;})
  26. #define f(g,z) U(g,z,Ux)
  27. #define g(g,z) U(g,z,uf,Ux)
  28. #define i(a,z) {unsigned _n=a;ii=-1;W(++i<_n){z;}}
  29. #define j(a,z) {unsigned _n=a;ij=-1;W(++j<_n){z;}}
  30. #define l(a,z) e(typeof(z)e_=z;(a)<e_?(a):e_)
  31. #define m(a,z) e(typeof(z)e_=z;(a)>e_?(a):e_)
  32. #define n(z) i(nx,z)
  33. #define r(z,y) e(typeof(z)r=z;y;r)
  34. #define t(t,x) ((U)(t)<<61|(x))
  35. #define x(z,y) e(typeof(z)x=z;y)
  36. #define C(t,x) bu(convertvector)(x,t)
  37. #define F(g,z) U(g,z,Ua,Ux)
  38. #define G(g,z) U(g,z,uf,Ua,Ux)
  39. #define N(z) L(Tx,nx,z)
  40. #define O ((V*)x)[i]
  41. #define P(b,z) if(e(b))return e(z);
  42. #define Q(z...) P(96==(z),96)
  43. #define R(t,n,z) r(T(t,n),z)
  44. #define U(g,z,x...) ZU g(x){return e(z);}
  45. #define V(g,z,x...) ZV g(x){return e(z);}
  46. #define W(z) while(e(z))
  47. #define _N(z) _(N(z))
  48. #define _K(n,z) _(K(n,z))
  49. #define _R(t,n,z) _(R(t,n,z))
  50. #define _T(t,z) _(L(t,nx,z))
  51. #define q3(o) Qd(1!=f&&1<f-5)f-=5;P(Bx,b##o(f,x))Qz(2!=Lx)
  52. #define i0(a,b) o(pshufb)(a,b)
  53. #define i2(a,b) o(pshufd)(a,b)
  54. #define VF(g,z) V(g,z,Va,Vb)
  55. #define ai(a,b) (a)+(b)
  56. #define v1($,z) f($,tx?e(Q(x=$( v_(x)))_v(x)):Tx?e(z):f1($, x))
  57. #define V1($,z) F($,tx?e(Q(x=$(a,v_(x)))_v(x)):Tx?e(z):fr($,a,x))
  58. #define bu(f) __builtin_##f
  59. #define AN(f,s,x...) __attribute((naked))U f(x){asm(s);}
  60. #define _W(z) ii=nx;W(i--){z;}
  61. #define Ui(g,z) U(g,z,ii)
  62. #define Us(g,z) U(g,z,ss)
  63. #define Zs(g,a,x...) static char*g(x){return e(a);}
  64. #define nb(z) bu(popcountl)(z)
  65. #define ib(z) bu(ctzl)(z)
  66. #define lb(z) bu(clzl)(z)
  67. #define a3(t) $3(f-1,t##a+t##x,t##a-t##x,t##a*t##x)
  68. #define b3(a,x) $3(f-7,(a)<x,(a)>x,(a)==x)
  69. #define N6(z) i(63+nx>>6,z)
  70. #define nS(g,z) U(g,z,in,ss)
  71. #define ve(g,z) U(g,z,ee)
  72. #define vV(g,z) U(g,z,Va)
  73. #define IU(a) r(ib(a),a&=a-1)
  74. #define Z_(f,x...) static _ f[]={x};
  75. #define Qx(f) Ux=f(s);Q(x)
  76. #define Qs(e,s) P(e,err((U)__func__,(U)s))
  77. #define QZ e(Qz(1)0)
  78. #define Nx tn(Tx,nx)
  79. #define Uu C(VU,((vu*)x)[i])
  80. #define _u (Ve)C(Vu,((UU*)x)[i])
  81. #define u_ (Ve)C(Vu,((UU*)x)[i]>>32)
  82. #define Ix (Vu)Cx
  83. #define Ex (Ve)Cx
  84. #define Ux U x
  85. #define Vv V v
  86. #define Va V a
  87. #define Vb V b
  88. #define ax a(x,xx)
  89. #define xx *UX
  90. #define mx sx[-6]
  91. #define R_ UR[-1]
  92. #define si s[i]
  93. #define xb sx[i/32]
  94. #define Ca x(a,tx?cx:Cx)
  95. #define Ia x(a,tx?ux:Ix)
  96. #define Ea x(a,tx?ex:Ex)
  97. #define ca x(a,cx)
  98. #define AU r_(aU)
  99. #define XU r_(xU)
  100. #define UR ((U*)r)
  101. #define UA ((U*)a)
  102. #define UX ((U*)x)
  103. #define aU ((U*)a)[i]
  104. #define rU ((U*)r)[i]
  105. #define xU ((U*)x)[i]
  106. #define na ((u*)a)[-1]
  107. #define nx ((u*)x)[-1]
  108. #define xc sx[i]
  109. #define rc (sr)[i]
  110. #define ru ((u*)r)[i]
  111. #define xu ((u*)x)[i]
  112. #define rV ((V*)r)[i]
  113. #define aV ((V*)a)[i]
  114. #define sr (char*)r
  115. #define sa (char*)a
  116. #define sx ((char*)x)
  117. #define rx ((u*)x)[-2]
  118. #define Tx sx[-5]
  119. #define Bx (1==Tx)
  120. #define tx (x>>61)
  121. #define Cx O
  122. #define ss char*s
  123. #define cc char c
  124. #define ee float e
  125. #define uf unsigned f
  126. #define ii unsigned i
  127. #define ij unsigned j
  128. #define ik unsigned k
  129. #define im unsigned m
  130. #define in unsigned n
  131. #define it unsigned t
  132. #define Ur U r
  133. #define Ua U a
  134. #define Un U n
  135. #define oo ws("oo\n")
  136. #define x_ sx[nx-1]
  137. #define Zc static char
  138. #define Zu static u
  139. #define S(f,i) static AN(f,"mov %rcx,%r10;mov $"#i",%rax;syscall;ret",Ux,...)
  140. AN(_start,"lea 8(%rsp),%rsi;call main")AN(ut,"rdtsc;shl $32,%rdx;or%rdx,%rax;ret")S(_w,0)S(w_,1)S(f_,2)S(_f,3)S(_l,4)S(m_,9)S(_k,60)
  141. Zc*_P,B=32;Zu n,A,M1=65535,N=1<<31,L[]={3,0,0,2,2,3},g=95<<23;static float E[]={1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9};Ui(tb,t(1,i))Ui(tc,t(2,i))Ui(ti,t(3,i))f(l2,64-lb(x-1))
  142. ve(ue,*(u*)&e)ve(te,t(4,ue(e)))ve(eq,1-1e-6<e&&1+1e-6>e)f(qe,2==Tx&&32>x_%128)f(qf,!Tx&&qe(xx))g(tn,1==f?7+x>>3:x<<L[f])f(sb,ii=nx/64;if(nx%64)xU&=b(nx%64);r(0,N6(r+=nb(xU))))
  143. Ui(g_,ij=N&i;j>>2|b(29)&m(g,i)-g)f(G_,g_(x)|g_(x>>32)<<30)Ui(_g,ij=i&b(29);j?N&i<<2|j+g:0)f(_G,_g(x)|_g(x>>30)<<32)f(z4,64/4-lb(x)/4)f(q0,10>x-48)f(qa,26>x-97)
  144. Us(sl,ii=0;W(si)++i;i)Zs(ws,w_(2,(U)s,sl(s));s,ss)f(wc,w_(2,(U)&x,1))F(err,if(a)ws(sa);wc(58);ws(sx);wc(10);96)U(OO,ws("OO\n");_k(0))
  145. U(dn,i(nN(n),rV=O)r+n,Ur,Un,Ux)U(is,i(nN(n),Ua=b_(c==O);P(a,l(n,n0*i+ib(a))))n,cc,in,V*x)g(ig,is(f,nx,sx))g(qg,nx>ig(f,x))nS(ns,R(2,n,dn(r,n,(U)s)))Us(xs,ns(sl(s),s))
  146. #define ix ux
  147. #define ia ua
  148. #define cx (char)x
  149. #define px (128>x)
  150. #define lx L[tx]
  151. #define Lx L[Tx]
  152. #define ux (unsigned)x
  153. #define ex a(ux,*(float*)&a)
  154. #define au x(a,xu)
  155. #define pa x(a,px)
  156. #define ta x(a,tx)
  157. #define ua x(a,ux)
  158. #define ea x(a,ex)
  159. #define Ta x(a,Tx)
  160. #define Qz(e) Qs(e,"nyi")
  161. #define Qr(e) Qs(e,"rank")
  162. #define Qt(e) Qs(e,"type")
  163. #define Qn(e) Qs(e,"count")
  164. #define Qd(e) Qs(e,"domain")
  165. #define $3(z,a,b,c) e(unsigned y=z;!y?e(a):1==y?e(b):e(c))
  166. #define $4(z,a,b,c,d) e(unsigned y=z;!y?e(a):1==y?e(b):2==y?e(c):e(d))
  167. #define $5(z,a,b,c,d,x) e(unsigned y=z;!y?e(a):1==y?e(b):2==y?e(c):3==y?e(d):e(x))
  168. #define $6(z,a,b,c,d,x,f) e(unsigned y=z;!y?e(a):1==y?e(b):2==y?e(c):3==y?e(d):4==y?e(x):e(f))
  169. #define C6(z,a,b,c,d,e,f) switch(z){case 0:{a;break;}case 1:{b;break;}case 2:{c;break;}case 3:{d;break;}case 4:{e;break;}default:{f;}}
  170. #define IF(z,a) if(z){a;}else //f(wi,cc[21];ss=c+20;*s=10;do*--s=48+x%10;W(x/=10);w_(2,s,c+21-s);x)f(Y,wx(r_(x));x)