1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* 1 /* 3 * Copyright (C) 2013 Regents of the Universit !! 2 * linux/arch/alpha/lib/memset.S >> 3 * >> 4 * This is an efficient (and small) implementation of the C library "memset()" >> 5 * function for the alpha. >> 6 * >> 7 * (C) Copyright 1996 Linus Torvalds >> 8 * >> 9 * This routine is "moral-ware": you are free to use it any way you wish, and >> 10 * the only obligation I put on you is a moral one: if you make any improvements >> 11 * to the routine, please send me your improvements for me to use similarly. >> 12 * >> 13 * The scheduling comments are according to the EV5 documentation (and done by >> 14 * hand, so they might well be incorrect, please do tell me about it..) 4 */ 15 */ 5 !! 16 #include <asm/export.h> 6 !! 17 .set noat 7 #include <linux/linkage.h> !! 18 .set noreorder 8 #include <asm/asm.h> !! 19 .text 9 !! 20 .globl memset 10 /* void *memset(void *, int, size_t) */ !! 21 .globl __memset 11 SYM_FUNC_START(__memset) !! 22 .globl ___memset 12 move t0, a0 /* Preserve return value !! 23 .globl __memsetw 13 !! 24 .globl __constant_c_memset 14 /* Defer to byte-oriented fill for sma !! 25 15 sltiu a3, a2, 16 !! 26 .ent ___memset 16 bnez a3, 4f !! 27 .align 5 17 !! 28 ___memset: 18 /* !! 29 .frame $30,0,$26,0 19 * Round to nearest XLEN-aligned addre !! 30 .prologue 0 20 * greater than or equal to start addr !! 31 21 */ !! 32 and $17,255,$1 /* E1 */ 22 addi a3, t0, SZREG-1 !! 33 insbl $17,1,$17 /* .. E0 */ 23 andi a3, a3, ~(SZREG-1) !! 34 bis $17,$1,$17 /* E0 (p-c latency, next cycle) */ 24 beq a3, t0, 2f /* Skip if already ali !! 35 sll $17,16,$1 /* E1 (p-c latency, next cycle) */ 25 /* Handle initial misalignment */ !! 36 26 sub a4, a3, t0 !! 37 bis $17,$1,$17 /* E0 (p-c latency, next cycle) */ 27 1: !! 38 sll $17,32,$1 /* E1 (p-c latency, next cycle) */ 28 sb a1, 0(t0) !! 39 bis $17,$1,$17 /* E0 (p-c latency, next cycle) */ 29 addi t0, t0, 1 !! 40 ldq_u $31,0($30) /* .. E1 */ 30 bltu t0, a3, 1b !! 41 31 sub a2, a2, a4 /* Update count */ !! 42 .align 5 32 !! 43 __constant_c_memset: 33 2: /* Duff's device with 32 XLEN stores per it !! 44 addq $18,$16,$6 /* E0 */ 34 /* Broadcast value into all bytes */ !! 45 bis $16,$16,$0 /* .. E1 */ 35 andi a1, a1, 0xff !! 46 xor $16,$6,$1 /* E0 */ 36 slli a3, a1, 8 !! 47 ble $18,end /* .. E1 */ 37 or a1, a3, a1 !! 48 38 slli a3, a1, 16 !! 49 bic $1,7,$1 /* E0 */ 39 or a1, a3, a1 !! 50 beq $1,within_one_quad /* .. E1 (note EV5 zero-latency forwarding) */ 40 #ifdef CONFIG_64BIT !! 51 and $16,7,$3 /* E0 */ 41 slli a3, a1, 32 !! 52 beq $3,aligned /* .. E1 (note EV5 zero-latency forwarding) */ 42 or a1, a3, a1 !! 53 43 #endif !! 54 ldq_u $4,0($16) /* E0 */ 44 !! 55 bis $16,$16,$5 /* .. E1 */ 45 /* Calculate end address */ !! 56 insql $17,$16,$2 /* E0 */ 46 andi a4, a2, ~(SZREG-1) !! 57 subq $3,8,$3 /* .. E1 */ 47 add a3, t0, a4 !! 58 48 !! 59 addq $18,$3,$18 /* E0 $18 is new count ($3 is negative) */ 49 andi a4, a4, 31*SZREG /* Calculate re !! 60 mskql $4,$16,$4 /* .. E1 (and possible load stall) */ 50 beqz a4, 3f /* Shortcut if !! 61 subq $16,$3,$16 /* E0 $16 is new aligned destination */ 51 neg a4, a4 !! 62 bis $2,$4,$1 /* .. E1 */ 52 addi a4, a4, 32*SZREG /* Calculate in !! 63 53 !! 64 bis $31,$31,$31 /* E0 */ 54 /* Adjust start address with offset */ !! 65 ldq_u $31,0($30) /* .. E1 */ 55 sub t0, t0, a4 !! 66 stq_u $1,0($5) /* E0 */ 56 !! 67 bis $31,$31,$31 /* .. E1 */ 57 /* Jump into loop body */ !! 68 58 /* Assumes 32-bit instruction lengths !! 69 .align 4 59 la a5, 3f !! 70 aligned: 60 #ifdef CONFIG_64BIT !! 71 sra $18,3,$3 /* E0 */ 61 srli a4, a4, 1 !! 72 and $18,7,$18 /* .. E1 */ 62 #endif !! 73 bis $16,$16,$5 /* E0 */ 63 add a5, a5, a4 !! 74 beq $3,no_quad /* .. E1 */ 64 jr a5 !! 75 65 3: !! 76 .align 3 66 REG_S a1, 0(t0) !! 77 loop: 67 REG_S a1, SZREG(t0) !! 78 stq $17,0($5) /* E0 */ 68 REG_S a1, 2*SZREG(t0) !! 79 subq $3,1,$3 /* .. E1 */ 69 REG_S a1, 3*SZREG(t0) !! 80 addq $5,8,$5 /* E0 */ 70 REG_S a1, 4*SZREG(t0) !! 81 bne $3,loop /* .. E1 */ 71 REG_S a1, 5*SZREG(t0) !! 82 72 REG_S a1, 6*SZREG(t0) !! 83 no_quad: 73 REG_S a1, 7*SZREG(t0) !! 84 bis $31,$31,$31 /* E0 */ 74 REG_S a1, 8*SZREG(t0) !! 85 beq $18,end /* .. E1 */ 75 REG_S a1, 9*SZREG(t0) !! 86 ldq $7,0($5) /* E0 */ 76 REG_S a1, 10*SZREG(t0) !! 87 mskqh $7,$6,$2 /* .. E1 (and load stall) */ 77 REG_S a1, 11*SZREG(t0) !! 88 78 REG_S a1, 12*SZREG(t0) !! 89 insqh $17,$6,$4 /* E0 */ 79 REG_S a1, 13*SZREG(t0) !! 90 bis $2,$4,$1 /* .. E1 */ 80 REG_S a1, 14*SZREG(t0) !! 91 stq $1,0($5) /* E0 */ 81 REG_S a1, 15*SZREG(t0) !! 92 ret $31,($26),1 /* .. E1 */ 82 REG_S a1, 16*SZREG(t0) !! 93 83 REG_S a1, 17*SZREG(t0) !! 94 .align 3 84 REG_S a1, 18*SZREG(t0) !! 95 within_one_quad: 85 REG_S a1, 19*SZREG(t0) !! 96 ldq_u $1,0($16) /* E0 */ 86 REG_S a1, 20*SZREG(t0) !! 97 insql $17,$16,$2 /* E1 */ 87 REG_S a1, 21*SZREG(t0) !! 98 mskql $1,$16,$4 /* E0 (after load stall) */ 88 REG_S a1, 22*SZREG(t0) !! 99 bis $2,$4,$2 /* E0 */ 89 REG_S a1, 23*SZREG(t0) !! 100 90 REG_S a1, 24*SZREG(t0) !! 101 mskql $2,$6,$4 /* E0 */ 91 REG_S a1, 25*SZREG(t0) !! 102 mskqh $1,$6,$2 /* .. E1 */ 92 REG_S a1, 26*SZREG(t0) !! 103 bis $2,$4,$1 /* E0 */ 93 REG_S a1, 27*SZREG(t0) !! 104 stq_u $1,0($16) /* E0 */ 94 REG_S a1, 28*SZREG(t0) !! 105 95 REG_S a1, 29*SZREG(t0) !! 106 end: 96 REG_S a1, 30*SZREG(t0) !! 107 ret $31,($26),1 /* E1 */ 97 REG_S a1, 31*SZREG(t0) !! 108 .end ___memset 98 addi t0, t0, 32*SZREG !! 109 EXPORT_SYMBOL(___memset) 99 bltu t0, a3, 3b !! 110 EXPORT_SYMBOL(__constant_c_memset) 100 andi a2, a2, SZREG-1 /* Update count !! 111 101 !! 112 .align 5 102 4: !! 113 .ent __memsetw 103 /* Handle trailing misalignment */ !! 114 __memsetw: 104 beqz a2, 6f !! 115 .prologue 0 105 add a3, t0, a2 !! 116 106 5: !! 117 inswl $17,0,$1 /* E0 */ 107 sb a1, 0(t0) !! 118 inswl $17,2,$2 /* E0 */ 108 addi t0, t0, 1 !! 119 inswl $17,4,$3 /* E0 */ 109 bltu t0, a3, 5b !! 120 or $1,$2,$1 /* .. E1 */ 110 6: !! 121 inswl $17,6,$4 /* E0 */ 111 ret !! 122 or $1,$3,$1 /* .. E1 */ 112 SYM_FUNC_END(__memset) !! 123 or $1,$4,$17 /* E0 */ 113 SYM_FUNC_ALIAS_WEAK(memset, __memset) !! 124 br __constant_c_memset /* .. E1 */ 114 SYM_FUNC_ALIAS(__pi_memset, __memset) !! 125 115 SYM_FUNC_ALIAS(__pi___memset, __memset) !! 126 .end __memsetw >> 127 EXPORT_SYMBOL(__memsetw) >> 128 >> 129 memset = ___memset >> 130 __memset = ___memset >> 131 EXPORT_SYMBOL(memset) >> 132 EXPORT_SYMBOL(__memset)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.