changeset 6605:5ddfba86d5a4

fixing memory overwrite bugs again ...
author michael
date Sat, 29 Jun 2002 20:50:11 +0000
parents 62ce54563e56
children 50b5d8367318
files postproc/rgb2rgb_template.c
diffstat 1 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/postproc/rgb2rgb_template.c	Sat Jun 29 16:27:48 2002 +0000
+++ b/postproc/rgb2rgb_template.c	Sat Jun 29 20:50:11 2002 +0000
@@ -63,13 +63,13 @@
   const uint8_t *s = src;
   const uint8_t *end;
 #ifdef HAVE_MMX
-  uint8_t *mm_end;
+  const uint8_t *mm_end;
 #endif
   end = s + src_size;
 #ifdef HAVE_MMX
   __asm __volatile(PREFETCH"	%0"::"m"(*s):"memory");
+  mm_end = end - 23;
   __asm __volatile("movq	%0, %%mm7"::"m"(mask32):"memory");
-  mm_end = (uint8_t*)((((unsigned long)end)/24)*24);
   while(s < mm_end)
   {
     __asm __volatile(
@@ -114,12 +114,12 @@
   const uint8_t *s = src;
   const uint8_t *end;
 #ifdef HAVE_MMX
-  uint8_t *mm_end;
+  const uint8_t *mm_end;
 #endif
   end = s + src_size;
 #ifdef HAVE_MMX
   __asm __volatile(PREFETCH"	%0"::"m"(*s):"memory");
-  mm_end = (uint8_t*)((((unsigned long)end)/32)*32);
+  mm_end = end - 31;
   while(s < mm_end)
   {
     __asm __volatile(
@@ -196,12 +196,12 @@
   register const uint8_t* s=src;
   register uint8_t* d=dst;
   register const uint8_t *end;
-  uint8_t *mm_end;
+  const uint8_t *mm_end;
   end = s + src_size;
 #ifdef HAVE_MMX
   __asm __volatile(PREFETCH"	%0"::"m"(*s));
   __asm __volatile("movq	%0, %%mm4"::"m"(mask15s));
-  mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
+  mm_end = end - 15;
   while(s<mm_end)
   {
 	__asm __volatile(
@@ -225,7 +225,7 @@
   __asm __volatile(SFENCE:::"memory");
   __asm __volatile(EMMS:::"memory");
 #endif
-    mm_end = (uint8_t*)((((unsigned long)end)/4)*4);
+    mm_end = end - 3;
     while(s < mm_end)
     {
 	register unsigned x= *((uint32_t *)s);
@@ -266,7 +266,7 @@
 	    "movq	%0, %%mm7\n\t"
 	    "movq	%1, %%mm6\n\t"
 	    ::"m"(red_16mask),"m"(green_16mask));
-	mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
+	mm_end = end - 15;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -330,7 +330,7 @@
 	    "movq	%0, %%mm7\n\t"
 	    "movq	%1, %%mm6\n\t"
 	    ::"m"(red_15mask),"m"(green_15mask));
-	mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
+	mm_end = end - 15;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -394,7 +394,7 @@
 	    "movq	%0, %%mm7\n\t"
 	    "movq	%1, %%mm6\n\t"
 	    ::"m"(red_16mask),"m"(green_16mask));
-	mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
+	mm_end = end - 11;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -457,7 +457,7 @@
 	    "movq	%0, %%mm7\n\t"
 	    "movq	%1, %%mm6\n\t"
 	    ::"m"(red_15mask),"m"(green_15mask));
-	mm_end = (uint8_t*)((((unsigned long)end)/16)*16);
+	mm_end = end - 11;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -539,7 +539,7 @@
 	end = s + src_size/2;
 #ifdef HAVE_MMX
 	__asm __volatile(PREFETCH"	%0"::"m"(*s):"memory");
-	mm_end = (uint16_t*)((((unsigned long)end)/8)*8);
+	mm_end = end - 7;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -681,7 +681,7 @@
 	end = s + src_size/2;
 #ifdef HAVE_MMX
 	__asm __volatile(PREFETCH"	%0"::"m"(*s):"memory");
-	mm_end = (uint16_t*)((((unsigned long)end)/8)*8);
+	mm_end = end - 7;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -823,7 +823,7 @@
 #ifdef HAVE_MMX
 	__asm __volatile(PREFETCH"	%0"::"m"(*s):"memory");
 	__asm __volatile("pxor	%%mm7,%%mm7\n\t":::"memory");
-	mm_end = (uint16_t*)((((unsigned long)end)/4)*4);
+	mm_end = end - 3;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -888,7 +888,7 @@
 #ifdef HAVE_MMX
 	__asm __volatile(PREFETCH"	%0"::"m"(*s):"memory");
 	__asm __volatile("pxor	%%mm7,%%mm7\n\t":::"memory");
-	mm_end = (uint16_t*)((((unsigned long)end)/4)*4);
+	mm_end = end - 3;
 	while(s < mm_end)
 	{
 	    __asm __volatile(
@@ -964,7 +964,7 @@
 		"addl $8, %%eax			\n\t"
 		"cmpl %2, %%eax			\n\t"
 		" jb 1b				\n\t"
-		:: "r" (src), "r"(dst), "r" (src_size)
+		:: "r" (src), "r"(dst), "r" (src_size-7)
 		: "%eax"
 	);