From effadce6c756247ea8bae32dc13bb3e6f464f0eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
Date: Sun, 16 Jul 2023 18:18:02 +0300
Subject: [PATCH] avcodec/x86/mathops: clip constants used with shift
instructions within inline assembly
Fixes assembling with binutil as >= 2.41
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/x86/mathops.h | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h
index 6298f5ed1983..ca7e2dffc107 100644
a
|
b
|
|
35 | 35 | static av_always_inline av_const int MULL(int a, int b, unsigned shift) |
36 | 36 | { |
37 | 37 | int rt, dummy; |
| 38 | if (__builtin_constant_p(shift)) |
38 | 39 | __asm__ ( |
39 | 40 | "imull %3 \n\t" |
40 | 41 | "shrdl %4, %%edx, %%eax \n\t" |
41 | 42 | :"=a"(rt), "=d"(dummy) |
42 | | :"a"(a), "rm"(b), "ci"((uint8_t)shift) |
| 43 | :"a"(a), "rm"(b), "i"(shift & 0x1F) |
43 | 44 | ); |
| 45 | else |
| 46 | __asm__ ( |
| 47 | "imull %3 \n\t" |
| 48 | "shrdl %4, %%edx, %%eax \n\t" |
| 49 | :"=a"(rt), "=d"(dummy) |
| 50 | :"a"(a), "rm"(b), "c"((uint8_t)shift) |
| 51 | ); |
44 | 52 | return rt; |
45 | 53 | } |
46 | 54 | |
… |
… |
__asm__ volatile(\
|
113 | 121 | // avoid +32 for shift optimization (gcc should do that ...) |
114 | 122 | #define NEG_SSR32 NEG_SSR32 |
115 | 123 | static inline int32_t NEG_SSR32( int32_t a, int8_t s){ |
| 124 | if (__builtin_constant_p(s)) |
116 | 125 | __asm__ ("sarl %1, %0\n\t" |
117 | 126 | : "+r" (a) |
118 | | : "ic" ((uint8_t)(-s)) |
| 127 | : "i" (-s & 0x1F) |
119 | 128 | ); |
| 129 | else |
| 130 | __asm__ ("sarl %1, %0\n\t" |
| 131 | : "+r" (a) |
| 132 | : "c" ((uint8_t)(-s)) |
| 133 | ); |
120 | 134 | return a; |
121 | 135 | } |
122 | 136 | |
123 | 137 | #define NEG_USR32 NEG_USR32 |
124 | 138 | static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ |
| 139 | if (__builtin_constant_p(s)) |
125 | 140 | __asm__ ("shrl %1, %0\n\t" |
126 | 141 | : "+r" (a) |
127 | | : "ic" ((uint8_t)(-s)) |
| 142 | : "i" (-s & 0x1F) |
128 | 143 | ); |
| 144 | else |
| 145 | __asm__ ("shrl %1, %0\n\t" |
| 146 | : "+r" (a) |
| 147 | : "c" ((uint8_t)(-s)) |
| 148 | ); |
129 | 149 | return a; |
130 | 150 | } |
131 | 151 | |