root / tests / cris / check_lz.c @ f97572e5
History | View | Annotate | Download (768 Bytes)
1 | dd43edf4 | ths | #include <stdio.h> |
---|---|---|---|
2 | dd43edf4 | ths | #include <stdlib.h> |
3 | dd43edf4 | ths | #include <stdint.h> |
4 | dd43edf4 | ths | #include "sys.h" |
5 | dd43edf4 | ths | |
6 | dd43edf4 | ths | extern inline int cris_lz(int x) |
7 | dd43edf4 | ths | { |
8 | dd43edf4 | ths | int r;
|
9 | dd43edf4 | ths | asm ("lz\t%1, %0\n" : "=r" (r) : "r" (x)); |
10 | dd43edf4 | ths | return r;
|
11 | dd43edf4 | ths | } |
12 | dd43edf4 | ths | |
13 | dd43edf4 | ths | void check_lz(void) |
14 | dd43edf4 | ths | { |
15 | dd43edf4 | ths | int i;
|
16 | dd43edf4 | ths | |
17 | dd43edf4 | ths | if (cris_lz(0) != 32) |
18 | dd43edf4 | ths | err(); |
19 | dd43edf4 | ths | if (cris_lz(1) != 31) |
20 | dd43edf4 | ths | err(); |
21 | dd43edf4 | ths | if (cris_lz(2) != 30) |
22 | dd43edf4 | ths | err(); |
23 | dd43edf4 | ths | if (cris_lz(4) != 29) |
24 | dd43edf4 | ths | err(); |
25 | dd43edf4 | ths | if (cris_lz(8) != 28) |
26 | dd43edf4 | ths | err(); |
27 | dd43edf4 | ths | |
28 | dd43edf4 | ths | /* try all positions with a single bit. */
|
29 | dd43edf4 | ths | for (i = 1; i < 32; i++) { |
30 | dd43edf4 | ths | if (cris_lz(1 << (i-1)) != (32 - i)) |
31 | dd43edf4 | ths | err(); |
32 | dd43edf4 | ths | } |
33 | dd43edf4 | ths | |
34 | dd43edf4 | ths | /* try all positions with all bits. */
|
35 | dd43edf4 | ths | for (i = 1; i < 32; i++) { |
36 | dd43edf4 | ths | /* split up this computation to clarify it. */
|
37 | dd43edf4 | ths | uint32_t val; |
38 | dd43edf4 | ths | val = (unsigned int)-1 >> (32 - i); |
39 | dd43edf4 | ths | if (cris_lz(val) != (32 - i)) |
40 | dd43edf4 | ths | err(); |
41 | dd43edf4 | ths | } |
42 | dd43edf4 | ths | } |
43 | dd43edf4 | ths | |
44 | dd43edf4 | ths | int main(void) |
45 | dd43edf4 | ths | { |
46 | dd43edf4 | ths | check_lz(); |
47 | dd43edf4 | ths | pass(); |
48 | dd43edf4 | ths | exit(0);
|
49 | dd43edf4 | ths | } |