genset.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. TYPE
  13. { TNormalSet = array[0..31] of byte;}
  14. TNormalSet = array[0..7] of longint;
  15. {$ifndef FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  16. { Error No pascal version of FPC_SET_LOAD_SMALL}
  17. { THIS DEPENDS ON THE ENDIAN OF THE ARCHITECTURE!
  18. Not anymore PM}
  19. procedure do_load_small(p : pointer;l:longint);[public,alias:'FPC_SET_LOAD_SMALL'];
  20. {
  21. load a normal set p from a smallset l
  22. }
  23. begin
  24. Fillchar(p^,SizeOf(TNormalSet),#0);
  25. TNormalSet(p^)[0] := l;
  26. end;
  27. {$endif FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  28. {$ifndef FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
  29. procedure do_create_element(p : pointer;b : byte);[public,alias:'FPC_SET_CREATE_ELEMENT'];
  30. {
  31. create a new set in p from an element b
  32. }
  33. begin
  34. Fillchar(p^,SizeOf(TNormalSet),#0);
  35. TNormalSet(p^)[b div 32] := 1 shl (b mod 32);
  36. end;
  37. {$endif FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
  38. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  39. procedure do_set_byte(p : pointer;b : byte);[public,alias:'FPC_SET_SET_BYTE'];
  40. {
  41. add the element b to the set pointed by p
  42. }
  43. var
  44. c: longint;
  45. begin
  46. c := TNormalSet(p^)[b div 32];
  47. c := (1 shl (b mod 32)) or c;
  48. TNormalSet(p^)[b div 32] := c;
  49. end;
  50. {$endif FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  51. {$ifndef FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  52. procedure do_unset_byte(p : pointer;b : byte);[public,alias:'FPC_SET_UNSET_BYTE'];
  53. {
  54. suppresses the element b to the set pointed by p
  55. used for exclude(set,element)
  56. }
  57. var
  58. c: longint;
  59. begin
  60. c := TNormalSet(p^)[b div 32];
  61. c := c and not (1 shl (b mod 32));
  62. TNormalSet(p^)[b div 32] := c;
  63. end;
  64. {$endif FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  65. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  66. procedure do_set_range(p : pointer;l,h : byte);[public,alias:'FPC_SET_SET_RANGE'];
  67. {
  68. bad implementation, but it's very seldom used
  69. }
  70. var
  71. i: integer;
  72. c: longint;
  73. begin
  74. for i:=l to h do
  75. begin
  76. c := TNormalSet(p^)[i div 32];
  77. c := (1 shl (i mod 32)) or c;
  78. TNormalSet(p^)[i div 32] := c;
  79. end;
  80. end;
  81. {$endif}
  82. {$ifndef FPC_SYSTEM_HAS_FPC_SET_IN_BYTE}
  83. { saveregisters is a bit of overkill, but this routine should save all registers }
  84. { and it should be overriden for each platform and be written in assembler }
  85. { by saving all required registers. }
  86. function do_in_byte(p : pointer;b : byte):boolean;[public,alias:'FPC_SET_IN_BYTE'];saveregisters;
  87. {
  88. tests if the element b is in the set p the carryflag is set if it present
  89. }
  90. var
  91. c: longint;
  92. begin
  93. c := TNormalSet(p^)[b div 32];
  94. if ((1 shl (b mod 32)) and c) <> 0 then
  95. do_in_byte := TRUE
  96. else
  97. do_in_byte := FALSE;
  98. end;
  99. {$endif}
  100. {$ifndef FPC_SYSTEM_HAS_FPC_SET_ADD_SETS}
  101. procedure do_add_sets(set1,set2,dest : pointer);[public,alias:'FPC_SET_ADD_SETS'];
  102. {
  103. adds set1 and set2 into set dest
  104. }
  105. var
  106. i: integer;
  107. begin
  108. for i:=0 to 7 do
  109. TnormalSet(dest^)[i] := TNormalSet(set1^)[i] or TNormalSet(set2^)[i];
  110. end;
  111. {$endif}
  112. {$ifndef FPC_SYSTEM_HAS_FPC_SET_MUL_SETS}
  113. procedure do_mul_sets(set1,set2,dest:pointer);[public,alias:'FPC_SET_MUL_SETS'];
  114. {
  115. multiplies (takes common elements of) set1 and set2 result put in dest
  116. }
  117. var
  118. i: integer;
  119. begin
  120. for i:=0 to 7 do
  121. TnormalSet(dest^)[i] := TNormalSet(set1^)[i] and TNormalSet(set2^)[i];
  122. end;
  123. {$endif}
  124. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SUB_SETS}
  125. procedure do_sub_sets(set1,set2,dest:pointer);[public,alias:'FPC_SET_SUB_SETS'];
  126. {
  127. computes the diff from set1 to set2 result in dest
  128. }
  129. var
  130. i: integer;
  131. begin
  132. for i:=0 to 7 do
  133. TnormalSet(dest^)[i] := TNormalSet(set1^)[i] and not TNormalSet(set2^)[i];
  134. end;
  135. {$endif}
  136. {$ifndef FPC_SYSTEM_HAS_FPC_SET_SYMDIF_SETS}
  137. procedure do_symdif_sets(set1,set2,dest:pointer);[public,alias:'FPC_SET_SYMDIF_SETS'];
  138. {
  139. computes the symetric diff from set1 to set2 result in dest
  140. }
  141. var
  142. i: integer;
  143. begin
  144. for i:=0 to 7 do
  145. TnormalSet(dest^)[i] := TNormalSet(set1^)[i] xor TNormalSet(set2^)[i];
  146. end;
  147. {$endif}
  148. {$ifndef FPC_SYSTEM_HAS_FPC_SET_COMP_SETS}
  149. { saveregisters is a bit of overkill, but this routine should save all registers }
  150. { and it should be overriden for each platform and be written in assembler }
  151. { by saving all required registers. }
  152. function do_comp_sets(set1,set2 : pointer):boolean;[public,alias:'FPC_SET_COMP_SETS'];saveregisters;
  153. {
  154. compares set1 and set2 zeroflag is set if they are equal
  155. }
  156. var
  157. i: integer;
  158. begin
  159. do_comp_sets := false;
  160. for i:=0 to 7 do
  161. if TNormalSet(set1^)[i] <> TNormalSet(set2^)[i] then
  162. exit;
  163. do_comp_sets := true;
  164. end;
  165. {$endif}
  166. {$ifndef FPC_SYSTEM_HAS_FPC_SET_CONTAINS_SET}
  167. { saveregisters is a bit of overkill, but this routine should save all registers }
  168. { and it should be overriden for each platform and be written in assembler }
  169. { by saving all required registers. }
  170. function do_contains_sets(set1,set2 : pointer):boolean;[public,alias:'FPC_SET_CONTAINS_SETS'];saveregisters;
  171. {
  172. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  173. }
  174. var
  175. i : integer;
  176. begin
  177. do_contains_sets := false;
  178. for i:=0 to 7 do
  179. if (TNormalSet(set1^)[i] and TNormalSet(set2^)[i]) <> TNormalSet(set1^)[i] then
  180. exit;
  181. do_contains_sets := true;
  182. end;
  183. {$endif}
  184. {
  185. $Log$
  186. Revision 1.4 2001-06-27 21:37:38 peter
  187. * v10 merges
  188. Revision 1.3 2001/05/18 22:59:59 peter
  189. * merged fixes branch fixes
  190. Revision 1.2 2001/05/09 19:57:07 peter
  191. *** empty log message ***
  192. }