1*09ff5f3bSriastradh/* $NetBSD: atomic_swap.S,v 1.10 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 366740bb54SchsENTRY(_atomic_swap_32) 3707a0a325Smatt movl 4(%sp), %a0 3807a0a325Smatt1: movl (%a0), %d0 3907a0a325Smatt movl 8(%sp), %d1 4065726debSmatt casl %d0, %d1, (%a0) 41935eacf3Sad bne 1b 42935eacf3Sad /* %d0 now contains the old value */ 43935eacf3Sad movl %d0, %a0 /* pointers return also in %a0 */ 44935eacf3Sad rts 4565726debSmattEND(_atomic_swap_32) 46935eacf3SadATOMIC_OP_ALIAS(atomic_swap_32,_atomic_swap_32) 47935eacf3SadATOMIC_OP_ALIAS(atomic_swap_uint,_atomic_swap_32) 48935eacf3SadSTRONG_ALIAS(_atomic_swap_uint,_atomic_swap_32) 49935eacf3SadATOMIC_OP_ALIAS(atomic_swap_ulong,_atomic_swap_32) 50935eacf3SadSTRONG_ALIAS(_atomic_swap_ulong,_atomic_swap_32) 51935eacf3SadATOMIC_OP_ALIAS(atomic_swap_ptr,_atomic_swap_32) 52935eacf3SadSTRONG_ALIAS(_atomic_swap_ptr,_atomic_swap_32) 53b290679aSmartinCRT_ALIAS(__sync_lock_test_and_set_4,_atomic_swap_32) 54bd7dee05SjoergCRT_ALIAS(__atomic_exchange_4,_atomic_swap_32) 550ac513acSmartin 560ac513acSmartin 570ac513acSmartinENTRY(_atomic_swap_16) 580ac513acSmartin movl 4(%sp), %a0 590ac513acSmartin1: movw (%a0), %d0 600ac513acSmartin movw 8(%sp), %d1 610ac513acSmartin casw %d0, %d1, (%a0) 620ac513acSmartin bne 1b 630ac513acSmartin /* %d0 now contains the old value */ 640ac513acSmartin rts 650ac513acSmartinEND(_atomic_swap_16) 660ac513acSmartinATOMIC_OP_ALIAS(atomic_swap_16,_atomic_swap_16) 67b290679aSmartinCRT_ALIAS(__sync_lock_test_and_set_2,_atomic_swap_16) 68bd7dee05SjoergCRT_ALIAS(__atomic_exchange_2,_atomic_swap_16) 690ac513acSmartin 700ac513acSmartinENTRY(_atomic_swap_8) 710ac513acSmartin movl 4(%sp), %a0 720ac513acSmartin1: movb (%a0), %d0 730ac513acSmartin movb 8(%sp), %d1 740ac513acSmartin casb %d0, %d1, (%a0) 750ac513acSmartin bne 1b 760ac513acSmartin /* %d0 now contains the old value */ 770ac513acSmartin rts 780ac513acSmartinEND(_atomic_swap_8) 790ac513acSmartinATOMIC_OP_ALIAS(atomic_swap_8,_atomic_swap_8) 80b290679aSmartinCRT_ALIAS(__sync_lock_test_and_set_1,_atomic_swap_8) 81bd7dee05SjoergCRT_ALIAS(__atomic_exchange_1,_atomic_swap_8) 82