set.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Jonas Maebe, member of the
  4. 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. {$ifdef FPC_OLD_BIGENDIAN_SETS}
  13. {$define FPC_SYSTEM_HAS_FPC_SET_LOAD_SMALL}
  14. function fpc_set_load_small(l: fpc_small_set): fpc_normal_set;assembler;[public,alias:'FPC_SET_LOAD_SMALL']; compilerproc;
  15. {
  16. load a normal set p from a smallset l
  17. on entry: p in r3, l in r4
  18. }
  19. asm
  20. stw r4,0(r3)
  21. li r0,0
  22. stw r0,4(r3)
  23. stw r0,8(r3)
  24. stw r0,12(r3)
  25. stw r0,16(r3)
  26. stw r0,20(r3)
  27. stw r0,24(r3)
  28. stw r0,28(r3)
  29. end;
  30. {$define FPC_SYSTEM_HAS_FPC_SET_CREATE_ELEMENT}
  31. { checked 2001/09/28 (JM) }
  32. function fpc_set_create_element(b : byte): fpc_normal_set;assembler;[public,alias:'FPC_SET_CREATE_ELEMENT']; compilerproc;
  33. {
  34. create a new set in p from an element b
  35. on entry: pointer to result in r3, b in r4
  36. }
  37. asm
  38. li r0,0
  39. stw r0,0(r3)
  40. stw r0,4(r3)
  41. stw r0,8(r3)
  42. stw r0,12(r3)
  43. stw r0,16(r3)
  44. stw r0,20(r3)
  45. stw r0,24(r3)
  46. stw r0,28(r3)
  47. // r0 := 1 shl r4[27-31] -> bit index in dword (rotate instructions
  48. // with count in register only consider lower 5 bits of this register)
  49. li r0,1
  50. rlwnm r0,r0,r4,0,31
  51. // get the index of the correct *dword* in the set
  52. // (((b div 8) div 4)*4= (b div 8) and not(3))
  53. // r5 := (r4 rotl(32-3)) and (0x01ffffff8)
  54. rlwinm r4,r4,31-3+1,3,31-2
  55. // store the result
  56. stwx r0,r3,r4
  57. end;
  58. {$define FPC_SYSTEM_HAS_FPC_SET_SET_BYTE}
  59. function fpc_set_set_byte(const source: fpc_normal_set; b : byte): fpc_normal_set;assembler; compilerproc;
  60. {
  61. add the element b to the set pointed by p
  62. on entry: result in r3, source in r4, b in r5
  63. }
  64. asm
  65. // copy source to result
  66. lfd f0,0(r4)
  67. lfd f1,8(r4)
  68. lfd f2,16(r4)
  69. lfd f3,24(r4)
  70. stfd f0,0(r3)
  71. stfd f1,8(r3)
  72. stfd f2,16(r3)
  73. stfd f3,24(r3)
  74. // get the index of the correct *dword* in the set
  75. // r0 := (r5 rotl(32-3)) and (0x0fffffff8)
  76. rlwinm r0,r5,31-3+1,3,31-2
  77. // load dword in which the bit has to be set (and update r3 to this address)
  78. lwzux r4,r3,r0
  79. li r0,1
  80. // generate bit which has to be inserted
  81. // (can't use rlwimi, since that one only works for constants)
  82. rlwnm r5,r0,r5,0,31
  83. // insert it
  84. or r5,r4,r5
  85. // store result
  86. stw r5,0(r3)
  87. end;
  88. {$define FPC_SYSTEM_HAS_FPC_SET_UNSET_BYTE}
  89. function fpc_set_unset_byte(const source: fpc_normal_set; b : byte): fpc_normal_set;assembler; compilerproc;
  90. {
  91. suppresses the element b to the set pointed by p
  92. used for exclude(set,element)
  93. on entry: p in r3, b in r4
  94. }
  95. asm
  96. // copy source to result
  97. lfd f0,0(r4)
  98. lfd f1,8(r4)
  99. lfd f2,16(r4)
  100. lfd f3,24(r4)
  101. stfd f0,0(r3)
  102. stfd f1,8(r3)
  103. stfd f2,16(r3)
  104. stfd f3,24(r3)
  105. // get the index of the correct *dword* in the set
  106. // r0 := (r4 rotl(32-3)) and (0x0fffffff8)
  107. rlwinm r0,r5,31-3+1,3,31-2
  108. // load dword in which the bit has to be set (and update r3 to this address)
  109. lwzux r4,r3,r0
  110. li r0,1
  111. // generate bit which has to be removed
  112. rlwnm r5,r0,r5,0,31
  113. // remove it
  114. andc r5,r4,r5
  115. // store result
  116. stw r4,0(r3)
  117. end;
  118. {$define FPC_SYSTEM_HAS_FPC_SET_SET_RANGE}
  119. function fpc_set_set_range(const orgset: fpc_normal_set; l,h : byte): fpc_normal_set;assembler; compilerproc;
  120. {
  121. on entry: result in r3, l in r4, h in r5
  122. on entry: result in r3, ptr to orgset in r4, l in r5, h in r6
  123. }
  124. asm
  125. // copy source to result
  126. lfd f0,0(r4)
  127. lfd f1,8(r4)
  128. lfd f2,16(r4)
  129. lfd f3,24(r4)
  130. stfd f0,0(r3)
  131. stfd f1,8(r3)
  132. stfd f2,16(r3)
  133. stfd f3,24(r3)
  134. cmplw cr0,r5,r6
  135. bgt cr0,.Lset_range_exit
  136. rlwinm r4,r5,31-3+1,3,31-2 // divide by 8 to get starting and ending byte-
  137. { load the set the data cache }
  138. dcbtst r3,r4
  139. rlwinm r9,r6,31-3+1,3,31-2 // address and clear two lowest bits to get
  140. // start/end longint address
  141. sub. r9,r9,r4 // are bit lo and hi in the same longint?
  142. rlwinm r6,r6,0,31-5+1,31 // hi := hi mod 32 (= "hi and 31", but the andi
  143. // instr. only exists in flags modifying form)
  144. rlwinm r5,r5,0,31-5+1,31 // lo := lo mod 32 (= "lo and 31", but the andi
  145. // instr. only exists in flags modifying form)
  146. li r10,-1 // r10 = $0x0ffffffff = bitmask to be inserted
  147. subfic r6,r6,31 // hi := 31 - (hi mod 32) = shift count for later
  148. slw r10,r10,r5 // shift bitmask to clear bits below lo
  149. lwzux r5,r3,r4 // go to starting pos in set and load value
  150. // (lo is not necessary anymore)
  151. beq .Lset_range_hi // if bit lo and hi in same longint, keep
  152. // current mask and adjust for hi bit
  153. subic. r9,r9,4 // bit hi in next longint?
  154. or r5,r5,r10 // merge and
  155. stw r5,0(r3) // store current mask
  156. li r10,-1 // new mask
  157. lwzu r5,4(r3) // load next longint of set
  158. beq .Lset_range_hi // bit hi in this longint -> go to adjust for hi
  159. subi r3,r3,4
  160. .Lset_range_loop:
  161. subic. r9,r9,4
  162. stwu r10,4(r3) // fill longints in between with full mask
  163. bne .Lset_range_loop
  164. lwzu r5,4(r3) // load next value from set
  165. .Lset_range_hi: // in all cases, r3 here contains the address of
  166. // the longint which contains the hi bit and r4
  167. // contains this longint
  168. srw r9,r10,r6 // r9 := bitmask shl (31 - (hi mod 32)) =
  169. // bitmask with bits higher than hi cleared
  170. // (r8 = $0xffffffff unless the first beq was
  171. // taken)
  172. and r10,r9,r10 // combine lo and hi bitmasks for this longint
  173. or r5,r5,r10 // and combine with existing set
  174. stw r5,0(r3) // store to set
  175. .Lset_range_exit:
  176. end;
  177. {$define FPC_SYSTEM_HAS_FPC_SET_ADD_SETS}
  178. function fpc_set_add_sets(const set1,set2: fpc_normal_set): fpc_normal_set;assembler;[public,alias:'FPC_SET_ADD_SETS']; compilerproc;
  179. {
  180. adds set1 and set2 into set dest
  181. on entry: result in r3, set1 in r4, set2 in r5
  182. }
  183. asm
  184. { load the begin of the result set in the data cache }
  185. dcbtst 0,r3
  186. li r0,8
  187. mtctr r0
  188. subi r5,r5,4
  189. subi r4,r4,4
  190. subi r3,r3,4
  191. .LMADDSETS1:
  192. lwzu r0,4(r4)
  193. lwzu r10,4(r5)
  194. or r0,r0,r10
  195. stwu r0,4(r3)
  196. bdnz .LMADDSETS1
  197. end;
  198. {$define FPC_SYSTEM_HAS_FPC_SET_MUL_SETS}
  199. function fpc_set_mul_sets(const set1,set2: fpc_normal_set): fpc_normal_set;assembler;[public,alias:'FPC_SET_MUL_SETS']; compilerproc;
  200. {
  201. multiplies (takes common elements of) set1 and set2 result put in dest
  202. on entry: result in r3, set1 in r4, set2 in r5
  203. }
  204. asm
  205. { load the begin of the result set in the data cache }
  206. dcbtst 0,r3
  207. li r0,8
  208. mtctr r0
  209. subi r5,r5,4
  210. subi r4,r4,4
  211. subi r3,r3,4
  212. .LMMULSETS1:
  213. lwzu r0,4(r4)
  214. lwzu r10,4(r5)
  215. and r0,r0,r10
  216. stwu r0,4(r3)
  217. bdnz .LMMULSETS1
  218. end;
  219. {$define FPC_SYSTEM_HAS_FPC_SET_SUB_SETS}
  220. function fpc_set_sub_sets(const set1,set2: fpc_normal_set): fpc_normal_set;assembler;[public,alias:'FPC_SET_SUB_SETS']; compilerproc;
  221. {
  222. computes the diff from set1 to set2 result in dest
  223. on entry: result in r3, set1 in r4, set2 in r5
  224. }
  225. asm
  226. { load the begin of the result set in the data cache }
  227. dcbtst 0,r3
  228. li r0,8
  229. mtctr r0
  230. subi r5,r5,4
  231. subi r4,r4,4
  232. subi r3,r3,4
  233. .LMSUBSETS1:
  234. lwzu r0,4(r4)
  235. lwzu r10,4(r5)
  236. andc r0,r0,r10
  237. stwu r0,4(r3)
  238. bdnz .LMSUBSETS1
  239. end;
  240. {$define FPC_SYSTEM_HAS_FPC_SET_SYMDIF_SETS}
  241. function fpc_set_symdif_sets(const set1,set2: fpc_normal_set): fpc_normal_set;assembler;[public,alias:'FPC_SET_SYMDIF_SETS']; compilerproc;
  242. {
  243. computes the symetric diff from set1 to set2 result in dest
  244. on entry: result in r3, set1 in r4, set2 in r5
  245. }
  246. asm
  247. { load the begin of the result set in the data cache }
  248. dcbtst 0,r3
  249. li r0,8
  250. mtctr r0
  251. subi r5,r5,4
  252. subi r4,r4,4
  253. subi r3,r3,4
  254. .LMSYMDIFSETS1:
  255. lwzu r0,4(r4)
  256. lwzu r10,4(r5)
  257. xor r0,r0,r10
  258. stwu r0,4(r3)
  259. bdnz .LMSYMDIFSETS1
  260. end;
  261. {$define FPC_SYSTEM_HAS_FPC_SET_COMP_SETS}
  262. function fpc_set_comp_sets(const set1,set2: fpc_normal_set): boolean;assembler;[public,alias:'FPC_SET_COMP_SETS']; compilerproc;
  263. {
  264. compares set1 and set2 zeroflag is set if they are equal
  265. on entry: set1 in r3, set2 in r4
  266. }
  267. asm
  268. li r0,8
  269. mtctr r0
  270. subi r3,r3,4
  271. subi r4,r4,4
  272. .LMCOMPSETS1:
  273. lwzu r0,4(r3)
  274. lwzu r10,4(r4)
  275. sub. r0,r0,r10
  276. bdnzt cr0*4+eq,.LMCOMPSETS1
  277. cntlzw r3,r0
  278. srwi. r3,r3,5
  279. end;
  280. {$define FPC_SYSTEM_HAS_FPC_SET_CONTAINS_SET}
  281. function fpc_set_contains_sets(const set1,set2: fpc_normal_set): boolean;assembler;[public,alias:'FPC_SET_CONTAINS_SETS']; compilerproc;
  282. {
  283. on exit, zero flag is set if set1 <= set2 (set2 contains set1)
  284. on entry: set1 in r3, set2 in r4
  285. }
  286. asm
  287. li r0,8
  288. mtctr r0
  289. subi r3,r3,4
  290. subi r4,r4,4
  291. .LMCONTAINSSETS1:
  292. lwzu r0,4(r3)
  293. lwzu r10,4(r4)
  294. { set1 and not(set2) = 0? }
  295. andc. r0,r0,r10
  296. bdnzt cr0*4+eq,.LMCONTAINSSETS1
  297. cntlzw r3,r0
  298. srwi. r3,r3,5
  299. end;
  300. {$endif FPC_OLD_BIGENDIAN_SETS}