6 #ifndef EASTL_INTERNAL_FILL_HELP_H
7 #define EASTL_INTERNAL_FILL_HELP_H
10 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
14 #include <EASTL/internal/config.h>
16 #if defined(EA_COMPILER_MICROSOFT) && (defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64))
27 template <
bool bIsScalar>
30 template <
typename ForwardIterator,
typename T>
31 static void do_fill(ForwardIterator first, ForwardIterator last,
const T& value)
35 for(; first != last; ++first)
43 template <
typename ForwardIterator,
typename T>
44 static void do_fill(ForwardIterator first, ForwardIterator last,
const T& value)
46 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
50 for(
const T temp = value; first != last; ++first)
53 *first =
static_cast<value_type
>(temp);
74 template <
typename ForwardIterator,
typename T>
75 inline void fill(ForwardIterator first, ForwardIterator last,
const T& value)
88 #if (defined(EA_COMPILER_GNUC) || defined(__clang__)) && (defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64))
89 #if defined(EA_PROCESSOR_X86_64)
90 template <
typename Value>
91 inline void fill(uint64_t* first, uint64_t* last, Value c)
93 uintptr_t
count = (uintptr_t)(last - first);
94 uint64_t value = (uint64_t)(c);
96 __asm__ __volatile__ (
"cld\n\t"
98 :
"+c" (
count),
"+D" (first),
"=m" (first)
104 template <
typename Value>
105 inline void fill(int64_t* first, int64_t* last, Value c)
107 uintptr_t
count = (uintptr_t)(last - first);
108 int64_t value = (int64_t)(c);
110 __asm__ __volatile__ (
"cld\n\t"
112 :
"+c" (
count),
"+D" (first),
"=m" (first)
118 template <
typename Value>
119 inline void fill(uint32_t* first, uint32_t* last, Value c)
121 uintptr_t
count = (uintptr_t)(last - first);
122 uint32_t value = (uint32_t)(c);
124 __asm__ __volatile__ (
"cld\n\t"
126 :
"+c" (
count),
"+D" (first),
"=m" (first)
132 template <
typename Value>
133 inline void fill(int32_t* first, int32_t* last, Value c)
135 uintptr_t
count = (uintptr_t)(last - first);
136 int32_t value = (int32_t)(c);
138 __asm__ __volatile__ (
"cld\n\t"
140 :
"+c" (
count),
"+D" (first),
"=m" (first)
146 template <
typename Value>
147 inline void fill(uint16_t* first, uint16_t* last, Value c)
149 uintptr_t
count = (uintptr_t)(last - first);
150 uint16_t value = (uint16_t)(c);
152 __asm__ __volatile__ (
"cld\n\t"
154 :
"+c" (
count),
"+D" (first),
"=m" (first)
160 template <
typename Value>
161 inline void fill(int16_t* first, int16_t* last, Value c)
163 uintptr_t
count = (uintptr_t)(last - first);
164 int16_t value = (int16_t)(c);
166 __asm__ __volatile__ (
"cld\n\t"
168 :
"+c" (
count),
"+D" (first),
"=m" (first)
173 #elif defined(EA_COMPILER_MICROSOFT) && (defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64))
174 #if defined(EA_PROCESSOR_X86_64)
175 template <
typename Value>
176 inline void fill(uint64_t* first, uint64_t* last, Value c)
178 __stosq(first, (uint64_t)c, (
size_t)(last - first));
181 template <
typename Value>
182 inline void fill(int64_t* first, int64_t* last, Value c)
184 __stosq((uint64_t*)first, (uint64_t)c, (
size_t)(last - first));
188 template <
typename Value>
189 inline void fill(uint32_t* first, uint32_t* last, Value c)
191 __stosd((
unsigned long*)first, (
unsigned long)c, (
size_t)(last - first));
194 template <
typename Value>
195 inline void fill(int32_t* first, int32_t* last, Value c)
197 __stosd((
unsigned long*)first, (
unsigned long)c, (
size_t)(last - first));
200 template <
typename Value>
201 inline void fill(uint16_t* first, uint16_t* last, Value c)
203 __stosw(first, (uint16_t)c, (
size_t)(last - first));
206 template <
typename Value>
207 inline void fill(int16_t* first, int16_t* last, Value c)
209 __stosw((uint16_t*)first, (uint16_t)c, (
size_t)(last - first));
214 inline void fill(
char* first,
char* last,
const char& c)
216 __builtin_memset(first, (
unsigned char)c, (
size_t)(last - first));
219 inline void fill(
char* first,
char* last,
const int c)
221 __builtin_memset(first, (
unsigned char)c, (
size_t)(last - first));
224 inline void fill(
unsigned char* first,
unsigned char* last,
const unsigned char& c)
226 __builtin_memset(first, (
unsigned char)c, (
size_t)(last - first));
229 inline void fill(
unsigned char* first,
unsigned char* last,
const int c)
231 __builtin_memset(first, (
unsigned char)c, (
size_t)(last - first));
234 inline void fill(
signed char* first,
signed char* last,
const signed char& c)
236 __builtin_memset(first, (
unsigned char)c, (
size_t)(last - first));
239 inline void fill(
signed char* first,
signed char* last,
const int c)
241 __builtin_memset(first, (
unsigned char)c, (
size_t)(last - first));
244 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__ICL)
245 inline void fill(
bool* first,
bool* last,
const bool& b)
247 __builtin_memset(first, (
char)b, (
size_t)(last - first));
259 template <
bool bIsScalar>
262 template <
typename OutputIterator,
typename Size,
typename T>
263 static OutputIterator do_fill(OutputIterator first, Size n,
const T& value)
265 for(; n-- > 0; ++first)
274 template <
typename OutputIterator,
typename Size,
typename T>
275 static OutputIterator do_fill(OutputIterator first, Size n,
const T& value)
277 typedef typename eastl::iterator_traits<OutputIterator>::value_type value_type;
282 for(
const T temp = value; n-- > 0; ++first)
283 *first =
static_cast<value_type
>(temp);
298 template <
typename OutputIterator,
typename Size,
typename T>
299 OutputIterator
fill_n(OutputIterator first, Size n,
const T& value)
304 template <
typename Size>
305 inline char*
fill_n(
char* first, Size n,
const char& c)
307 return (
char*)__builtin_memset(first, (
char)c, (
size_t)n) + n;
310 template <
typename Size>
311 inline unsigned char*
fill_n(
unsigned char* first, Size n,
const unsigned char& c)
313 return (
unsigned char*)__builtin_memset(first, (
unsigned char)c, (
size_t)n) + n;
316 template <
typename Size>
317 inline signed char*
fill_n(
signed char* first, Size n,
const signed char& c)
319 return (
signed char*)__builtin_memset(first, (
signed char)c, n) + (size_t)n;
322 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__ICL)
323 template <
typename Size>
324 inline bool*
fill_n(
bool* first, Size n,
const bool& b)
326 return (
bool*)__builtin_memset(first, (
char)b, n) + (size_t)n;
330 #if (defined(EA_COMPILER_GNUC) || defined(__clang__)) && (defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64))
331 #if defined(EA_PROCESSOR_X86_64)
332 template <
typename Size,
typename Value>
333 inline uint64_t*
fill_n(uint64_t* first, Size n, Value c)
335 uintptr_t
count = (uintptr_t)(n);
336 uint64_t value = (uint64_t)(c);
338 __asm__ __volatile__ (
"cld\n\t"
340 :
"+c" (
count),
"+D" (first),
"=m" (first)
347 template <
typename Size,
typename Value>
348 inline int64_t*
fill_n(int64_t* first, Size n, Value c)
350 uintptr_t
count = (uintptr_t)(n);
351 int64_t value = (int64_t)(c);
353 __asm__ __volatile__ (
"cld\n\t"
355 :
"+c" (
count),
"+D" (first),
"=m" (first)
362 template <
typename Size,
typename Value>
363 inline uint32_t*
fill_n(uint32_t* first, Size n, Value c)
365 uintptr_t
count = (uintptr_t)(n);
366 uint32_t value = (uint32_t)(c);
368 __asm__ __volatile__ (
"cld\n\t"
370 :
"+c" (
count),
"+D" (first),
"=m" (first)
377 template <
typename Size,
typename Value>
378 inline int32_t*
fill_n(int32_t* first, Size n, Value c)
380 uintptr_t
count = (uintptr_t)(n);
381 int32_t value = (int32_t)(c);
383 __asm__ __volatile__ (
"cld\n\t"
385 :
"+c" (
count),
"+D" (first),
"=m" (first)
392 template <
typename Size,
typename Value>
393 inline uint16_t*
fill_n(uint16_t* first, Size n, Value c)
395 uintptr_t
count = (uintptr_t)(n);
396 uint16_t value = (uint16_t)(c);
398 __asm__ __volatile__ (
"cld\n\t"
400 :
"+c" (
count),
"+D" (first),
"=m" (first)
407 template <
typename Size,
typename Value>
408 inline int16_t*
fill_n(int16_t* first, Size n, Value c)
410 uintptr_t
count = (uintptr_t)(n);
411 int16_t value = (int16_t)(c);
413 __asm__ __volatile__ (
"cld\n\t"
415 :
"+c" (
count),
"+D" (first),
"=m" (first)
421 #elif defined(EA_COMPILER_MICROSOFT) && (defined(EA_PROCESSOR_X86) || defined(EA_PROCESSOR_X86_64))
422 #if defined(EA_PROCESSOR_X86_64)
423 template <
typename Size,
typename Value>
424 inline uint64_t*
fill_n(uint64_t* first, Size n, Value c)
426 __stosq(first, (uint64_t)c, (
size_t)n);
430 template <
typename Size,
typename Value>
431 inline int64_t*
fill_n(int64_t* first, Size n, Value c)
433 __stosq((uint64_t*)first, (uint64_t)c, (
size_t)n);
438 template <
typename Size,
typename Value>
439 inline uint32_t*
fill_n(uint32_t* first, Size n, Value c)
441 __stosd((
unsigned long*)first, (
unsigned long)c, (
size_t)n);
445 template <
typename Size,
typename Value>
446 inline int32_t*
fill_n(int32_t* first, Size n, Value c)
448 __stosd((
unsigned long*)first, (
unsigned long)c, (
size_t)n);
452 template <
typename Size,
typename Value>
453 inline uint16_t*
fill_n(uint16_t* first, Size n, Value c)
455 __stosw(first, (uint16_t)c, (
size_t)n);
459 template <
typename Size,
typename Value>
460 inline int16_t*
fill_n(int16_t* first, Size n, Value c)
462 __stosw((uint16_t*)first, (uint16_t)c, (
size_t)n);
EA Standard Template Library.
Definition: algorithm.h:288
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)
Definition: algorithm.h:1347
OutputIterator fill_n(OutputIterator first, Size n, const T &value)
Definition: fill_help.h:299
void fill(ForwardIterator first, ForwardIterator last, const T &value)
Definition: fill_help.h:75
Definition: fill_help.h:29
Definition: fill_help.h:261