set.inc 12 KB

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