genset.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2001 by the Free Pascal development team
  5. Include file with set operations called by the compiler
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  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']; {$ifdef hascompilerproc} compilerproc; {$endif}
  17. {
  18. load a normal set p from a smallset l
  19. }
  20. begin
  21. fpc_set_load_small[0] := l;
  22. FillDWord(fpc_set_load_small[1],7,0);
  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']; {$ifdef hascompilerproc} compilerproc; {$endif}
  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. fpc_set_create_element[b div 32] := 1 shl (b mod 32);
  33. end;
  34. {$endif FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
  35. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  36. {$ifdef hascompilerproc}
  37. function fpc_set_set_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  38. {
  39. add the element b to the set "source"
  40. }
  41. var
  42. c: longint;
  43. begin
  44. move(source,fpc_set_set_byte,sizeof(source));
  45. c := fpc_set_set_byte[b div 32];
  46. c := (1 shl (b mod 32)) or c;
  47. fpc_set_set_byte[b div 32] := c;
  48. end;
  49. {$else hascompilerproc}
  50. procedure do_set_byte(p : pointer;b : byte);[public,alias:'FPC_SET_SET_BYTE'];
  51. {
  52. add the element b to the set pointed by p
  53. }
  54. var
  55. c: longint;
  56. begin
  57. c := fpc_normal_set(p^)[b div 32];
  58. c := (1 shl (b mod 32)) or c;
  59. fpc_normal_set(p^)[b div 32] := c;
  60. end;
  61. {$endif hascompilerproc}
  62. {$endif FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  63. {$ifndef FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  64. {$ifdef hascompilerproc}
  65. function fpc_set_unset_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  66. {
  67. suppresses the element b to the set pointed by p
  68. used for exclude(set,element)
  69. }
  70. var
  71. c: longint;
  72. begin
  73. move(source,fpc_set_unset_byte,sizeof(source));
  74. c := fpc_set_unset_byte[b div 32];
  75. c := c and not (1 shl (b mod 32));
  76. fpc_set_unset_byte[b div 32] := c;
  77. end;
  78. {$else hascompilerproc}
  79. procedure do_unset_byte(p : pointer;b : byte);[public,alias:'FPC_SET_UNSET_BYTE'];
  80. {
  81. suppresses the element b to the set pointed by p
  82. used for exclude(set,element)
  83. }
  84. var
  85. c: longint;
  86. begin
  87. c := fpc_normal_set(p^)[b div 32];
  88. c := c and not (1 shl (b mod 32));
  89. fpc_normal_set(p^)[b div 32] := c;
  90. end;
  91. {$endif hascompilerproc}
  92. {$endif FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  93. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  94. {$ifdef hascompilerproc}
  95. function fpc_set_set_range(const orgset: fpc_normal_set; l,h : byte): fpc_normal_set; compilerproc;
  96. {
  97. adds the range [l..h] to the set orgset
  98. }
  99. var
  100. i: integer;
  101. c: longint;
  102. begin
  103. move(orgset,fpc_set_set_range,sizeof(orgset));
  104. for i:=l to h do
  105. begin
  106. c := fpc_set_set_range[i div 32];
  107. c := (1 shl (i mod 32)) or c;
  108. fpc_set_set_range[i div 32] := c;
  109. end;
  110. end;
  111. {$else hascompilerproc}
  112. procedure do_set_range(p : pointer;l,h : byte);[public,alias:'FPC_SET_SET_RANGE'];
  113. {
  114. bad implementation, but it's very seldom used
  115. }
  116. var
  117. i: integer;
  118. c: longint;
  119. begin
  120. for i:=l to h do
  121. begin
  122. c := fpc_normal_set(p^)[i div 32];
  123. c := (1 shl (i mod 32)) or c;
  124. fpc_normal_set(p^)[i div 32] := c;
  125. end;
  126. end;
  127. {$endif hascompilerproc}
  128. {$endif ndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  129. {$ifndef FPC_SYSTEM_HAS_FPC_SET_IN_BYTE}
  130. 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}
  131. {
  132. tests if the element b is in the set p the carryflag is set if it present
  133. }
  134. begin
  135. fpc_set_in_byte := (p[b div 32] and (1 shl (b mod 32))) <> 0;
  136. end;
  137. {$endif}
  138. {$ifndef FPC_SYSTEM_HAS_FPC_SET_ADD_SETS}
  139. {$ifdef hascompilerproc}
  140. function fpc_set_add_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_ADD_SETS']; compilerproc;
  141. var
  142. dest: fpc_normal_set absolute fpc_set_add_sets;
  143. {$else hascompilerproc}
  144. procedure do_add_sets(const set1,set2: fpc_normal_Set; var dest : fpc_normal_set);[public,alias:'FPC_SET_ADD_SETS'];
  145. {$endif hascompilerproc}
  146. {
  147. adds set1 and set2 into set dest
  148. }
  149. var
  150. i: integer;
  151. begin
  152. for i:=0 to 7 do
  153. dest[i] := set1[i] or set2[i];
  154. end;
  155. {$endif}
  156. {$ifndef FPC_SYSTEM_HAS_FPC_SET_MUL_SETS}
  157. {$ifdef hascompilerproc}
  158. function fpc_set_mul_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_MUL_SETS']; compilerproc;
  159. var
  160. dest: fpc_normal_set absolute fpc_set_mul_sets;
  161. {$else hascompilerproc}
  162. procedure do_mul_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_MUL_SETS'];
  163. {$endif hascompilerproc}
  164. {
  165. multiplies (takes common elements of) set1 and set2 result put in dest
  166. }
  167. var
  168. i: integer;
  169. begin
  170. for i:=0 to 7 do
  171. dest[i] := set1[i] and set2[i];
  172. end;
  173. {$endif}
  174. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SUB_SETS}
  175. {$ifdef hascompilerproc}
  176. function fpc_set_sub_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SUB_SETS']; compilerproc;
  177. var
  178. dest: fpc_normal_set absolute fpc_set_sub_sets;
  179. {$else hascompilerproc}
  180. procedure do_sub_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_SUB_SETS'];
  181. {$endif hascompilerproc}
  182. {
  183. computes the diff from set1 to set2 result in dest
  184. }
  185. var
  186. i: integer;
  187. begin
  188. for i:=0 to 7 do
  189. dest[i] := set1[i] and not set2[i];
  190. end;
  191. {$endif}
  192. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SYMDIF_SETS}
  193. {$ifdef hascompilerproc}
  194. function fpc_set_symdif_sets(const set1,set2: fpc_normal_set): fpc_normal_set;[public,alias:'FPC_SET_SYMDIF_SETS']; compilerproc;
  195. var
  196. dest: fpc_normal_set absolute fpc_set_symdif_sets;
  197. {$else hascompilerproc}
  198. procedure do_symdif_sets(const set1,set2: fpc_normal_set; var dest: fpc_normal_set);[public,alias:'FPC_SET_SYMDIF_SETS'];
  199. {$endif hascompilerproc}
  200. {
  201. computes the symetric diff from set1 to set2 result in dest
  202. }
  203. var
  204. i: integer;
  205. begin
  206. for i:=0 to 7 do
  207. dest[i] := set1[i] xor set2[i];
  208. end;
  209. {$endif}
  210. {$ifndef FPC_SYSTEM_HAS_FPC_SET_COMP_SETS}
  211. 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}
  212. {
  213. compares set1 and set2 zeroflag is set if they are equal
  214. }
  215. var
  216. i: integer;
  217. begin
  218. fpc_set_comp_sets:= false;
  219. for i:=0 to 7 do
  220. if set1[i] <> set2[i] then
  221. exit;
  222. fpc_set_comp_sets:= true;
  223. end;
  224. {$endif}
  225. {$ifndef FPC_SYSTEM_HAS_FPC_SET_CONTAINS_SET}
  226. function fpc_set_contains_sets(const set1,set2 : fpc_normal_set):boolean;[public,alias:'FPC_SET_CONTAINS_SETS'];{$ifdef hascompilerproc} compilerproc; {$else} saveregisters; {$endif}
  227. {
  228. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  229. }
  230. var
  231. i : integer;
  232. begin
  233. fpc_set_contains_sets:= false;
  234. for i:=0 to 7 do
  235. if (set1[i] and not set2[i]) <> 0 then
  236. exit;
  237. fpc_set_contains_sets:= true;
  238. end;
  239. {$endif}
  240. {
  241. $Log$
  242. Revision 1.8 2004-10-24 20:01:41 peter
  243. * saveregisters calling convention is obsolete
  244. Revision 1.7 2002/09/07 15:07:45 peter
  245. * old logs removed and tabs fixed
  246. }