provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri for MSVC
cover provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri for MSVC
MSVC does not support inline assembly so use movdiri intrinsic and provide abstracted rte_ffs{32,64} inline functions instead of directly using GCC built-ins.
Tyler Retzlaff (2):
eal: provide movdiri for MSVC
eal: add rte ffs32 and rte ffs64 inline functions
lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++ lib/eal/x86/include/rte_io.h | 4 ++++ 2 files changed, 38 insertions(+)
Signature · 1 line
1.8.3.1
PATCH 1/2 eal: provide movdiri for MSVC
MSVC does not support inline assembly instead it provides compiler intrinsics. Provide conditional compile for MSVC for movdiri using the _directstoreu_u32 intrinsic.
--- lib/eal/x86/include/rte_io.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/eal/x86/include/rte_io.h +4 -0
@@ -22,11 +22,15 @@ static __rte_always_inline void__rte_x86_movdiri (uint32_t value,volatile void *addr) { +#ifdef RTE_TOOLCHAIN_MSVC +_directstoreu_u32 ((void *)(uintptr_t )addr, value); +#else asmvolatile (/* MOVDIRI */ ".byte 0x40, 0x0f, 0x38, 0xf9, 0x02" : :"a" (value),"d" (addr)); +#endif } __rte_experimental
Signature · 1 line
1.8.3.1
PATCH 2/2 eal: add rte ffs32 and rte ffs64 inline functions
In reply to Tyler Retzlaffprovide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in intrinsics.
--- lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
lib/eal/include/rte_bitops.h +34 -0
@@ -405,6 +405,28 @@ return (unsigned int)__popcnt64(v); } +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +unsigned long rv; + +if (0 ==_BitScanForward (&rv, v)) +return 0 ; + +return (unsigned int )rv +1 ; +} + +static inline unsigned int +rte_ffs64 (uint64_t v) +{ +unsigned long rv; + +if (0 ==_BitScanForward64 (&rv, v)) +return 0 ; + +return (unsigned int )rv +1 ; +} +#else /**
@@ -491,6 +513,18 @@ return (unsigned int)__builtin_popcountll(v); } +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +return (unsigned int )__builtin_ffs (v); +} + +static inline unsigned int +rte_ffs64 (uint64_t v) +{ +return (unsigned int )__builtin_ffsll (v); +} +#endif /**
Signature · 1 line
1.8.3.1
Re: [PATCH 2/2] eal: add rte ffs32 and rte ffs64 inline functions
Quoted 5 lines · Tyler Retzlaff
provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in intrinsics.
Signed-off-by Tyler Retzlaff <[email protected]>
Please add a unit test and an entry in the release notes.
Quoted 9 lines
--- lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)lib/eal/include/rte_bitops.h +0
-0
lib/eal/include/rte_bitops.h line 413
Quoted 9 lines
lib/eal/include/rte_bitops.h +6
-0@@ -405,6 +405,28 @@return (unsigned int )__popcnt64 (v); } +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +unsigned long rv; + +if (0 ==_BitScanForward (&rv, v))
_BitScanForward(&rv, v) == 0 please.
Signature · 1 line
David Marchand
Re: [PATCH 2/2] eal: add rte ffs32 and rte ffs64 inline functions
Quoted 22 lines · David Marchand
Quoted 5 lines · Tyler Retzlaff
provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in intrinsics.
Signed-off-by Tyler Retzlaff <[email protected]>Please add a unit test and an entry in the release notes.
Quoted 12 lines
--- lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)lib/eal/include/rte_bitops.h +0
-0@@ -405,6 +405,28 @@return (unsigned int )__popcnt64 (v); }
Quoted 13 lines
lib/eal/include/rte_bitops.h line 413
Quoted 6 lines
lib/eal/include/rte_bitops.h +6
-0+static inline unsigned int +rte_ffs32 (uint32_t v) +{ +unsigned long rv; + +if (0 ==_BitScanForward (&rv, v))
_BitScanForward(&rv, v)== 0 please.Signature · 1 line
David Marchand
Thanks David. I'll make the change suggested and add some unit tests. --
Andre Muezerie
v2 cover provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri
In reply to Tyler RetzlaffMSVC does not support inline assembly so use movdiri intrinsic and provide abstracted rte_ffs{32,64} inline functions instead of directly using GCC built-ins.
v2:
* Moved constants to the right side of the comparison
* Added tests for rte_ffs32 and rte_ffs64 functions
Andre Muezerie (1):
app/test: add test for rte_ffs32 and rte_ffs64 functions.
Tyler Retzlaff (2):
eal: provide movdiri for MSVC
eal: add rte ffs32 and rte ffs64 inline functions
app/test/test_bitops.c | 38 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++ lib/eal/x86/include/rte_io.h | 4 ++++ 3 files changed, 76 insertions(+)
--
2.47.0.vfs.0.3
PATCH v2 1/3 eal: provide movdiri for MSVC
From: Tyler Retzlaff <[email protected]>
MSVC does not support inline assembly. Instead it provides compiler intrinsics. Provide conditional compile for MSVC for movdiri using the _directstoreu_u32 intrinsic.
--- lib/eal/x86/include/rte_io.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/eal/x86/include/rte_io.h +4 -0
@@ -22,11 +22,15 @@ extern "C" { static __rte_always_inline void__rte_x86_movdiri (uint32_t value,volatile void *addr) { +#ifdef RTE_TOOLCHAIN_MSVC +_directstoreu_u32 ((void *)(uintptr_t )addr, value); +#else asmvolatile (/* MOVDIRI */ ".byte 0x0f, 0x38, 0xf9, 0x02" : :"a" (value),"d" (addr)); +#endif } __rte_experimental
Signature · 1 line
2.47.0.vfs.0.3
PATCH v2 2/3 eal: add rte ffs32 and rte ffs64 inline functions
In reply to Andre MuezerieFrom: Tyler Retzlaff <[email protected]>
Provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in intrinsics.
--- lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
lib/eal/include/rte_bitops.h +34 -0
@@ -958,6 +958,28 @@ rte_popcount64(uint64_t v) return (unsigned int)__popcnt64(v); } +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +unsigned long rv; + +if (_BitScanForward (&rv, v) ==0 ) +return 0 ; + +return (unsigned int )rv +1 ; +} + +static inline unsigned int +rte_ffs64 (uint64_t v) +{ +unsigned long rv; + +if (_BitScanForward64 (&rv, v) ==0 ) +return 0 ; + +return (unsigned int )rv +1 ; +} +#else /**
@@ -1044,6 +1066,18 @@ rte_popcount64(uint64_t v) return (unsigned int)__builtin_popcountll(v); } +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +return (unsigned int )__builtin_ffs (v); +} + +static inline unsigned int +rte_ffs64 (uint64_t v) +{ +return (unsigned int )__builtin_ffsll (v); +} +#endif /**
Signature · 1 line
2.47.0.vfs.0.3
PATCH v2 3/3 app/test: add test for rte_ffs32 and rte_ffs64 functions.
In reply to Andre MuezerieAdd tests for new rte_ffs32 and rte_ffs64 functions.
--- app/test/test_bitops.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
app/test/test_bitops.c +38 -0
@@ -406,6 +406,42 @@ test_bit_relaxed_test_set_clear(void)return TEST_SUCCESS ; } +static int +test_bit_scan_forward (void ) +{ +unsigned int bit_nr; + +TEST_ASSERT ((bit_nr =rte_ffs32 (0 )) ==0 , +"rte_ffs32 returned unexpected %d" , bit_nr); + +for (int i =0 ; i <32 ; ++i) { +uint32_t n =RTE_BIT32 (i); + +TEST_ASSERT ((bit_nr =rte_ffs32 (n)) == (unsigned int )(i+1 ), +"rte_ffs32 returned unexpected %d" , bit_nr); + } + +return TEST_SUCCESS ; +} + +static int +test_bit_scan_forward64 (void ) +{ +unsigned int bit_nr; + +TEST_ASSERT ((bit_nr =rte_ffs64 (0 )) ==0 , +"rte_ffs64 returned unexpected %d" , bit_nr); + +for (int i =0 ; i <64 ; ++i) { +uint64_t n =RTE_BIT64 (i); + +TEST_ASSERT ((bit_nr =rte_ffs64 (n)) == (unsigned int )(i+1 ), +"rte_ffs64 returned unexpected %d" , bit_nr); + } + +return TEST_SUCCESS ; +} +static struct unit_test_suite test_suite = { .suite_name ="Bitops test suite" , .unit_test_cases = {
@@ -428,6 +464,8 @@ static struct unit_test_suite test_suite = {TEST_CASE (test_bit_relaxed_set),TEST_CASE (test_bit_relaxed_clear),TEST_CASE (test_bit_relaxed_test_set_clear), +TEST_CASE (test_bit_scan_forward), +TEST_CASE (test_bit_scan_forward64), TEST_CASES_END() } };
Signature · 1 line
2.47.0.vfs.0.3
Re: [PATCH v2 0/3] provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri
In reply to Andre MuezerieQuoted 12 lines · Andre Muezerie
MSVC does not support inline assembly so use movdiri intrinsic and provide abstracted rte_ffs{32,64} inline functions instead of directly using GCC built-ins.
v2:
* Moved constants to the right side of the comparison
* Added tests forrte_ffs32andrte_ffs64functionsAndre Muezerie (1):
app/test: add test forrte_ffs32andrte_ffs64functions.
Quoted 9 lines
Tyler Retzlaff (2):
eal: provide movdiri for MSVC
eal: add rte ffs32 and rte ffs64 inline functionsapp/test/test_bitops.c | 38 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++ lib/eal/x86/include/rte_io.h | 4 ++++ 3 files changed, 76 insertions(+)
I see nothing wrong with adding those wrappers to ease MSVC support. Just, those two ffs helpers should be marked experimental.
And the unit tests for counting/searching bits had been separated in a dedicated app/test/test_bitcount.c.
Signature · 1 line
David Marchand
Re: [PATCH v2 0/3] provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri
Quoted 24 lines · David Marchand
Quoted 12 lines · Andre Muezerie
MSVC does not support inline assembly so use movdiri intrinsic and provide abstracted rte_ffs{32,64} inline functions instead of directly using GCC built-ins.
v2:
* Moved constants to the right side of the comparison
* Added tests forrte_ffs32andrte_ffs64functionsAndre Muezerie (1):
app/test: add test forrte_ffs32andrte_ffs64functions.Quoted 9 lines
Tyler Retzlaff (2):
eal: provide movdiri for MSVC
eal: add rte ffs32 and rte ffs64 inline functionsapp/test/test_bitops.c | 38 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++ lib/eal/x86/include/rte_io.h | 4 ++++ 3 files changed, 76 insertions(+)
Quoted 9 lines
I see nothing wrong with adding those wrappers to ease MSVC support. Just, those two ffs helpers should be marked experimental.
And the unit tests for counting/searching bits had been separated in a dedicated
app/test/test_bitcount.c.Signature · 1 line
David Marchand
Thanks for the review David. I sent a v3 series addressing these issues.
v3 cover provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri
In reply to Tyler RetzlaffMSVC does not support inline assembly so use movdiri intrinsic and provide abstracted rte_ffs{32,64} inline functions instead of directly using GCC built-ins.
v3:
* Added __rte_experimental to the new functions.
* Added comments to the new functions.
* Moved tests to test_bitcount.c
v2:
* Moved constants to the right side of the comparison
* Added tests for rte_ffs32 and rte_ffs64 functions
Andre Muezerie (1):
app/test: add test for rte_ffs32 and rte_ffs64 functions.
Tyler Retzlaff (2):
eal: provide movdiri for MSVC
eal: add rte ffs32 and rte ffs64 inline functions
app/test/test_bitcount.c | 38 ++++++++++++++++++ lib/eal/include/rte_bitops.h | 74 ++++++++++++++++++++++++++++++++++++ lib/eal/x86/include/rte_io.h | 4 ++ 3 files changed, 116 insertions(+)
--
2.47.2.vfs.0.1
PATCH v3 1/3 eal: provide movdiri for MSVC
From: Tyler Retzlaff <[email protected]>
MSVC does not support inline assembly. Instead it provides compiler intrinsics. Provide conditional compile for MSVC for movdiri using the _directstoreu_u32 intrinsic.
--- lib/eal/x86/include/rte_io.h | 4 ++++ 1 file changed, 4 insertions(+)
lib/eal/x86/include/rte_io.h +4 -0
@@ -22,11 +22,15 @@ extern "C" { static __rte_always_inline void__rte_x86_movdiri (uint32_t value,volatile void *addr) { +#ifdef RTE_TOOLCHAIN_MSVC +_directstoreu_u32 ((void *)(uintptr_t )addr, value); +#else asmvolatile (/* MOVDIRI */ ".byte 0x0f, 0x38, 0xf9, 0x02" : :"a" (value),"d" (addr)); +#endif } __rte_experimental
Signature · 1 line
2.47.2.vfs.0.1
PATCH v3 2/3 eal: add rte ffs32 and rte ffs64 inline functions
In reply to Andre MuezerieFrom: Tyler Retzlaff <[email protected]>
Provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in intrinsics.
--- lib/eal/include/rte_bitops.h | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
lib/eal/include/rte_bitops.h +74 -0
@@ -958,6 +958,48 @@ rte_popcount64(uint64_t v) return (unsigned int)__popcnt64(v); } +/** +* Search v from least significant bit (LSB) to the most +* significant bit (MSB) for a set bit (1). +* +* @param v +* The value. +* @return +* Bit index + 1 if a set bit is found, zero otherwise. +*/ +__rte_experimental +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +unsigned long rv; + +if (_BitScanForward (&rv, v) ==0 ) +return 0 ; + +return (unsigned int )rv +1 ; +} + +/** +* Search v from least significant bit (LSB) to the most +* significant bit (MSB) for a set bit (1). +* +* @param v +* The value. +* @return +* Bit index + 1 if a set bit is found, zero otherwise. +*/ +__rte_experimental +static inline unsigned int +rte_ffs64 (uint64_t v) +{ +unsigned long rv; + +if (_BitScanForward64 (&rv, v) ==0 ) +return 0 ; + +return (unsigned int )rv +1 ; +} +#else /**
@@ -1044,6 +1086,38 @@ rte_popcount64(uint64_t v) return (unsigned int)__builtin_popcountll(v); } +/** +* Search v from least significant bit (LSB) to the most +* significant bit (MSB) for a set bit (1). +* +* @param v +* The value. +* @return +* Bit index + 1 if a set bit is found, zero otherwise. +*/ +__rte_experimental +static inline unsigned int +rte_ffs32 (uint32_t v) +{ +return (unsigned int )__builtin_ffs (v); +} + +/** +* Search v from least significant bit (LSB) to the most +* significant bit (MSB) for a set bit (1). +* +* @param v +* The value. +* @return +* Bit index + 1 if a set bit is found, zero otherwise. +*/ +__rte_experimental +static inline unsigned int +rte_ffs64 (uint64_t v) +{ +return (unsigned int )__builtin_ffsll (v); +} +#endif /**
Signature · 1 line
2.47.2.vfs.0.1
PATCH v3 3/3 app/test: add test for rte_ffs32 and rte_ffs64 functions.
In reply to Andre MuezerieAdd tests for new rte_ffs32 and rte_ffs64 functions.
--- app/test/test_bitcount.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
app/test/test_bitcount.c +38 -0
@@ -12,6 +12,42 @@RTE_LOG_REGISTER (bitcount_logtype_test, test.bitcount,INFO ); +static int +test_bit_scan_forward (void ) +{ +unsigned int bit_nr; + +TEST_ASSERT ((bit_nr =rte_ffs32 (0 )) ==0 , +"rte_ffs32 returned unexpected %d" , bit_nr); + +for (int i =0 ; i <32 ; ++i) { +uint32_t n =RTE_BIT32 (i); + +TEST_ASSERT ((bit_nr =rte_ffs32 (n)) == (unsigned int )(i+1 ), +"rte_ffs32 returned unexpected %d" , bit_nr); + } + +return TEST_SUCCESS ; +} + +static int +test_bit_scan_forward64 (void ) +{ +unsigned int bit_nr; + +TEST_ASSERT ((bit_nr =rte_ffs64 (0 )) ==0 , +"rte_ffs64 returned unexpected %d" , bit_nr); + +for (int i =0 ; i <64 ; ++i) { +uint64_t n =RTE_BIT64 (i); + +TEST_ASSERT ((bit_nr =rte_ffs64 (n)) == (unsigned int )(i+1 ), +"rte_ffs64 returned unexpected %d" , bit_nr); + } + +return TEST_SUCCESS ; +} +static int test_clz32 (void ) {
@@ -117,6 +153,8 @@ static struct unit_test_suite bitcount_test_suite = { .setup = NULL, .teardown = NULL, .unit_test_cases = { +TEST_CASE (test_bit_scan_forward), +TEST_CASE (test_bit_scan_forward64),TEST_CASE (test_clz32),TEST_CASE (test_clz64), TEST_CASE(test_ctz32),
Signature · 1 line
2.47.2.vfs.0.1
Re: [PATCH v3 0/3] provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri
In reply to Andre MuezerieQuoted 17 lines · Andre Muezerie
MSVC does not support inline assembly so use movdiri intrinsic and provide abstracted rte_ffs{32,64} inline functions instead of directly using GCC built-ins.
v3:
* Added__rte_experimentalto the new functions.
* Added comments to the new functions.
* Moved tests totest_bitcount.cv2:
* Moved constants to the right side of the comparison
* Added tests forrte_ffs32andrte_ffs64functionsAndre Muezerie (1):
app/test: add test forrte_ffs32andrte_ffs64functions.
Quoted 8 lines
Tyler Retzlaff (2):
eal: provide movdiri for MSVC
eal: add rte ffs32 and rte ffs64 inline functionsapp/test/test_bitcount.c | 38 ++++++++++++++++++ lib/eal/include/rte_bitops.h | 74 ++++++++++++++++++++++++++++++++++++ lib/eal/x86/include/rte_io.h | 4 ++ 3 files changed, 116 insertions(+)
Series applied, thanks Tyler and André.
Signature · 1 line
David Marchand