tree-optimization/110506 - bogus non-zero mask in CCP for vector types
[official-gcc.git] / gcc / d / d-port.cc
blobeb685825e5bba77f366dea1acd67ceef3e1551d0
1 /* d-port.cc -- D frontend interface to the gcc back-end.
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
4 GCC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
9 GCC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
18 #include "config.h"
19 #include "system.h"
20 #include "coretypes.h"
22 #include "dmd/root/port.h"
23 #include "dmd/target.h"
25 #include "tree.h"
28 /* Implements the Port interface defined by the frontend.
29 A mini library for doing compiler/system specific things. */
31 /* Compare the first N bytes of S1 and S2 without regard to the case. */
33 int
34 Port::memicmp (const char *s1, const char *s2, d_size_t n)
36 int result = 0;
38 for (d_size_t i = 0; i < n; i++)
40 char c1 = s1[i];
41 char c2 = s2[i];
43 result = c1 - c2;
44 if (result)
46 result = TOUPPER (c1) - TOUPPER (c2);
47 if (result)
48 break;
52 return result;
55 /* Convert all characters in S to uppercase. */
57 char *
58 Port::strupr (char *s)
60 char *t = s;
62 while (*s)
64 *s = TOUPPER (*s);
65 s++;
68 return t;
71 /* Return true if the real_t value from string BUFFER overflows
72 as a result of rounding down to float mode. */
74 bool
75 Port::isFloat32LiteralOutOfRange (const char *buffer)
77 real_t r;
79 real_from_string3 (&r.rv (), buffer, TYPE_MODE (float_type_node));
81 return r == target.RealProperties.infinity;
84 /* Return true if the real_t value from string BUFFER overflows
85 as a result of rounding down to double mode. */
87 bool
88 Port::isFloat64LiteralOutOfRange (const char *buffer)
90 real_t r;
92 real_from_string3 (&r.rv (), buffer, TYPE_MODE (double_type_node));
94 return r == target.RealProperties.infinity;
97 /* Fetch a little-endian 16-bit value from BUFFER. */
99 unsigned
100 Port::readwordLE (const void *buffer)
102 const unsigned char *p = (const unsigned char *) buffer;
104 return ((unsigned) p[1] << 8) | (unsigned) p[0];
107 /* Fetch a big-endian 16-bit value from BUFFER. */
109 unsigned
110 Port::readwordBE (const void *buffer)
112 const unsigned char *p = (const unsigned char *) buffer;
114 return ((unsigned) p[0] << 8) | (unsigned) p[1];
117 /* Fetch a little-endian 32-bit value from BUFFER. */
119 unsigned
120 Port::readlongLE (const void *buffer)
122 const unsigned char *p = (const unsigned char *) buffer;
124 return (((unsigned) p[3] << 24)
125 | ((unsigned) p[2] << 16)
126 | ((unsigned) p[1] << 8)
127 | (unsigned) p[0]);
130 /* Fetch a big-endian 32-bit value from BUFFER. */
132 unsigned
133 Port::readlongBE (const void *buffer)
135 const unsigned char *p = (const unsigned char *) buffer;
137 return (((unsigned) p[0] << 24)
138 | ((unsigned) p[1] << 16)
139 | ((unsigned) p[2] << 8)
140 | (unsigned) p[3]);
143 /* Write an SZ-byte sized VALUE to BUFFER, ignoring endian-ness. */
145 void
146 Port::valcpy (void *buffer, uint64_t value, d_size_t sz)
148 gcc_assert (((d_size_t) buffer) % sz == 0);
150 switch (sz)
152 case 1:
153 *(uint8_t *) buffer = (uint8_t) value;
154 break;
156 case 2:
157 *(uint16_t *) buffer = (uint16_t) value;
158 break;
160 case 4:
161 *(uint32_t *) buffer = (uint32_t) value;
162 break;
164 case 8:
165 *(uint64_t *) buffer = (uint64_t) value;
166 break;
168 default:
169 gcc_unreachable ();