tests.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. Test:y_cell_ReverseBits0()
  65. {
  66. ASSERT(Cell_ReverseBits(0) == 0x00000000);
  67. ASSERT(Cell_ReverseBits(1) == 0x80000000);
  68. ASSERT(Cell_ReverseBits(2) == 0x40000000);
  69. ASSERT(Cell_ReverseBits(3) == 0xC0000000);
  70. ASSERT(Cell_ReverseBits(4) == 0x20000000);
  71. ASSERT(Cell_ReverseBits(0b01010101010) == 0b01010101010000000000000000000000);
  72. ASSERT(Cell_ReverseBits(0b1111000001111000011) == 0b11000011110000011110000000000000);
  73. }
  74. Test:y_cell_ExpandCompress()
  75. {
  76. new o, x, m, n;
  77. //printf("1");
  78. o = 0b11110000101001011100001100001111;
  79. m = 0b01010000000000000000000000000000;
  80. //PRINT(x);
  81. x = Cell_CompressRight(o, m);
  82. n = Cell_ExpandLeft(x, m);
  83. ASSERT(o & m == n);
  84. ASSERT(x == 0b00000000000000000000000000000011);
  85. //PRINT(n);
  86. //printf("2");
  87. o = 0b11110000101001011100001100001111;
  88. m = 0b01010101010100000000000000000000;
  89. //PRINT(x);
  90. x = Cell_CompressRight(o, m);
  91. n = Cell_ExpandLeft(x, m);
  92. ASSERT(o & m == n);
  93. ASSERT(x == 0b00000000000000000000000000110000);
  94. //PRINT(n);
  95. //printf("3");
  96. o = 0b11110000101001011100001100001111;
  97. m = 0b00111100000000000000000000000000;
  98. //PRINT(x);
  99. x = Cell_CompressRight(o, m);
  100. n = Cell_ExpandLeft(x, m);
  101. ASSERT(o & m == n);
  102. ASSERT(x == 0b00000000000000000000000000001100);
  103. //PRINT(n);
  104. //printf("4");
  105. o = 0b11110000101001011100001100001111;
  106. m = 0b00000000000000000000111111111111;
  107. //PRINT(x);
  108. x = Cell_CompressRight(o, m);
  109. n = Cell_ExpandLeft(x, m);
  110. ASSERT(o & m == n);
  111. ASSERT(x == 0b00000000000000000000001100001111);
  112. //PRINT(n);
  113. //printf("5");
  114. o = 0b11110000101001011100001100001111;
  115. m = 0b00000000000000000000111111000000;
  116. //PRINT(x);
  117. x = Cell_CompressRight(o, m);
  118. n = Cell_ExpandLeft(x, m);
  119. ASSERT(o & m == n);
  120. ASSERT(x == 0b00000000000000000000000000001100);
  121. //PRINT(n);
  122. //printf("6");
  123. o = 0b11110000101001011100001100001111;
  124. m = 0b00000110000000100001100001100000;
  125. //PRINT(x);
  126. x = Cell_CompressRight(o, m);
  127. n = Cell_ExpandLeft(x, m);
  128. ASSERT(o & m == n);
  129. ASSERT(x == 0b00000000000000000000000000000000);
  130. //PRINT(n);
  131. }
  132. // Test:y_cell_ReverseBits1()
  133. // {
  134. // for (new i = 0; i != 1000000; ++i)
  135. // {
  136. // new
  137. // count = 0;
  138. // for (new j = 0x80000000, k = 1; j; j >>>= 1, k <<= 1)
  139. // {
  140. // if (i & j) count |= k;
  141. // }
  142. // if (Cell_ReverseBits(i) != count)
  143. // {
  144. // ASSERT(Cell_ReverseBits(i) == count);
  145. // break;
  146. // }
  147. // }
  148. // }
  149. // Test:y_cell_ReverseBits2()
  150. // {
  151. // for (new i = 1000000000; i != 1000123000; ++i)
  152. // {
  153. // new
  154. // count = 0;
  155. // for (new j = 0x80000000, k = 1; j; j >>>= 1, k <<= 1)
  156. // {
  157. // if (i & j) count |= k;
  158. // }
  159. // if (Cell_ReverseBits(i) != count)
  160. // {
  161. // ASSERT(Cell_ReverseBits(i) == count);
  162. // break;
  163. // }
  164. // }
  165. // }
  166. // Test:y_cell_ReverseBits3()
  167. // {
  168. // for (new i = -999888; i != 0; ++i)
  169. // {
  170. // new
  171. // count = 0;
  172. // for (new j = 0x80000000, k = 1; j; j >>>= 1, k <<= 1)
  173. // {
  174. // if (i & j) count |= k;
  175. // }
  176. // if (Cell_ReverseBits(i) != count)
  177. // {
  178. // ASSERT(Cell_ReverseBits(i) == count);
  179. // break;
  180. // }
  181. // }
  182. // }
  183. Test:y_cell_ReverseNibbles0()
  184. {
  185. ASSERT(Cell_ReverseNibbles(0) == 0);
  186. ASSERT(Cell_ReverseNibbles(1) == 0x10000000);
  187. ASSERT(Cell_ReverseNibbles(2) == 0x20000000);
  188. ASSERT(Cell_ReverseNibbles(3) == 0x30000000);
  189. ASSERT(Cell_ReverseNibbles(4) == 0x40000000);
  190. ASSERT(Cell_ReverseNibbles(0b1010101010) == 0b10101010001000000000000000000000);
  191. ASSERT(Cell_ReverseNibbles(0b1111000001111000011) == 0b00111100001110000111000000000000);
  192. }
  193. // Test:y_cell_ReverseNibbles1()
  194. // {
  195. // for (new i = 0; i != 1000000; ++i)
  196. // {
  197. // new
  198. // count = 0,
  199. // k = i;
  200. // for (new j = 0; j != 8; ++j)
  201. // {
  202. // count <<= 4;
  203. // count |= k & 0x0F;
  204. // k >>>= 4;
  205. // }
  206. // if (Cell_ReverseNibbles(i) != count)
  207. // {
  208. // ASSERT(Cell_ReverseNibbles(i) == count);
  209. // break;
  210. // }
  211. // }
  212. // }
  213. // Test:y_cell_ReverseNibbles2()
  214. // {
  215. // for (new i = 1000000000; i != 1000123000; ++i)
  216. // {
  217. // new
  218. // count = 0,
  219. // k = i;
  220. // for (new j = 0; j != 8; ++j)
  221. // {
  222. // count <<= 4;
  223. // count |= k & 0x0F;
  224. // k >>>= 4;
  225. // }
  226. // if (Cell_ReverseNibbles(i) != count)
  227. // {
  228. // ASSERT(Cell_ReverseNibbles(i) == count);
  229. // break;
  230. // }
  231. // }
  232. // }
  233. // Test:y_cell_ReverseNibbles3()
  234. // {
  235. // for (new i = -999888; i != 0; ++i)
  236. // {
  237. // new
  238. // count = 0,
  239. // k = i;
  240. // for (new j = 0; j != 8; ++j)
  241. // {
  242. // count <<= 4;
  243. // count |= k & 0x0F;
  244. // k >>>= 4;
  245. // }
  246. // if (Cell_ReverseNibbles(i) != count)
  247. // {
  248. // ASSERT(Cell_ReverseNibbles(i) == count);
  249. // break;
  250. // }
  251. // }
  252. // }
  253. Test:y_cell_ReverseBytes0()
  254. {
  255. ASSERT(Cell_ReverseBytes(0) == 0);
  256. ASSERT(Cell_ReverseBytes(1) == 0x01000000);
  257. ASSERT(Cell_ReverseBytes(2) == 0x02000000);
  258. ASSERT(Cell_ReverseBytes(3) == 0x03000000);
  259. ASSERT(Cell_ReverseBytes(4) == 0x04000000);
  260. ASSERT(Cell_ReverseBytes(0b1010101010) == 0b10101010000000100000000000000000);
  261. ASSERT(Cell_ReverseBytes(0b1111000001111000011) == 0b11000011100000110000011100000000);
  262. }
  263. // Test:y_cell_ReverseBytes1()
  264. // {
  265. // for (new i = 0; i != 1000000; ++i)
  266. // {
  267. // new
  268. // count = 0,
  269. // k = i;
  270. // for (new j = 0; j != 4; ++j)
  271. // {
  272. // count <<= 8;
  273. // count |= k & 0xFF;
  274. // k >>>= 8;
  275. // }
  276. // if (Cell_ReverseBytes(i) != count)
  277. // {
  278. // ASSERT(Cell_ReverseBytes(i) == count);
  279. // break;
  280. // }
  281. // }
  282. // }
  283. // Test:y_cell_ReverseBytes2()
  284. // {
  285. // for (new i = 1000000000; i != 1000123000; ++i)
  286. // {
  287. // new
  288. // count = 0,
  289. // k = i;
  290. // for (new j = 0; j != 4; ++j)
  291. // {
  292. // count <<= 8;
  293. // count |= k & 0xFF;
  294. // k >>>= 8;
  295. // }
  296. // if (Cell_ReverseBytes(i) != count)
  297. // {
  298. // ASSERT(Cell_ReverseBytes(i) == count);
  299. // break;
  300. // }
  301. // }
  302. // }
  303. // Test:y_cell_ReverseBytes3()
  304. // {
  305. // for (new i = -999888; i != 0; ++i)
  306. // {
  307. // new
  308. // count = 0,
  309. // k = i;
  310. // for (new j = 0; j != 4; ++j)
  311. // {
  312. // count <<= 8;
  313. // count |= k & 0xFF;
  314. // k >>>= 8;
  315. // }
  316. // if (Cell_ReverseBytes(i) != count)
  317. // {
  318. // ASSERT(Cell_ReverseBytes(i) == count);
  319. // break;
  320. // }
  321. // }
  322. // }
  323. static stock y_cell_CountBits_v1(GLOBAL_TAG_TYPES:data)
  324. {
  325. static const
  326. scCount[256] =
  327. {
  328. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
  329. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  330. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  331. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  332. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  333. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  334. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  335. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  336. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  337. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  338. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  339. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  340. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  341. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  342. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  343. 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
  344. };
  345. return scCount[data >>> 24] + scCount[(data >>> 16) & 0xFF] + scCount[(data >>> 8) & 0xFF] + scCount[data & 0xFF];
  346. }
  347. static stock y_cell_CountBits_v2(GLOBAL_TAG_TYPES:data)
  348. {
  349. data = data - ((data >>> 1) & 0x55555555);
  350. data = (data & 0x33333333) + ((data >>> 2) & 0x33333333);
  351. return ((data + (data >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24;
  352. }
  353. static stock y_cell_CountBits_v3(GLOBAL_TAG_TYPES:data)
  354. {
  355. // This function is a perfect candidate for re-writing in pure assembly.
  356. // data = data - ((data >>> 1) & 0x55555555);
  357. #emit LOAD.S.pri data // From this point on, just use registers!
  358. #emit PUSH.pri
  359. #emit SHR.C.pri 1
  360. #emit CONST.alt 0x55555555
  361. #emit AND // No "AND.C" annoyingly.
  362. #emit POP.alt
  363. #emit SUB.alt
  364. // data = (data & 0x33333333) + ((data >>> 2) & 0x33333333);
  365. #emit PUSH.pri
  366. #emit SHR.C.pri 2
  367. #emit CONST.alt 0x33333333
  368. #emit AND
  369. #emit SWAP.pri // Put the second half of the code on the stack.
  370. #emit AND // "alt" is already the correct value.
  371. #emit POP.alt
  372. #emit ADD
  373. // return ((data + (data >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24;
  374. #emit MOVE.alt
  375. #emit SHR.C.pri 4
  376. #emit ADD
  377. #emit CONST.alt 0xF0F0F0F
  378. #emit AND
  379. #emit SMUL.C 0x1010101
  380. #emit SHR.C.pri 24
  381. #emit RETN
  382. return 0;
  383. }
  384. static stock y_cell_CountBits_v4(GLOBAL_TAG_TYPES:data)
  385. {
  386. static const
  387. scCount[256] =
  388. {
  389. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
  390. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  391. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  392. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  393. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  394. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  395. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  396. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  397. 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  398. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  399. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  400. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  401. 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  402. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  403. 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  404. 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
  405. };
  406. // return scCount[data >>> 24] + scCount[(data >>> 16) & 0xFF] + scCount[(data >>> 8) & 0xFF] + scCount[data & 0xFF];
  407. #emit CONST.alt scCount // Get the address of the table.
  408. #emit ADDR.pri data // Get the address of the parameter.
  409. #emit PUSH.pri
  410. // Load the first value.
  411. #emit LODB.I 1
  412. #emit LIDX
  413. // Store the data.
  414. #emit SWAP.pri
  415. #emit PUSH.pri
  416. // Load the second value
  417. #emit ADD.C 1
  418. #emit LODB.I 1
  419. #emit LIDX
  420. // Store the data.
  421. #emit SWAP.pri
  422. #emit PUSH.pri
  423. // Load the third value
  424. #emit ADD.C 2
  425. #emit LODB.I 1
  426. #emit LIDX
  427. // Store the data.
  428. #emit SWAP.pri
  429. // Load the fourth value
  430. #emit ADD.C 3
  431. #emit LODB.I 1
  432. #emit LIDX
  433. // We now have a stack with three results, and a fourth in "pri".
  434. #emit POP.alt
  435. #emit ADD
  436. #emit POP.alt
  437. #emit ADD
  438. #emit POP.alt
  439. #emit ADD
  440. // Return.
  441. #emit RETN
  442. return 0;
  443. }
  444. Test:y_cell_CountBits0()
  445. {
  446. ASSERT(y_cell_CountBits_v4(0) == 0);
  447. ASSERT(y_cell_CountBits_v4(1) == 1);
  448. ASSERT(y_cell_CountBits_v4(2) == 1);
  449. ASSERT(y_cell_CountBits_v4(3) == 2);
  450. ASSERT(y_cell_CountBits_v4(4) == 1);
  451. ASSERT(y_cell_CountBits_v4(0b1010101010) == 5);
  452. ASSERT(y_cell_CountBits_v4(0b1111000001111000011) == 10);
  453. #if 0
  454. new
  455. t0, t1, t2, t3, t4;
  456. t0 = GetTickCount();
  457. for (new i = 0; i != 10000000; ++i)
  458. {
  459. for (new j = 1; j < 100000000; j *= 3)
  460. {
  461. y_cell_CountBits_v1(j);
  462. }
  463. }
  464. t1 = GetTickCount();
  465. printf("Time 1: %d", t1 - t0);
  466. t1 = GetTickCount();
  467. for (new i = 0; i != 10000000; ++i)
  468. {
  469. for (new j = 1; j < 100000000; j *= 3)
  470. {
  471. y_cell_CountBits_v2(j);
  472. }
  473. }
  474. t2 = GetTickCount();
  475. printf("Time 2: %d", t2 - t1);
  476. t2 = GetTickCount();
  477. for (new i = 0; i != 10000000; ++i)
  478. {
  479. for (new j = 1; j < 100000000; j *= 3)
  480. {
  481. y_cell_CountBits_v3(j);
  482. }
  483. }
  484. t3 = GetTickCount();
  485. printf("Time 3: %d", t3 - t2);
  486. t3 = GetTickCount();
  487. for (new i = 0; i != 10000000; ++i)
  488. {
  489. for (new j = 1; j < 100000000; j *= 3)
  490. {
  491. y_cell_CountBits_v4(j);
  492. }
  493. }
  494. t4 = GetTickCount();
  495. printf("Time 4: %d", t4 - t3);
  496. #endif
  497. }
  498. // Test:y_cell_CountBits1()
  499. // {
  500. // for (new i = 0; i != 1000000; ++i)
  501. // {
  502. // new
  503. // count = 0;
  504. // for (new j = 0x80000000; j; j >>>= 1)
  505. // {
  506. // if (i & j) ++count;
  507. // }
  508. // if (y_cell_CountBits_v4(i) != count)
  509. // {
  510. // ASSERT(y_cell_CountBits_v4(i) == count);
  511. // break;
  512. // }
  513. // }
  514. // }
  515. // Test:y_cell_CountBits2()
  516. // {
  517. // for (new i = 1000000000; i != 1000123000; ++i)
  518. // {
  519. // new
  520. // count = 0;
  521. // for (new j = 0x80000000; j; j >>>= 1)
  522. // {
  523. // if (i & j) ++count;
  524. // }
  525. // if (y_cell_CountBits_v4(i) != count)
  526. // {
  527. // ASSERT(y_cell_CountBits_v4(i) == count);
  528. // break;
  529. // }
  530. // }
  531. // }
  532. // Test:y_cell_CountBits3()
  533. // {
  534. // for (new i = -999888; i != 0; ++i)
  535. // {
  536. // new
  537. // count = 0;
  538. // for (new j = 0x80000000; j; j >>>= 1)
  539. // {
  540. // if (i & j) ++count;
  541. // }
  542. // if (y_cell_CountBits_v4(i) != count)
  543. // {
  544. // ASSERT(y_cell_CountBits_v4(i) == count);
  545. // break;
  546. // }
  547. // }
  548. // }
  549. Test:y_cell_GetLowestComponent()
  550. {
  551. ASSERT(Cell_GetLowestComponent(0) == 0);
  552. ASSERT(Cell_GetLowestComponent(1) == 1);
  553. ASSERT(Cell_GetLowestComponent(2) == 2);
  554. ASSERT(Cell_GetLowestComponent(6) == 2);
  555. ASSERT(Cell_GetLowestComponent(0x110) == 0x10);
  556. for (new i = 0; i != 32; ++i)
  557. {
  558. new
  559. k = 1 << i,
  560. l = k;
  561. ASSERT(Cell_GetLowestComponent(l) == k);
  562. l |= 2 << i;
  563. ASSERT(Cell_GetLowestComponent(l) == k);
  564. l |= 4 << i;
  565. ASSERT(Cell_GetLowestComponent(l) == k);
  566. l |= 8 << i;
  567. ASSERT(Cell_GetLowestComponent(l) == k);
  568. }
  569. }
  570. Test:y_cell_GetLowestBit()
  571. {
  572. ASSERT(Cell_GetLowestBit(0) == 0);
  573. ASSERT(Cell_GetLowestBit(1) == 0);
  574. ASSERT(Cell_GetLowestBit(0x800) == 11);
  575. ASSERT(Cell_GetLowestBit(0x111) == 0);
  576. ASSERT(Cell_GetLowestBit(6) == 1);
  577. for (new i = 0; i != 32; ++i)
  578. {
  579. new
  580. k = 1 << i;
  581. ASSERT(Cell_GetLowestBit(k) == i);
  582. k |= 2 << i;
  583. ASSERT(Cell_GetLowestBit(k) == i);
  584. k |= 4 << i;
  585. ASSERT(Cell_GetLowestBit(k) == i);
  586. k |= 8 << i;
  587. ASSERT(Cell_GetLowestBit(k) == i);
  588. }
  589. }
  590. Test:y_cell_GetLowestBitEx()
  591. {
  592. ASSERT(Cell_GetLowestBitEx(0) == 0);
  593. ASSERT(Cell_GetLowestBitEx(1) == 1);
  594. ASSERT(Cell_GetLowestBitEx(0x800) == 12);
  595. ASSERT(Cell_GetLowestBitEx(0x111) == 1);
  596. ASSERT(Cell_GetLowestBitEx(6) == 2);
  597. for (new i = 0; i != 32; ++i)
  598. {
  599. new
  600. k = 1 << i;
  601. ASSERT(Cell_GetLowestBitEx(k) == i + 1);
  602. k |= 2 << i;
  603. ASSERT(Cell_GetLowestBitEx(k) == i + 1);
  604. k |= 4 << i;
  605. ASSERT(Cell_GetLowestBitEx(k) == i + 1);
  606. k |= 8 << i;
  607. ASSERT(Cell_GetLowestBitEx(k) == i + 1);
  608. }
  609. }