1 ; Copyright (C) 2012-2024 Free Software Foundation, Inc. 2 ; Contributed by Red Hat. 3 ; 4 ; This file is free software; you can redistribute it and/or modify it 5 ; under the terms of the GNU General Public License as published by the 6 ; Free Software Foundation; either version 3, or (at your option) any 7 ; later version. 8 ; 9 ; This file is distributed in the hope that it will be useful, but 10 ; WITHOUT ANY WARRANTY; without even the implied warranty of 11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 ; General Public License for more details. 13 ; 14 ; Under Section 7 of GPL version 3, you are granted additional 15 ; permissions described in the GCC Runtime Library Exception, version 16 ; 3.1, as published by the Free Software Foundation. 17 ; 18 ; You should have received a copy of the GNU General Public License and 19 ; a copy of the GCC Runtime Library Exception along with this program; 20 ; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 21 ; <http://www.gnu.org/licenses/>. 22 23 #ifdef __MSP430X_LARGE__ 24 #define ret_ RETA 25 #else 26 #define ret_ RET 27 #endif 28 29 .text 30 31 ;; int __cmpsi2 (signed long A, signed long B) 32 ;; 33 ;; Performs a signed comparison of A and B. 34 ;; If A is less than B it returns 0. If A is greater 35 ;; than B it returns 2. If they are equal it returns 1. 36 37 ;; Note - this code is also used by the __ucmpsi2 routine below. 38 39 .global __cmpsi2 40 .type __cmpsi2, @function 41 __cmpsi2: 42 ;; A is in r12 (low), r13 (high) 43 ;; B is in r14 (low), r15 (high) 44 ;; Result put in r12 45 46 cmp.w r13, r15 47 jeq .L_compare_low 48 jge .L_less_than 49 .L_greater_than: 50 mov.w #2, r12 51 ret_ 52 .L_less_than: 53 mov.w #0, r12 54 ret_ 55 56 .L_compare_low: 57 cmp.w r12, r14 58 jl .L_greater_than 59 jne .L_less_than 60 mov.w #1, r12 61 ret_ 62 63 .size __cmpsi2, . - __cmpsi2 64 65 66 ;; int __ucmpsi2 (unsigned long A, unsigned long B) 67 ;; 68 ;; Performs an unsigned comparison of A and B. 69 ;; If A is less than B it returns 0. If A is greater 70 ;; than B it returns 2. If they are equal it returns 1. 71 72 ;;; Note - this function branches into the __cmpsi2 code above. 73 74 .global __ucmpsi2 75 .type __ucmpsi2, @function 76 __ucmpsi2: 77 ;; A is in r12 (low), r13 (high) 78 ;; B is in r14 (low), r15 (high) 79 ;; Result put in r12 80 81 tst r13 82 jn .L_top_bit_set_in_A 83 tst r15 84 ;;; If the top bit of B is set, but A's is clear we know that A < B. 85 jn .L_less_than 86 ;;; Neither A nor B has their top bit set so we can use the __cmpsi2 routine. 87 ;;; Note we use Jc rather than BR as that saves two bytes. The TST insn always 88 ;;; sets the C bit. 89 jc __cmpsi2 90 91 .L_top_bit_set_in_A: 92 tst r15 93 ;;; If both A and B have their top bit set we can use the __cmpsi2 routine. 94 jn __cmpsi2 95 ;;; Otherwise A has its top bit set and B does not so A > B. 96 jc .L_greater_than 97 98 .size __ucmpsi2, . - __ucmpsi2 99