summaryrefslogtreecommitdiffstats
path: root/testing/mpv/0001-video-filter-fix-PIC-compile-on-x86.patch
blob: 8a00bdd9d1ef0caff2a2776c7192475caf6d8b91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From b7b7649fe791fc460ba973463f37a368191c5c87 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 26 Nov 2013 08:46:53 +0000
Subject: [PATCH] video/filter: fix PIC compile on x86

When using PIC on x86 (eg with hardened toolchains) the ebx register is
reserverd and cannot be used in assembly code.

For vf_eq we allow the compiler to use memory as input.

For vf_noise we temoporarily borrow the ebp register.

This fixes #361.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
 video/filter/vf_eq.c    | 3 ++-
 video/filter/vf_noise.c | 9 +++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/video/filter/vf_eq.c b/video/filter/vf_eq.c
index 1bca39b..3cba73b 100644
--- a/video/filter/vf_eq.c
+++ b/video/filter/vf_eq.c
@@ -133,6 +133,7 @@ void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src,
   int      pel;
   short    brvec[4];
   short    contvec[4];
+  unsigned wcount = w >> 3;
 
 //  printf("\nmmx: src=%p dst=%p w=%d h=%d ds=%d ss=%d\n",src,dst,w,h,dstride,sstride);
 
@@ -170,7 +171,7 @@ void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src,
       "decl %%eax \n\t"
       "jnz 1b \n\t"
       : "=r" (src), "=r" (dst)
-      : "0" (src), "1" (dst), "r" (w >> 3), "r" (brvec), "r" (contvec)
+      : "0" (src), "1" (dst), "g" (wcount), "r" (brvec), "r" (contvec)
       : "%eax"
     );
 
diff --git a/video/filter/vf_noise.c b/video/filter/vf_noise.c
index c81a1d1..5e7bf75 100644
--- a/video/filter/vf_noise.c
+++ b/video/filter/vf_noise.c
@@ -216,13 +216,16 @@ static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int le
 #if HAVE_MMX
 static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
 	x86_reg mmx_len= len&(~7);
+	uint8_t *src_mmx_len = src+mmx_len;
 
 	__asm__ volatile(
+		"push %%"REG_BP"		\n\t"
+		"mov %0, %%"REG_BP"		\n\t"
 		"mov %5, %%"REG_a"		\n\t"
 		".align 4                       \n\t"
 		"1:				\n\t"
 		"movq (%1, %%"REG_a"), %%mm1	\n\t"
-		"movq (%0, %%"REG_a"), %%mm0	\n\t"
+		"movq (%%"REG_BP", %%"REG_a"), %%mm0	\n\t"
 		"paddb (%2, %%"REG_a"), %%mm1	\n\t"
 		"paddb (%3, %%"REG_a"), %%mm1	\n\t"
 		"movq %%mm0, %%mm2		\n\t"
@@ -243,7 +246,9 @@ static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t
 		"movq %%mm1, (%4, %%"REG_a")	\n\t"
 		"add $8, %%"REG_a"		\n\t"
 		" js 1b				\n\t"
-		:: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
+		"pop %%"REG_BP"			\n\t"
+		:: "g" (src_mmx_len), "r" (shift[0]+mmx_len),
+		   "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
                    "r" (dst+mmx_len), "g" (-mmx_len)
 		: "%"REG_a
 	);
-- 
1.8.4.3