1 /* 2 * Copyright (C) 2004 by Digital Mars, www.digitalmars.com 3 * Written by Walter Bright 4 * 5 * This software is provided 'as-is', without any express or implied 6 * warranty. In no event will the authors be held liable for any damages 7 * arising from the use of this software. 8 * 9 * Permission is granted to anyone to use this software for any purpose, 10 * including commercial applications, and to alter it and redistribute it 11 * freely, in both source and binary form, subject to the following 12 * restrictions: 13 * 14 * o The origin of this software must not be misrepresented; you must not 15 * claim that you wrote the original software. If you use this software 16 * in a product, an acknowledgment in the product documentation would be 17 * appreciated but is not required. 18 * o Altered source versions must be plainly marked as such, and must not 19 * be misrepresented as being the original software. 20 * o This notice may not be removed or altered from any source 21 * distribution. 22 */ 23 module rt.compiler.dmd.rt.memset; 24 25 26 extern (C) 27 { 28 // Functions from the C library. 29 void *memcpy(void *, void *, size_t); 30 } 31 32 extern (C): 33 34 short *_memset16(short *p, short value, size_t count) 35 { 36 short *pstart = p; 37 short *ptop; 38 39 for (ptop = &p[count]; p < ptop; p++) 40 *p = value; 41 return pstart; 42 } 43 44 45 int *_memset32(int *p, int value, size_t count) 46 { 47 version (D_InlineAsm_X86) 48 { 49 asm 50 { 51 mov EDI,p ; 52 mov EAX,value ; 53 mov ECX,count ; 54 mov EDX,EDI ; 55 rep ; 56 stosd ; 57 mov EAX,EDX ; 58 } 59 } 60 else 61 { 62 int *pstart = p; 63 int *ptop; 64 65 for (ptop = &p[count]; p < ptop; p++) 66 *p = value; 67 return pstart; 68 } 69 } 70 71 long *_memset64(long *p, long value, size_t count) 72 { 73 long *pstart = p; 74 long *ptop; 75 76 for (ptop = &p[count]; p < ptop; p++) 77 *p = value; 78 return pstart; 79 } 80 81 cdouble *_memset128(cdouble *p, cdouble value, size_t count) 82 { 83 cdouble *pstart = p; 84 cdouble *ptop; 85 86 for (ptop = &p[count]; p < ptop; p++) 87 *p = value; 88 return pstart; 89 } 90 91 real *_memset80(real *p, real value, size_t count) 92 { 93 real *pstart = p; 94 real *ptop; 95 96 for (ptop = &p[count]; p < ptop; p++) 97 *p = value; 98 return pstart; 99 } 100 101 creal *_memset160(creal *p, creal value, size_t count) 102 { 103 creal *pstart = p; 104 creal *ptop; 105 106 for (ptop = &p[count]; p < ptop; p++) 107 *p = value; 108 return pstart; 109 } 110 111 void *_memsetn(void *p, void *value, int count, size_t sizelem) 112 { void *pstart = p; 113 int i; 114 115 for (i = 0; i < count; i++) 116 { 117 memcpy(p, value, sizelem); 118 p = cast(void *)(cast(char *)p + sizelem); 119 } 120 return pstart; 121 } 122 123 float *_memsetFloat(float *p, float value, size_t count) 124 { 125 float *pstart = p; 126 float *ptop; 127 128 for (ptop = &p[count]; p < ptop; p++) 129 *p = value; 130 return pstart; 131 } 132 133 double *_memsetDouble(double *p, double value, size_t count) 134 { 135 double *pstart = p; 136 double *ptop; 137 138 for (ptop = &p[count]; p < ptop; p++) 139 *p = value; 140 return pstart; 141 }