2323
2424******************************************************************************************/
2525
26+ #include < cstddef>
2627#include < cstdint>
2728#include < cstring>
2829
@@ -32,13 +33,15 @@ typedef signed long long DItype __attribute__((mode (DI)));
3233typedef unsigned long long UDItype __attribute__ ((mode (DI)));
3334typedef unsigned int USItype __attribute__ ((mode (SI)));
3435
35- extern int __builtin_clzll (long long unsigned int );
36+ extern int __builtin_clzll (unsigned long long );
3637
3738#define DWtype DItype
3839#define UDWtype UDItype
3940#define UWtype USItype
4041
42+ UDWtype __udivdi3 (UDWtype n, UDWtype d);
4143UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp);
44+ UDWtype __umoddi3 (UDWtype u, UDWtype v);
4245
4346UDWtype __udivdi3 (UDWtype n, UDWtype d)
4447{
@@ -69,8 +72,8 @@ UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
6972
7073 if (y <= r)
7174 {
72- lz1 = __builtin_clzll (d );
73- lz2 = __builtin_clzll (n );
75+ lz1 = static_cast <USItype>( __builtin_clzll ( static_cast < unsigned long long >(d)) );
76+ lz2 = static_cast <USItype>( __builtin_clzll ( static_cast < unsigned long long >(n)) );
7477
7578 k = lz1 - lz2;
7679 y = (y << k);
@@ -128,39 +131,48 @@ UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
128131 return q;
129132}
130133
134+ #if defined(__GNUC__)
135+ #pragma GCC diagnostic push
136+ #pragma GCC diagnostic ignored "-Wcast-align"
137+ #endif
138+
131139void * memset (void * str, int c, size_t n)
132140{
133- uint8_t *ptr = (uint8_t *) str;
134- uint32_t value = (uint8_t ) c;
141+ std::uint8_t * ptr { reinterpret_cast <std::uint8_t *>(str) };
142+
143+ const std::uint8_t uc { static_cast <std::uint8_t >(c) };
144+
145+ std::uint32_t value = static_cast <std::uint32_t >(uc);
135146
136147 // Set value to repeat the byte across a 32-bit word.
137- value |= value << 8 ;
138- value |= value << 16 ;
148+ value |= value << unsigned { UINT8_C ( 8 ) } ;
149+ value |= value << unsigned { UINT8_C ( 16 ) } ;
139150
140151 // Align to the next 32-bit boundary.
141- while (((uintptr_t )ptr & 3 ) && n > 0 )
152+ while ( (static_cast <unsigned >(reinterpret_cast <std::uintptr_t >(ptr) & unsigned { UINT8_C (3 ) }) != 0U )
153+ && (n > std::size_t { UINT8_C (0 ) }))
142154 {
143- *ptr++ = ( uint8_t ) c ;
155+ *ptr++ = uc ;
144156
145157 --n;
146158 }
147159
148160 // Set memory in 32-bit chunks.
149- uint32_t * ptr32 = ( uint32_t *) ptr ;
161+ std:: uint32_t * ptr32 { reinterpret_cast <std:: uint32_t *>(ptr) } ;
150162
151- while (n >= 4 )
163+ while (n >= std:: size_t { UINT8_C ( 4 ) } )
152164 {
153165 *ptr32++ = value;
154166
155- n -= 4 ;
167+ n -= std:: size_t { UINT8_C ( 4 ) } ;
156168 }
157169
158170 // Handle any remaining bytes.
159- ptr = ( uint8_t *) ptr32;
171+ ptr = reinterpret_cast <std:: uint8_t *>( ptr32) ;
160172
161- while (n > 0 )
173+ while (n > std:: size_t { UINT8_C ( 0 ) } )
162174 {
163- *ptr++ = ( uint8_t ) c ;
175+ *ptr++ = uc ;
164176
165177 --n;
166178 }
@@ -170,8 +182,8 @@ void* memset(void* str, int c, size_t n)
170182
171183void * memcpy (void * dest, const void * src, size_t n)
172184{
173- uint8_t *d = ( uint8_t *) dest ;
174- const uint8_t * s = ( const uint8_t *) src ;
185+ std:: uint8_t * d { reinterpret_cast <std:: uint8_t *>(dest) } ;
186+ const std:: uint8_t * s { reinterpret_cast < const uint8_t *>(src) } ;
175187
176188 // Align destination to the next 32-bit boundary.
177189 while (((uintptr_t ) d & 3 ) && n > 0 )
@@ -183,8 +195,8 @@ void* memcpy (void* dest, const void* src, size_t n)
183195
184196 // Copy memory in 32-bit chunks.
185197
186- uint32_t * d32 = ( uint32_t *) d ;
187- const uint32_t * s32 = ( const uint32_t *) s ;
198+ std:: uint32_t * d32 { reinterpret_cast <std:: uint32_t *>(d) } ;
199+ const std:: uint32_t * s32 { reinterpret_cast < const uint32_t *>(s) } ;
188200
189201 while (n >= 4 )
190202 {
@@ -195,8 +207,8 @@ void* memcpy (void* dest, const void* src, size_t n)
195207
196208 // Handle any remaining bytes.
197209
198- d = ( uint8_t *) d32;
199- s = ( const uint8_t *) s32;
210+ d = reinterpret_cast <std:: uint8_t *>( d32) ;
211+ s = reinterpret_cast < const uint8_t *>( s32) ;
200212
201213 while (n > 0 )
202214 {
@@ -208,4 +220,8 @@ void* memcpy (void* dest, const void* src, size_t n)
208220 return dest;
209221}
210222
223+ #if defined(__GNUC__)
224+ #pragma GCC diagnostic pop
225+ #endif
226+
211227} // extern "C"
0 commit comments