virtio: Remove malloc failure checks (Jan Kiszka)
[sniper_test.git] / tests / cris / check_lz.c
blob7b30a265ad6d3f92fe3331f89ecd913ec807c321
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include "sys.h"
6 extern inline int cris_lz(int x)
8 int r;
9 asm ("lz\t%1, %0\n" : "=r" (r) : "r" (x));
10 return r;
13 void check_lz(void)
15 int i;
17 if (cris_lz(0) != 32)
18 err();
19 if (cris_lz(1) != 31)
20 err();
21 if (cris_lz(2) != 30)
22 err();
23 if (cris_lz(4) != 29)
24 err();
25 if (cris_lz(8) != 28)
26 err();
28 /* try all positions with a single bit. */
29 for (i = 1; i < 32; i++) {
30 if (cris_lz(1 << (i-1)) != (32 - i))
31 err();
34 /* try all positions with all bits. */
35 for (i = 1; i < 32; i++) {
36 /* split up this computation to clarify it. */
37 uint32_t val;
38 val = (unsigned int)-1 >> (32 - i);
39 if (cris_lz(val) != (32 - i))
40 err();
44 int main(void)
46 check_lz();
47 pass();
48 exit(0);