Skip to content

Commit

Permalink
api: hints: fix type conversion problem in odp_unlikely()
Browse files Browse the repository at this point in the history
Convert the argument of odp_unlikely() to boolean before passing it
to __builtin_expect() which takes a long int argument. This prevents
implementation-defined behaviour when the argument of odp_unlikely()
does not fit in a long int. In certain systems with 32-bit long,
odp_unlikely() currently turns certain non-zero 64-bit values to zero,
breaking the code that is using odp_unlikely().

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
  • Loading branch information
JannePeltonen committed Dec 11, 2023
1 parent 2824925 commit cc035c8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/odp/api/spec/hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern "C" {
/**
* Branch unlikely taken
*/
#define odp_unlikely(x) __builtin_expect((x), 0)
#define odp_unlikely(x) __builtin_expect(!!(x), 0)

/*
* __builtin_prefetch (const void *addr, rw, locality)
Expand Down

0 comments on commit cc035c8

Please sign in to comment.