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.
28 check_log_2_floor(uint32_t x, int n)
30 if (log_2_floor(x) != n) {
31 fprintf(stderr, "log_2_floor(%"PRIu32") is %d but should be %d\n",
32 x, log_2_floor(x), n);
38 check_ctz(uint32_t x, int n)
41 fprintf(stderr, "ctz(%"PRIu32") is %d but should be %d\n",
52 for (n = 0; n < 32; n++) {
53 /* Check minimum x such that f(x) == n. */
54 check_log_2_floor(1 << n, n);
57 /* Check maximum x such that f(x) == n. */
58 check_log_2_floor((1 << n) | ((1 << n) - 1), n);
59 check_ctz(UINT32_MAX << n, n);
61 /* Check a random value in the middle. */
62 check_log_2_floor((random_uint32() & ((1 << n) - 1)) | (1 << n), n);
63 check_ctz((random_uint32() | 1) << n, n);
67 * (log_2_floor(0) is undefined.) */