set.inc 13 KB

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