genset.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. convert sets
  182. }
  183. procedure fpc_varset_load(const l;sourcesize : longint;var dest;size : ptrint); compilerproc;
  184. begin
  185. if sourcesize>size then
  186. sourcesize:=size;
  187. move(l,plongint(@dest)^,sourcesize);
  188. FillChar((@dest+sourcesize)^,size-sourcesize,0);
  189. end;
  190. {$endif ndef FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  191. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_CREATE_ELEMENT}
  192. {
  193. create a new set in p from an element b
  194. }
  195. procedure fpc_varset_create_element(b,size : ptrint; var data); compilerproc;
  196. type
  197. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  198. begin
  199. FillChar(data,size,0);
  200. tbytearray(data)[b div 8]:=1 shl (b mod 8);
  201. end;
  202. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_CREATE_ELEMENT}
  203. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SET_BYTE}
  204. {
  205. add the element b to the set "source"
  206. }
  207. procedure fpc_varset_set(const source;var dest; b,size : ptrint); compilerproc;
  208. type
  209. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  210. begin
  211. move(source,dest,size);
  212. tbytearray(dest)[b div 8]:=tbytearray(dest)[b div 8] or (1 shl (b mod 8));
  213. end;
  214. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SET_BYTE}
  215. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_UNSET_BYTE}
  216. {
  217. suppresses the element b to the set pointed by p
  218. used for exclude(set,element)
  219. }
  220. procedure fpc_varset_unset(const source;var dest; b,size : ptrint); compilerproc;
  221. type
  222. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  223. begin
  224. move(source,dest,size);
  225. tbytearray(dest)[b div 8]:=tbytearray(dest)[b div 8] and not (1 shl (b mod 8));
  226. end;
  227. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_UNSET_BYTE}
  228. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SET_RANGE}
  229. {
  230. adds the range [l..h] to the set orgset
  231. }
  232. procedure fpc_varset_set_range(const orgset; var dest;l,h,size : ptrint); compilerproc;
  233. type
  234. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  235. var
  236. i : ptrint;
  237. begin
  238. move(orgset,dest,size);
  239. for i:=l to h do
  240. tbytearray(dest)[i div 8]:=(1 shl (i mod 8)) or tbytearray(dest)[i div 8];
  241. end;
  242. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SET_RANGE}
  243. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_IN_BYTE}
  244. {
  245. tests if the element b is in the set p the carryflag is set if it present
  246. }
  247. function fpc_varset_in(const p; b : ptrint): boolean; compilerproc;
  248. type
  249. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  250. begin
  251. fpc_varset_in:=(tbytearray(p)[b div 8] and (1 shl (b mod 8)))<>0;
  252. end;
  253. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_IN_BYTE}
  254. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_ADD_SETS}
  255. {
  256. adds set1 and set2 into set dest
  257. }
  258. procedure fpc_varset_add_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  259. type
  260. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  261. var
  262. i : ptrint;
  263. begin
  264. for i:=0 to size-1 do
  265. tbytearray(dest)[i]:=tbytearray(set1)[i] or tbytearray(set2)[i];
  266. end;
  267. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_ADD_SETS}
  268. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_MUL_SETS}
  269. {
  270. multiplies (takes common elements of) set1 and set2 result put in dest
  271. }
  272. procedure fpc_varset_mul_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  273. type
  274. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  275. var
  276. i : ptrint;
  277. begin
  278. for i:=0 to size-1 do
  279. tbytearray(dest)[i]:=tbytearray(set1)[i] and tbytearray(set2)[i];
  280. end;
  281. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_MUL_SETS}
  282. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SUB_SETS}
  283. {
  284. computes the diff from set1 to set2 result in dest
  285. }
  286. procedure fpc_varset_sub_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  287. type
  288. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  289. var
  290. i : ptrint;
  291. begin
  292. for i:=0 to size-1 do
  293. tbytearray(dest)[i]:=tbytearray(set1)[i] and not tbytearray(set2)[i];
  294. end;
  295. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SUB_SETS}
  296. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SYMDIF_SETS}
  297. {
  298. computes the symetric diff from set1 to set2 result in dest
  299. }
  300. procedure fpc_varset_symdif_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] xor tbytearray(set2)[i];
  308. end;
  309. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SYMDIF_SETS}
  310. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_COMP_SETS}
  311. {
  312. compares set1 and set2 zeroflag is set if they are equal
  313. }
  314. function fpc_varset_comp_sets(const set1,set2;size : ptrint):boolean; compilerproc;
  315. type
  316. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  317. var
  318. i : ptrint;
  319. begin
  320. fpc_varset_comp_sets:= false;
  321. for i:=0 to size-1 do
  322. if tbytearray(set1)[i]<>tbytearray(set2)[i] then
  323. exit;
  324. fpc_varset_comp_sets:=true;
  325. end;
  326. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_COMP_SETS}
  327. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_CONTAINS_SET}
  328. {
  329. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  330. }
  331. function fpc_varset_contains_sets(const set1,set2;size : ptrint):boolean; compilerproc;
  332. type
  333. tbytearray = array[0..sizeof(sizeint)-1] of byte;
  334. var
  335. i : ptrint;
  336. begin
  337. fpc_varset_contains_sets:= false;
  338. for i:=0 to size-1 do
  339. if (tbytearray(set1)[i] and not tbytearray(set2)[i])<>0 then
  340. exit;
  341. fpc_varset_contains_sets:=true;
  342. end;
  343. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_CONTAINS_SET}