Issue 24414 - ImportC: undefined identifier `__builtin_clz`
Summary: ImportC: undefined identifier `__builtin_clz`
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-26 09:43 UTC by Richard (Rikki) Andrew Cattermole
Modified: 2024-02-26 16:09 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Richard (Rikki) Andrew Cattermole 2024-02-26 09:43:11 UTC
Another ImportC intrinsic that is missing ``__builtin_clz``.

From the NewsGroup comment: https://forum.dlang.org/post/sotawneftuxhgxmmeuoo@forum.dlang.org
Comment 1 Alex Bryan 2024-02-26 16:09:32 UTC
I've ran into this issue before and worked around it by putting this in a D file:

module util;
// for C files built with import C that try to use GCC/clang builtin that importC does not provide

extern(C) int __builtin_clz(int v)    
{    
    return clz(v);    
}    
    
// count leading zeros.    
int clz(uint v) pure nothrow @nogc @safe    
in(v != 0)    
{    
    import core.bitop : bsr;    
    return 31 - bsr(v);    
}


and putting
__import util
at the top of the C file