1 /** 2 * Contains a memset implementation used by compiler-generated code. 3 * 4 * Copyright: Copyright Digital Mars 2004 - 2010. 5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 * Authors: Walter Bright 7 * Source: $(DRUNTIMESRC rt/_memset.d) 8 */ 9 10 /* Copyright Digital Mars 2004 - 2010. 11 * Distributed under the Boost Software License, Version 1.0. 12 * (See accompanying file LICENSE or copy at 13 * http://www.boost.org/LICENSE_1_0.txt) 14 */ 15 module rt.memset; 16 17 import rt.util.utility : d_cdouble, d_creal; 18 19 extern (C) 20 { 21 // Functions from the C library. 22 void *memcpy(void *, void *, size_t); 23 } 24 25 extern (C): 26 27 short *_memset16(short *p, short value, size_t count) 28 { 29 short *pstart = p; 30 short *ptop; 31 32 for (ptop = &p[count]; p < ptop; p++) 33 *p = value; 34 return pstart; 35 } 36 37 int *_memset32(int *p, int value, size_t count) 38 { 39 version (D_InlineAsm_X86) 40 { 41 asm 42 { 43 mov EDI,p ; 44 mov EAX,value ; 45 mov ECX,count ; 46 mov EDX,EDI ; 47 rep ; 48 stosd ; 49 mov EAX,EDX ; 50 } 51 } 52 else 53 { 54 int *pstart = p; 55 int *ptop; 56 57 for (ptop = &p[count]; p < ptop; p++) 58 *p = value; 59 return pstart; 60 } 61 } 62 63 long *_memset64(long *p, long value, size_t count) 64 { 65 long *pstart = p; 66 long *ptop; 67 68 for (ptop = &p[count]; p < ptop; p++) 69 *p = value; 70 return pstart; 71 } 72 73 d_cdouble *_memset128(d_cdouble *p, d_cdouble value, size_t count) 74 { 75 d_cdouble *pstart = p; 76 d_cdouble *ptop; 77 78 for (ptop = &p[count]; p < ptop; p++) 79 *p = value; 80 return pstart; 81 } 82 83 void[] *_memset128ii(void[] *p, void[] value, size_t count) 84 { 85 void[] *pstart = p; 86 void[] *ptop; 87 88 for (ptop = &p[count]; p < ptop; p++) 89 *p = value; 90 return pstart; 91 } 92 93 real *_memset80(real *p, real value, size_t count) 94 { 95 real *pstart = p; 96 real *ptop; 97 98 for (ptop = &p[count]; p < ptop; p++) 99 *p = value; 100 return pstart; 101 } 102 103 d_creal *_memset160(d_creal *p, d_creal value, size_t count) 104 { 105 d_creal *pstart = p; 106 d_creal *ptop; 107 108 for (ptop = &p[count]; p < ptop; p++) 109 *p = value; 110 return pstart; 111 } 112 113 void *_memsetn(void *p, void *value, int count, size_t sizelem) 114 { void *pstart = p; 115 int i; 116 117 for (i = 0; i < count; i++) 118 { 119 memcpy(p, value, sizelem); 120 p = cast(void *)(cast(char *)p + sizelem); 121 } 122 return pstart; 123 } 124 125 float *_memsetFloat(float *p, float value, size_t count) 126 { 127 float *pstart = p; 128 float *ptop; 129 130 for (ptop = &p[count]; p < ptop; p++) 131 *p = value; 132 return pstart; 133 } 134 135 double *_memsetDouble(double *p, double value, size_t count) 136 { 137 double *pstart = p; 138 double *ptop; 139 140 for (ptop = &p[count]; p < ptop; p++) 141 *p = value; 142 return pstart; 143 } 144 145 version (D_SIMD) 146 { 147 import core.simd; 148 149 void16* _memsetSIMD(void16 *p, void16 value, size_t count) 150 { 151 foreach (i; 0..count) 152 p[i] = value; 153 return p; 154 } 155 }