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. 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 23r8 = 0xffef0 24r16 = 0xffee8 25r9 = 0xffef1 26r17 = 0xffee9 27r10 = 0xffef2 28r18 = 0xffeea 29r11 = 0xffef3 30r19 = 0xffeeb 31r12 = 0xffef4 32r20 = 0xffeec 33r13 = 0xffef5 34r21 = 0xffeed 35r14 = 0xffef6 36r22 = 0xffeee 37r15 = 0xffef7 38r23 = 0xffeef 39 40 .text 41 .global ___lshrsi3 42 .type ___lshrsi3, @function 43___lshrsi3: 44 45 ;; input: 46 ;; 47 ;; [zero] 48 ;; [count] <= $sp+8 49 ;; [in MSB] 50 ;; [in] 51 ;; [in] 52 ;; [in LSB] <- $sp+4 53 54 ;; output: 55 ;; 56 ;; [r8..r11] result 57 58 ;; registers: 59 ;; 60 ;; AX - temp for shift/rotate 61 ;; B - count 62 63 mov a, [sp+8] ; A now contains the count 64 65 cmp a, #0x20 66 bc $.Lcount_is_normal 67 68 ;; count is out of bounds, just return zero. 69 movw r8, #0 70 movw r10, #0 71 ret 72 73.Lcount_is_normal: 74 cmp0 a 75 bnz $.Lcount_is_nonzero 76 77 ;; count is zero, just copy IN to OUT 78 movw ax, [sp+4] 79 movw r8, ax 80 movw ax, [sp+6] 81 movw r10, ax 82 ret 83 84.Lcount_is_nonzero: 85 mov b, a ; B now contains the count also 86 bf a.4, $.Lcount_lt_16 87 88 ;; count >= 16, shift 16 at a time. 89 movw r10, #0 90 movw ax, [sp+6] 91 movw r8, ax 92 mov a, b 93 and a, #0x0f 94 sknz 95 ret 96 97 mov b, a ; B now contains the remaining count 98 inc b 99 br $.Lloop_top 100 101.Lcount_lt_16: 102 ;; count is nonzero. Do one 103 movw ax, [sp+6] 104 shrw ax,1 105 movw r10, ax 106 mov a, [sp+5] 107 rorc a,1 108 mov r9, a 109 mov a, [sp+4] 110 rorc a,1 111 mov r8, a 112 113 ;; we did one shift above; do as many more as we need now. 114.Lloop_top: 115 dec b 116 sknz 117 ret 118 119 movw ax, r10 120 shrw ax,1 121 movw r10, ax 122 mov a, r9 123 rorc a,1 124 mov r9, a 125 mov a, r8 126 rorc a,1 127 mov r8, a 128 129 br $.Lloop_top 130 131 .size ___lshrsi3, .-___lshrsi3 132