Merged revisions 196716,196830,198094,198116,198502,198877,199007,199262,199319,19946...
[official-gcc.git] / main / libgcc / config / rl78 / lshrsi3.S
blob8bd997897aa06b650b5ba02e829a5de59471a801
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/>.
23 #include "vregs.h"
24         
25         .text
26         .global ___lshrsi3
27         .type   ___lshrsi3, @function
28 ___lshrsi3:
30         ;; input:
31         ;; 
32         ;; [zero]
33         ;; [count]   <= $sp+8
34         ;; [in MSB]
35         ;; [in]
36         ;; [in]
37         ;; [in LSB]  <- $sp+4
39         ;; output:
40         ;; 
41         ;; [r8..r11] result
43         ;; registers:
44         ;;
45         ;; AX - temp for shift/rotate
46         ;; B  - count
48         mov     a, [sp+8]       ; A now contains the count
50         cmp     a, #0x20
51         bc      $.Lcount_is_normal
53         ;; count is out of bounds, just return zero.
54         movw    r8, #0
55         movw    r10, #0
56         ret
58 .Lcount_is_normal:
59         cmp0    a
60         bnz     $.Lcount_is_nonzero
62         ;; count is zero, just copy IN to OUT
63         movw    ax, [sp+4]
64         movw    r8, ax
65         movw    ax, [sp+6]
66         movw    r10, ax
67         ret
69 .Lcount_is_nonzero:
70         mov     b, a            ; B now contains the count also
71         bf      a.4, $.Lcount_lt_16
73         ;; count >= 16, shift 16 at a time.
74         movw    r10, #0
75         movw    ax, [sp+6]
76         movw    r8, ax
77         mov     a, b
78         and     a, #0x0f
79         sknz
80         ret
82         mov     b, a            ; B now contains the remaining count
83         inc     b
84         br      $.Lloop_top
86 .Lcount_lt_16:  
87         ;; count is nonzero.  Do one 
88         movw    ax, [sp+6]
89         shrw    ax,1
90         movw    r10, ax
91         mov     a, [sp+5]
92         rorc    a,1
93         mov     r9, a
94         mov     a, [sp+4]
95         rorc    a,1
96         mov     r8, a
98         ;; we did one shift above; do as many more as we need now.
99 .Lloop_top:     
100         dec     b
101         sknz
102         ret
104         movw    ax, r10
105         shrw    ax,1
106         movw    r10, ax
107         mov     a, r9
108         rorc    a,1
109         mov     r9, a
110         mov     a, r8
111         rorc    a,1
112         mov     r8, a
114         br      $.Lloop_top
116         .size   ___lshrsi3, .-___lshrsi3