1 1.1 mrg /* Shift functions for the GCC support library for the Renesas RL78 processors. 2 1.10 mrg Copyright (C) 2011-2022 Free Software Foundation, Inc. 3 1.1 mrg Contributed by Red Hat. 4 1.1 mrg 5 1.1 mrg This file is part of GCC. 6 1.1 mrg 7 1.1 mrg GCC is free software; you can redistribute it and/or modify 8 1.1 mrg it under the terms of the GNU General Public License as published by 9 1.1 mrg the Free Software Foundation; either version 3, or (at your option) 10 1.1 mrg any later version. 11 1.1 mrg 12 1.1 mrg GCC is distributed in the hope that it will be useful, 13 1.1 mrg but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 mrg GNU General Public License for more details. 16 1.1 mrg 17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 18 1.1 mrg permissions described in the GCC Runtime Library Exception, version 19 1.1 mrg 3.1, as published by the Free Software Foundation. 20 1.1 mrg 21 1.1 mrg You should have received a copy of the GNU General Public License and 22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24 1.1 mrg <http://www.gnu.org/licenses/>. */ 25 1.1 mrg 26 1.1 mrg typedef int sint32_type __attribute__ ((mode (SI))); 28 1.1 mrg typedef unsigned int uint32_type __attribute__ ((mode (SI))); 29 1.1 mrg typedef int sint16_type __attribute__ ((mode (HI))); 30 1.1 mrg typedef unsigned int uint16_type __attribute__ ((mode (HI))); 31 1.1 mrg 32 1.1 mrg uint32_type __ashlsi3 (uint32_type in, char bit); 33 1.1 mrg sint32_type __ashrsi3 (sint32_type in, char bit); 34 1.1 mrg int __clrsbhi2 (sint16_type x); 35 1.1 mrg extern int __clrsbsi2 (sint32_type x); 36 1.1 mrg 37 1.1 mrg typedef struct 38 1.1 mrg { 39 1.1 mrg union 40 1.1 mrg { 41 1.1 mrg uint32_type u; 42 1.1 mrg uint16_type h[2]; 43 1.1 mrg } u; 44 1.1 mrg } dd; 45 1.1 mrg 46 1.1 mrg uint32_type 47 1.1 mrg __ashlsi3 (uint32_type in, char bit) 48 1.1 mrg { 49 1.1 mrg uint16_type h, l; 50 1.1 mrg dd d; 51 1.1 mrg 52 1.1 mrg if (bit > 32) 53 1.1 mrg return 0; 54 1.1 mrg if (bit < 0) 55 1.1 mrg return in; 56 1.1 mrg 57 1.1 mrg d.u.u = in; 58 1.1 mrg h = d.u.h[1]; 59 1.1 mrg l = d.u.h[0]; 60 1.1 mrg 61 1.1 mrg if (bit > 15) 62 1.1 mrg { 63 1.1 mrg h = l; 64 1.1 mrg l = 0; 65 1.1 mrg bit -= 16; 66 1.1 mrg } 67 1.1 mrg 68 1.1 mrg while (bit) 69 1.1 mrg { 70 1.1 mrg h = (h << 1) | (l >> 15); 71 1.1 mrg l <<= 1; 72 1.1 mrg bit --; 73 1.1 mrg } 74 1.1 mrg 75 1.1 mrg d.u.h[1] = h; 76 1.1 mrg d.u.h[0] = l; 77 1.1 mrg return d.u.u; 78 1.1 mrg } 79 1.1 mrg 80 1.1 mrg sint32_type 81 1.1 mrg __ashrsi3 (sint32_type in, char bit) 82 1.1 mrg { 83 1.1 mrg sint16_type h; 84 1.1 mrg uint16_type l; 85 1.1 mrg dd d; 86 1.1 mrg 87 1.1 mrg if (bit > 32) 88 1.1 mrg return 0; 89 1.1 mrg if (bit < 0) 90 1.1 mrg return in; 91 1.1 mrg 92 1.1 mrg d.u.u = in; 93 1.1 mrg h = d.u.h[1]; 94 1.1 mrg l = d.u.h[0]; 95 1.1 mrg 96 1.1 mrg while (bit) 97 1.1 mrg { 98 1.1 mrg l = (h << 15) | (l >> 1); 99 1.1 mrg h >>= 1; 100 1.1 mrg bit --; 101 1.1 mrg } 102 1.1 mrg 103 1.1 mrg d.u.h[1] = h; 104 1.1 mrg d.u.h[0] = l; 105 1.1 mrg return d.u.u; 106 1.1 mrg } 107 1.1 mrg 108 1.1 mrg int 109 1.1 mrg __clrsbhi2 (sint16_type x) 110 1.1 mrg { 111 1.1 mrg if (x == 0) 112 1.1 mrg return 15; 113 1.1 mrg return __clrsbsi2 ((sint32_type) x) - 16; 114 } 115