17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*dfb96a4fSab196087 * Common Development and Distribution License (the "License"). 6*dfb96a4fSab196087 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate/* 22*dfb96a4fSab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate .ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate .file "%M%" 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate#if defined(_KERNEL) 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * Legacy kernel interfaces; they will go away (eventually). 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(cas8,atomic_cas_8,function) 377c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(cas32,atomic_cas_32,function) 387c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(cas64,atomic_cas_64,function) 397c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(caslong,atomic_cas_ulong,function) 407c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(casptr,atomic_cas_ptr,function) 417c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(atomic_and_long,atomic_and_ulong,function) 427c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(atomic_or_long,atomic_or_ulong,function) 437c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(swapl,atomic_swap_32,function) 447c478bd9Sstevel@tonic-gate#else 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * Include the definitions for the libc weak aliases. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate#include "../atomic_asm_weak.h" 497c478bd9Sstevel@tonic-gate#endif 507c478bd9Sstevel@tonic-gate 51*dfb96a4fSab196087 /* 52*dfb96a4fSab196087 * NOTE: If atomic_inc_8 and atomic_inc_8_nv are ever 53*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 54*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 55*dfb96a4fSab196087 * from atomic_inc_8_nv. 56*dfb96a4fSab196087 */ 577c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_8) 587c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_8_nv) 597c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uchar) 607c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uchar_nv) 617c478bd9Sstevel@tonic-gate ba add_8 627c478bd9Sstevel@tonic-gate add %g0, 1, %o1 637c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uchar_nv) 647c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uchar) 657c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_8_nv) 667c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_8) 677c478bd9Sstevel@tonic-gate 68*dfb96a4fSab196087 /* 69*dfb96a4fSab196087 * NOTE: If atomic_dec_8 and atomic_dec_8_nv are ever 70*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 71*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 72*dfb96a4fSab196087 * from atomic_dec_8_nv. 73*dfb96a4fSab196087 */ 747c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_8) 757c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_8_nv) 767c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uchar) 777c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uchar_nv) 787c478bd9Sstevel@tonic-gate ba add_8 797c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 807c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uchar_nv) 817c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uchar) 827c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_8_nv) 837c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_8) 847c478bd9Sstevel@tonic-gate 85*dfb96a4fSab196087 /* 86*dfb96a4fSab196087 * NOTE: If atomic_add_8 and atomic_add_8_nv are ever 87*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 88*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 89*dfb96a4fSab196087 * from atomic_add_8_nv. 90*dfb96a4fSab196087 */ 917c478bd9Sstevel@tonic-gate ENTRY(atomic_add_8) 927c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_8_nv) 937c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_char) 947c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_char_nv) 957c478bd9Sstevel@tonic-gateadd_8: 967c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 977c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 987c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 997c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 1007c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 1017c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 1027c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 1037c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 1047c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 1057c478bd9Sstevel@tonic-gate1: 1067c478bd9Sstevel@tonic-gate add %o2, %o1, %o5 ! add value to the old value 1077c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 ! clear other bits 1087c478bd9Sstevel@tonic-gate andn %o2, %o3, %o4 ! clear target bits 1097c478bd9Sstevel@tonic-gate or %o4, %o5, %o5 ! insert the new value 1107c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 1117c478bd9Sstevel@tonic-gate cmp %o2, %o5 1127c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 1137c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 1147c478bd9Sstevel@tonic-gate add %o2, %o1, %o5 1157c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 1167c478bd9Sstevel@tonic-gate retl 1177c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 1187c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_char_nv) 1197c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_char) 1207c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_8_nv) 1217c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_8) 1227c478bd9Sstevel@tonic-gate 123*dfb96a4fSab196087 /* 124*dfb96a4fSab196087 * NOTE: If atomic_inc_16 and atomic_inc_16_nv are ever 125*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 126*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 127*dfb96a4fSab196087 * from atomic_inc_16_nv. 128*dfb96a4fSab196087 */ 1297c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_16) 1307c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_16_nv) 1317c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ushort) 1327c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ushort_nv) 1337c478bd9Sstevel@tonic-gate ba add_16 1347c478bd9Sstevel@tonic-gate add %g0, 1, %o1 1357c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ushort_nv) 1367c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ushort) 1377c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_16_nv) 1387c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_16) 1397c478bd9Sstevel@tonic-gate 140*dfb96a4fSab196087 /* 141*dfb96a4fSab196087 * NOTE: If atomic_dec_16 and atomic_dec_16_nv are ever 142*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 143*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 144*dfb96a4fSab196087 * from atomic_dec_16_nv. 145*dfb96a4fSab196087 */ 1467c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_16) 1477c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_16_nv) 1487c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ushort) 1497c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ushort_nv) 1507c478bd9Sstevel@tonic-gate ba add_16 1517c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 1527c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ushort_nv) 1537c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ushort) 1547c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_16_nv) 1557c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_16) 1567c478bd9Sstevel@tonic-gate 157*dfb96a4fSab196087 /* 158*dfb96a4fSab196087 * NOTE: If atomic_add_16 and atomic_add_16_nv are ever 159*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 160*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 161*dfb96a4fSab196087 * from atomic_add_16_nv. 162*dfb96a4fSab196087 */ 1637c478bd9Sstevel@tonic-gate ENTRY(atomic_add_16) 1647c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_16_nv) 1657c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_short) 1667c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_short_nv) 1677c478bd9Sstevel@tonic-gateadd_16: 1687c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 1697c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 1707c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 1717c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 1727c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 1737c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 1747c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 1757c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 1767c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 1777c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 1787c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 1797c478bd9Sstevel@tonic-gate1: 1807c478bd9Sstevel@tonic-gate add %o1, %o2, %o5 ! add value to the old value 1817c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 ! clear other bits 1827c478bd9Sstevel@tonic-gate andn %o2, %o3, %o4 ! clear target bits 1837c478bd9Sstevel@tonic-gate or %o4, %o5, %o5 ! insert the new value 1847c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 1857c478bd9Sstevel@tonic-gate cmp %o2, %o5 1867c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 1877c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 1887c478bd9Sstevel@tonic-gate add %o1, %o2, %o5 1897c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 1907c478bd9Sstevel@tonic-gate retl 1917c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 1927c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_short_nv) 1937c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_short) 1947c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_16_nv) 1957c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_16) 1967c478bd9Sstevel@tonic-gate 197*dfb96a4fSab196087 /* 198*dfb96a4fSab196087 * NOTE: If atomic_inc_32 and atomic_inc_32_nv are ever 199*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 200*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 201*dfb96a4fSab196087 * from atomic_inc_32_nv. 202*dfb96a4fSab196087 */ 2037c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_32) 2047c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_32_nv) 2057c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uint) 2067c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uint_nv) 2077c478bd9Sstevel@tonic-gate ba add_32 2087c478bd9Sstevel@tonic-gate add %g0, 1, %o1 2097c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uint_nv) 2107c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uint) 2117c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_32_nv) 2127c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_32) 2137c478bd9Sstevel@tonic-gate 214*dfb96a4fSab196087 /* 215*dfb96a4fSab196087 * NOTE: If atomic_dec_32 and atomic_dec_32_nv are ever 216*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 217*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 218*dfb96a4fSab196087 * from atomic_dec_32_nv. 219*dfb96a4fSab196087 */ 2207c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_32) 2217c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_32_nv) 2227c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uint) 2237c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uint_nv) 2247c478bd9Sstevel@tonic-gate ba add_32 2257c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 2267c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uint_nv) 2277c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uint) 2287c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_32_nv) 2297c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_32) 2307c478bd9Sstevel@tonic-gate 231*dfb96a4fSab196087 /* 232*dfb96a4fSab196087 * NOTE: If atomic_add_32 and atomic_add_32_nv are ever 233*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 234*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 235*dfb96a4fSab196087 * from atomic_add_32_nv. 236*dfb96a4fSab196087 */ 2377c478bd9Sstevel@tonic-gate ENTRY(atomic_add_32) 2387c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_32_nv) 2397c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_int) 2407c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_int_nv) 2417c478bd9Sstevel@tonic-gateadd_32: 2427c478bd9Sstevel@tonic-gate ld [%o0], %o2 2437c478bd9Sstevel@tonic-gate1: 2447c478bd9Sstevel@tonic-gate add %o2, %o1, %o3 2457c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 2467c478bd9Sstevel@tonic-gate cmp %o2, %o3 2477c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 2487c478bd9Sstevel@tonic-gate mov %o3, %o2 2497c478bd9Sstevel@tonic-gate retl 2507c478bd9Sstevel@tonic-gate add %o2, %o1, %o0 ! return new value 2517c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_int_nv) 2527c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_int) 2537c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_32_nv) 2547c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_32) 2557c478bd9Sstevel@tonic-gate 256*dfb96a4fSab196087 /* 257*dfb96a4fSab196087 * NOTE: If atomic_inc_64 and atomic_inc_64_nv are ever 258*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 259*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 260*dfb96a4fSab196087 * from atomic_inc_64_nv. 261*dfb96a4fSab196087 */ 2627c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_64) 2637c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_64_nv) 2647c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ulong) 2657c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ulong_nv) 2667c478bd9Sstevel@tonic-gate ba add_64 2677c478bd9Sstevel@tonic-gate add %g0, 1, %o1 2687c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ulong_nv) 2697c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ulong) 2707c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_64_nv) 2717c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_64) 2727c478bd9Sstevel@tonic-gate 273*dfb96a4fSab196087 /* 274*dfb96a4fSab196087 * NOTE: If atomic_dec_64 and atomic_dec_64_nv are ever 275*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 276*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 277*dfb96a4fSab196087 * from atomic_dec_64_nv. 278*dfb96a4fSab196087 */ 2797c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_64) 2807c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_64_nv) 2817c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ulong) 2827c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ulong_nv) 2837c478bd9Sstevel@tonic-gate ba add_64 2847c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 2857c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ulong_nv) 2867c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ulong) 2877c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_64_nv) 2887c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_64) 2897c478bd9Sstevel@tonic-gate 290*dfb96a4fSab196087 /* 291*dfb96a4fSab196087 * NOTE: If atomic_add_64 and atomic_add_64_nv are ever 292*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 293*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 294*dfb96a4fSab196087 * from atomic_add_64_nv. 295*dfb96a4fSab196087 */ 2967c478bd9Sstevel@tonic-gate ENTRY(atomic_add_64) 2977c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_64_nv) 2987c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_ptr) 2997c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_ptr_nv) 3007c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_long) 3017c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_long_nv) 3027c478bd9Sstevel@tonic-gateadd_64: 3037c478bd9Sstevel@tonic-gate ldx [%o0], %o2 3047c478bd9Sstevel@tonic-gate1: 3057c478bd9Sstevel@tonic-gate add %o2, %o1, %o3 3067c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 3077c478bd9Sstevel@tonic-gate cmp %o2, %o3 3087c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 3097c478bd9Sstevel@tonic-gate mov %o3, %o2 3107c478bd9Sstevel@tonic-gate retl 3117c478bd9Sstevel@tonic-gate add %o2, %o1, %o0 ! return new value 3127c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_long_nv) 3137c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_long) 3147c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_ptr_nv) 3157c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_ptr) 3167c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_64_nv) 3177c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_64) 3187c478bd9Sstevel@tonic-gate 319*dfb96a4fSab196087 /* 320*dfb96a4fSab196087 * NOTE: If atomic_or_8 and atomic_or_8_nv are ever 321*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 322*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 323*dfb96a4fSab196087 * from atomic_or_8_nv. 324*dfb96a4fSab196087 */ 3257c478bd9Sstevel@tonic-gate ENTRY(atomic_or_8) 3267c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_8_nv) 3277c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uchar) 3287c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uchar_nv) 3297c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 3307c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 3317c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 3327c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 3337c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 3347c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 3357c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 3367c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 3377c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 3387c478bd9Sstevel@tonic-gate1: 3397c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 ! or in the new value 3407c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 3417c478bd9Sstevel@tonic-gate cmp %o2, %o5 3427c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 3437c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 3447c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 3457c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 3467c478bd9Sstevel@tonic-gate retl 3477c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 3487c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uchar_nv) 3497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uchar) 3507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_8_nv) 3517c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_8) 3527c478bd9Sstevel@tonic-gate 353*dfb96a4fSab196087 /* 354*dfb96a4fSab196087 * NOTE: If atomic_or_16 and atomic_or_16_nv are ever 355*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 356*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 357*dfb96a4fSab196087 * from atomic_or_16_nv. 358*dfb96a4fSab196087 */ 3597c478bd9Sstevel@tonic-gate ENTRY(atomic_or_16) 3607c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_16_nv) 3617c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ushort) 3627c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ushort_nv) 3637c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 3647c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 3657c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 3667c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 3677c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 3687c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 3697c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 3707c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 3717c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 3727c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 3737c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 3747c478bd9Sstevel@tonic-gate1: 3757c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 ! or in the new value 3767c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 3777c478bd9Sstevel@tonic-gate cmp %o2, %o5 3787c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 3797c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 3807c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 ! or in the new value 3817c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 3827c478bd9Sstevel@tonic-gate retl 3837c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 3847c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ushort_nv) 3857c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ushort) 3867c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_16_nv) 3877c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_16) 3887c478bd9Sstevel@tonic-gate 389*dfb96a4fSab196087 /* 390*dfb96a4fSab196087 * NOTE: If atomic_or_32 and atomic_or_32_nv are ever 391*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 392*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 393*dfb96a4fSab196087 * from atomic_or_32_nv. 394*dfb96a4fSab196087 */ 3957c478bd9Sstevel@tonic-gate ENTRY(atomic_or_32) 3967c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_32_nv) 3977c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uint) 3987c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uint_nv) 3997c478bd9Sstevel@tonic-gate ld [%o0], %o2 4007c478bd9Sstevel@tonic-gate1: 4017c478bd9Sstevel@tonic-gate or %o2, %o1, %o3 4027c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 4037c478bd9Sstevel@tonic-gate cmp %o2, %o3 4047c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 4057c478bd9Sstevel@tonic-gate mov %o3, %o2 4067c478bd9Sstevel@tonic-gate retl 4077c478bd9Sstevel@tonic-gate or %o2, %o1, %o0 ! return new value 4087c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uint_nv) 4097c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uint) 4107c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_32_nv) 4117c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_32) 4127c478bd9Sstevel@tonic-gate 413*dfb96a4fSab196087 /* 414*dfb96a4fSab196087 * NOTE: If atomic_or_64 and atomic_or_64_nv are ever 415*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 416*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 417*dfb96a4fSab196087 * from atomic_or_64_nv. 418*dfb96a4fSab196087 */ 4197c478bd9Sstevel@tonic-gate ENTRY(atomic_or_64) 4207c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_64_nv) 4217c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ulong) 4227c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ulong_nv) 4237c478bd9Sstevel@tonic-gate ldx [%o0], %o2 4247c478bd9Sstevel@tonic-gate1: 4257c478bd9Sstevel@tonic-gate or %o2, %o1, %o3 4267c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 4277c478bd9Sstevel@tonic-gate cmp %o2, %o3 4287c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 4297c478bd9Sstevel@tonic-gate mov %o3, %o2 4307c478bd9Sstevel@tonic-gate retl 4317c478bd9Sstevel@tonic-gate or %o2, %o1, %o0 ! return new value 4327c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ulong_nv) 4337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ulong) 4347c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_64_nv) 4357c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_64) 4367c478bd9Sstevel@tonic-gate 437*dfb96a4fSab196087 /* 438*dfb96a4fSab196087 * NOTE: If atomic_and_8 and atomic_and_8_nv are ever 439*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 440*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 441*dfb96a4fSab196087 * from atomic_and_8_nv. 442*dfb96a4fSab196087 */ 4437c478bd9Sstevel@tonic-gate ENTRY(atomic_and_8) 4447c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_8_nv) 4457c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uchar) 4467c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uchar_nv) 4477c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 4487c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 4497c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 4507c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 4517c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 4527c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 4537c478bd9Sstevel@tonic-gate orn %o1, %o3, %o1 ! all ones in other bytes 4547c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 4557c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 4567c478bd9Sstevel@tonic-gate1: 4577c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 ! and in the new value 4587c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 4597c478bd9Sstevel@tonic-gate cmp %o2, %o5 4607c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 4617c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 4627c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 4637c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 4647c478bd9Sstevel@tonic-gate retl 4657c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 4667c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar_nv) 4677c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar) 4687c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8_nv) 4697c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8) 4707c478bd9Sstevel@tonic-gate 471*dfb96a4fSab196087 /* 472*dfb96a4fSab196087 * NOTE: If atomic_and_16 and atomic_and_16_nv are ever 473*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 474*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 475*dfb96a4fSab196087 * from atomic_and_16_nv. 476*dfb96a4fSab196087 */ 4777c478bd9Sstevel@tonic-gate ENTRY(atomic_and_16) 4787c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_16_nv) 4797c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ushort) 4807c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ushort_nv) 4817c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 4827c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 4837c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 4847c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 4857c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 4867c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 4877c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 4887c478bd9Sstevel@tonic-gate orn %o1, %o3, %o1 ! all ones in the other half 4897c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 4907c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 4917c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 4927c478bd9Sstevel@tonic-gate1: 4937c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 ! and in the new value 4947c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 4957c478bd9Sstevel@tonic-gate cmp %o2, %o5 4967c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 4977c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 4987c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 4997c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 5007c478bd9Sstevel@tonic-gate retl 5017c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 5027c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ushort_nv) 5037c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ushort) 5047c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_16_nv) 5057c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_16) 5067c478bd9Sstevel@tonic-gate 507*dfb96a4fSab196087 /* 508*dfb96a4fSab196087 * NOTE: If atomic_and_32 and atomic_and_32_nv are ever 509*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 510*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 511*dfb96a4fSab196087 * from atomic_and_32_nv. 512*dfb96a4fSab196087 */ 5137c478bd9Sstevel@tonic-gate ENTRY(atomic_and_32) 5147c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_32_nv) 5157c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uint) 5167c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uint_nv) 5177c478bd9Sstevel@tonic-gate ld [%o0], %o2 5187c478bd9Sstevel@tonic-gate1: 5197c478bd9Sstevel@tonic-gate and %o2, %o1, %o3 5207c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 5217c478bd9Sstevel@tonic-gate cmp %o2, %o3 5227c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 5237c478bd9Sstevel@tonic-gate mov %o3, %o2 5247c478bd9Sstevel@tonic-gate retl 5257c478bd9Sstevel@tonic-gate and %o2, %o1, %o0 ! return new value 5267c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uint_nv) 5277c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uint) 5287c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_32_nv) 5297c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_32) 5307c478bd9Sstevel@tonic-gate 531*dfb96a4fSab196087 /* 532*dfb96a4fSab196087 * NOTE: If atomic_and_64 and atomic_and_64_nv are ever 533*dfb96a4fSab196087 * separated, you need to also edit the libc sparcv9 platform 534*dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 535*dfb96a4fSab196087 * from atomic_and_64_nv. 536*dfb96a4fSab196087 */ 5377c478bd9Sstevel@tonic-gate ENTRY(atomic_and_64) 5387c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_64_nv) 5397c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ulong) 5407c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ulong_nv) 5417c478bd9Sstevel@tonic-gate ldx [%o0], %o2 5427c478bd9Sstevel@tonic-gate1: 5437c478bd9Sstevel@tonic-gate and %o2, %o1, %o3 5447c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 5457c478bd9Sstevel@tonic-gate cmp %o2, %o3 5467c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 5477c478bd9Sstevel@tonic-gate mov %o3, %o2 5487c478bd9Sstevel@tonic-gate retl 5497c478bd9Sstevel@tonic-gate and %o2, %o1, %o0 ! return new value 5507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ulong_nv) 5517c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ulong) 5527c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_64_nv) 5537c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_64) 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_8) 5567c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_uchar) 5577c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 5587c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 5597c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 5607c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 5617c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 5627c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 5637c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 5647c478bd9Sstevel@tonic-gate sll %o2, %g1, %o2 ! %o2 = shifted to bit offset 5657c478bd9Sstevel@tonic-gate and %o2, %o3, %o2 ! %o2 = single byte value 5667c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 5677c478bd9Sstevel@tonic-gate ld [%o0], %o4 ! read old value 5687c478bd9Sstevel@tonic-gate1: 5697c478bd9Sstevel@tonic-gate andn %o4, %o3, %o4 ! clear target bits 5707c478bd9Sstevel@tonic-gate or %o4, %o2, %o5 ! insert the new value 5717c478bd9Sstevel@tonic-gate or %o4, %o1, %o4 ! insert the comparison value 5727c478bd9Sstevel@tonic-gate cas [%o0], %o4, %o5 5737c478bd9Sstevel@tonic-gate cmp %o4, %o5 ! did we succeed? 5747c478bd9Sstevel@tonic-gate be,pt %icc, 2f 5757c478bd9Sstevel@tonic-gate and %o5, %o3, %o4 ! isolate the old value 5767c478bd9Sstevel@tonic-gate cmp %o1, %o4 ! should we have succeeded? 5777c478bd9Sstevel@tonic-gate be,a,pt %icc, 1b ! yes, try again 5787c478bd9Sstevel@tonic-gate mov %o5, %o4 ! %o4 = old value 5797c478bd9Sstevel@tonic-gate2: 5807c478bd9Sstevel@tonic-gate retl 5817c478bd9Sstevel@tonic-gate srl %o4, %g1, %o0 ! %o0 = old value 5827c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_uchar) 5837c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_8) 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_16) 5867c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ushort) 5877c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 5887c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 5897c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 5907c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 5917c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 5927c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 5937c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 5947c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 5957c478bd9Sstevel@tonic-gate sll %o2, %g1, %o2 ! %o2 = shifted to bit offset 5967c478bd9Sstevel@tonic-gate and %o2, %o3, %o2 ! %o2 = single short value 5977c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 5987c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 5997c478bd9Sstevel@tonic-gate ld [%o0], %o4 ! read old value 6007c478bd9Sstevel@tonic-gate1: 6017c478bd9Sstevel@tonic-gate andn %o4, %o3, %o4 ! clear target bits 6027c478bd9Sstevel@tonic-gate or %o4, %o2, %o5 ! insert the new value 6037c478bd9Sstevel@tonic-gate or %o4, %o1, %o4 ! insert the comparison value 6047c478bd9Sstevel@tonic-gate cas [%o0], %o4, %o5 6057c478bd9Sstevel@tonic-gate cmp %o4, %o5 ! did we succeed? 6067c478bd9Sstevel@tonic-gate be,pt %icc, 2f 6077c478bd9Sstevel@tonic-gate and %o5, %o3, %o4 ! isolate the old value 6087c478bd9Sstevel@tonic-gate cmp %o1, %o4 ! should we have succeeded? 6097c478bd9Sstevel@tonic-gate be,a,pt %icc, 1b ! yes, try again 6107c478bd9Sstevel@tonic-gate mov %o5, %o4 ! %o4 = old value 6117c478bd9Sstevel@tonic-gate2: 6127c478bd9Sstevel@tonic-gate retl 6137c478bd9Sstevel@tonic-gate srl %o4, %g1, %o0 ! %o0 = old value 6147c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ushort) 6157c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_16) 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_32) 6187c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_uint) 6197c478bd9Sstevel@tonic-gate cas [%o0], %o1, %o2 6207c478bd9Sstevel@tonic-gate retl 6217c478bd9Sstevel@tonic-gate mov %o2, %o0 6227c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_uint) 6237c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_32) 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_64) 6267c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ptr) 6277c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ulong) 6287c478bd9Sstevel@tonic-gate casx [%o0], %o1, %o2 6297c478bd9Sstevel@tonic-gate retl 6307c478bd9Sstevel@tonic-gate mov %o2, %o0 6317c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ulong) 6327c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ptr) 6337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_64) 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_8) 6367c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_uchar) 6377c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 6387c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 6397c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 6407c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 6417c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 6427c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 6437c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 6447c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 6457c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 6467c478bd9Sstevel@tonic-gate1: 6477c478bd9Sstevel@tonic-gate andn %o2, %o3, %o5 ! clear target bits 6487c478bd9Sstevel@tonic-gate or %o5, %o1, %o5 ! insert the new value 6497c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 6507c478bd9Sstevel@tonic-gate cmp %o2, %o5 6517c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 6527c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 6537c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 6547c478bd9Sstevel@tonic-gate retl 6557c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = old value 6567c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_uchar) 6577c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_8) 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_16) 6607c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ushort) 6617c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 6627c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 6637c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 6647c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 6657c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 6667c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 6677c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 6687c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 6697c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 6707c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 6717c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 6727c478bd9Sstevel@tonic-gate1: 6737c478bd9Sstevel@tonic-gate andn %o2, %o3, %o5 ! clear target bits 6747c478bd9Sstevel@tonic-gate or %o5, %o1, %o5 ! insert the new value 6757c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 6767c478bd9Sstevel@tonic-gate cmp %o2, %o5 6777c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 6787c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 6797c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 6807c478bd9Sstevel@tonic-gate retl 6817c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = old value 6827c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ushort) 6837c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_16) 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_32) 6867c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_uint) 6877c478bd9Sstevel@tonic-gate ld [%o0], %o2 6887c478bd9Sstevel@tonic-gate1: 6897c478bd9Sstevel@tonic-gate mov %o1, %o3 6907c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 6917c478bd9Sstevel@tonic-gate cmp %o2, %o3 6927c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 6937c478bd9Sstevel@tonic-gate mov %o3, %o2 6947c478bd9Sstevel@tonic-gate retl 6957c478bd9Sstevel@tonic-gate mov %o3, %o0 6967c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_uint) 6977c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_32) 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_64) 7007c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ptr) 7017c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ulong) 7027c478bd9Sstevel@tonic-gate ldx [%o0], %o2 7037c478bd9Sstevel@tonic-gate1: 7047c478bd9Sstevel@tonic-gate mov %o1, %o3 7057c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 7067c478bd9Sstevel@tonic-gate cmp %o2, %o3 7077c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 7087c478bd9Sstevel@tonic-gate mov %o3, %o2 7097c478bd9Sstevel@tonic-gate retl 7107c478bd9Sstevel@tonic-gate mov %o3, %o0 7117c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ulong) 7127c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ptr) 7137c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_64) 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate ENTRY(atomic_set_long_excl) 7167c478bd9Sstevel@tonic-gate mov 1, %o3 7177c478bd9Sstevel@tonic-gate slln %o3, %o1, %o3 7187c478bd9Sstevel@tonic-gate ldn [%o0], %o2 7197c478bd9Sstevel@tonic-gate1: 7207c478bd9Sstevel@tonic-gate andcc %o2, %o3, %g0 ! test if the bit is set 7217c478bd9Sstevel@tonic-gate bnz,a,pn %ncc, 2f ! if so, then fail out 7227c478bd9Sstevel@tonic-gate mov -1, %o0 7237c478bd9Sstevel@tonic-gate or %o2, %o3, %o4 ! set the bit, and try to commit it 7247c478bd9Sstevel@tonic-gate casn [%o0], %o2, %o4 7257c478bd9Sstevel@tonic-gate cmp %o2, %o4 7267c478bd9Sstevel@tonic-gate bne,a,pn %ncc, 1b ! failed to commit, try again 7277c478bd9Sstevel@tonic-gate mov %o4, %o2 7287c478bd9Sstevel@tonic-gate mov %g0, %o0 7297c478bd9Sstevel@tonic-gate2: 7307c478bd9Sstevel@tonic-gate retl 7317c478bd9Sstevel@tonic-gate nop 7327c478bd9Sstevel@tonic-gate SET_SIZE(atomic_set_long_excl) 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate ENTRY(atomic_clear_long_excl) 7357c478bd9Sstevel@tonic-gate mov 1, %o3 7367c478bd9Sstevel@tonic-gate slln %o3, %o1, %o3 7377c478bd9Sstevel@tonic-gate ldn [%o0], %o2 7387c478bd9Sstevel@tonic-gate1: 7397c478bd9Sstevel@tonic-gate andncc %o3, %o2, %g0 ! test if the bit is clear 7407c478bd9Sstevel@tonic-gate bnz,a,pn %ncc, 2f ! if so, then fail out 7417c478bd9Sstevel@tonic-gate mov -1, %o0 7427c478bd9Sstevel@tonic-gate andn %o2, %o3, %o4 ! clear the bit, and try to commit it 7437c478bd9Sstevel@tonic-gate casn [%o0], %o2, %o4 7447c478bd9Sstevel@tonic-gate cmp %o2, %o4 7457c478bd9Sstevel@tonic-gate bne,a,pn %ncc, 1b ! failed to commit, try again 7467c478bd9Sstevel@tonic-gate mov %o4, %o2 7477c478bd9Sstevel@tonic-gate mov %g0, %o0 7487c478bd9Sstevel@tonic-gate2: 7497c478bd9Sstevel@tonic-gate retl 7507c478bd9Sstevel@tonic-gate nop 7517c478bd9Sstevel@tonic-gate SET_SIZE(atomic_clear_long_excl) 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate#if !defined(_KERNEL) 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate /* 7567c478bd9Sstevel@tonic-gate * Spitfires and Blackbirds have a problem with membars in the 7577c478bd9Sstevel@tonic-gate * delay slot (SF_ERRATA_51). For safety's sake, we assume 7587c478bd9Sstevel@tonic-gate * that the whole world needs the workaround. 7597c478bd9Sstevel@tonic-gate */ 7607c478bd9Sstevel@tonic-gate ENTRY(membar_enter) 7617c478bd9Sstevel@tonic-gate membar #StoreLoad|#StoreStore 7627c478bd9Sstevel@tonic-gate retl 7637c478bd9Sstevel@tonic-gate nop 7647c478bd9Sstevel@tonic-gate SET_SIZE(membar_enter) 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate ENTRY(membar_exit) 7677c478bd9Sstevel@tonic-gate membar #LoadStore|#StoreStore 7687c478bd9Sstevel@tonic-gate retl 7697c478bd9Sstevel@tonic-gate nop 7707c478bd9Sstevel@tonic-gate SET_SIZE(membar_exit) 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate ENTRY(membar_producer) 7737c478bd9Sstevel@tonic-gate membar #StoreStore 7747c478bd9Sstevel@tonic-gate retl 7757c478bd9Sstevel@tonic-gate nop 7767c478bd9Sstevel@tonic-gate SET_SIZE(membar_producer) 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate ENTRY(membar_consumer) 7797c478bd9Sstevel@tonic-gate membar #LoadLoad 7807c478bd9Sstevel@tonic-gate retl 7817c478bd9Sstevel@tonic-gate nop 7827c478bd9Sstevel@tonic-gate SET_SIZE(membar_consumer) 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate#endif /* !_KERNEL */ 785