qemu/tests/tcg/cris/check_lz.c
<<
>>
Prefs
   1#include <stdio.h>
   2#include <stdlib.h>
   3#include <stdint.h>
   4#include "sys.h"
   5
   6static 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
  13void 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
  44int main(void)
  45{
  46        check_lz();
  47        pass();
  48        exit(0);
  49}
  50