0005-Fixes-assembling-with-binutils-as-2.41.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From effadce6c756247ea8bae32dc13bb3e6f464f0eb Mon Sep 17 00:00:00 2001
  2. From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
  3. Date: Sun, 16 Jul 2023 18:18:02 +0300
  4. Subject: [PATCH] avcodec/x86/mathops: clip constants used with shift
  5. instructions within inline assembly
  6. Fixes assembling with binutils as >= 2.41
  7. Upstream: http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=effadce6c756247ea8bae32dc13bb3e6f464f0eb
  8. Bug reports for this change in binutils:
  9. https://fftrac-bg.ffmpeg.org/ticket/10405
  10. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108941
  11. https://sourceware.org/bugzilla/show_bug.cgi?id=30578
  12. Signed-off-by: James Almer <jamrial@gmail.com>
  13. Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
  14. ---
  15. libavcodec/x86/mathops.h | 26 +++++++++++++++++++++++---
  16. 1 file changed, 23 insertions(+), 3 deletions(-)
  17. diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h
  18. index 6298f5ed19..ca7e2dffc1 100644
  19. --- a/libavcodec/x86/mathops.h
  20. +++ b/libavcodec/x86/mathops.h
  21. @@ -35,12 +35,20 @@
  22. static av_always_inline av_const int MULL(int a, int b, unsigned shift)
  23. {
  24. int rt, dummy;
  25. + if (__builtin_constant_p(shift))
  26. __asm__ (
  27. "imull %3 \n\t"
  28. "shrdl %4, %%edx, %%eax \n\t"
  29. :"=a"(rt), "=d"(dummy)
  30. - :"a"(a), "rm"(b), "ci"((uint8_t)shift)
  31. + :"a"(a), "rm"(b), "i"(shift & 0x1F)
  32. );
  33. + else
  34. + __asm__ (
  35. + "imull %3 \n\t"
  36. + "shrdl %4, %%edx, %%eax \n\t"
  37. + :"=a"(rt), "=d"(dummy)
  38. + :"a"(a), "rm"(b), "c"((uint8_t)shift)
  39. + );
  40. return rt;
  41. }
  42. @@ -113,19 +121,31 @@ __asm__ volatile(\
  43. // avoid +32 for shift optimization (gcc should do that ...)
  44. #define NEG_SSR32 NEG_SSR32
  45. static inline int32_t NEG_SSR32( int32_t a, int8_t s){
  46. + if (__builtin_constant_p(s))
  47. __asm__ ("sarl %1, %0\n\t"
  48. : "+r" (a)
  49. - : "ic" ((uint8_t)(-s))
  50. + : "i" (-s & 0x1F)
  51. );
  52. + else
  53. + __asm__ ("sarl %1, %0\n\t"
  54. + : "+r" (a)
  55. + : "c" ((uint8_t)(-s))
  56. + );
  57. return a;
  58. }
  59. #define NEG_USR32 NEG_USR32
  60. static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
  61. + if (__builtin_constant_p(s))
  62. __asm__ ("shrl %1, %0\n\t"
  63. : "+r" (a)
  64. - : "ic" ((uint8_t)(-s))
  65. + : "i" (-s & 0x1F)
  66. );
  67. + else
  68. + __asm__ ("shrl %1, %0\n\t"
  69. + : "+r" (a)
  70. + : "c" ((uint8_t)(-s))
  71. + );
  72. return a;
  73. }
  74. --
  75. 2.30.2