121173Sjkh/* SPDX-License-Identifier: GPL-2.0 */
250479Speter/*
350479Speter * linux/arch/alpha/lib/memset.S
421173Sjkh *
521173Sjkh * This is an efficient (and small) implementation of the C library "memset()"
621173Sjkh * function for the alpha.
721173Sjkh *
821173Sjkh *	(C) Copyright 1996 Linus Torvalds
921173Sjkh *
1021173Sjkh * This routine is "moral-ware": you are free to use it any way you wish, and
1121173Sjkh * the only obligation I put on you is a moral one: if you make any improvements
1221173Sjkh * to the routine, please send me your improvements for me to use similarly.
1321173Sjkh *
14159363Strhodes * The scheduling comments are according to the EV5 documentation (and done by
15159363Strhodes * hand, so they might well be incorrect, please do tell me about it..)
16159363Strhodes */
17159363Strhodes#include <linux/export.h>
18159363Strhodes	.set noat
19159363Strhodes	.set noreorder
20159363Strhodes.text
2164057Salex	.globl memset
2264057Salex	.globl __memset
2364057Salex	.globl ___memset
2421173Sjkh	.globl __memset16
2564057Salex	.globl __constant_c_memset
2664057Salex
27100446Swosch	.ent ___memset
2821369Smax.align 5
2964057Salex___memset:
3093217Sru	.frame $30,0,$26,0
3164057Salex	.prologue 0
3221173Sjkh
3393217Sru	and $17,255,$1		/* E1 */
3421173Sjkh	insbl $17,1,$17		/* .. E0 */
3521173Sjkh	bis $17,$1,$17		/* E0 (p-c latency, next cycle) */
3664047Salex	sll $17,16,$1		/* E1 (p-c latency, next cycle) */
37281478Seadler
3821173Sjkh	bis $17,$1,$17		/* E0 (p-c latency, next cycle) */
3921173Sjkh	sll $17,32,$1		/* E1 (p-c latency, next cycle) */
4021173Sjkh	bis $17,$1,$17		/* E0 (p-c latency, next cycle) */
4121173Sjkh	ldq_u $31,0($30)	/* .. E1 */
4293217Sru
4321173Sjkh.align 5
44215293Sjoel__constant_c_memset:
45215293Sjoel	addq $18,$16,$6		/* E0 */
46215293Sjoel	bis $16,$16,$0		/* .. E1 */
4721173Sjkh	xor $16,$6,$1		/* E0 */
4821173Sjkh	ble $18,end		/* .. E1 */
4964047Salex
5021173Sjkh	bic $1,7,$1		/* E0 */
5193217Sru	beq $1,within_one_quad	/* .. E1 (note EV5 zero-latency forwarding) */
5221173Sjkh	and $16,7,$3		/* E0 */
5321173Sjkh	beq $3,aligned		/* .. E1 (note EV5 zero-latency forwarding) */
5421173Sjkh
5521173Sjkh	ldq_u $4,0($16)		/* E0 */
5621173Sjkh	bis $16,$16,$5		/* .. E1 */
5721173Sjkh	insql $17,$16,$2	/* E0 */
5821173Sjkh	subq $3,8,$3		/* .. E1 */
5921173Sjkh
6093217Sru	addq $18,$3,$18		/* E0	$18 is new count ($3 is negative) */
6137283Sjkh	mskql $4,$16,$4		/* .. E1 (and possible load stall) */
6221173Sjkh	subq $16,$3,$16		/* E0 	$16 is new aligned destination */
6321173Sjkh	bis $2,$4,$1		/* .. E1 */
6421173Sjkh
6521173Sjkh	bis $31,$31,$31		/* E0 */
6621173Sjkh	ldq_u $31,0($30)	/* .. E1 */
6721173Sjkh	stq_u $1,0($5)		/* E0 */
68156171Sceri	bis $31,$31,$31		/* .. E1 */
69156171Sceri
7021173Sjkh.align 4
7121173Sjkhaligned:
7265298Smarkm	sra $18,3,$3		/* E0 */
7321173Sjkh	and $18,7,$18		/* .. E1 */
7421173Sjkh	bis $16,$16,$5		/* E0 */
7521173Sjkh	beq $3,no_quad		/* .. E1 */
7621173Sjkh
7721173Sjkh.align 3
78281478Seadlerloop:
79281478Seadler	stq $17,0($5)		/* E0 */
80281478Seadler	subq $3,1,$3		/* .. E1 */
8121173Sjkh	addq $5,8,$5		/* E0 */
8221173Sjkh	bne $3,loop		/* .. E1 */
8321173Sjkh
8421173Sjkhno_quad:
8521173Sjkh	bis $31,$31,$31		/* E0 */
8621173Sjkh	beq $18,end		/* .. E1 */
8721173Sjkh	ldq $7,0($5)		/* E0 */
8821173Sjkh	mskqh $7,$6,$2		/* .. E1 (and load stall) */
8921173Sjkh
9021173Sjkh	insqh $17,$6,$4		/* E0 */
91100446Swosch	bis $2,$4,$1		/* .. E1 */
92	stq $1,0($5)		/* E0 */
93	ret $31,($26),1		/* .. E1 */
94
95.align 3
96within_one_quad:
97	ldq_u $1,0($16)		/* E0 */
98	insql $17,$16,$2	/* E1 */
99	mskql $1,$16,$4		/* E0 (after load stall) */
100	bis $2,$4,$2		/* E0 */
101
102	mskql $2,$6,$4		/* E0 */
103	mskqh $1,$6,$2		/* .. E1 */
104	bis $2,$4,$1		/* E0 */
105	stq_u $1,0($16)		/* E0 */
106
107end:
108	ret $31,($26),1		/* E1 */
109	.end ___memset
110EXPORT_SYMBOL(___memset)
111EXPORT_SYMBOL(__constant_c_memset)
112
113	.align 5
114	.ent __memset16
115__memset16:
116	.prologue 0
117
118	inswl $17,0,$1		/* E0 */
119	inswl $17,2,$2		/* E0 */
120	inswl $17,4,$3		/* E0 */
121	or $1,$2,$1		/* .. E1 */
122	inswl $17,6,$4		/* E0 */
123	or $1,$3,$1		/* .. E1 */
124	or $1,$4,$17		/* E0 */
125	br __constant_c_memset	/* .. E1 */
126
127	.end __memset16
128EXPORT_SYMBOL(__memset16)
129
130memset = ___memset
131__memset = ___memset
132	EXPORT_SYMBOL(memset)
133	EXPORT_SYMBOL(__memset)
134