genset.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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}