|
Last change
on this file since 3033 was 1392, checked in by bird, 22 years ago |
|
This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.
|
-
Property cvs2svn:cvs-rev
set to
1.1.1.2
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
974 bytes
|
| Line | |
|---|
| 1 | #include "f2c.h"
|
|---|
| 2 |
|
|---|
| 3 | #ifndef LONGBITS
|
|---|
| 4 | #define LONGBITS 32
|
|---|
| 5 | #endif
|
|---|
| 6 |
|
|---|
| 7 | integer
|
|---|
| 8 | lbit_bits (integer a, integer b, integer len)
|
|---|
| 9 | {
|
|---|
| 10 | /* Assume 2's complement arithmetic */
|
|---|
| 11 |
|
|---|
| 12 | unsigned long x, y;
|
|---|
| 13 |
|
|---|
| 14 | x = (unsigned long) a;
|
|---|
| 15 | y = (unsigned long) -1L;
|
|---|
| 16 | x >>= b;
|
|---|
| 17 | y <<= len;
|
|---|
| 18 | return (integer) (x & ~y);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | integer
|
|---|
| 22 | lbit_cshift (integer a, integer b, integer len)
|
|---|
| 23 | {
|
|---|
| 24 | unsigned long x, y, z;
|
|---|
| 25 |
|
|---|
| 26 | x = (unsigned long) a;
|
|---|
| 27 | if (len <= 0)
|
|---|
| 28 | {
|
|---|
| 29 | if (len == 0)
|
|---|
| 30 | return 0;
|
|---|
| 31 | goto full_len;
|
|---|
| 32 | }
|
|---|
| 33 | if (len >= LONGBITS)
|
|---|
| 34 | {
|
|---|
| 35 | full_len:
|
|---|
| 36 | if (b >= 0)
|
|---|
| 37 | {
|
|---|
| 38 | b %= LONGBITS;
|
|---|
| 39 | return (integer) (x << b | x >> (LONGBITS - b));
|
|---|
| 40 | }
|
|---|
| 41 | b = -b;
|
|---|
| 42 | b %= LONGBITS;
|
|---|
| 43 | return (integer) (x << (LONGBITS - b) | x >> b);
|
|---|
| 44 | }
|
|---|
| 45 | y = z = (unsigned long) -1;
|
|---|
| 46 | y <<= len;
|
|---|
| 47 | z &= ~y;
|
|---|
| 48 | y &= x;
|
|---|
| 49 | x &= z;
|
|---|
| 50 | if (b >= 0)
|
|---|
| 51 | {
|
|---|
| 52 | b %= len;
|
|---|
| 53 | return (integer) (y | (z & (x << b | x >> (len - b))));
|
|---|
| 54 | }
|
|---|
| 55 | b = -b;
|
|---|
| 56 | b %= len;
|
|---|
| 57 | return (integer) (y | (z & (x >> b | x << (len - b))));
|
|---|
| 58 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.