OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgcc/] [config/] [picochip/] [lshrsi3.c] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 734 jeremybenn
/*
2
 
3
picoChip GCC support for 32-bit logical shift right.
4
 
5
Copyright (C) 2003, 2004, 2005, 2008, 2009  Free Software Foundation, Inc.
6
Contributed by Picochip Ltd.
7
Maintained by Daniel Towner (daniel.towner@picochip.com)
8
 
9
This file is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by the
11
Free Software Foundation; either version 3, or (at your option) any
12
later version.
13
 
14
This file is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
General Public License for more details.
18
 
19
Under Section 7 of GPL version 3, you are granted additional
20
permissions described in the GCC Runtime Library Exception, version
21
3.1, as published by the Free Software Foundation.
22
 
23
You should have received a copy of the GNU General Public License and
24
a copy of the GCC Runtime Library Exception along with this program;
25
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
26
<http://www.gnu.org/licenses/>.  */
27
 
28
typedef int HItype __attribute__ ((mode (HI)));
29
typedef unsigned int UHItype __attribute__ ((mode (HI)));
30
typedef unsigned int USItype __attribute__ ((mode (SI)));
31
 
32
typedef struct USIstruct {
33
  UHItype low, high;
34
} USIstruct;
35
 
36
typedef union USIunion {
37
  USItype l;
38
  USIstruct s;
39
} USIunion;
40
 
41
USItype __lshrsi3(USIunion value, HItype count) {
42
  USIunion result;
43
  int temp;
44
 
45
  /* Ignore a zero count until we get into the (count < 16)
46
     clause. This is slightly slower when shifting by zero, but faster
47
     and smaller in all other cases (due to the better scheduling
48
     opportunities available by putting the test near computational
49
     instructions. */
50
 
51
  if (count < 16) {
52
    /* Shift low and high words by the count. */
53
    result.s.low = value.s.low >> count;
54
    result.s.high = value.s.high >> count;
55
 
56
    /* There is now a hole in the upper `count' bits of the low
57
       word. Shift the lower `count' bits of the upper word into the
58
       low word. This only works when count isn't zero. */
59
    if (count != 0) {
60
      temp = value.s.high << (16 - count);
61
      result.s.low |= temp;
62
    }
63
 
64
  } else {
65
    /* Shift the upper word of the source into the lower word of the
66
       result, and zero the result's upper word. Note that we actually
67
       ned to shift by (count - 16), but as we are only using the
68
       bottom 4 bits, this is equivalent to shifting by count. */
69
    result.s.low = value.s.high >> count;
70
    result.s.high = 0;
71
 
72
  }
73
 
74
  return result.l;
75
 
76
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.