@@ -39,7 +39,7 @@ static int nlz1a(unsigned x) {
39
39
if ((x >> 24 ) == 0 ) {n = n + 8 ; x = x << 8 ;}
40
40
if ((x >> 28 ) == 0 ) {n = n + 4 ; x = x << 4 ;}
41
41
if ((x >> 30 ) == 0 ) {n = n + 2 ; x = x << 2 ;}
42
- n = n - (x >> 31 );
42
+ n = n - static_cast < int > (x >> 31 );
43
43
return n;
44
44
}
45
45
// On basic Risc, 12 to 20 instructions.
@@ -54,7 +54,7 @@ static int nlz2(unsigned x) {
54
54
y = x >> 4 ; if (y != 0 ) {n = n - 4 ; x = y;}
55
55
y = x >> 2 ; if (y != 0 ) {n = n - 2 ; x = y;}
56
56
y = x >> 1 ; if (y != 0 ) return n - 2 ;
57
- return n - x ;
57
+ return n - static_cast < int >(x) ;
58
58
}
59
59
60
60
// As above but coded as a loop for compactness:
@@ -69,15 +69,15 @@ static int nlz2a(unsigned x) {
69
69
y = x >> c; if (y != 0 ) {n = n - c; x = y;}
70
70
c = c >> 1 ;
71
71
} while (c != 0 );
72
- return n - x ;
72
+ return n - static_cast < int >(x) ;
73
73
}
74
74
75
- static int nlz3 (int x) {
75
+ static int nlz3 (unsigned x) {
76
76
int y, n;
77
77
78
78
n = 0 ;
79
- y = x ;
80
- L: if (x < 0 ) return n;
79
+ y = static_cast < int >(x) ;
80
+ L: if (x > 0x7fffffff ) return n;
81
81
if (y == 0 ) return 32 - n;
82
82
n = n + 1 ;
83
83
x = x << 1 ;
@@ -98,19 +98,19 @@ static int nlz4(unsigned x) {
98
98
n = 16 - m; // is nonzero, set n = 0 and
99
99
x = x >> m; // shift x right 16.
100
100
// Now x is of the form 0000xxxx.
101
- y = x - 0x100 ; // If positions 8-15 are 0,
102
- m = (y >> 16 ) & 8 ; // add 8 to n and shift x left 8.
103
- n = n + m;
101
+ y = static_cast < int >(x) - 0x100 ;
102
+ m = (y >> 16 ) & 8 ; // If positions 8-15 are 0,
103
+ n = n + m; // add 8 to n and shift x left 8.
104
104
x = x << m;
105
105
106
- y = x - 0x1000 ; // If positions 12-15 are 0,
107
- m = (y >> 16 ) & 4 ; // add 4 to n and shift x left 4.
108
- n = n + m;
106
+ y = static_cast < int >(x) - 0x1000 ;
107
+ m = (y >> 16 ) & 4 ; // If positions 12-15 are 0,
108
+ n = n + m; // add 4 to n and shift x left 4.
109
109
x = x << m;
110
110
111
- y = x - 0x4000 ; // If positions 14-15 are 0,
112
- m = (y >> 16 ) & 2 ; // add 2 to n and shift x left 2.
113
- n = n + m;
111
+ y = static_cast < int >(x) - 0x4000 ;
112
+ m = (y >> 16 ) & 2 ; // If positions 14-15 are 0,
113
+ n = n + m; // add 2 to n and shift x left 2.
114
114
x = x << m;
115
115
116
116
y = x >> 14 ; // Set y = 0, 1, 2, or 3.
@@ -305,8 +305,8 @@ static int nlz10b(unsigned x)
305
305
return table[x >> 26 ];
306
306
}
307
307
308
- int errors;
309
- static void error (int x, int y)
308
+ static int errors;
309
+ static void error (unsigned x, int y)
310
310
{
311
311
errors = errors + 1 ;
312
312
std::printf (" Error for x = %08x, got %d\n " , x, y);
0 commit comments