OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [software/] [app/] [test64.c] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
#include <hf-risc.h>
2
 
3
union big{
4
        struct{
5
                uint32_t high;
6
                uint32_t low;
7
        } l;
8
        uint64_t unum;
9
        int64_t num;
10
};
11
 
12
int main(){
13
        int32_t i, j;
14
        uint64_t a, b;
15
        int64_t c, d;
16
        union big stuff;
17
 
18
        printf("test unsigned multiply...\n");
19
        a = 0x89abcdef;
20
        b = 3;
21
        for (i = 0; i < 20; i++){
22
                stuff.unum = a * b;
23
                printf("%x * %x = %x%x\n", (uint32_t)a, (uint32_t)b, stuff.l.high, stuff.l.low);
24
                b *= 3;
25
        }
26
 
27
        printf("test unsigned divide...\n");
28
        a = stuff.unum;
29
        for (i = 0; i < 20; i++){
30
                stuff.unum = a / b;
31
                printf("%x%x / %x%x = %x%x\n", (uint32_t)(a >> 32), (uint32_t)(a & 0xffffffff), (uint32_t)(b >> 32), (uint32_t)(b & 0xffffffff), stuff.l.high, stuff.l.low);
32
                b /= 3;
33
        }
34
 
35
        printf("test signed multiply...\n");
36
        c = 0x89abcdef;
37
        d = -3;
38
        for (i = 0; i < 20; i++){
39
                stuff.num = c * d;
40
                printf("%x * %x = %x%x\n", (uint32_t)c, (uint32_t)d, stuff.l.high, stuff.l.low);
41
                d *= 3;
42
        }
43
 
44
        printf("test signed divide...\n");
45
        c = stuff.num | 1LL << 63;
46
        for (i = 0; i < 20; i++){
47
                stuff.unum = c / d;
48
                printf("%x%x / %x%x = %x%x\n", (uint32_t)(c >> 32), (uint32_t)(c & 0xffffffff), (uint32_t)(d >> 32), (uint32_t)(d & 0xffffffff), stuff.l.high, stuff.l.low);
49
                d /= 3;
50
        }
51
 
52
        stuff.unum = 1;
53
 
54
        printf("testing left shifts..\n");
55
        for (i = 0; i < 64; i++){
56
                printf("%x %x\n", stuff.l.high, stuff.l.low);
57
                stuff.unum <<= 1;
58
        }
59
 
60
        stuff.unum = 1LL << 63;
61
 
62
        printf("testing right (logical) shifts..\n");
63
        for (i = 0; i < 64; i++){
64
                printf("%x %x\n", stuff.l.high, stuff.l.low);
65
                stuff.unum >>= 1;
66
        }
67
 
68
        stuff.unum = 1LL << 63;
69
 
70
        printf("testing right (arithmetic) shifts..\n");
71
        for (i = 0; i < 64; i++){
72
                printf("%x %x\n", stuff.l.high, stuff.l.low);
73
                stuff.num >>= 1;
74
        }
75
 
76
        return 0;
77
}
78
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.