genset.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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']; {$ifdef hascompilerproc} compilerproc; {$endif}
  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']; {$ifdef hascompilerproc} compilerproc; {$endif}
  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. {$ifdef hascompilerproc}
  36. function fpc_set_set_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  37. {
  38. add the element b to the set "source"
  39. }
  40. var
  41. c: longint;
  42. begin
  43. move(source,fpc_set_set_byte,sizeof(source));
  44. c := fpc_set_set_byte[b div 32];
  45. c := (1 shl (b mod 32)) or c;
  46. fpc_set_set_byte[b div 32] := c;
  47. end;
  48. {$else hascompilerproc}
  49. procedure do_set_byte(p : pointer;b : byte);[public,alias:'FPC_SET_SET_BYTE'];
  50. {
  51. add the element b to the set pointed by p
  52. }
  53. var
  54. c: longint;
  55. begin
  56. c := fpc_normal_set(p^)[b div 32];
  57. c := (1 shl (b mod 32)) or c;
  58. fpc_normal_set(p^)[b div 32] := c;
  59. end;
  60. {$endif hascompilerproc}
  61. {$endif FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  62. {$ifndef FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  63. {$ifdef hascompilerproc}
  64. function fpc_set_unset_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  65. {
  66. suppresses the element b to the set pointed by p
  67. used for exclude(set,element)
  68. }
  69. var
  70. c: longint;
  71. begin
  72. move(source,fpc_set_unset_byte,sizeof(source));
  73. c := fpc_set_unset_byte[b div 32];
  74. c := c and not (1 shl (b mod 32));
  75. fpc_set_unset_byte[b div 32] := c;
  76. end;
  77. {$else hascompilerproc}
  78. procedure do_unset_byte(p : pointer;b : byte);[public,alias:'FPC_SET_UNSET_BYTE'];
  79. {
  80. suppresses the element b to the set pointed by p
  81. used for exclude(set,element)
  82. }
  83. var
  84. c: longint;
  85. begin
  86. c := fpc_normal_set(p^)[b div 32];
  87. c := c and not (1 shl (b mod 32));
  88. fpc_normal_set(p^)[b div 32] := c;
  89. end;
  90. {$endif hascompilerproc}
  91. {$endif FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  92. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  93. {$ifdef hascompilerproc}
  94. function fpc_set_set_range(const orgset: fpc_normal_set; l,h : byte): fpc_normal_set; compilerproc;
  95. {
  96. adds the range [l..h] to the set orgset
  97. }
  98. var
  99. i: integer;
  100. c: longint;
  101. begin
  102. move(orgset,fpc_set_set_range,sizeof(orgset));
  103. for i:=l to h do
  104. begin
  105. c := fpc_set_set_range[i div 32];
  106. c := (1 shl (i mod 32)) or c;
  107. fpc_set_set_range[i div 32] := c;
  108. end;
  109. end;
  110. {$else hascompilerproc}
  111. procedure do_set_range(p : pointer;l,h : byte);[public,alias:'FPC_SET_SET_RANGE'];
  112. {
  113. bad implementation, but it's very seldom used
  114. }
  115. var
  116. i: integer;
  117. c: longint;
  118. begin
  119. for i:=l to h do
  120. begin
  121. c := fpc_normal_set(p^)[i div 32];
  122. c := (1 shl (i mod 32)) or c;
  123. fpc_normal_set(p^)[i div 32] := c;
  124. end;
  125. end;
  126. {$endif hascompilerproc}
  127. {$endif ndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  128. {$ifndef FPC_SYSTEM_HAS_FPC_SET_IN_BYTE}
  129. function fpc_set_in_byte(const p: fpc_normal_set; b: byte): boolean; [public,alias:'FPC_SET_IN_BYTE']; {$ifdef hascompilerproc} compilerproc; {$else} {$ifndef NOSAVEREGISTERS}saveregisters;{$endif} {$endif}
  130. {
  131. tests if the element b is in the set p the carryflag is set if it present
  132. }
  133. begin
  134. fpc_set_in_byte := (p[b div 32] and (1 shl (b mod 32))) <> 0;
  135. end;
  136. {$endif}
  137. {$ifndef FPC_SYSTEM_HAS_FPC_SET_ADD_SETS}
  138. {$ifdef hascompilerproc}
  139. function fpc_set_add_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_ADD_SETS']; compilerproc;
  140. var
  141. dest: fpc_normal_set absolute fpc_set_add_sets;
  142. {$else hascompilerproc}
  143. procedure do_add_sets(const set1,set2: fpc_normal_Set; var dest : fpc_normal_set);[public,alias:'FPC_SET_ADD_SETS'];
  144. {$endif hascompilerproc}
  145. {
  146. adds set1 and set2 into set dest
  147. }
  148. var
  149. i: integer;
  150. begin
  151. for i:=0 to 7 do
  152. dest[i] := set1[i] or set2[i];
  153. end;
  154. {$endif}
  155. {$ifndef FPC_SYSTEM_HAS_FPC_SET_MUL_SETS}
  156. {$ifdef hascompilerproc}
  157. function fpc_set_mul_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_MUL_SETS']; compilerproc;
  158. var
  159. dest: fpc_normal_set absolute fpc_set_mul_sets;
  160. {$else hascompilerproc}
  161. procedure do_mul_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_MUL_SETS'];
  162. {$endif hascompilerproc}
  163. {
  164. multiplies (takes common elements of) set1 and set2 result put in dest
  165. }
  166. var
  167. i: integer;
  168. begin
  169. for i:=0 to 7 do
  170. dest[i] := set1[i] and set2[i];
  171. end;
  172. {$endif}
  173. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SUB_SETS}
  174. {$ifdef hascompilerproc}
  175. function fpc_set_sub_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SUB_SETS']; compilerproc;
  176. var
  177. dest: fpc_normal_set absolute fpc_set_sub_sets;
  178. {$else hascompilerproc}
  179. procedure do_sub_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_SUB_SETS'];
  180. {$endif hascompilerproc}
  181. {
  182. computes the diff from set1 to set2 result in dest
  183. }
  184. var
  185. i: integer;
  186. begin
  187. for i:=0 to 7 do
  188. dest[i] := set1[i] and not set2[i];
  189. end;
  190. {$endif}
  191. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SYMDIF_SETS}
  192. {$ifdef hascompilerproc}
  193. function fpc_set_symdif_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SYMDIF_SETS']; compilerproc;
  194. var
  195. dest: fpc_normal_set absolute fpc_set_symdif_sets;
  196. {$else hascompilerproc}
  197. procedure do_symdif_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_SYMDIF_SETS'];
  198. {$endif hascompilerproc}
  199. {
  200. computes the symetric diff from set1 to set2 result in dest
  201. }
  202. var
  203. i: integer;
  204. begin
  205. for i:=0 to 7 do
  206. dest[i] := set1[i] xor set2[i];
  207. end;
  208. {$endif}
  209. {$ifndef FPC_SYSTEM_HAS_FPC_SET_COMP_SETS}
  210. function fpc_set_comp_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_COMP_SETS'];{$ifdef hascompilerproc} compilerproc; {$else} {$ifndef NOSAVEREGISTERS}saveregisters;{$endif} {$endif}
  211. {
  212. compares set1 and set2 zeroflag is set if they are equal
  213. }
  214. var
  215. i: integer;
  216. begin
  217. fpc_set_comp_sets:= false;
  218. for i:=0 to 7 do
  219. if set1[i] <> set2[i] then
  220. exit;
  221. fpc_set_comp_sets:= true;
  222. end;
  223. {$endif}
  224. {$ifndef FPC_SYSTEM_HAS_FPC_SET_CONTAINS_SET}
  225. function fpc_set_contains_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_CONTAINS_SETS'];{$ifdef hascompilerproc} compilerproc; {$else} saveregisters; {$endif}
  226. {
  227. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  228. }
  229. var
  230. i : integer;
  231. begin
  232. fpc_set_contains_sets:= false;
  233. for i:=0 to 7 do
  234. if (set1[i] and not set2[i]) <> 0 then
  235. exit;
  236. fpc_set_contains_sets:= true;
  237. end;
  238. {$endif}
  239. {
  240. $Log: genset.inc,v $
  241. Revision 1.9 2005/02/14 17:13:22 peter
  242. * truncate log
  243. }