genset.inc 11 KB

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