summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/malloc.c86
-rw-r--r--src/common/malloc.h12
-rw-r--r--src/map/map.h2
-rw-r--r--src/map/status.c2
4 files changed, 37 insertions, 65 deletions
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 700da0f88..303bf9cac 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -116,14 +116,14 @@ void aFree_ (void *p, const char *file, int line, const char *func)
void* _bcallocA(size_t size, size_t cnt)
{
void *ret = MALLOCA(size * cnt);
- if (ret) //memset(ret, 0, size * cnt);
+ if (ret) //malloc_set(ret, 0, size * cnt);
malloc_set(ret, 0, size*cnt);
return ret;
}
void* _bcalloc(size_t size, size_t cnt)
{
void *ret = MALLOC(size * cnt);
- if (ret) //memset(ret, 0, size * cnt);
+ if (ret) //malloc_set(ret, 0, size * cnt);
malloc_set(ret, 0, size*cnt);
return ret;
}
@@ -327,7 +327,7 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func ) {
void* _mcalloc(size_t num, size_t size, const char *file, int line, const char *func ) {
void *p = _mmalloc(num * size,file,line,func);
- //memset(p,0,num * size);
+ //malloc_set(p,0,num * size);
malloc_set(p,0,num*size);
return p;
}
@@ -686,79 +686,51 @@ static void memmgr_init (void)
}
#endif
-#ifdef MEMSET_TURBO
- // This function is practically useless if the the size of the data is
- // static. It decides whether to use setword or setdword.
- void malloc_set(void *dest, int value, int size)
- {
- if(size%4 == 0)
- malloc_tsetdword(dest, value, size);
- else if(size%2 == 0)
- malloc_tsetword(dest, (short)value, size);
- else
- memset(dest, value, (size_t) size);
+#if defined(MEMSET_TURBO) || defined(_WIN32)
+ void malloc_set(void *dest, int value, int count){
+ _asm
+ {
+ mov eax, value
+ mov ecx, count
+ mov ebx, ecx
+ mov edi, dest
+ shr ecx, 2
+ test ecx, ecx
+ jz ByteOp
+ shl ecx, 2
+ sub ebx, ecx
+ shr ecx, 2
+ rep stosd
+ test ebx, ebx
+ jz Done
+ ByteOp:
+ mov ecx, ebx
+ rep stosb
+ Done:
+ }
}
-
// Sets 32-bit aligned memory.
void malloc_tsetdword(void *dest, int value, int count){
-#ifdef _WIN32
_asm
{
- mov edx, 0
- mov eax, count
- mov ebx, 4
- idiv ebx
mov edi, dest
- mov ecx, eax
+ mov ecx, count
+ shr ecx, 2
mov eax, value
rep stosd
}
-#else
- __asm__("movl $0, %%edx;
- movl %1, %%eax;
- movl $4, %%ebx;
- idivl %%ebx;
- movl %0, %%edi;
- movl %%eax, %%ecx;
- movl %2, %%eax;
- rep;
- stosd;"
- :
- : "g" (dest), "g" (count), "g" (value)
- : "edx", "eax", "ebx", "edi", "ecx"
- );
-#endif
}
// Sets 16-bit aligned memory.
void malloc_tsetword(void *dest, short value, int count){
-#ifdef _WIN32
_asm
{
- mov edx, 0
- mov eax, count
- mov ebx, 2
- idiv ebx
mov edi, dest
- mov ecx, eax
+ mov ecx, count
+ shr ecx, 1
mov ax, value
rep stosw
}
-#else
- __asm__("movl $0, %%edx;
- movl %1, %%eax;
- movl $2, %%ebx;
- idivl %%ebx;
- movl %0, %%edi;
- movl %%eax, %%ecx;
- movw %2, %%ax;
- rep;
- stosw;"
- :
- : "g" (dest), "g" (count), "g" (value)
- : "edx", "eax", "ebx", "edi", "ecx", "ax"
- );
-#endif
}
#endif
diff --git a/src/common/malloc.h b/src/common/malloc.h
index d3df667a6..322ee9e79 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -4,7 +4,7 @@
#ifndef _MALLOC_H_
#define _MALLOC_H_
-//#define MEMSET_TURBO
+#define MEMSET_TURBO
#ifndef __NETBSD__
#if __STDC_VERSION__ < 199901L
@@ -156,14 +156,14 @@ unsigned int malloc_usage (void);
#define INLINE inline
#endif
#endif
-#ifdef MEMSET_TURBO
- INLINE void malloc_tsetdword(void *dest, int value, int count);
- INLINE void malloc_tsetword(void *dest, short value, int count);
- INLINE void malloc_set(void *dest, int value, int size);
+#if defined(MEMSET_TURBO) || defined(_WIN32)
+ INLINE void malloc_set(void *, int, int);
+ INLINE void malloc_tsetdword(void *, int, int);
+ INLINE void malloc_tsetword(void *, short, int);
#else
+ #define malloc_set(x,y,z) memset(x,y,z)
#define malloc_tsetdword(x,y,z) memset(x,y,z)
#define malloc_tsetword(x,y,z) memset(x,y,z)
- #define malloc_set(x,y,z) memset(x,y,z)
#endif
void malloc_init (void);
void malloc_final (void);
diff --git a/src/map/map.h b/src/map/map.h
index 9ca8af739..59c77594e 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -424,7 +424,7 @@ struct vending {
struct weapon_data {
int atkmods[3];
// all the variables except atkmods get zero'ed in each call of status_calc_pc
- // NOTE: if you want to add a non-zeroed variable, you need to update the memset call
+ // NOTE: if you want to add a non-zeroed variable, you need to update the malloc_set call
// in status_calc_pc as well! All the following are automatically zero'ed. [Skotlex]
int overrefine;
int star;
diff --git a/src/map/status.c b/src/map/status.c
index 12a20a335..ffa243604 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -1589,7 +1589,7 @@ int status_calc_pc(struct map_session_data* sd,int first)
malloc_set(&status->max_hp, 0, sizeof(struct status_data)-(sizeof(status->hp)+sizeof(status->sp)+sizeof(status->lhw)));
malloc_set(status->lhw, 0, sizeof(struct weapon_atk));
- //FIXME: Most of these stuff should be calculated once, but how do I fix the memset above to do that? [Skotlex]
+ //FIXME: Most of these stuff should be calculated once, but how do I fix the malloc_set above to do that? [Skotlex]
status->speed = DEFAULT_WALK_SPEED;
status->mode = MD_CANMOVE|MD_CANATTACK|MD_LOOTER|MD_ASSIST|MD_AGGRESSIVE|MD_CASTSENSOR;
status->size = (sd->class_&JOBL_BABY)?0:1;