Skip to content

Commit 4f1f5a7

Browse files
committed
Remove fls(), use pg_leftmost_one_pos32() instead.
Commit 4f658dc provided the traditional BSD fls() function in src/port/fls.c so it could be used in several places. Later we added a bunch of similar facilities in pg_bitutils.h, based on compiler builtins that map to hardware instructions. It's a bit confusing to have both 1-based and 0-based variants of this operation in use in different parts of the tree, and neither is blessed by a standard. Let's drop fls.c and the configure probe, and reuse the newer code. Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CA%2BhUKG%2B7dSX1XF8yFGmYk-%3D48dbjH2kmzZj16XvhbrWP-9BzRg%40mail.gmail.com
1 parent 3225399 commit 4f1f5a7

File tree

11 files changed

+19
-92
lines changed

11 files changed

+19
-92
lines changed

configure

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16771,19 +16771,6 @@ esac
1677116771

1677216772
fi
1677316773

16774-
ac_fn_c_check_func "$LINENO" "fls" "ac_cv_func_fls"
16775-
if test "x$ac_cv_func_fls" = xyes; then :
16776-
$as_echo "#define HAVE_FLS 1" >>confdefs.h
16777-
16778-
else
16779-
case " $LIBOBJS " in
16780-
*" fls.$ac_objext "* ) ;;
16781-
*) LIBOBJS="$LIBOBJS fls.$ac_objext"
16782-
;;
16783-
esac
16784-
16785-
fi
16786-
1678716774
ac_fn_c_check_func "$LINENO" "getopt" "ac_cv_func_getopt"
1678816775
if test "x$ac_cv_func_getopt" = xyes; then :
1678916776
$as_echo "#define HAVE_GETOPT 1" >>confdefs.h

configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,6 @@ fi
19111911
AC_REPLACE_FUNCS(m4_normalize([
19121912
dlopen
19131913
explicit_bzero
1914-
fls
19151914
getopt
19161915
getpeereid
19171916
getrusage

src/backend/access/hash/hashutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ _hash_get_oldblock_from_newbucket(Relation rel, Bucket new_bucket)
436436
* started. Masking the most significant bit of new bucket would give us
437437
* old bucket.
438438
*/
439-
mask = (((uint32) 1) << (fls(new_bucket) - 1)) - 1;
439+
mask = (((uint32) 1) << pg_leftmost_one_pos32(new_bucket)) - 1;
440440
old_bucket = new_bucket & mask;
441441

442442
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE);

src/backend/optimizer/path/allpaths.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "parser/parsetree.h"
4848
#include "partitioning/partbounds.h"
4949
#include "partitioning/partprune.h"
50+
#include "port/pg_bitutils.h"
5051
#include "rewrite/rewriteManip.h"
5152
#include "utils/lsyscache.h"
5253

@@ -1491,7 +1492,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
14911492
if (enable_parallel_append)
14921493
{
14931494
parallel_workers = Max(parallel_workers,
1494-
fls(list_length(live_childrels)));
1495+
pg_leftmost_one_pos32(list_length(live_childrels)) + 1);
14951496
parallel_workers = Min(parallel_workers,
14961497
max_parallel_workers_per_gather);
14971498
}
@@ -1542,7 +1543,7 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
15421543
* the planned number of parallel workers.
15431544
*/
15441545
parallel_workers = Max(parallel_workers,
1545-
fls(list_length(live_childrels)));
1546+
pg_leftmost_one_pos32(list_length(live_childrels)) + 1);
15461547
parallel_workers = Min(parallel_workers,
15471548
max_parallel_workers_per_gather);
15481549
Assert(parallel_workers > 0);

src/backend/optimizer/prep/prepunion.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
675675
if (enable_parallel_append)
676676
{
677677
parallel_workers = Max(parallel_workers,
678-
fls(list_length(partial_pathlist)));
678+
pg_leftmost_one_pos32(list_length(partial_pathlist)) + 1);
679679
parallel_workers = Min(parallel_workers,
680680
max_parallel_workers_per_gather);
681681
}

src/backend/utils/mmgr/dsa.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "postgres.h"
5252

5353
#include "port/atomics.h"
54+
#include "port/pg_bitutils.h"
5455
#include "storage/dsm.h"
5556
#include "storage/ipc.h"
5657
#include "storage/lwlock.h"
@@ -137,7 +138,18 @@ typedef size_t dsa_segment_index;
137138
* free pages? There is no point in looking in segments in lower bins; they
138139
* definitely can't service a request for n free pages.
139140
*/
140-
#define contiguous_pages_to_segment_bin(n) Min(fls(n), DSA_NUM_SEGMENT_BINS - 1)
141+
static inline size_t
142+
contiguous_pages_to_segment_bin(size_t n)
143+
{
144+
size_t bin;
145+
146+
if (n == 0)
147+
bin = 0;
148+
else
149+
bin = pg_leftmost_one_pos_size_t(n) + 1;
150+
151+
return Min(bin, DSA_NUM_SEGMENT_BINS - 1);
152+
}
141153

142154
/* Macros for access to locks. */
143155
#define DSA_AREA_LOCK(area) (&area->control->lock)

src/include/pg_config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@
191191
/* Define to 1 if you have the `fdatasync' function. */
192192
#undef HAVE_FDATASYNC
193193

194-
/* Define to 1 if you have the `fls' function. */
195-
#undef HAVE_FLS
196-
197194
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
198195
#undef HAVE_FSEEKO
199196

src/include/port.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,6 @@ extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
366366
#define pgoff_t off_t
367367
#endif
368368

369-
#ifndef HAVE_FLS
370-
extern int fls(int mask);
371-
#endif
372-
373369
#ifndef HAVE_GETPEEREID
374370
/* On Windows, Perl might have incompatible definitions of uid_t and gid_t. */
375371
#ifndef PLPERL_HAVE_UID_GID

src/port/fls.c

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/tools/msvc/Mkvcbuild.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ sub mkvcbuild
9999
$solution = CreateSolution($vsVersion, $config);
100100

101101
our @pgportfiles = qw(
102-
chklocale.c explicit_bzero.c fls.c fdatasync.c
102+
chklocale.c explicit_bzero.c fdatasync.c
103103
getpeereid.c getrusage.c inet_aton.c
104104
getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c
105105
snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c

src/tools/msvc/Solution.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ sub GenerateFiles
258258
HAVE_EXECINFO_H => undef,
259259
HAVE_EXPLICIT_BZERO => undef,
260260
HAVE_FDATASYNC => 1,
261-
HAVE_FLS => undef,
262261
HAVE_FSEEKO => 1,
263262
HAVE_FUNCNAME__FUNC => undef,
264263
HAVE_FUNCNAME__FUNCTION => 1,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy