PR middle-end/58809
[official-gcc.git] / libgcc / config / rl78 / cmpsi2.S
blob7fdc76a03f65cf9e0ca5877eff754a423b4fb7ff
1 ;   Copyright (C) 2011-2013 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.
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/>.
24 #include "vregs.h"
26         .text
28         ;;   int __cmpsi2 (signed long A, signed long B)
29         ;;
30         ;; Performs a signed comparison of A and B.
31         ;; If A is less than B it returns 0.  If A is greater
32         ;; than B it returns 2.  If they are equal it returns 1.
34         .global ___cmpsi2
35         .type   ___cmpsi2, @function
36 ___cmpsi2:
37         ;; A is at [sp+4]
38         ;; B is at [sp+8]
39         ;; Result put in R8
41         ;; Initialise default return value.
42         onew    bc
43         
44         ;;  Compare the high words.
45         movw    ax, [sp + 10]
46         movw    de, ax
47         movw    ax, [sp + 6]
48         cmpw    ax, de
49         skz
50         br      !!.Lconvert_to_signed
52 .Lcompare_bottom_words: 
53         ;; The top words are equal - compare the bottom words.
54         ;; Note - code from __ucmpsi2 branches into here.
55         movw   ax, [sp + 8]
56         movw   de, ax
57         movw   ax, [sp + 4]
58         cmpw   ax, de
59         sknz
60         br      !!.Lless_than_or_greater_than
61         ;; The words are equal - return 1.
62         ;; Note - we could branch to the return code at the end of the
63         ;; function but a branch instruction takes 4 bytes, and the
64         ;; return sequence itself is only 4 bytes long...
65         movw    ax, bc
66         movw    r8, ax
67         ret
69 .Lconvert_to_signed:    
70         ;; The top words are different.  Unfortunately the comparison
71         ;; is always unsigned, so to get a signed result we XOR the CY
72         ;; flag with the top bits of AX and DE.
73         xor1    cy, a.7
74         mov     a, d
75         xor1    cy, a.7
76         ;; Fall through.
78 .Lless_than_or_greater_than:
79         ;; We now have a signed less than/greater than result in CY.
80         ;; Return 0 for less than, 2 for greater than.
81         ;; Note - code from __ucmpsi2 branches into here.
82         incw    bc
83         sknc
84         clrw    bc
86         ;; Get the result value, currently in BC, into r8
87         movw    ax, bc
88         movw    r8, ax
89         ret
91         .size   ___cmpsi2, . - ___cmpsi2
92         
93         
94         ;;   int __ucmpsi2 (unsigned long A, unsigned long B)
95         ;;
96         ;; Performs an unsigned comparison of A and B.
97         ;; If A is less than B it returns 0.  If A is greater
98         ;; than B it returns 2.  If they are equal it returns 1.
100         .global ___ucmpsi2
101         .type   ___ucmpsi2, @function
102 ___ucmpsi2:
103         ;; A is at [sp+4]
104         ;; B is at [sp+8]
105         ;; Result put in R8..R9
107         ;; Initialise default return value.
108         onew    bc
110         ;;  Compare the high words.
111         movw    ax, [sp + 10]
112         movw    de, ax
113         movw    ax, [sp + 6]
114         cmpw    ax, de
115         skz
116         ;; Note: These branches go into the __cmpsi2 code!
117         br      !!.Lless_than_or_greater_than
118         br      !!.Lcompare_bottom_words
120         .size   ___ucmpsi2, . - ___ucmpsi2
121