select.red 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. %
  2. % Run using smallr35 to select code to compile into C.
  3. % I run "reduce.tst" as the main test to tune against, but also
  4. % use data collected (elsewhere) to ensure that the most heavily
  5. % used functions in various other tests are catered for.
  6. %
  7. %
  8. % I recompile the patches module in case it has changed since the main
  9. % image file that I am using was created.
  10. %
  11. on comp, backtrace;
  12. in "../cslsrc/patches.red"$
  13. % It is a misery that the REDUCE test files do not tidy up after themselves,
  14. % so if I want to run several in the same job I have to put well-judged
  15. % CLEAR statements between. If I miss out some of these almost any
  16. % curious behaviour might arise.
  17. on echo;
  18. lisp verbos 3;
  19. % Here I set up a list that documents what appear to be the most
  20. % heavily used few functions in each of a number of the test files.
  21. % I will force these to be compiled into C regardless of what is in the
  22. % benchmark files that I process as well
  23. lisp (force_these := '(
  24. % Reduce.tst
  25. getel1 simpcar noncomp ordop delcp multd addf terminalp
  26. multf prin2!* !*ssave getrtypeor getrtype timesip getrtype2
  27. exchk simp ordad getel readch1
  28. % Int.tst
  29. ordop reorder multd addf delall powers0 multf maxdeg
  30. noncomp rmultpf quotf1 quotf negf addd raddf degr
  31. !*n2f !*d2q minusf ordpp
  32. % Factor.tst
  33. !*n2f adjoin!-term multiply!-by!-constant!-mod!-p plus!-mod!-p
  34. remainder!-in!-vector mksp getpower addf multd times!-term!-mod!-p
  35. multf listsum to noncomp times!-mod!-p fkern clear!-column addd
  36. minus!-mod!-p multdm
  37. % Decompos.tst
  38. freeof freeofl !*n2f smember addf ordop multd multf
  39. to adjoin!-term noncomp addd multdm adddm mkspm sub2chk
  40. multiply!-by!-constant!-mod!-p plus!-mod!-p ordpp exchk
  41. % Limits.tst
  42. ps!:getv ps!:last!-term ps!:order ps!:get!-term ps!:evaluate exchk
  43. multsq retimes1 prepf1 quotf addsq prepf ps!:times!-erule replus
  44. retimes ps!:putv !*d2q exchk1 prepsq prepd
  45. % Matrix.tst
  46. addf multd !*n2f multf addd to c!:ordxp c!:ordexp noncomp
  47. adddm negf c!:extadd ordop quotf1 c!:extmult mkspm sub2chk
  48. c!:ordexn scprint multdm
  49. % Groebner.tst
  50. evlexcomp vevzero!?1 vevmtest!? bcnumtimes evcomp bcint2op
  51. bcprod vevcan0 evsum quotf evzero!? diplength groebsearchinlist
  52. listsum exchk multd reorder retimes1 vevmaptozero1 ordop
  53. % Roots.tst
  54. CSL_normbf CSL_timbf round!:mt round!:last plus!: divide!:
  55. conv!:mt ncoeffs gftimesn difference!: plubf terminalp
  56. lastpair abs!: gfplusn gfrsq cut!:mt gfdot readch1 gbfdot
  57. % Solve.tst
  58. ordop freeof freeofl smember addf multd multf !*n2f noncomp
  59. negf to exchk ordpp vevmtest!? addd multdm retimes1 reorder
  60. adddm mkspm
  61. % Compact.tst
  62. termsf addf !*n2f addd multd multf noncomp to
  63. adddm negf mkspm sub2chk multdm kernels1 red!-weight1
  64. !:minus nonzero!-length ordop mv!-pow!-!+ ordpp
  65. % Gcd.tst
  66. !*n2f adjoin!-term multiply!-by!-constant!-mod!-p
  67. plus!-mod!-p mksp addf getpower multd addd
  68. times!-term!-mod!-p times!-mod!-p ordop multf
  69. fkern noncomp powers2 to adddm raddf reorder
  70. % Excalc.tst
  71. ordop reorder delall maxdeg powers0 rmultpf raddf
  72. quotf to quotf1 lastpair reordop addf multf quotfm
  73. exchk ordpp noncomp negf multd
  74. % Tps.tst
  75. ps!:getv ps!:last!-term ps!:order quotf exchk
  76. ps!:get!-term retimes1 prepf1 prepf minusf multsq
  77. ps!:evaluate replus revpr retimes gcdf lnc quotf1
  78. terminalp scprint
  79. % Taylor.tst
  80. tayexp!-plus2 gcdfd1 quotf tayexp!-greaterp multd
  81. exceeds!-order lastpair tayexp!-difference addf
  82. gcdf minusf quotf1 multf multsq gcdf1 gcdfd add!-degrees
  83. lnc terminalp ordop
  84. % Sum.tst
  85. addf noncomp multf multd to !*n2f addd ordop reorder
  86. adddm multdm mkspm sub2chk lastpair raddf ordpp exchk
  87. negf rmultpf quotf1
  88. % Algint.tst
  89. addf multd ordop reorder multf noncomp delall
  90. powers0 to !*n2f addd quotf1 maxdeg rmultpf
  91. negf adddm subs2f1 depends ldepends raddf
  92. % Scope.tst
  93. lastpair terminalp initbrsea testred initwght
  94. token prin2x readch1 numberofocc downwght1 pnthxzz
  95. lispeval smember inshisto delcp pprin2
  96. downwght toknump init
  97. % Gentran.tst
  98. lastpair terminalp pprin2 readch1 token prin2x
  99. listp exchk prepf1 retimes1 delcp ordop nconc!*
  100. toknump mkvar lispeval exchk1 noncomp reversip!*
  101. % Arnum.tst
  102. !*n2f multd addf adjoin!-term remainder!-in!-vector
  103. multf to addd rnzerop!: multdm noncomp rnequiv adddm
  104. rnonep!: int!-equiv!-chk times!-in!-vector mkrn
  105. plus!-mod!-p multiply!-by!-constant!-mod!-p mksp
  106. % Elem.tst
  107. delcp terminalp readch1 exchk sinitl striptag
  108. s!:prinl1 CSL_normbf convprec!* prin2x token
  109. replus convchk prepf retimes1 errorset!* errorp round!:mt
  110. % Complex.tst
  111. !*n2f CSL_normbf terminalp multd remainder!-in!-vector
  112. adjoin!-term round!:mt addf readch1 round!:last
  113. multiply!-by!-constant!-mod!-p scprint prin2!*
  114. gizerop!: mkgi times!-in!-vector addd striptag
  115. % Rounded.tst
  116. terminalp smemql CSL_normbf readch1 s!:assoc
  117. round!:mt round!:last prin2!* !*ssave token
  118. prin2x exchk scprint convprec divide!: sinitl getrtype
  119. round!*
  120. % Math.tst
  121. terminalp readch1 prin2x token delcp reversip!* mkvar
  122. token1 toknump convertmode scan formc arrayp
  123. eolcheck xread1 getrmacro macrochk form1
  124. % Spde.tst
  125. ordop ldepends depends exchk prepf1 ordpp
  126. retimes1 multsq ordad addf difff nconc!* exchk1
  127. addsq !*d2q multd simpcar multf sqchk
  128. % Avector.tst
  129. prin2!* negnumberchk update!-pline ordop maprint
  130. putpline noncomp multf layout!-formula scprint
  131. prepf1 addf quotf1 oprin exchk negf retimes1
  132. nconc!* to exptpri
  133. % Orthovec.tst
  134. exchk prepf1 retimes1 nconc!* exchk1 prepf retimes
  135. getrtype getrtypeor reval replus simpcar prepd
  136. getrtype2 sqchk reval2 simp prepsqxx !*ssave
  137. % Specfn.tst
  138. CSL_normbf round!:mt subs3f round!:last exchk
  139. revpr quotsq convprec!* !*ssave striptag subs3q
  140. divide!: simpcar subs3f1 getrtype2 getrtype multsq
  141. addsq convchk
  142. ))$
  143. symbolic procedure cf(p, q);
  144. (float caddr p/float cadr p) > (float caddr q/float cadr q);
  145. symbolic mapstore 4; % reset counts;
  146. in "../xmpl/reduce.tst";
  147. symbolic (w_reduce := sort(mapstore 2, function cf))$
  148. clear a, xx, yy, zz, k1, ki, kf, p1, pf,
  149. ei, ef, ki, kf, p1, pf, gp, ix, iy, iz,
  150. p2, p3, p4, qi, q2, ga, gb, w;
  151. % The lines commented out thus "%---" are a prototype of how to
  152. % include one or more further test files in this benchmark/tuning
  153. % suite.
  154. %--- symbolic mapstore 4;
  155. %---
  156. %--- in "../xmpl/int.tst";
  157. %---
  158. %--- symbolic (w_int := sort(mapstore 2, function cf))$
  159. %---
  160. %--- clear f1s, a, z, u, v;
  161. symbolic;
  162. fluid '(w);
  163. w := w_reduce$
  164. symbolic procedure top_twenty x;
  165. begin
  166. scalar y;
  167. for i := 1:20 do
  168. if x then << y := car x . y; x := cdr x >>;
  169. return y
  170. end;
  171. symbolic procedure addin r;
  172. begin
  173. scalar v;
  174. v := assoc(car r, w);
  175. if not v then w := r . w
  176. else w := list(car r, cadr r + cadr v, caddr r + caddr v) . delete(v, w);
  177. return nil
  178. end;
  179. %--- w_int := top_twenty w_int$
  180. for i := 1:20 do <<
  181. %--- if w_int then << addin car w_int; w_int := cdr w_int >>;
  182. nil >>;
  183. z := w$ w := nil;
  184. for each v in z do begin
  185. scalar name, name1;
  186. name := car v;
  187. name1 := symbol!-env name;
  188. if not atom name1 then <<
  189. name1 := cdr name1;
  190. if vectorp name1 then name := getv(name1, 0) >>;
  191. addin list(name, cadr v, caddr v) end;
  192. w := sort(w, function cf)$
  193. for each fn in force_these do begin
  194. scalar name1;
  195. name1 := symbol!-env fn;
  196. if not atom name1 and vectorp cdr name1 then fn := getv(cdr name1, 0);
  197. addin list(fn, 0, 0);
  198. force_these := cdr force_these end;
  199. total_bytes_executed := 0;
  200. for each v in w do total_bytes_executed := total_bytes_executed + caddr v;
  201. symbolic procedure listsize(x, n);
  202. if null x then n
  203. else if atom x then n+1
  204. else listsize(cdr x, listsize(car x, n+1));
  205. fnames := '("u01" "u02" "u03" "u04" "u05"
  206. "u06" "u07" "u08" "u09" "u10"
  207. "u11" "u12");
  208. size_per_file := 4300;
  209. symbolic procedure get!-saved m;
  210. << loaded!-packages!* := nil;
  211. load!-package m;
  212. for each x in oblist() do
  213. if not atsoc(x, w) then remprop(x, '!*savedef)
  214. >>;
  215. % With !*savedef = '!*savedef when I load a module I do not load the
  216. % executable code in it - just the saved function definitions on
  217. % property lists (also I execute any code in the file that is not
  218. % just defining a function). Since some modules define functions
  219. % that they then call, I need to define suitable placeholders here.
  220. symbolic procedure set!-teeny!-primes(); nil;
  221. symbolic procedure initio(); nil;
  222. symbolic procedure find!!flim(); nil;
  223. algebraic procedure get!-eulers!-constant n; 0;
  224. % The taylor module defines and uses a macro (taylor!:) in a way that
  225. % seems to make it hard for me to handle using the general mechanism
  226. % I use below.
  227. get!-saved 'taylor;
  228. !*savedef := '!*savedef;
  229. <<
  230. % I load the files here with the largest module first. This is intended
  231. % to ease memory pressure. But I put the core system last so that
  232. % definitions in it take precedense over those in optional modules.
  233. get!-saved 'algint;
  234. % get!-saved 'int;
  235. get!-saved 'scope;
  236. % get!-saved 'gentran;
  237. get!-saved 'factor;
  238. % get!-saved 'ezgcd;
  239. get!-saved 'roots;
  240. get!-saved 'excalc;
  241. get!-saved 'groebnr2;
  242. % get!-saved 'groebner;
  243. % get!-saved 'dipoly;
  244. get!-saved 'solve;
  245. get!-saved 'specfn2;
  246. % get!-saved 'specfn;
  247. % get!-saved 'specfaux;
  248. get!-saved 'numeric;
  249. get!-saved 'matrix;
  250. % get!-saved 'spde; Not loaded because of function clashes
  251. get!-saved 'misc;
  252. % get!-saved 'tps;
  253. get!-saved 'rlisp88;
  254. get!-saved 'arnum;
  255. get!-saved 'odesolve;
  256. % get!-saved 'rcref; Not loaded because I will not worry about speed here
  257. % get!-saved 'avector; Not loaded because of function clashes
  258. get!-saved 'hephys;
  259. % get!-saved 'orthovec; Not loaded because of function clashes
  260. get!-saved 'compact;
  261. % get!-saved 'rprint; Not loaded because I will not worry about speed here
  262. % get!-saved 'cedit; Not loaded because I will not worry about speed here
  263. % get!-saved 'pretty; Not loaded because I will not worry about speed here
  264. get!-saved 'module;
  265. % Now do some tidying up - to try to free up some memory
  266. for each x in oblist() do
  267. for each y in '(simpfn dfn opmtch klist kvalue avalue) do
  268. remprop(x, y);
  269. % I reload the most basic bits of REDUCE once again to ensure that the
  270. % definitions that I will compile into C come from these modules even
  271. % if some other package redefines something critical.
  272. get!-saved 'rlisp;
  273. get!-saved 'cslrend;
  274. get!-saved 'poly;
  275. get!-saved 'alg;
  276. get!-saved 'arith;
  277. get!-saved 'mathpr;
  278. off echo;
  279. in "../cslsrc/patches.red"$
  280. on echo;
  281. !*savedef := nil;
  282. set!-print!-precision 4;
  283. benefit := 0;
  284. symbolic verbos nil;
  285. global '(rprifn!*);
  286. load_package ccomp;
  287. on fastfor, fastvector, unsafecar;
  288. while fnames do begin
  289. scalar bulk;
  290. princ "About to create "; printc car fnames;
  291. c!:ccompilestart car fnames;
  292. bulk := 0;
  293. while bulk < size_per_file and w do begin
  294. scalar name, defn, value;
  295. name := caar w;
  296. value := float caddar w/((1.0+sqrt float cadar w)*1000.0);
  297. defn := get(name, '!*savedef);
  298. remprop('name, '!*savedef); % Save a little space.
  299. if null defn then <<
  300. princ "+++ "; prin name; printc ": no saved definition found";
  301. w := cdr w >>
  302. else <<
  303. bulk := listsize(defn, bulk);
  304. if bulk < size_per_file then <<
  305. benefit := benefit + caddar w;
  306. prin name; ttab 30; prin value;
  307. ttab 45; print (100.0*float benefit/float total_bytes_executed);
  308. c!:ccmpout1 ('de . name . cdr defn);
  309. w := cdr w >> >> end;
  310. eval '(c!-end);
  311. fnames := cdr fnames
  312. end;
  313. terpri();
  314. printc "*** End of compilation from REDUCE into C ***";
  315. terpri();
  316. bulk := 0;
  317. % I list the next 50 functions that WOULD get selected - just for interest.
  318. while bulk < 50 and w do
  319. begin
  320. name := caar w;
  321. value := float caddar w/((1.0+sqrt float cadar w)*1000.0);
  322. defn := get(name, '!*savedef);
  323. if null defn then <<
  324. princ "+++ "; prin name; printc ": no saved definition found";
  325. w := cdr w >>
  326. else <<
  327. bulk := bulk+1;
  328. benefit := benefit + caddar w;
  329. prin name; ttab 30; prin value;
  330. ttab 45; print (100.0*float benefit/float total_bytes_executed);
  331. w := cdr w >> end;
  332. nil >>;
  333. quit;
  334.