#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src,size_t n)
{
if (n==0)
return dest;
#if defined(__x86_64__) || defined(_M_X64)
size_t i=0;
if(n>=8)
while(i<n/8*8){
*(uint64_t*)(dest + i) = *(uint64_t*)(src+i);
i+=8;
}
if(n-i>=4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#elif defined(__i386) || defined(_M_IX86)
size_t i;i=0;
if(n>=4)
while(i<n/4*4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#endif
return dest;
}
#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src,size_t n)
{
if (n==0)
return dest;
#if defined(__x86_64__) || defined(_M_X64)
size_t i=0;
if(n>=8)
while(i<n/8*8){
*(uint64_t*)(dest + i) = *(uint64_t*)(src+i);
i+=8;
}
if(n-i>=4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#elif defined(__i386) || defined(_M_IX86)
size_t i;
if(n>=4)
while(i<n/4*4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#endif
return dest;
}
#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src,size_t n)
{
if (n==0)
return dest;
#if defined(__x86_64__) || defined(_M_X64)
size_t i=0;
if(n>=8)
while(i<n/8*8){
*(uint64_t*)(dest + i) = *(uint64_t*)(src+i);
i+=8;
}
if(n-i>=4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#elif defined(__i386) || defined(_M_IX86)
size_t i=0;
if(n>=4)
while(i<n/4*4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#endif
return dest;
}
EDITS
sorry for being inconvenient posting buggy code
I made some aggressive testing with memcmp()
to check for correct data transmission and valgrind
valgrind to check for memory leaks and It passed all the tests.
I I didn't post the testing code because I think it could be useless since I don't want it to be reviewed.
EDITS
sorry for being inconvenient posting buggy code
I made some aggressive testing with memcmp()
to check for correct data transmission and valgrind
to check for memory leaks and It passed all the tests.
I didn't post the testing code because I think it could be useless since I don't want it to be reviewed
I made some aggressive testing with memcmp()
to check for correct data transmission and valgrind to check for memory leaks and It passed all the tests. I didn't post the testing code because I think it could be useless since I don't want it to be reviewed.
#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src,size_t n)
{
if (n==0)
return dest;
#if defined(__x86_64__) || defined(_M_X64)
uint64_tsize_t i;i=0;
forif(i=0;i<nn>=8)
while(i<n/8;i++8*8){
*((uint64_t*)(dest + i) = *((uint64_t*)(src+i);
for(i = i+=8;
}
if(in-1)*2;i<n/4;i++i>=4){
*((uint32_t*)(dest + i) = *((uint32_t*)(src+i);
for i+=4;
}
if(in-i>=2){
*(uint16_t*)(dest+i) = *(i-1uint16_t*)*4;i<n;i++(src+i);
*i+=2;
}
if(n-i>=1)
*(char*uint8_t*)(dest+i) = *((char*uint8_t*)(src+i);
#elif defined(__i386) || defined(_M_IX86)
uint8_tsize_t i;
forif(i=0;i<nn>=4)
while(i<n/4;i++4*4){
*((uint32_t*)(dest + i) = *((uint32_t*)(src+i);
for(i = i+=4;
}
if(in-1)*4;i<n;i++i>=2){
*((char*uint16_t*)(dest+i) = *((char*uint16_t*)(src+i);
#else i+=2;
while}
if(n-->=0i>=1)
*((char*uint8_t*)dest+n(dest+i) = *((char*uint8_t*)src+n(src+i);
#endif
return dest;
}
EDITS
sorry for being inconvenient posting buggy code
I made some aggressive testing with memcmp()
to check for correct data transmission and valgrind
to check for memory leaks and It passed all the tests.
I didn't post the testing code because I think it could be useless since I don't want it to be reviewed
#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src,size_t n)
{
#if defined(__x86_64__) || defined(_M_X64)
uint64_t i;
for(i=0;i<n/8;i++)
*((uint64_t*)dest + i) = *((uint64_t*)src+i);
for(i = (i-1)*2;i<n/4;i++)
*((uint32_t*)dest + i) = *((uint32_t*)src+i);
for(i = (i-1)*4;i<n;i++)
*((char*)dest+i) = *((char*)src+i);
#elif defined(__i386) || defined(_M_IX86)
uint8_t i;
for(i=0;i<n/4;i++)
*((uint32_t*)dest + i) = *((uint32_t*)src+i);
for(i = (i-1)*4;i<n;i++)
*((char*)dest+i) = *((char*)src+i);
#else
while(n-->=0)
*((char*)dest+n) = *((char*)src+n);
#endif
return dest;
}
#include <stddef.h>
#include <stdint.h>
void *memcpy(void *dest, const void *src,size_t n)
{
if (n==0)
return dest;
#if defined(__x86_64__) || defined(_M_X64)
size_t i=0;
if(n>=8)
while(i<n/8*8){
*(uint64_t*)(dest + i) = *(uint64_t*)(src+i);
i+=8;
}
if(n-i>=4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#elif defined(__i386) || defined(_M_IX86)
size_t i;
if(n>=4)
while(i<n/4*4){
*(uint32_t*)(dest + i) = *(uint32_t*)(src+i);
i+=4;
}
if(n-i>=2){
*(uint16_t*)(dest+i) = *(uint16_t*)(src+i);
i+=2;
}
if(n-i>=1)
*(uint8_t*)(dest+i) = *(uint8_t*)(src+i);
#endif
return dest;
}
EDITS
sorry for being inconvenient posting buggy code
I made some aggressive testing with memcmp()
to check for correct data transmission and valgrind
to check for memory leaks and It passed all the tests.
I didn't post the testing code because I think it could be useless since I don't want it to be reviewed