genset.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2001 by the Free Pascal development team
  4. Include file with set operations called by the compiler
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  12. {$ifndef FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  13. { Error No pascal version of FPC_SET_LOAD_SMALL}
  14. { THIS DEPENDS ON THE ENDIAN OF THE ARCHITECTURE!
  15. Not anymore PM}
  16. function fpc_set_load_small(l: fpc_small_set): fpc_normal_set; [public,alias:'FPC_SET_LOAD_SMALL']; compilerproc;
  17. {
  18. load a normal set p from a smallset l
  19. }
  20. begin
  21. FillDWord(fpc_set_load_small,sizeof(fpc_set_load_small) div 4,0);
  22. move(l,fpc_set_load_small,sizeof(l));
  23. end;
  24. {$endif FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  25. {$ifndef FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
  26. function fpc_set_create_element(b : byte): fpc_normal_set;[public,alias:'FPC_SET_CREATE_ELEMENT']; compilerproc;
  27. {
  28. create a new set in p from an element b
  29. }
  30. begin
  31. FillDWord(fpc_set_create_element,SizeOf(fpc_set_create_element) div 4,0);
  32. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  33. fpc_set_create_element[b div 32] := 1 shl (b mod 32);
  34. {$else}
  35. fpc_set_create_element[b] := 1;
  36. {$endif}
  37. end;
  38. {$endif FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
  39. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  40. function fpc_set_set_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  41. {
  42. add the element b to the set "source"
  43. }
  44. var
  45. c: longint;
  46. begin
  47. move(source,fpc_set_set_byte,sizeof(source));
  48. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  49. c := fpc_set_set_byte[b div 32];
  50. c := (1 shl (b mod 32)) or c;
  51. fpc_set_set_byte[b div 32] := c;
  52. {$else}
  53. fpc_set_set_byte[b] := 1;
  54. {$endif}
  55. end;
  56. {$endif FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  57. {$ifndef FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  58. function fpc_set_unset_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  59. {
  60. suppresses the element b to the set pointed by p
  61. used for exclude(set,element)
  62. }
  63. var
  64. c: longint;
  65. begin
  66. move(source,fpc_set_unset_byte,sizeof(source));
  67. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  68. c := fpc_set_unset_byte[b div 32];
  69. c := c and not (1 shl (b mod 32));
  70. fpc_set_unset_byte[b div 32] := c;
  71. {$else}
  72. fpc_set_unset_byte[b] := 0;
  73. {$endif}
  74. end;
  75. {$endif FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  76. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  77. function fpc_set_set_range(const orgset: fpc_normal_set; l,h : byte): fpc_normal_set; compilerproc;
  78. {
  79. adds the range [l..h] to the set orgset
  80. }
  81. var
  82. i: integer;
  83. c: longint;
  84. begin
  85. move(orgset,fpc_set_set_range,sizeof(orgset));
  86. for i:=l to h do
  87. begin
  88. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  89. c := fpc_set_set_range[i div 32];
  90. c := (1 shl (i mod 32)) or c;
  91. fpc_set_set_range[i div 32] := c;
  92. {$else}
  93. fpc_set_set_range[i] := 1;
  94. {$endif}
  95. end;
  96. end;
  97. {$endif ndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  98. {$ifndef FPC_SYSTEM_HAS_FPC_SET_ADD_SETS}
  99. function fpc_set_add_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_ADD_SETS']; compilerproc;
  100. var
  101. src1: fpc_normal_set_long absolute set1;
  102. src2: fpc_normal_set_long absolute set2;
  103. dest: fpc_normal_set_long absolute fpc_set_add_sets;
  104. {
  105. adds set1 and set2 into set dest
  106. }
  107. var
  108. i: integer;
  109. begin
  110. for i:=0 to 7 do
  111. dest[i] := src1[i] or src2[i];
  112. end;
  113. {$endif}
  114. {$ifndef FPC_SYSTEM_HAS_FPC_SET_MUL_SETS}
  115. function fpc_set_mul_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_MUL_SETS']; compilerproc;
  116. var
  117. src1: fpc_normal_set_long absolute set1;
  118. src2: fpc_normal_set_long absolute set2;
  119. dest: fpc_normal_set_long absolute fpc_set_mul_sets;
  120. {
  121. multiplies (takes common elements of) set1 and set2 result put in dest
  122. }
  123. var
  124. i: integer;
  125. begin
  126. for i:=0 to 7 do
  127. dest[i] := src1[i] and src2[i];
  128. end;
  129. {$endif}
  130. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SUB_SETS}
  131. function fpc_set_sub_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SUB_SETS']; compilerproc;
  132. var
  133. src1: fpc_normal_set_long absolute set1;
  134. src2: fpc_normal_set_long absolute set2;
  135. dest: fpc_normal_set_long absolute fpc_set_sub_sets;
  136. {
  137. computes the diff from set1 to set2 result in dest
  138. }
  139. var
  140. i: integer;
  141. begin
  142. for i:=0 to 7 do
  143. dest[i] := src1[i] and not src2[i];
  144. end;
  145. {$endif}
  146. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SYMDIF_SETS}
  147. function fpc_set_symdif_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SYMDIF_SETS']; compilerproc;
  148. var
  149. src1: fpc_normal_set_long absolute set1;
  150. src2: fpc_normal_set_long absolute set2;
  151. dest: fpc_normal_set_long absolute fpc_set_symdif_sets;
  152. {
  153. computes the symetric diff from set1 to set2 result in dest
  154. }
  155. var
  156. i: integer;
  157. begin
  158. for i:=0 to 7 do
  159. dest[i] := src1[i] xor src2[i];
  160. end;
  161. {$endif}
  162. {$ifndef FPC_SYSTEM_HAS_FPC_SET_COMP_SETS}
  163. function fpc_set_comp_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_COMP_SETS'];compilerproc;
  164. {
  165. compares set1 and set2 zeroflag is set if they are equal
  166. }
  167. var
  168. i: integer;
  169. src1: fpc_normal_set_long absolute set1;
  170. src2: fpc_normal_set_long absolute set2;
  171. begin
  172. fpc_set_comp_sets:= false;
  173. for i:=0 to 7 do
  174. if src1[i] <> src2[i] then
  175. exit;
  176. fpc_set_comp_sets:= true;
  177. end;
  178. {$endif}
  179. {$ifndef FPC_SYSTEM_HAS_FPC_SET_CONTAINS_SET}
  180. function fpc_set_contains_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_CONTAINS_SETS'];compilerproc;
  181. {
  182. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  183. }
  184. var
  185. i : integer;
  186. src1: fpc_normal_set_long absolute set1;
  187. src2: fpc_normal_set_long absolute set2;
  188. begin
  189. fpc_set_contains_sets:= false;
  190. for i:=0 to 7 do
  191. if (src1[i] and not src2[i]) <> 0 then
  192. exit;
  193. fpc_set_contains_sets:= true;
  194. end;
  195. {$endif}
  196. {$endif ndef FPC_NEW_BIGENDIAN_SETS}
  197. {****************************************************************************
  198. Var sets
  199. ****************************************************************************}
  200. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_LOAD_SMALL}
  201. {
  202. convert sets
  203. }
  204. procedure fpc_varset_load(const l;sourcesize : longint;var dest;size : ptrint); compilerproc;
  205. begin
  206. if sourcesize>size then
  207. sourcesize:=size;
  208. move(l,plongint(@dest)^,sourcesize);
  209. FillChar((@dest+sourcesize)^,size-sourcesize,0);
  210. end;
  211. {$endif ndef FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  212. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_CREATE_ELEMENT}
  213. {
  214. create a new set in p from an element b
  215. }
  216. procedure fpc_varset_create_element(b,size : ptrint; var data); compilerproc;
  217. type
  218. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  219. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  220. {$else}
  221. tbsetarray = bitpacked array[0..sizeof(sizeint)-1] of 0..1;
  222. {$endif}
  223. begin
  224. FillChar(data,size,0);
  225. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  226. tbytearray(data)[b div 8]:=1 shl (b mod 8);
  227. {$else}
  228. tbsetarray(data)[b]:=1;
  229. {$endif}
  230. end;
  231. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_CREATE_ELEMENT}
  232. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SET_BYTE}
  233. {
  234. add the element b to the set "source"
  235. }
  236. procedure fpc_varset_set(const source;var dest; b,size : ptrint); compilerproc;
  237. type
  238. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  239. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  240. {$else}
  241. tbsetarray = bitpacked array[0..sizeof(sizeint)-1] of 0..1;
  242. {$endif}
  243. begin
  244. move(source,dest,size);
  245. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  246. tbytearray(dest)[b div 8]:=tbytearray(dest)[b div 8] or (1 shl (b mod 8));
  247. {$else}
  248. tbsetarray(dest)[b]:=1;
  249. {$endif}
  250. end;
  251. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SET_BYTE}
  252. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_UNSET_BYTE}
  253. {
  254. suppresses the element b to the set pointed by p
  255. used for exclude(set,element)
  256. }
  257. procedure fpc_varset_unset(const source;var dest; b,size : ptrint); compilerproc;
  258. type
  259. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  260. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  261. {$else}
  262. tbsetarray = bitpacked array[0..sizeof(sizeint)-1] of 0..1;
  263. {$endif}
  264. begin
  265. move(source,dest,size);
  266. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  267. tbytearray(dest)[b div 8]:=tbytearray(dest)[b div 8] and not (1 shl (b mod 8));
  268. {$else}
  269. tbsetarray(dest)[b]:=0;
  270. {$endif}
  271. end;
  272. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_UNSET_BYTE}
  273. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SET_RANGE}
  274. {
  275. adds the range [l..h] to the set orgset
  276. }
  277. procedure fpc_varset_set_range(const orgset; var dest;l,h,size : ptrint); compilerproc;
  278. type
  279. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  280. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  281. {$else}
  282. tbsetarray = bitpacked array[0..sizeof(sizeint)-1] of 0..1;
  283. {$endif}
  284. var
  285. i : ptrint;
  286. begin
  287. move(orgset,dest,size);
  288. for i:=l to h do
  289. {$ifndef FPC_NEW_BIGENDIAN_SETS}
  290. tbytearray(dest)[i div 8]:=(1 shl (i mod 8)) or tbytearray(dest)[i div 8];
  291. {$else}
  292. tbsetarray(dest)[i]:=1;
  293. {$endif}
  294. end;
  295. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SET_RANGE}
  296. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_ADD_SETS}
  297. {
  298. adds set1 and set2 into set dest
  299. }
  300. procedure fpc_varset_add_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  301. type
  302. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  303. var
  304. i : ptrint;
  305. begin
  306. for i:=0 to size-1 do
  307. tbytearray(dest)[i]:=tbytearray(set1)[i] or tbytearray(set2)[i];
  308. end;
  309. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_ADD_SETS}
  310. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_MUL_SETS}
  311. {
  312. multiplies (takes common elements of) set1 and set2 result put in dest
  313. }
  314. procedure fpc_varset_mul_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  315. type
  316. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  317. var
  318. i : ptrint;
  319. begin
  320. for i:=0 to size-1 do
  321. tbytearray(dest)[i]:=tbytearray(set1)[i] and tbytearray(set2)[i];
  322. end;
  323. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_MUL_SETS}
  324. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SUB_SETS}
  325. {
  326. computes the diff from set1 to set2 result in dest
  327. }
  328. procedure fpc_varset_sub_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  329. type
  330. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  331. var
  332. i : ptrint;
  333. begin
  334. for i:=0 to size-1 do
  335. tbytearray(dest)[i]:=tbytearray(set1)[i] and not tbytearray(set2)[i];
  336. end;
  337. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SUB_SETS}
  338. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SYMDIF_SETS}
  339. {
  340. computes the symetric diff from set1 to set2 result in dest
  341. }
  342. procedure fpc_varset_symdif_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  343. type
  344. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  345. var
  346. i : ptrint;
  347. begin
  348. for i:=0 to size-1 do
  349. tbytearray(dest)[i]:=tbytearray(set1)[i] xor tbytearray(set2)[i];
  350. end;
  351. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SYMDIF_SETS}
  352. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_COMP_SETS}
  353. {
  354. compares set1 and set2 zeroflag is set if they are equal
  355. }
  356. function fpc_varset_comp_sets(const set1,set2;size : ptrint):boolean; compilerproc;
  357. type
  358. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  359. var
  360. i : ptrint;
  361. begin
  362. fpc_varset_comp_sets:= false;
  363. for i:=0 to size-1 do
  364. if tbytearray(set1)[i]<>tbytearray(set2)[i] then
  365. exit;
  366. fpc_varset_comp_sets:=true;
  367. end;
  368. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_COMP_SETS}
  369. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_CONTAINS_SET}
  370. {
  371. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  372. }
  373. function fpc_varset_contains_sets(const set1,set2;size : ptrint):boolean; compilerproc;
  374. type
  375. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  376. var
  377. i : ptrint;
  378. begin
  379. fpc_varset_contains_sets:= false;
  380. for i:=0 to size-1 do
  381. if (tbytearray(set1)[i] and not tbytearray(set2)[i])<>0 then
  382. exit;
  383. fpc_varset_contains_sets:=true;
  384. end;
  385. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_CONTAINS_SET}