genset.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. {****************************************************************************
  12. Var sets
  13. ****************************************************************************}
  14. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_LOAD_SMALL}
  15. {
  16. convert sets
  17. }
  18. {$ifdef FPC_SETBASE_USED}
  19. procedure fpc_varset_load(const l;sourcesize : longint;var dest;size,srcminusdstbase : ptrint); compilerproc;
  20. var
  21. srcptr, dstptr: pointer;
  22. begin
  23. srcptr:=@l;
  24. dstptr:=@dest;
  25. { going from a higher base to a lower base, e.g.
  26. src: 001f0000, base=2,size=4 -> 0000001f0000 in base 0
  27. dstr in base = 1 (-> srcminusdstbase = 1) -> to
  28. 00001f0000, base=1 -> need to prepend "srcminusdstbase" zero bytes
  29. }
  30. if (srcminusdstbase>0) then
  31. begin
  32. { fill the skipped part with 0 }
  33. fillchar(dstptr^,srcminusdstbase,0);
  34. inc(dstptr,srcminusdstbase);
  35. dec(size,srcminusdstbase);
  36. end
  37. else if (srcminusdstbase<0) then
  38. begin
  39. { inc/dec switched since srcminusdstbase < 0 }
  40. dec(srcptr,srcminusdstbase);
  41. inc(sourcesize,srcminusdstbase);
  42. end;
  43. if sourcesize>size then
  44. sourcesize:=size;
  45. move(srcptr^,dstptr^,sourcesize);
  46. { fill the leftover (if any) with 0 }
  47. FillChar((dstptr+sourcesize)^,size-sourcesize,0);
  48. end;
  49. {$else FPC_SETBASE_USED}
  50. procedure fpc_varset_load(const l;sourcesize : longint;var dest;size : ptrint); compilerproc;
  51. begin
  52. if sourcesize>size then
  53. sourcesize:=size;
  54. move(l,plongint(@dest)^,sourcesize);
  55. FillChar((@dest+sourcesize)^,size-sourcesize,0);
  56. end;
  57. {$endif FPC_SETBASE_USED}
  58. {$endif ndef FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  59. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_CREATE_ELEMENT}
  60. {
  61. create a new set in p from an element b
  62. }
  63. procedure fpc_varset_create_element(b,size : ptrint; var data); compilerproc;
  64. type
  65. tbsetarray = bitpacked array[0..high(sizeint)-1] of 0..1;
  66. begin
  67. FillChar(data,size,0);
  68. tbsetarray(data)[b]:=1;
  69. end;
  70. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_CREATE_ELEMENT}
  71. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SET_BYTE}
  72. {
  73. add the element b to the set "source"
  74. }
  75. procedure fpc_varset_set(const source;var dest; b,size : ptrint); compilerproc;
  76. type
  77. tbsetarray = bitpacked array[0..high(sizeint)-1] of 0..1;
  78. begin
  79. move(source,dest,size);
  80. tbsetarray(dest)[b]:=1;
  81. end;
  82. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SET_BYTE}
  83. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_UNSET_BYTE}
  84. {
  85. suppresses the element b to the set pointed by p
  86. used for exclude(set,element)
  87. }
  88. procedure fpc_varset_unset(const source;var dest; b,size : ptrint); compilerproc;
  89. type
  90. tbsetarray = bitpacked array[0..high(sizeint)-1] of 0..1;
  91. begin
  92. move(source,dest,size);
  93. tbsetarray(dest)[b]:=0;
  94. end;
  95. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_UNSET_BYTE}
  96. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SET_RANGE}
  97. {
  98. adds the range [l..h] to the set orgset
  99. }
  100. procedure fpc_varset_set_range(const orgset; var dest;l,h,size : ptrint); compilerproc;
  101. type
  102. tbsetarray = bitpacked array[0..high(sizeint)-1] of 0..1;
  103. var
  104. i : ptrint;
  105. begin
  106. move(orgset,dest,size);
  107. for i:=l to h do
  108. tbsetarray(dest)[i]:=1;
  109. end;
  110. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SET_RANGE}
  111. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_ADD_SETS}
  112. {
  113. adds set1 and set2 into set dest
  114. }
  115. procedure fpc_varset_add_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  116. type
  117. tbytearray = array[0..high(sizeint)-1] of byte;
  118. var
  119. i : ptrint;
  120. begin
  121. for i:=0 to size-1 do
  122. tbytearray(dest)[i]:=tbytearray(set1)[i] or tbytearray(set2)[i];
  123. end;
  124. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_ADD_SETS}
  125. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_MUL_SETS}
  126. {
  127. multiplies (takes common elements of) set1 and set2 result put in dest
  128. }
  129. procedure fpc_varset_mul_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  130. type
  131. tbytearray = array[0..high(sizeint)-1] of byte;
  132. var
  133. i : ptrint;
  134. begin
  135. for i:=0 to size-1 do
  136. tbytearray(dest)[i]:=tbytearray(set1)[i] and tbytearray(set2)[i];
  137. end;
  138. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_MUL_SETS}
  139. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SUB_SETS}
  140. {
  141. computes the diff from set1 to set2 result in dest
  142. }
  143. procedure fpc_varset_sub_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  144. type
  145. tbytearray = array[0..high(sizeint)-1] of byte;
  146. var
  147. i : ptrint;
  148. begin
  149. for i:=0 to size-1 do
  150. tbytearray(dest)[i]:=tbytearray(set1)[i] and not tbytearray(set2)[i];
  151. end;
  152. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SUB_SETS}
  153. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_SYMDIF_SETS}
  154. {
  155. computes the symetric diff from set1 to set2 result in dest
  156. }
  157. procedure fpc_varset_symdif_sets(const set1,set2; var dest;size : ptrint); compilerproc;
  158. type
  159. tbytearray = array[0..high(sizeint)-1] of byte;
  160. var
  161. i : ptrint;
  162. begin
  163. for i:=0 to size-1 do
  164. tbytearray(dest)[i]:=tbytearray(set1)[i] xor tbytearray(set2)[i];
  165. end;
  166. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_SYMDIF_SETS}
  167. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_COMP_SETS}
  168. {
  169. compares set1 and set2 zeroflag is set if they are equal
  170. }
  171. function fpc_varset_comp_sets(const set1,set2;size : ptrint):boolean; compilerproc;
  172. type
  173. tbytearray = array[0..high(sizeint)-1] of byte;
  174. var
  175. i : ptrint;
  176. begin
  177. fpc_varset_comp_sets:= false;
  178. for i:=0 to size-1 do
  179. if tbytearray(set1)[i]<>tbytearray(set2)[i] then
  180. exit;
  181. fpc_varset_comp_sets:=true;
  182. end;
  183. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_COMP_SETS}
  184. {$ifndef FPC_SYSTEM_HAS_FPC_VARSET_CONTAINS_SET}
  185. {
  186. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  187. }
  188. function fpc_varset_contains_sets(const set1,set2;size : ptrint):boolean; compilerproc;
  189. type
  190. tbytearray = array[0..high(sizeint)-1] of byte;
  191. var
  192. i : ptrint;
  193. begin
  194. fpc_varset_contains_sets:= false;
  195. for i:=0 to size-1 do
  196. if (tbytearray(set1)[i] and not tbytearray(set2)[i])<>0 then
  197. exit;
  198. fpc_varset_contains_sets:=true;
  199. end;
  200. {$endif ndef FPC_SYSTEM_HAS_FPC_VARSET_CONTAINS_SET}