Skip to content

Memcpy size optimized enhancement#5

Open
i3abghany wants to merge 2 commits into
mainfrom
memcpy-size-optimized
Open

Memcpy size optimized enhancement#5
i3abghany wants to merge 2 commits into
mainfrom
memcpy-size-optimized

Conversation

@i3abghany

@i3abghany i3abghany commented Mar 19, 2025

Copy link
Copy Markdown
Collaborator

This optimizes the memcpy version used when PREFER_SIZE_OVER_SPEED is specified. This introduces two changes:

  1. Use lbu instead of lb to avoid unnecessary sign extension in hardware
  2. Use compressed registers exclusively to make sure all instructions are compressed. When C and ZCB extensions are available, this is the generated machine code:
0001175c <memcpy>:
   1175c:	86aa                	mv	a3,a0
   1175e: 	c619                	beqz	a2,1176c <memcpy+0x10>
   11760: 	8198                	lbu	a4,0(a1)
   11762:	8a98                	sb	a4,0(a3)
   11764:	167d                	addi	a2,a2,-1
   11766: 	0685                	addi	a3,a3,1
   11768: 	0585                	addi	a1,a1,1
   1176a: 	fa7d                	bnez	a2,11760 <memcpy+0x4>
   1176c:       8082                	ret

…lementation

Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
@i3abghany i3abghany force-pushed the memcpy-size-optimized branch from 4fadce4 to 1476b22 Compare March 26, 2025 03:33
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.

1 participant