Skip to content

Conversation

@earlephilhower
Copy link
Contributor

Replace the ARM assembly for dual 16b swap with generic GCC builtin macros to allow building CYW43 SPI PIO driver for RISC-V

Fixes #2044

@kilograham
Copy link
Contributor

This might be more compact

__force_inline static uint32_t __swap16x2(uint32_t a) {
#ifndef __riscv
    pico_default_asm ("rev16 %0, %0" : "+l" (a) : : );
#else
    uint32_t tmp;
    pico_default_asm (
        "rev8 %1, %0\n"
        "rori %0, %1, 16\n"
        : "+l" (a), "=l" (tmp));
#endif
    return a;
}

@earlephilhower
Copy link
Contributor Author

Agreed. Quick check of generated assembly using __builtin gives

  5c:	6987d713          	rev8	a4,a5
  60:	83c1                	srli	a5,a5,0x10
  62:	8341                	srli	a4,a4,0x10
  64:	6987d793          	rev8	a5,a5
  68:	8fd9                	or	a5,a5,a4

22 bytes vs only 8 for the hand ASM.

  4a:	6987d713          	rev8	a4,a5
  4e:	61075793          	rori	a5,a4,0x10

I'll update and squash accordingly.

Add hand-coded assembly RISC-V version of swap16x2 for CYW32 SPI PIO
driver.

Fixes raspberrypi#2044
@earlephilhower
Copy link
Contributor Author

Updated with hand-asm patch. Verified the assembly output does match the ARM and GCC builtins.

@kilograham kilograham added this to the 2.1.0 milestone Nov 18, 2024
@kilograham kilograham merged commit 0f847db into raspberrypi:develop Nov 18, 2024
4 checks passed
@earlephilhower earlephilhower deleted the noasmp1 branch November 19, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants