[gcc r17-2700] AVR: Add __negdi2_r10 to libgcc.

Georg-Johann Lay via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:07e78425476eb1054d7e0973d6ef39ba73b62821

commit r17-2700-g07e78425476eb1054d7e0973d6ef39ba73b62821
Author: Georg-Johann Lay <[email protected]>
Date:   Sat Jul 25 15:14:50 2026 +0200

    AVR: Add __negdi2_r10 to libgcc.
    
    This patch introduces __negdi2_r10 to lib1funcs.S and tidies
    some 64-bit negations.
    
    libgcc/
            * config/avr/t-avr (FUNCS_notiny): Add _negdi2_r10.
            * config/avr/lib1funcs.S (__negdi2_r10): New function.
            (__divdi3_moddi3): Use it.
            * config/avr/lib1funcs-fixed.S (__mulQ64_work): Use it.

Diff:
---
 libgcc/config/avr/lib1funcs-fixed.S | 36 ++----------------------------------
 libgcc/config/avr/lib1funcs.S       | 31 +++++++++++++++++--------------
 libgcc/config/avr/t-avr             |  2 +-
 3 files changed, 20 insertions(+), 49 deletions(-)

diff --git a/libgcc/config/avr/lib1funcs-fixed.S b/libgcc/config/avr/lib1funcs-fixed.S
index 37f8151480da..f1b61e12e976 100644
--- a/libgcc/config/avr/lib1funcs-fixed.S
+++ b/libgcc/config/avr/lib1funcs-fixed.S
@@ -1154,40 +1154,8 @@ DEFUN __mulQ64_work
     eor     __tmp_reg__, B7
     push    __tmp_reg__
 
-    ;; A = |A|
-    .call_if_neg  A7, __negdi2
-
-    ;; Stash away |A|
-    wmov    r26, A6
-#ifdef __AVR_HAVE_MUL__
-    wmov    r0, A4
-#else
-    push    A5
-    push    A4
-#endif
-    push    A3
-    push    A2
-    push    A1
-    push    A0
-
-    ;; A = |B|
-    mov8    A0, B0
-    .call_if_neg  A7, __negdi2
-
-    ;; Restore B = |A|
-    wmov    B6, r26
-    pop     B0
-    pop     B1
-    pop     B2
-    pop     B3
-#ifdef __AVR_HAVE_MUL__
-    wmov    B4, r0
-    ;; No need to clear zero_reg since it won't be used until the
-    ;; next MUL in __umulditi3_raw -> __umulsidi3 -> __umulhisi3.
-#else
-    pop     B4
-    pop     B5
-#endif
+    .call_if_neg  A7, __negdi2          ; A = |A|
+    .call_if_neg  B7, __negdi2_r10      ; B = |B|
 
     set    ; for signed
     XICALL ; __muluxx3.2
diff --git a/libgcc/config/avr/lib1funcs.S b/libgcc/config/avr/lib1funcs.S
index 150cf82336a6..f780a6965dc4 100644
--- a/libgcc/config/avr/lib1funcs.S
+++ b/libgcc/config/avr/lib1funcs.S
@@ -1816,26 +1816,15 @@ DEFUN  __divdi3_moddi3
 22: ldi     NN, 1 << 7
     eor     SS, NN
 
-    ldi NN, -1
-    com B4     $  com B5     $  com B6     $  com B7
-               $  com B1     $  com B2     $  com B3
-    NEG B0
-               $  sbc B1,NN  $  sbc B2,NN  $  sbc B3,NN
-    sbc B4,NN  $  sbc B5,NN  $  sbc B6,NN  $  sbc B7,NN
+    XCALL   __negdi2_r10
 
 3:  ;; Do the unsigned 64-Bit Division/Modulo (depending on T-flag)
     XCALL   __udivmod64
 
     ;; Adjust Result's Sign
-#ifdef __AVR_ERRATA_SKIP_JMP_CALL__
-    tst     SS
-    brpl    4f
-#else
-    sbrc    SS, 7
-#endif /* __AVR_HAVE_JMP_CALL__ */
-    XCALL   __negdi2
+    .call_if_neg  SS, __negdi2
 
-4:  ;; Epilogue: Restore 12 Registers and return
+    ;; Epilogue: Restore 12 Registers and return
     do_epilogue_restores 12
 
 ENDF __divdi3_moddi3
@@ -1931,6 +1920,20 @@ DEFUN __negdi2
 ENDF __negdi2
 #endif /* L_negdi2 */
 
+#if defined (L_negdi2_r10)
+;; (set (reg:DI 10)
+;;      (neg:DI (reg:DI 10)))
+;; Requires zero_reg R1 = 0.
+DEFUN __negdi2_r10
+    COM  B7         $ com  B6       $ com  B5       $ com  B4
+    com  B3         $ com  B2       $ com  B1       $ com  B0
+
+    ADC  B0, r1     $ adc  B1, r1   $ adc  B2, r1   $ adc  B3, r1
+    adc  B4, r1     $ adc  B5, r1   $ adc  B6, r1   $ adc  B7, r1
+    ret
+ENDF __negdi2_r10
+#endif /* L_negdi2_r10 */
+
 #undef TT
 
 #undef C7
diff --git a/libgcc/config/avr/t-avr b/libgcc/config/avr/t-avr
index df85485e0a79..657c61a56664 100644
--- a/libgcc/config/avr/t-avr
+++ b/libgcc/config/avr/t-avr
@@ -67,7 +67,7 @@ FUNCS_notiny = \
 	_mulsidi3 _umulsidi3 \
 	_divdi3 _udivdi3 \
 	_udivmod64 \
-	_negdi2 \
+	_negdi2 _negdi2_r10 \
 	_prologue \
 	_epilogue \
 	_load_3 _load_4 \
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.