[PATCH] D86221: [compiler-rt][builtins] Do not assume int to be at least 32 bit wide

Anatoly Trosinenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 19 10:49:18 PDT 2020


atrosinenko added a subscriber: scanon.
atrosinenko added a comment.

On one hand, this `clzdi()` implementation should be completely harmless when fallback is implemented via `clzsi()`. On the other hand, it may possibly be completely removed. This code snippet mimics one already existing for `clzsi` in int_types.h and for currently supported targets it can probably be even as simple as this (provided we can use C99):

  #if ULLONG_MAX == 0xFFFFFFFFFFFFFFFF
  #define clzdi __builtin_clzll
  #define ctzdi __builtin_ctzll
  #else
  #error could not determine appropriate clzdi macro for this system
  #endif



================
Comment at: compiler-rt/lib/builtins/int_lib.h:149
 
+static int __inline clzdi(di_int a) {
+#if defined __LP64__
----------------
@scanon

This function was copied from fp_lib.h almost unchanged, so it can be used from fp_extend.h (the version from that file is almost identical except it does not use the properly-sized `clzsi()` macro). But is this manual fallback implementation useful nowadays? As I can see, the implementation in fp_lib.h remained almost untouched since 2010 when this file was uploaded via {rGb1fdde1d01}. Now, `__builtin_clzll` is used in many places of compiler-rt/builtins library for seemingly the same purpose.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86221/new/

https://reviews.llvm.org/D86221



More information about the cfe-commits mailing list