2 * Copyright (c) 2011 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 check(uint32_t x, int n)
29 if (log_2_floor(x) != n) {
30 fprintf(stderr, "log_2_floor(%"PRIu32") is %d but should be %d\n",
31 x, log_2_floor(x), n);
41 for (n = 0; n < 32; n++) {
42 /* Check minimum x that has log2(x) == n. */
45 /* Check maximum x that has log2(x) == n. */
46 check((1 << n) | ((1 << n) - 1), n);
48 /* Check a random value in the middle. */
49 check((random_uint32() & ((1 << n) - 1)) | (1 << n), n);