set.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Carl-Eric Codere,
  4. member of the Free Pascal development team.
  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. { Converted by Carl Eric Codere }
  13. {*************************************************************************}
  14. { This inc. implements low-level set operations for the motorola }
  15. { 68000 familiy of processors. }
  16. { Based on original code bt Florian Kl„mpfl for the 80x86. }
  17. {*************************************************************************}
  18. { Edit by Sven: No m68k specific set routines for now (doesn't seem to be
  19. compatible to the way FPC handles sets today anyway...) }
  20. {$ifdef use_m68k_sets}
  21. { add the element b to the set pointed by p }
  22. { On entry }
  23. { a0 = pointer to set }
  24. { d0.b = element to add to the set }
  25. { Registers destroyed: d0,a1,d6 }
  26. procedure do_set;assembler;
  27. asm
  28. XDEF SET_SET_BYTE
  29. move.l d0,d6
  30. { correct long position: }
  31. { -> (value div 32)*4 = longint }
  32. { (value shr 5)*shl 2 }
  33. lsr.l #5,d6
  34. lsl.l #2,d6
  35. adda.l d6,a0 { correct offset from start address of set }
  36. move.l d0,d6 { bit is now in here }
  37. andi.l #31,d0 { bit number is = value mod 32 }
  38. { now bit set the value }
  39. move.l (a0),d0 { we must put bits into register }
  40. bset.l d6,d0 { otherwise btst will be a byte }
  41. { put result in carry flag } { operation. }
  42. bne @LDOSET1
  43. andi.b #$fe,ccr { clear carry flag }
  44. bra @LDOSET2
  45. @LDOSET1:
  46. ori.b #$01,ccr { set carry flag }
  47. @LDOSET2:
  48. move.l d0,(a0) { restore the value at that location }
  49. { of the set. }
  50. end;
  51. { Finds an element in a set }
  52. { a0 = address of set }
  53. { d0.b = value to compare with }
  54. { CARRY SET IF FOUND ON EXIT }
  55. { Registers destroyed: d0,a0,d6 }
  56. procedure do_in; assembler;
  57. { Returns Carry set then = in set , otherwise carry is cleared }
  58. { (D0) }
  59. asm
  60. XDEF SET_IN_BYTE
  61. move.l d0,d6
  62. { correct long position: }
  63. { -> (value div 32)*4 = longint }
  64. { (value shr 5)*shl 2 }
  65. lsr.l #5,d6
  66. lsl.l #2,d6
  67. adda.l d6,a0 { correct offset from start address of set }
  68. move.l d0,d6 { bit is now in here }
  69. andi.l #31,d0 { bit number is = value mod 32 }
  70. move.l (a0),d0 { we must put bits into register }
  71. btst.l d6,d0 { otherwise btst will be a byte }
  72. { put result in carry flag } { operation. }
  73. bne @LDOIN1
  74. andi.b #$fe,ccr { clear carry flag }
  75. bra @LDOIN2
  76. @LDOIN1:
  77. ori.b #$01,ccr { set carry flag }
  78. @LDOIN2:
  79. end;
  80. { vereinigt set1 und set2 und speichert das Ergebnis in dest }
  81. procedure add_sets(set1,set2,dest : pointer);[public,alias: 'SET_ADD_SETS'];
  82. { PSEUDO-CODE:
  83. type
  84. destination = array[1..8] of longint;
  85. for i:=1 to 8 do
  86. destination(dest^)[i] := destination(set1^)[i] OR destination(set2^)[i];
  87. }
  88. begin
  89. asm
  90. { saved used register }
  91. move.l a2,-(sp)
  92. move.l 8(a6),a0
  93. move.l 12(a6),a1
  94. move.l 16(a6),a2
  95. move.l #32,d6
  96. @LMADDSETS1:
  97. move.b (a0)+,d0
  98. or.b (a1)+,d0
  99. move.b d0,(a2)+
  100. subq.b #1,d6
  101. bne @LMADDSETS1
  102. { restore register }
  103. move.l a2,(sp)+
  104. end ['d0','d6','a0','a1'];
  105. end;
  106. { computes the symetric diff from set1 to set2 }
  107. { result in dest }
  108. procedure sym_sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SYMDIF_SETS'];
  109. begin
  110. asm
  111. { saved used register }
  112. move.l a2,-(sp)
  113. move.l 8(a6),a0
  114. move.l 12(a6),a1
  115. move.l 16(a6),a2
  116. move.l #32,d6
  117. @LMADDSETS1:
  118. move.b (a0)+,d0
  119. move.b (a1)+,d1
  120. eor.b d1,d0
  121. move.b d0,(a2)+
  122. subq.b #1,d6
  123. bne @LMADDSETS1
  124. { restore register }
  125. move.l a2,(sp)+
  126. end;
  127. end;
  128. { bad implementation, but it's very seldom used }
  129. procedure do_set(p : pointer;l,h : byte);[public,alias: 'SET_SET_RANGE'];
  130. begin
  131. asm
  132. move.b h,d0
  133. @LSetRLoop:
  134. cmp.b l,d0
  135. blt @Lend
  136. move.w d0,-(sp)
  137. { adjust value to correct endian }
  138. lsl.w #8,d0
  139. pea p
  140. // jsr SET_SET_BYTE
  141. sub.b #1,d0
  142. bra @LSetRLoop
  143. @Lend:
  144. end;
  145. end;
  146. { bildet den Durchschnitt von set1 und set2 }
  147. { und speichert das Ergebnis in dest }
  148. procedure mul_sets(set1,set2,dest : pointer);[public,alias: 'SET_MUL_SETS'];
  149. { type
  150. larray = array[0..7] of longint;
  151. for i:=0 to 7 do
  152. larray(dest^)[i] := larray(set1^)[i] AND larray(set2^)[i];
  153. }
  154. begin
  155. asm
  156. { saved used register }
  157. move.l a2,-(sp)
  158. move.l 8(a6),a0
  159. move.l 12(a6),a1
  160. move.l 16(a6),a2
  161. move.l #32,d6
  162. @LMMULSETS1:
  163. move.b (a0)+,d0
  164. and.b (a1)+,d0
  165. move.b d0,(a2)+
  166. subq.b #1,d6
  167. bne @LMMULSETS1
  168. { restore register }
  169. move.l a2,(sp)+
  170. end ['d0','d6','a0','a1'];
  171. end;
  172. { bildet die Differenz von set1 und set2 }
  173. { und speichert das Ergebnis in dest }
  174. procedure sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SUB_SETS'];
  175. { type
  176. larray = array[0..7] of longint;
  177. begin
  178. for i:=0 to 7 do
  179. larray(dest^)[i] := larray(set1^)[i] AND NOT (larray(set2^)[i]);
  180. end;
  181. }
  182. begin
  183. asm
  184. { saved used register }
  185. move.l a2,-(sp)
  186. move.l 8(a6),a0
  187. move.l 12(a6),a1
  188. move.l 16(a6),a2
  189. move.l #32,d6
  190. @LSUBSETS1:
  191. move.b (a0)+,d0
  192. move.b (a1)+,d1
  193. not.b d1
  194. and.b d1,d0
  195. move.b d0,(a2)+
  196. sub.b #1,d6
  197. bne @LSUBSETS1
  198. { restore register }
  199. move.l a2,(sp)+
  200. end ['d0','d1','d6','a0','a1'];
  201. end;
  202. { compare both sets }
  203. { compares set1 and set2 }
  204. { zeroflag is set if they are equal }
  205. { on entry : a0 = pointer to first set }
  206. { : a1 = pointer to second set }
  207. procedure comp_sets; assembler;
  208. asm
  209. XDEF SET_COMP_SETS
  210. move.l #32,d6
  211. @LMCOMPSETS1:
  212. move.b (a0)+,d0
  213. move.b (a1),d1
  214. cmp.b d1,d0
  215. bne @LMCOMPSETEND
  216. adda.l #1,a1
  217. sub.b #1,d6
  218. bne @LMCOMPSETS1
  219. { we are here only if the two sets are equal }
  220. { we have zero flag set, and that what is expected }
  221. cmp.b d0,d0
  222. @LMCOMPSETEND:
  223. end;
  224. procedure do_set(p : pointer;b : word);[public,alias: 'SET_SET_WORD'];
  225. begin
  226. asm
  227. move.l 8(a6),a0
  228. move.w 12(a6),d6
  229. andi.l #$fff8,d6
  230. lsl.l #3,d6
  231. adda.l d6,a0
  232. move.b 12(a6),d6
  233. andi.l #7,d6
  234. move.l (a0),d0 { we must put bits into register }
  235. btst.l d6,d0 { otherwise btst will be a byte }
  236. { put result in carry flag } { operation. }
  237. bne @LBIGDOSET1
  238. andi.b #$fe,ccr { clear carry flag }
  239. bra @LBIGDOSET2
  240. @LBIGDOSET1:
  241. ori.b #$01,ccr { set carry flag }
  242. @LBIGDOSET2:
  243. end ['d0','a0','d6'];
  244. end;
  245. { testet, ob das Element b in der Menge p vorhanden ist }
  246. { und setzt das Carryflag entsprechend }
  247. procedure do_in(p : pointer;b : word);[public,alias: 'SET_IN_WORD'];
  248. begin
  249. asm
  250. move.l 8(a6),a0
  251. move.w 12(a6),d6
  252. andi.l #$fff8,d6
  253. lsl.l #3,d6
  254. adda.l d6,a0 { correct offset from start address of set }
  255. move.b 12(a6),d6
  256. andi.l #7,d6
  257. move.l (a0),d0 { we must put bits into register }
  258. btst.l d6,d0 { otherwise btst will be a byte }
  259. { put result in carry flag } { operation. }
  260. bne @LBIGDOIN1
  261. andi.b #$fe,ccr { clear carry flag }
  262. bra @LBIGDOIN2
  263. @LBIGDOIN1:
  264. ori.b #$01,ccr { set carry flag }
  265. @LBIGDOIN2:
  266. end ['d0','a0','d6'];
  267. end;
  268. { vereinigt set1 und set2 und speichert das Ergebnis in dest }
  269. { size is the number of bytes in the set }
  270. procedure add_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_ADD_SETS_SIZE'];
  271. begin
  272. asm
  273. { saved used register }
  274. move.l a2,-(sp)
  275. move.l 8(a6),a0
  276. move.l 12(a6),a1
  277. move.l 16(a6),a2
  278. move.l 20(a6),d6
  279. @LBIGMADDSETS1:
  280. move.l (a0)+,d0
  281. or.l (a1)+,d0
  282. move.l d0,(a2)+
  283. subq.l #4,d6
  284. bne @LBIGMADDSETS1
  285. { restore register }
  286. move.l a2,(sp)+
  287. end ['d0','d6','a0','a1'];
  288. end;
  289. procedure mul_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_MUL_SETS_SIZE'];
  290. { bildet den Durchschnitt von set1 und set2 }
  291. { und speichert das Ergebnis in dest }
  292. { size is the number of bytes in the set }
  293. begin
  294. asm
  295. { saved used register }
  296. move.l a2,-(sp)
  297. move.l 8(a6),a0
  298. move.l 12(a6),a1
  299. move.l 16(a6),a2
  300. move.l 20(a6),d6
  301. @LBIGMMULSETS1:
  302. move.l (a0)+,d0
  303. and.l (a1)+,d0
  304. move.l d0,(a2)+
  305. subq.l #4,d6
  306. bne @LBIGMMULSETS1
  307. { restore register }
  308. move.l a2,(sp)+
  309. end ['d0','d6','a0','a1'];
  310. end;
  311. { bildet die Differenz von set1 und set2 }
  312. { und speichert das Ergebnis in dest }
  313. { size is the number of bytes in the set }
  314. procedure sub_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_SUB_SETS_SIZE'];
  315. begin
  316. asm
  317. { saved used register }
  318. move.l a2,-(sp)
  319. move.l 8(a6),a0
  320. move.l 12(a6),a1
  321. move.l 16(a6),a2
  322. move.l 20(a6),d6
  323. @BIGSUBSETS1:
  324. move.l (a0)+,d0
  325. not.l d0
  326. and.l (a1)+,d0
  327. move.l d0,(a2)+
  328. subq.l #4,d6
  329. bne @BIGSUBSETS1
  330. { restore register }
  331. move.l a2,(sp)+
  332. end ['d0','d6','a0','a1'];
  333. end;
  334. { vergleicht Mengen und setzt die Flags entsprechend }
  335. procedure comp_sets(set1,set2 : pointer;size : longint);[public,alias: 'SET_COMP_SETS_SIZE'];
  336. begin
  337. asm
  338. move.l 8(a6),a0 { set1 - esi}
  339. move.l 12(a6),a1 { set2 - edi }
  340. move.l 16(a6),d6
  341. @MCOMPSETS1:
  342. move.l (a0)+,d0
  343. move.l (a1),d1
  344. cmp.l d1,d0
  345. bne @BIGMCOMPSETEND
  346. add.l #4,a1
  347. subq.l #1,d6
  348. bne @MCOMPSETS1
  349. { we are here only if the two sets are equal }
  350. { we have zero flag set, and that what is expected }
  351. cmp.l d0,d0
  352. @BIGMCOMPSETEND:
  353. end;
  354. end;
  355. {$endif}