> On 12 May 2020, at 11:41, Andreas Schultz <andreas.schu...@travelping.com> 
> wrote:
> 
> Hi,
> 
> There are few places in VPP (most notable when trying to convert a netmask 
> into a length) that can pass 0 (zero) into min_log2 and expect to get a 
> meaningful result.
> 
> Obviously log2(0) is undefined. It turns out that this also applies to the 
> return of min_log2. Under the hood the function uses __builtin_clzl, and the 
> return of that function is also undefined for input 0.
> 
>  __builtin_clzl  could be replaced with __builtin_ia32_lzcnt_u64 on supported 
> CPUs to avoid the undefined behaviour. That would still not fix the problem 
> that passing 0 into a log function is broken by design.

Compiler uses LZCNT for __builtin_clzl when target -march supports it. Today we 
use -march=corei7 as baseline and that one doesn’t know about LZCNT, so BSR is 
emitted instead, which indeed have undefined behaviour. In other words 
replacing __builtin_clzl with __builtin_ia32_lzcnt_u64 will not work, but 
simply changing baseline -march= to something newer will address that 
transparently...




-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#16331): https://lists.fd.io/g/vpp-dev/message/16331
Mute This Topic: https://lists.fd.io/mt/74155196/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to