Merged revisions 208012,208018-208019,208021,208023-208030,208033,208037,208040-20804...
[official-gcc.git] / main / gcc / testsuite / gcc.target / aarch64 / aapcs64 / validate_memory.h
blob24431c662016467b5f679887cb9d542d38620af9
1 /* Memory validation functions for AArch64 procedure call standard.
2 Copyright (C) 2012 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef VALIDATE_MEMORY_H
22 #define VALIDATE_MEMORY_H
24 enum structure_type
26 flat = 0,
27 i32in128,
28 f32in64,
29 i8in64,
30 i16in64,
31 i32in64,
34 /* Some explicit declarations as I can't include files outside the testsuite.
36 typedef long unsigned int size_t;
37 int memcmp (void *, void *, size_t);
39 /* These two arrays contain element size and block size data for the enumeration
40 above. */
41 const int element_size[] = { 1, 4, 4, 1, 2, 4 };
42 const int block_reverse_size[] = { 1, 16, 8, 8, 8, 8 };
44 int
45 validate_memory (void *mem1, char *mem2, size_t size, enum structure_type type)
47 /* In big-endian mode, the data in mem2 will have been byte-reversed in
48 register sized groups, while the data in mem1 will have been byte-reversed
49 according to the true structure of the data. To compare them, we need to
50 compare chunks of data in reverse order.
52 This is only implemented for homogeneous data layouts at the moment. For
53 hetrogeneous structures a custom compare case will need to be written. */
55 unsigned int i;
56 char *cmem1 = (char *) mem1;
57 switch (type)
59 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
60 case i8in64:
61 case i16in64:
62 case i32in64:
63 for (i = 0; i < size; i += element_size[type])
65 if (memcmp (cmem1 + i,
66 mem2 + block_reverse_size[type] - i - element_size[type],
67 element_size[type]))
68 return 1;
70 return 0;
71 break;
72 #endif
73 case f32in64:
74 case i32in128:
75 default:
76 break;
78 return memcmp (mem1, mem2, size);
81 #endif /* VALIDATE_MEMORY_H. */