Skip to content

Commit 73d4378

Browse files
committed
[s390x] Use XOR-in-place to zero small fixed-length blocks
The XOR instruction has a storage-and-storage format "xc" that can be used to zero small blocks of memory without needing to set up the four registers required for "mvcle". Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent 1a0ebb9 commit 73d4378

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/arch/s390x/include/bits/string.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ memset ( void *dest, int character, size_t len ) {
2727
struct s390x_pointer_pair dpair = { dest, len };
2828
char ( * dmem ) [ len ] = dest;
2929

30-
if ( __builtin_constant_p ( character ) ) {
31-
/* Constant fill character: use an immediate */
30+
if ( __builtin_constant_p ( len ) && ( len == 0 ) ) {
31+
/* Constant zero length: do nothing */
32+
} else if ( __builtin_constant_p ( character ) && ( character == 0 ) &&
33+
__builtin_constant_p ( len ) && ( len <= 256 ) ) {
34+
/* Constant small length, zeroing: use XOR-in-place */
35+
__asm__ ( "xc %O0(%1, %R0), %0"
36+
: "=Q" ( *dmem )
37+
: "i" ( len ) );
38+
} else if ( __builtin_constant_p ( character ) ) {
39+
/* Constant fill character: use "mvcle" with an immediate */
3240
__asm__ ( "\n1:\n\t"
3341
"mvcle %0, %2, %3\n\t"
3442
"jo 1b\n\t"
3543
: "+r" ( dpair ), "=m" ( *dmem )
3644
: "r" ( spair ), "i" ( character ) );
3745
} else {
38-
/* Variable fill character: use a register */
46+
/* Variable fill character: use "mvcle" with a register */
3947
__asm__ ( "\n1:\n\t"
4048
"mvcle %0, %2, 0(%3)\n\t"
4149
"jo 1b\n\t"

0 commit comments

Comments
 (0)