ソースを参照

Tweaked MEMSET_TURBO abit, temperory disabled GCC version.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8505 54d463be-8e91-2dee-dedb-b68131a5f0ec
Lance 18 年 前
コミット
8867e722ac
4 ファイル変更37 行追加65 行削除
  1. 29 57
      src/common/malloc.c
  2. 6 6
      src/common/malloc.h
  3. 1 1
      src/map/map.h
  4. 1 1
      src/map/status.c

+ 29 - 57
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
 

+ 6 - 6
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);

+ 1 - 1
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;

+ 1 - 1
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;