[riot-notifications] [RIOT-OS/RIOT] core/bitarithm: introduce bitarithm_get/set_masked(), convert pca9685 (#12238)

Kaspar Schleiser notifications at github.com
Mon Sep 16 23:13:15 CEST 2019


kaspar030 commented on this pull request.



> @@ -163,6 +163,47 @@ static inline unsigned bitarithm_lsb(unsigned v)
 }
 #endif
 
+/**
+ * @brief           Sets the masked bits in a word to the given value.
+ *
+ * @note            The mask should be compile-time constant so the compiler
+ *                  is able to optimize the entire loop away.
+ *
+ * @param       val The value to modify.
+ * @param[in]  mask The bitmask to apply.
+ * @param[in]  bits The new value of the masked bits.
+ *
+ */
+#define bitarithm_set_masked(val, mask, bits) do {                  \
+        const unsigned _mask = mask;                                \

Shouldn't this be equivalent?

```
static inline void bitarithm_set_masked_u32(uint32_t *val, uint32_t mask, uint32_t bits)
{
    *(val) = ((*(val) & ~mask) | ((bits << (__builtin_ffs(mask) - 1)) & mask));
}
```

(generated code looks different though)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/12238#discussion_r324888441
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190916/e4c415d1/attachment.htm>


More information about the notifications mailing list