set.inc 10 KB

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