1*09ff5f3bSriastradh/* $NetBSD: atomic_add.S,v 1.11 2022/04/06 22:47:56 riastradh Exp $ */ 2935eacf3Sad 3935eacf3Sad/*- 4935eacf3Sad * Copyright (c) 2007 The NetBSD Foundation, Inc. 5935eacf3Sad * All rights reserved. 6935eacf3Sad * 7935eacf3Sad * This code is derived from software contributed to The NetBSD Foundation 8935eacf3Sad * by Jason R. Thorpe. 9935eacf3Sad * 10935eacf3Sad * Redistribution and use in source and binary forms, with or without 11935eacf3Sad * modification, are permitted provided that the following conditions 12935eacf3Sad * are met: 13935eacf3Sad * 1. Redistributions of source code must retain the above copyright 14935eacf3Sad * notice, this list of conditions and the following disclaimer. 15935eacf3Sad * 2. Redistributions in binary form must reproduce the above copyright 16935eacf3Sad * notice, this list of conditions and the following disclaimer in the 17935eacf3Sad * documentation and/or other materials provided with the distribution. 18935eacf3Sad * 19935eacf3Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20935eacf3Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21935eacf3Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22935eacf3Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23935eacf3Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24935eacf3Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25935eacf3Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26935eacf3Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27935eacf3Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28935eacf3Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29935eacf3Sad * POSSIBILITY OF SUCH DAMAGE. 30935eacf3Sad */ 31935eacf3Sad 32935eacf3Sad#include "atomic_op_asm.h" 33935eacf3Sad 34935eacf3Sad .text 35935eacf3Sad .align 2 36935eacf3Sad 376740bb54SchsENTRY(_atomic_add_32) 3807a0a325Smatt movl 4(%sp), %a0 3907a0a325Smatt movl 8(%sp), %d0 4065726debSmatt addl %d0, (%a0) 41935eacf3Sad rts 4265726debSmattEND(_atomic_add_32) 43935eacf3SadATOMIC_OP_ALIAS(atomic_add_32,_atomic_add_32) 44935eacf3SadATOMIC_OP_ALIAS(atomic_add_int,_atomic_add_32) 45935eacf3SadSTRONG_ALIAS(_atomic_add_int,_atomic_add_32) 46935eacf3SadATOMIC_OP_ALIAS(atomic_add_long,_atomic_add_32) 47935eacf3SadSTRONG_ALIAS(_atomic_add_long,_atomic_add_32) 48935eacf3SadATOMIC_OP_ALIAS(atomic_add_ptr,_atomic_add_32) 49935eacf3SadSTRONG_ALIAS(_atomic_add_ptr,_atomic_add_32) 50935eacf3Sad 516740bb54SchsENTRY(_atomic_add_32_nv) 5207a0a325Smatt movl 4(%sp), %a0 5307a0a325Smatt1: movl (%a0), %d0 54935eacf3Sad movl %d0, %d1 5507a0a325Smatt addl 8(%sp), %d0 5665726debSmatt casl %d1, %d0, (%a0) 57935eacf3Sad bne 1b 58935eacf3Sad movl %d0, %a0 /* pointers return also in %a0 */ 59935eacf3Sad rts 6065726debSmattEND(_atomic_add_32_nv) 6165726debSmatt 62935eacf3SadATOMIC_OP_ALIAS(atomic_add_32_nv,_atomic_add_32_nv) 63935eacf3SadATOMIC_OP_ALIAS(atomic_add_int_nv,_atomic_add_32_nv) 64935eacf3SadSTRONG_ALIAS(_atomic_add_int_nv,_atomic_add_32_nv) 65935eacf3SadATOMIC_OP_ALIAS(atomic_add_long_nv,_atomic_add_32_nv) 66935eacf3SadSTRONG_ALIAS(_atomic_add_long_nv,_atomic_add_32_nv) 67935eacf3SadATOMIC_OP_ALIAS(atomic_add_ptr_nv,_atomic_add_32_nv) 68935eacf3SadSTRONG_ALIAS(_atomic_add_ptr_nv,_atomic_add_32_nv) 69b290679aSmartinCRT_ALIAS(__sync_add_and_fetch_4,_atomic_add_32_nv) 700ac513acSmartin 71ce6031c2SmartinENTRY(__sync_fetch_and_add_4) 72ce6031c2Smartin movl 4(%sp), %a0 73ce6031c2Smartin1: movl (%a0), %d0 74ce6031c2Smartin movl %d0, %d1 75ce6031c2Smartin addl 8(%sp), %d1 76ce6031c2Smartin casl %d0, %d1, (%a0) 77ce6031c2Smartin bne 1b 78ce6031c2Smartin movl %d0, %a0 /* pointers return also in %a0 */ 79ce6031c2Smartin rts 80ce6031c2SmartinEND(__sync_fetch_and_add_4) 81ce6031c2Smartin 820ac513acSmartinENTRY(_atomic_add_16_nv) 830ac513acSmartin movl 4(%sp), %a0 840ac513acSmartin1: movw (%a0), %d0 850ac513acSmartin movw %d0, %d1 860ac513acSmartin addw 8(%sp), %d0 870ac513acSmartin casw %d1, %d0, (%a0) 880ac513acSmartin bne 1b 890ac513acSmartin rts 900ac513acSmartinEND(_atomic_add_16_nv) 910ac513acSmartin 92b290679aSmartinCRT_ALIAS(__sync_add_and_fetch_2,_atomic_add_16_nv) 930ac513acSmartin 94ce6031c2SmartinENTRY(__sync_fetch_and_add_2) 95ce6031c2Smartin movl 4(%sp), %a0 96ce6031c2Smartin1: movw (%a0), %d0 97ce6031c2Smartin movw %d0, %d1 98ce6031c2Smartin addw 8(%sp), %d1 99ce6031c2Smartin casw %d0, %d1, (%a0) 100ce6031c2Smartin bne 1b 101ce6031c2Smartin rts 102ce6031c2SmartinEND(__sync_fetch_and_add_2) 103ce6031c2Smartin 1040ac513acSmartinENTRY(_atomic_add_8_nv) 1050ac513acSmartin movl 4(%sp), %a0 1060ac513acSmartin1: movb (%a0), %d0 1070ac513acSmartin movb %d0, %d1 1080ac513acSmartin addb 8(%sp), %d0 1090ac513acSmartin casb %d1, %d0, (%a0) 1100ac513acSmartin bne 1b 1110ac513acSmartin rts 1120ac513acSmartinEND(_atomic_add_8_nv) 1130ac513acSmartin 114b290679aSmartinCRT_ALIAS(__sync_add_and_fetch_1,_atomic_add_8_nv) 115ce6031c2Smartin 116ce6031c2SmartinENTRY(__sync_fetch_and_add_1) 117ce6031c2Smartin movl 4(%sp), %a0 118ce6031c2Smartin1: movb (%a0), %d0 119ce6031c2Smartin movb %d0, %d1 120ce6031c2Smartin addb 8(%sp), %d1 121ce6031c2Smartin casb %d0, %d1, (%a0) 122ce6031c2Smartin bne 1b 123ce6031c2Smartin rts 124ce6031c2SmartinEND(__sync_fetch_and_add_1) 125504e8e68Sjoerg 126504e8e68SjoergCRT_ALIAS(__atomic_fetch_add_1,__sync_fetch_and_add_1) 127504e8e68SjoergCRT_ALIAS(__atomic_fetch_add_2,__sync_fetch_and_add_2) 128504e8e68SjoergCRT_ALIAS(__atomic_fetch_add_4,__sync_fetch_and_add_4) 129