Ticket #18367: ffmpeg-binutils_2.41_fixes-1.patch

File ffmpeg-binutils_2.41_fixes-1.patch, 2.1 KB (added by thomas, 14 months ago)
  • libavcodec/x86/mathops.h

    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  
    3535static av_always_inline av_const int MULL(int a, int b, unsigned shift)
    3636{
    3737    int rt, dummy;
     38    if (__builtin_constant_p(shift))
    3839    __asm__ (
    3940        "imull %3               \n\t"
    4041        "shrdl %4, %%edx, %%eax \n\t"
    4142        :"=a"(rt), "=d"(dummy)
    42         :"a"(a), "rm"(b), "ci"((uint8_t)shift)
     43        :"a"(a), "rm"(b), "i"(shift & 0x1F)
    4344    );
     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        );
    4452    return rt;
    4553}
    4654
    __asm__ volatile(\  
    113121// avoid +32 for shift optimization (gcc should do that ...)
    114122#define NEG_SSR32 NEG_SSR32
    115123static inline  int32_t NEG_SSR32( int32_t a, int8_t s){
     124    if (__builtin_constant_p(s))
    116125    __asm__ ("sarl %1, %0\n\t"
    117126         : "+r" (a)
    118          : "ic" ((uint8_t)(-s))
     127         : "i" (-s & 0x1F)
    119128    );
     129    else
     130        __asm__ ("sarl %1, %0\n\t"
     131               : "+r" (a)
     132               : "c" ((uint8_t)(-s))
     133        );
    120134    return a;
    121135}
    122136
    123137#define NEG_USR32 NEG_USR32
    124138static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
     139    if (__builtin_constant_p(s))
    125140    __asm__ ("shrl %1, %0\n\t"
    126141         : "+r" (a)
    127          : "ic" ((uint8_t)(-s))
     142         : "i" (-s & 0x1F)
    128143    );
     144    else
     145        __asm__ ("shrl %1, %0\n\t"
     146               : "+r" (a)
     147               : "c" ((uint8_t)(-s))
     148        );
    129149    return a;
    130150}
    131151