~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to tests/cris/check_lz.c

  • Committer: ths
  • Date: 2007-10-08 12:45:38 UTC
  • Revision ID: git-v1:450d4ff553af32fc9d83fef20d7106b0151526b8
CRIS disassembler, originally from binutils, by Edgar E. Iglesias.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3356 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <stdlib.h>
3
 
#include <stdint.h>
4
 
#include "sys.h"
5
 
 
6
 
extern inline int cris_lz(int x)
7
 
{
8
 
        int r;
9
 
        asm ("lz\t%1, %0\n" : "=r" (r) : "r" (x));
10
 
        return r;
11
 
}
12
 
 
13
 
void check_lz(void)
14
 
{
15
 
        int i;
16
 
 
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();
27
 
 
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();
32
 
        }
33
 
 
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();
41
 
        }
42
 
}
43
 
 
44
 
int main(void)
45
 
{
46
 
        check_lz();
47
 
        pass();
48
 
        exit(0);
49
 
}