1*09ff5f3bSriastradh/* $NetBSD: atomic_cas.S,v 1.14 2022/04/06 22:47:56 riastradh Exp $ */ 2935eacf3Sad 3935eacf3Sad/*- 4646fc3baSad * Copyright (c) 2007, 2008 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_cas_32) 3707a0a325Smatt movl 4(%sp), %a0 3807a0a325Smatt movl 8(%sp), %d0 3907a0a325Smatt movl 12(%sp), %d1 4065726debSmatt casl %d0, %d1, (%a0) 41935eacf3Sad /* %d0 now contains the old value */ 42935eacf3Sad movl %d0, %a0 /* pointers return also in %a0 */ 43935eacf3Sad rts 4465726debSmattEND(_atomic_cas_32) 45646fc3baSad 46935eacf3SadATOMIC_OP_ALIAS(atomic_cas_32,_atomic_cas_32) 47935eacf3SadATOMIC_OP_ALIAS(atomic_cas_uint,_atomic_cas_32) 48935eacf3SadSTRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32) 49935eacf3SadATOMIC_OP_ALIAS(atomic_cas_ulong,_atomic_cas_32) 50935eacf3SadSTRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32) 51935eacf3SadATOMIC_OP_ALIAS(atomic_cas_ptr,_atomic_cas_32) 52935eacf3SadSTRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32) 53b290679aSmartinCRT_ALIAS(__sync_val_compare_and_swap_4,_atomic_cas_32) 54646fc3baSad 55646fc3baSadATOMIC_OP_ALIAS(atomic_cas_32_ni,_atomic_cas_32) 56646fc3baSadSTRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32) 57646fc3baSadATOMIC_OP_ALIAS(atomic_cas_uint_ni,_atomic_cas_32) 58646fc3baSadSTRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32) 59646fc3baSadATOMIC_OP_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32) 60646fc3baSadSTRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32) 61646fc3baSadATOMIC_OP_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32) 62646fc3baSadSTRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32) 630ac513acSmartin 640ac513acSmartinENTRY(__sync_bool_compare_and_swap_4) 650ac513acSmartin movl 4(%sp), %a0 6655d302deSisaki movl 8(%sp), %d0 670ac513acSmartin movl 12(%sp), %d1 6855d302deSisaki casl %d0, %d1, (%a0) 693940a87aSisaki beqs 1f 70566b4de5Smartin clrl %d0 /* return false */ 71566b4de5Smartin rts 723940a87aSisaki1: movql #1, %d0 /* return success */ 73566b4de5Smartin rts 740ac513acSmartinEND(__sync_bool_compare_and_swap_4) 750ac513acSmartin 760ac513acSmartinENTRY(_atomic_cas_16) 770ac513acSmartin movl 4(%sp), %a0 7855d302deSisaki movw 8+2(%sp), %d0 /* lower word */ 7955d302deSisaki movw 12+2(%sp), %d1 /* lower word */ 800ac513acSmartin casw %d0, %d1, (%a0) 810ac513acSmartin /* %d0 now contains the old value */ 820ac513acSmartin rts 830ac513acSmartinEND(_atomic_cas_16) 840ac513acSmartin 850ac513acSmartinATOMIC_OP_ALIAS(atomic_cas_16,_atomic_cas_16) 86b290679aSmartinCRT_ALIAS(__sync_val_compare_and_swap_2,_atomic_cas_16) 870ac513acSmartin 880ac513acSmartinENTRY(__sync_bool_compare_and_swap_2) 890ac513acSmartin movl 4(%sp), %a0 9055d302deSisaki movw 8+2(%sp), %d0 /* lower word */ 9155d302deSisaki movw 12+2(%sp), %d1 /* lower word */ 9255d302deSisaki casw %d0, %d1, (%a0) 932bb05299Smlelstv /* %d0 now contains the old value */ 943940a87aSisaki beqs 1f 95566b4de5Smartin clrl %d0 /* return failure */ 96566b4de5Smartin rts 973940a87aSisaki1: movql #1, %d0 /* return success */ 98566b4de5Smartin rts 990ac513acSmartinEND(__sync_bool_compare_and_swap_2) 1000ac513acSmartin 1010ac513acSmartinENTRY(_atomic_cas_8) 1020ac513acSmartin movl 4(%sp), %a0 10355d302deSisaki movb 8+3(%sp), %d0 /* lower byte */ 10455d302deSisaki movb 12+3(%sp), %d1 /* lower byte */ 1050ac513acSmartin casb %d0, %d1, (%a0) 1060ac513acSmartin /* %d0 now contains the old value */ 1070ac513acSmartin rts 1080ac513acSmartinEND(_atomic_cas_8) 1090ac513acSmartin 1100ac513acSmartinATOMIC_OP_ALIAS(atomic_cas_8,_atomic_cas_8) 111b290679aSmartinCRT_ALIAS(__sync_val_compare_and_swap_1,_atomic_cas_8) 1120ac513acSmartin 1130ac513acSmartin 1140ac513acSmartinENTRY(__sync_bool_compare_and_swap_1) 1150ac513acSmartin movl 4(%sp), %a0 11655d302deSisaki movb 8+3(%sp), %d0 /* lower byte */ 11755d302deSisaki movb 12+3(%sp), %d1 /* lower byte */ 11855d302deSisaki casb %d0, %d1, (%a0) 1192bb05299Smlelstv /* %d0 now contains the old value */ 1203940a87aSisaki beqs 1f 121566b4de5Smartin clrl %d0 /* return failure */ 122566b4de5Smartin rts 1233940a87aSisaki1: movql #1, %d0 /* return success */ 124566b4de5Smartin rts 1250ac513acSmartinEND(__sync_bool_compare_and_swap_1) 1260ac513acSmartin 127