On 03.04.2024 12:20, Oleksii Kurochko wrote:
> +#define emulate_cmpxchg_1_2(ptr, old, new, lr_sfx, sc_sfx) \
> +({ \
> +    uint32_t *aligned_ptr; \
> +    unsigned long alignment_mask = sizeof(*aligned_ptr) - sizeof(*(ptr)); \
> +    uint8_t new_val_bit = \
> +        ((unsigned long)(ptr) & alignment_mask) * BITS_PER_BYTE; \
> +    unsigned long mask = \
> +        GENMASK(((sizeof(*(ptr))) * BITS_PER_BYTE) - 1, 0) << new_val_bit; \
> +    unsigned int old_ = (old) << new_val_bit; \
> +    unsigned int new_ = (new) << new_val_bit; \
> +    unsigned int old_val; \
> +    unsigned int scratch; \
> +    \
> +    aligned_ptr = (uint32_t *)((unsigned long)ptr & ~alignment_mask); \
> +    \
> +    asm volatile ( \
> +        "0: lr.w" lr_sfx " %[scratch], %[ptr_]\n" \
> +        "   and  %[old_val], %[scratch], %[mask]\n" \
> +        "   bne  %[old_val], %z[old_], 1f\n" \
> +        /* the following line is an equivalent to:
> +         *     scratch = old_val & ~mask;
> +         * And to elimanate one ( likely register ) input it was decided
> +         * to use:
> +         *     scratch = old_val ^ scratch
> +         */ \

I'm surprised this compiles without \-es inside the comment as well. Line
splicing happens ahead of comment recognition as per the spec.

Everything else okay-ish to me now, but I can't very well given an ack for
a patch depending on things that haven't been committed yet and may never be.

Jan

Reply via email to