OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.dg/] [tree-ssa/] [pr32327-1.C] - Blame information for rev 853

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

Line No. Rev Author Line
1 149 jeremybenn
// { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } }
2
// { dg-options "-O2" }
3
 
4
// Endian sensitive.  This is a little-endian redux.
5
 
6
typedef long long int64;
7
typedef unsigned long long uint64;
8
typedef __SIZE_TYPE__ size_t;
9
 
10
extern "C" {
11
extern void *memcpy (void *__restrict __dest,
12
      __const void *__restrict __src, size_t __n) /*throw ()*/;
13
extern void abort (void);
14
}
15
 
16
inline uint64 Swap64(uint64 ull) {
17
 uint64 b0 = (ull >>  0) & 0xff;
18
 uint64 b1 = (ull >>  8) & 0xff;
19
 uint64 b2 = (ull >> 16) & 0xff;
20
 uint64 b3 = (ull >> 24) & 0xff;
21
 uint64 b4 = (ull >> 32) & 0xff;
22
 uint64 b5 = (ull >> 40) & 0xff;
23
 uint64 b6 = (ull >> 48) & 0xff;
24
 uint64 b7 = (ull >> 56) & 0xff;
25
 return (b0 << 56) | (b1 << 48) | (b2 << 40) | (b3 << 32) |
26
        (b4 << 24) | (b5 << 16) | (b6 <<  8) | (b7 <<  0);
27
}
28
 
29
inline void KeyFromUint64(uint64 ull, unsigned char* key) {
30
 uint64 ull_swap = Swap64(ull);
31
 memcpy(key, &ull_swap, sizeof(uint64));
32
}
33
 
34
inline int64 int64_from_double(const double& source) {
35
 int64 dest;
36
 memcpy(&dest, &source, sizeof(dest));
37
 return dest;
38
}
39
 
40
void KeyFromDouble(double x, unsigned char* key) __attribute__ ((noinline));
41
void KeyFromDouble(double x, unsigned char* key) {
42
 int64 n = int64_from_double(x);
43
 if (n >= 0) {
44
   n += 1ull << 63;
45
 } else {
46
   n = -n;
47
 }
48
 KeyFromUint64(n, key);
49
}
50
 
51
 
52
void TestKeyFromDouble(uint64 ull) {
53
 double d;
54
 memcpy(&d, &ull, sizeof(d));
55
 
56
 unsigned char key[sizeof(uint64)];
57
 unsigned char expected_key[sizeof(uint64)] = { 0x81, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
58
 
59
 KeyFromDouble(d, key);
60
 
61
 for (size_t i = 0; i < sizeof(key); ++i) {
62
   if ((key[i] & 0xff) != expected_key[i])
63
     abort ();
64
 }
65
}
66
 
67
int main() {
68
 TestKeyFromDouble(0x0123456789abcdefull);
69
 return 0;
70
}

powered by: WebSVN 2.1.0

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