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 5dfb96a4fSab196087 * Common Development and Distribution License (the "License"). 6dfb96a4fSab196087 * 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 */ 217257d1b4Sraf 227c478bd9Sstevel@tonic-gate/* 237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 279a70fc3bSMark J. Nelson .file "atomic.s" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h> 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate#if defined(_KERNEL) 327c478bd9Sstevel@tonic-gate /* 33*6ed9368aSJosef 'Jeff' Sipek * Legacy kernel interfaces; they will go away the moment our closed 34*6ed9368aSJosef 'Jeff' Sipek * bins no longer require them. 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#endif 457c478bd9Sstevel@tonic-gate 46dfb96a4fSab196087 /* 47dfb96a4fSab196087 * NOTE: If atomic_inc_8 and atomic_inc_8_nv are ever 48dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 49dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 50dfb96a4fSab196087 * from atomic_inc_8_nv. 51dfb96a4fSab196087 */ 527c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_8) 537c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_8_nv) 547c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uchar) 557c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uchar_nv) 567c478bd9Sstevel@tonic-gate ba add_8 577c478bd9Sstevel@tonic-gate add %g0, 1, %o1 587c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uchar_nv) 597c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uchar) 607c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_8_nv) 617c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_8) 627c478bd9Sstevel@tonic-gate 63dfb96a4fSab196087 /* 64dfb96a4fSab196087 * NOTE: If atomic_dec_8 and atomic_dec_8_nv are ever 65dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 66dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 67dfb96a4fSab196087 * from atomic_dec_8_nv. 68dfb96a4fSab196087 */ 697c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_8) 707c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_8_nv) 717c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uchar) 727c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uchar_nv) 737c478bd9Sstevel@tonic-gate ba add_8 747c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 757c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uchar_nv) 767c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uchar) 777c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_8_nv) 787c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_8) 797c478bd9Sstevel@tonic-gate 80dfb96a4fSab196087 /* 81dfb96a4fSab196087 * NOTE: If atomic_add_8 and atomic_add_8_nv are ever 82dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 83dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 84dfb96a4fSab196087 * from atomic_add_8_nv. 85dfb96a4fSab196087 */ 867c478bd9Sstevel@tonic-gate ENTRY(atomic_add_8) 877c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_8_nv) 887c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_char) 897c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_char_nv) 907c478bd9Sstevel@tonic-gateadd_8: 917c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 927c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 937c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 947c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 957c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 967c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 977c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 987c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 997c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 1007c478bd9Sstevel@tonic-gate1: 1017c478bd9Sstevel@tonic-gate add %o2, %o1, %o5 ! add value to the old value 1027c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 ! clear other bits 1037c478bd9Sstevel@tonic-gate andn %o2, %o3, %o4 ! clear target bits 1047c478bd9Sstevel@tonic-gate or %o4, %o5, %o5 ! insert the new value 1057c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 1067c478bd9Sstevel@tonic-gate cmp %o2, %o5 1077c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 1087c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 1097c478bd9Sstevel@tonic-gate add %o2, %o1, %o5 1107c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 1117c478bd9Sstevel@tonic-gate retl 1127c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 1137c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_char_nv) 1147c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_char) 1157c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_8_nv) 1167c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_8) 1177c478bd9Sstevel@tonic-gate 118dfb96a4fSab196087 /* 119dfb96a4fSab196087 * NOTE: If atomic_inc_16 and atomic_inc_16_nv are ever 120dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 121dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 122dfb96a4fSab196087 * from atomic_inc_16_nv. 123dfb96a4fSab196087 */ 1247c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_16) 1257c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_16_nv) 1267c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ushort) 1277c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ushort_nv) 1287c478bd9Sstevel@tonic-gate ba add_16 1297c478bd9Sstevel@tonic-gate add %g0, 1, %o1 1307c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ushort_nv) 1317c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ushort) 1327c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_16_nv) 1337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_16) 1347c478bd9Sstevel@tonic-gate 135dfb96a4fSab196087 /* 136dfb96a4fSab196087 * NOTE: If atomic_dec_16 and atomic_dec_16_nv are ever 137dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 138dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 139dfb96a4fSab196087 * from atomic_dec_16_nv. 140dfb96a4fSab196087 */ 1417c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_16) 1427c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_16_nv) 1437c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ushort) 1447c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ushort_nv) 1457c478bd9Sstevel@tonic-gate ba add_16 1467c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 1477c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ushort_nv) 1487c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ushort) 1497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_16_nv) 1507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_16) 1517c478bd9Sstevel@tonic-gate 152dfb96a4fSab196087 /* 153dfb96a4fSab196087 * NOTE: If atomic_add_16 and atomic_add_16_nv are ever 154dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 155dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 156dfb96a4fSab196087 * from atomic_add_16_nv. 157dfb96a4fSab196087 */ 1587c478bd9Sstevel@tonic-gate ENTRY(atomic_add_16) 1597c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_16_nv) 1607c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_short) 1617c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_short_nv) 1627c478bd9Sstevel@tonic-gateadd_16: 1637c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 1647c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 1657c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 1667c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 1677c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 1687c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 1697c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 1707c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 1717c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 1727c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 1737c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 1747c478bd9Sstevel@tonic-gate1: 1757c478bd9Sstevel@tonic-gate add %o1, %o2, %o5 ! add value to the old value 1767c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 ! clear other bits 1777c478bd9Sstevel@tonic-gate andn %o2, %o3, %o4 ! clear target bits 1787c478bd9Sstevel@tonic-gate or %o4, %o5, %o5 ! insert the new value 1797c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 1807c478bd9Sstevel@tonic-gate cmp %o2, %o5 1817c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 1827c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 1837c478bd9Sstevel@tonic-gate add %o1, %o2, %o5 1847c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 1857c478bd9Sstevel@tonic-gate retl 1867c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 1877c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_short_nv) 1887c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_short) 1897c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_16_nv) 1907c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_16) 1917c478bd9Sstevel@tonic-gate 192dfb96a4fSab196087 /* 193dfb96a4fSab196087 * NOTE: If atomic_inc_32 and atomic_inc_32_nv are ever 194dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 195dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 196dfb96a4fSab196087 * from atomic_inc_32_nv. 197dfb96a4fSab196087 */ 1987c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_32) 1997c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_32_nv) 2007c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uint) 2017c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uint_nv) 2027c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ulong) 2037c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ulong_nv) 2047c478bd9Sstevel@tonic-gate ba add_32 2057c478bd9Sstevel@tonic-gate add %g0, 1, %o1 2067c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ulong_nv) 2077c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ulong) 2087c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uint_nv) 2097c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uint) 2107c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_32_nv) 2117c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_32) 2127c478bd9Sstevel@tonic-gate 213dfb96a4fSab196087 /* 214dfb96a4fSab196087 * NOTE: If atomic_dec_32 and atomic_dec_32_nv are ever 215dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 216dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 217dfb96a4fSab196087 * from atomic_dec_32_nv. 218dfb96a4fSab196087 */ 2197c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_32) 2207c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_32_nv) 2217c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uint) 2227c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uint_nv) 2237c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ulong) 2247c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ulong_nv) 2257c478bd9Sstevel@tonic-gate ba add_32 2267c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 2277c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ulong_nv) 2287c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ulong) 2297c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uint_nv) 2307c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uint) 2317c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_32_nv) 2327c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_32) 2337c478bd9Sstevel@tonic-gate 234dfb96a4fSab196087 /* 235dfb96a4fSab196087 * NOTE: If atomic_add_32 and atomic_add_32_nv are ever 236dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 237dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 238dfb96a4fSab196087 * from atomic_add_32_nv. 239dfb96a4fSab196087 */ 2407c478bd9Sstevel@tonic-gate ENTRY(atomic_add_32) 2417c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_32_nv) 2427c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_int) 2437c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_int_nv) 2447c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_ptr) 2457c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_ptr_nv) 2467c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_long) 2477c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_long_nv) 2487c478bd9Sstevel@tonic-gateadd_32: 2497c478bd9Sstevel@tonic-gate ld [%o0], %o2 2507c478bd9Sstevel@tonic-gate1: 2517c478bd9Sstevel@tonic-gate add %o2, %o1, %o3 2527c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 2537c478bd9Sstevel@tonic-gate cmp %o2, %o3 2547c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 2557c478bd9Sstevel@tonic-gate mov %o3, %o2 2567c478bd9Sstevel@tonic-gate retl 2577c478bd9Sstevel@tonic-gate add %o2, %o1, %o0 ! return new value 2587c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_long_nv) 2597c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_long) 2607c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_ptr_nv) 2617c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_ptr) 2627c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_int_nv) 2637c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_int) 2647c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_32_nv) 2657c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_32) 2667c478bd9Sstevel@tonic-gate 267dfb96a4fSab196087 /* 268dfb96a4fSab196087 * NOTE: If atomic_inc_64 and atomic_inc_64_nv are ever 269dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 270dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 271dfb96a4fSab196087 * from atomic_inc_64_nv. 272dfb96a4fSab196087 */ 2737c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_64) 2747c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_64_nv) 2757c478bd9Sstevel@tonic-gate ba add_64 2767c478bd9Sstevel@tonic-gate add %g0, 1, %o1 2777c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_64_nv) 2787c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_64) 2797c478bd9Sstevel@tonic-gate 280dfb96a4fSab196087 /* 281dfb96a4fSab196087 * NOTE: If atomic_dec_64 and atomic_dec_64_nv are ever 282dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 283dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 284dfb96a4fSab196087 * from atomic_dec_64_nv. 285dfb96a4fSab196087 */ 2867c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_64) 2877c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_64_nv) 2887c478bd9Sstevel@tonic-gate ba add_64 2897c478bd9Sstevel@tonic-gate sub %g0, 1, %o1 2907c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_64_nv) 2917c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_64) 2927c478bd9Sstevel@tonic-gate 293dfb96a4fSab196087 /* 294dfb96a4fSab196087 * NOTE: If atomic_add_64 and atomic_add_64_nv are ever 295dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 296dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 297dfb96a4fSab196087 * from atomic_add_64_nv. 298dfb96a4fSab196087 */ 2997c478bd9Sstevel@tonic-gate ENTRY(atomic_add_64) 3007c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_64_nv) 3017c478bd9Sstevel@tonic-gate sllx %o1, 32, %o1 ! upper 32 in %o1, lower in %o2 3027c478bd9Sstevel@tonic-gate srl %o2, 0, %o2 3037c478bd9Sstevel@tonic-gate add %o1, %o2, %o1 ! convert 2 32-bit args into 1 64-bit 3047c478bd9Sstevel@tonic-gateadd_64: 3057c478bd9Sstevel@tonic-gate ldx [%o0], %o2 3067c478bd9Sstevel@tonic-gate1: 3077c478bd9Sstevel@tonic-gate add %o2, %o1, %o3 3087c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 3097c478bd9Sstevel@tonic-gate cmp %o2, %o3 3107c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 3117c478bd9Sstevel@tonic-gate mov %o3, %o2 3127c478bd9Sstevel@tonic-gate add %o2, %o1, %o1 ! return lower 32-bits in %o1 3137c478bd9Sstevel@tonic-gate retl 3147c478bd9Sstevel@tonic-gate srlx %o1, 32, %o0 ! return upper 32-bits in %o0 3157c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_64_nv) 3167c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_64) 3177c478bd9Sstevel@tonic-gate 318dfb96a4fSab196087 /* 319dfb96a4fSab196087 * NOTE: If atomic_or_8 and atomic_or_8_nv are ever 320dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 321dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 322dfb96a4fSab196087 * from atomic_or_8_nv. 323dfb96a4fSab196087 */ 3247c478bd9Sstevel@tonic-gate ENTRY(atomic_or_8) 3257c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_8_nv) 3267c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uchar) 3277c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uchar_nv) 3287c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 3297c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 3307c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 3317c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 3327c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 3337c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 3347c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 3357c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 3367c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 3377c478bd9Sstevel@tonic-gate1: 3387c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 ! or in the new value 3397c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 3407c478bd9Sstevel@tonic-gate cmp %o2, %o5 3417c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 3427c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 3437c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 3447c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 3457c478bd9Sstevel@tonic-gate retl 3467c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 3477c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uchar_nv) 3487c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uchar) 3497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_8_nv) 3507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_8) 3517c478bd9Sstevel@tonic-gate 352dfb96a4fSab196087 /* 353dfb96a4fSab196087 * NOTE: If atomic_or_16 and atomic_or_16_nv are ever 354dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 355dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 356dfb96a4fSab196087 * from atomic_or_16_nv. 357dfb96a4fSab196087 */ 3587c478bd9Sstevel@tonic-gate ENTRY(atomic_or_16) 3597c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_16_nv) 3607c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ushort) 3617c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ushort_nv) 3627c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 3637c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 3647c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 3657c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 3667c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 3677c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 3687c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 3697c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 3707c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 3717c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 3727c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 3737c478bd9Sstevel@tonic-gate1: 3747c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 ! or in the new value 3757c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 3767c478bd9Sstevel@tonic-gate cmp %o2, %o5 3777c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 3787c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 3797c478bd9Sstevel@tonic-gate or %o2, %o1, %o5 ! or in the new value 3807c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 3817c478bd9Sstevel@tonic-gate retl 3827c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 3837c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ushort_nv) 3847c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ushort) 3857c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_16_nv) 3867c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_16) 3877c478bd9Sstevel@tonic-gate 388dfb96a4fSab196087 /* 389dfb96a4fSab196087 * NOTE: If atomic_or_32 and atomic_or_32_nv are ever 390dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 391dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 392dfb96a4fSab196087 * from atomic_or_32_nv. 393dfb96a4fSab196087 */ 3947c478bd9Sstevel@tonic-gate ENTRY(atomic_or_32) 3957c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_32_nv) 3967c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uint) 3977c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uint_nv) 3987c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ulong) 3997c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ulong_nv) 4007c478bd9Sstevel@tonic-gate ld [%o0], %o2 4017c478bd9Sstevel@tonic-gate1: 4027c478bd9Sstevel@tonic-gate or %o2, %o1, %o3 4037c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 4047c478bd9Sstevel@tonic-gate cmp %o2, %o3 4057c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 4067c478bd9Sstevel@tonic-gate mov %o3, %o2 4077c478bd9Sstevel@tonic-gate retl 4087c478bd9Sstevel@tonic-gate or %o2, %o1, %o0 ! return new value 4097c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ulong_nv) 4107c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ulong) 4117c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uint_nv) 4127c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uint) 4137c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_32_nv) 4147c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_32) 4157c478bd9Sstevel@tonic-gate 416dfb96a4fSab196087 /* 417dfb96a4fSab196087 * NOTE: If atomic_or_64 and atomic_or_64_nv are ever 418dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 419dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 420dfb96a4fSab196087 * from atomic_or_64_nv. 421dfb96a4fSab196087 */ 4227c478bd9Sstevel@tonic-gate ENTRY(atomic_or_64) 4237c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_64_nv) 4247c478bd9Sstevel@tonic-gate sllx %o1, 32, %o1 ! upper 32 in %o1, lower in %o2 4257c478bd9Sstevel@tonic-gate srl %o2, 0, %o2 4267c478bd9Sstevel@tonic-gate add %o1, %o2, %o1 ! convert 2 32-bit args into 1 64-bit 4277c478bd9Sstevel@tonic-gate ldx [%o0], %o2 4287c478bd9Sstevel@tonic-gate1: 4297c478bd9Sstevel@tonic-gate or %o2, %o1, %o3 4307c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 4317c478bd9Sstevel@tonic-gate cmp %o2, %o3 4327c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 4337c478bd9Sstevel@tonic-gate mov %o3, %o2 4347c478bd9Sstevel@tonic-gate or %o2, %o1, %o1 ! return lower 32-bits in %o1 4357c478bd9Sstevel@tonic-gate retl 4367c478bd9Sstevel@tonic-gate srlx %o1, 32, %o0 ! return upper 32-bits in %o0 4377c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_64_nv) 4387c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_64) 4397c478bd9Sstevel@tonic-gate 440dfb96a4fSab196087 /* 441dfb96a4fSab196087 * NOTE: If atomic_and_8 and atomic_and_8_nv are ever 442dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 443dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 444dfb96a4fSab196087 * from atomic_and_8_nv. 445dfb96a4fSab196087 */ 4467c478bd9Sstevel@tonic-gate ENTRY(atomic_and_8) 4477c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_8_nv) 4487c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uchar) 4497c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uchar_nv) 4507c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 4517c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 4527c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 4537c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 4547c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 4557c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 4567c478bd9Sstevel@tonic-gate orn %o1, %o3, %o1 ! all ones in other bytes 4577c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 4587c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 4597c478bd9Sstevel@tonic-gate1: 4607c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 ! and in the new value 4617c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 4627c478bd9Sstevel@tonic-gate cmp %o2, %o5 4637c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 4647c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 4657c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 4667c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 4677c478bd9Sstevel@tonic-gate retl 4687c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 4697c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar_nv) 4707c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar) 4717c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8_nv) 4727c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8) 4737c478bd9Sstevel@tonic-gate 474dfb96a4fSab196087 /* 475dfb96a4fSab196087 * NOTE: If atomic_and_16 and atomic_and_16_nv are ever 476dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 477dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 478dfb96a4fSab196087 * from atomic_and_16_nv. 479dfb96a4fSab196087 */ 4807c478bd9Sstevel@tonic-gate ENTRY(atomic_and_16) 4817c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_16_nv) 4827c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ushort) 4837c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ushort_nv) 4847c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 4857c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 4867c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 4877c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 4887c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 4897c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 4907c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 4917c478bd9Sstevel@tonic-gate orn %o1, %o3, %o1 ! all ones in the other half 4927c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 4937c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 4947c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 4957c478bd9Sstevel@tonic-gate1: 4967c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 ! and in the new value 4977c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 4987c478bd9Sstevel@tonic-gate cmp %o2, %o5 4997c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 5007c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 5017c478bd9Sstevel@tonic-gate and %o2, %o1, %o5 5027c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 5037c478bd9Sstevel@tonic-gate retl 5047c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = new value 5057c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ushort_nv) 5067c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ushort) 5077c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_16_nv) 5087c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_16) 5097c478bd9Sstevel@tonic-gate 510dfb96a4fSab196087 /* 511dfb96a4fSab196087 * NOTE: If atomic_and_32 and atomic_and_32_nv are ever 512dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 513dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 514dfb96a4fSab196087 * from atomic_and_32_nv. 515dfb96a4fSab196087 */ 5167c478bd9Sstevel@tonic-gate ENTRY(atomic_and_32) 5177c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_32_nv) 5187c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uint) 5197c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uint_nv) 5207c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ulong) 5217c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ulong_nv) 5227c478bd9Sstevel@tonic-gate ld [%o0], %o2 5237c478bd9Sstevel@tonic-gate1: 5247c478bd9Sstevel@tonic-gate and %o2, %o1, %o3 5257c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 5267c478bd9Sstevel@tonic-gate cmp %o2, %o3 5277c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 5287c478bd9Sstevel@tonic-gate mov %o3, %o2 5297c478bd9Sstevel@tonic-gate retl 5307c478bd9Sstevel@tonic-gate and %o2, %o1, %o0 ! return new value 5317c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ulong_nv) 5327c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ulong) 5337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uint_nv) 5347c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uint) 5357c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_32_nv) 5367c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_32) 5377c478bd9Sstevel@tonic-gate 538dfb96a4fSab196087 /* 539dfb96a4fSab196087 * NOTE: If atomic_and_64 and atomic_and_64_nv are ever 540dfb96a4fSab196087 * separated, you need to also edit the libc sparc platform 541dfb96a4fSab196087 * specific mapfile and remove the NODYNSORT attribute 542dfb96a4fSab196087 * from atomic_and_64_nv. 543dfb96a4fSab196087 */ 5447c478bd9Sstevel@tonic-gate ENTRY(atomic_and_64) 5457c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_64_nv) 5467c478bd9Sstevel@tonic-gate sllx %o1, 32, %o1 ! upper 32 in %o1, lower in %o2 5477c478bd9Sstevel@tonic-gate srl %o2, 0, %o2 5487c478bd9Sstevel@tonic-gate add %o1, %o2, %o1 ! convert 2 32-bit args into 1 64-bit 5497c478bd9Sstevel@tonic-gate ldx [%o0], %o2 5507c478bd9Sstevel@tonic-gate1: 5517c478bd9Sstevel@tonic-gate and %o2, %o1, %o3 5527c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 5537c478bd9Sstevel@tonic-gate cmp %o2, %o3 5547c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 5557c478bd9Sstevel@tonic-gate mov %o3, %o2 5567c478bd9Sstevel@tonic-gate and %o2, %o1, %o1 ! return lower 32-bits in %o1 5577c478bd9Sstevel@tonic-gate retl 5587c478bd9Sstevel@tonic-gate srlx %o1, 32, %o0 ! return upper 32-bits in %o0 5597c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_64_nv) 5607c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_64) 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_8) 5637c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_uchar) 5647c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 5657c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 5667c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 5677c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 5687c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 5697c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 5707c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 5717c478bd9Sstevel@tonic-gate sll %o2, %g1, %o2 ! %o2 = shifted to bit offset 5727c478bd9Sstevel@tonic-gate and %o2, %o3, %o2 ! %o2 = single byte value 5737c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 5747c478bd9Sstevel@tonic-gate ld [%o0], %o4 ! read old value 5757c478bd9Sstevel@tonic-gate1: 5767c478bd9Sstevel@tonic-gate andn %o4, %o3, %o4 ! clear target bits 5777c478bd9Sstevel@tonic-gate or %o4, %o2, %o5 ! insert the new value 5787c478bd9Sstevel@tonic-gate or %o4, %o1, %o4 ! insert the comparison value 5797c478bd9Sstevel@tonic-gate cas [%o0], %o4, %o5 5807c478bd9Sstevel@tonic-gate cmp %o4, %o5 ! did we succeed? 5817c478bd9Sstevel@tonic-gate be,pt %icc, 2f 5827c478bd9Sstevel@tonic-gate and %o5, %o3, %o4 ! isolate the old value 5837c478bd9Sstevel@tonic-gate cmp %o1, %o4 ! should we have succeeded? 5847c478bd9Sstevel@tonic-gate be,a,pt %icc, 1b ! yes, try again 5857c478bd9Sstevel@tonic-gate mov %o5, %o4 ! %o4 = old value 5867c478bd9Sstevel@tonic-gate2: 5877c478bd9Sstevel@tonic-gate retl 5887c478bd9Sstevel@tonic-gate srl %o4, %g1, %o0 ! %o0 = old value 5897c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_uchar) 5907c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_8) 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_16) 5937c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ushort) 5947c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 5957c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 5967c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 5977c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 5987c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 5997c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 6007c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 6017c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 6027c478bd9Sstevel@tonic-gate sll %o2, %g1, %o2 ! %o2 = shifted to bit offset 6037c478bd9Sstevel@tonic-gate and %o2, %o3, %o2 ! %o2 = single short value 6047c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 6057c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 6067c478bd9Sstevel@tonic-gate ld [%o0], %o4 ! read old value 6077c478bd9Sstevel@tonic-gate1: 6087c478bd9Sstevel@tonic-gate andn %o4, %o3, %o4 ! clear target bits 6097c478bd9Sstevel@tonic-gate or %o4, %o2, %o5 ! insert the new value 6107c478bd9Sstevel@tonic-gate or %o4, %o1, %o4 ! insert the comparison value 6117c478bd9Sstevel@tonic-gate cas [%o0], %o4, %o5 6127c478bd9Sstevel@tonic-gate cmp %o4, %o5 ! did we succeed? 6137c478bd9Sstevel@tonic-gate be,pt %icc, 2f 6147c478bd9Sstevel@tonic-gate and %o5, %o3, %o4 ! isolate the old value 6157c478bd9Sstevel@tonic-gate cmp %o1, %o4 ! should we have succeeded? 6167c478bd9Sstevel@tonic-gate be,a,pt %icc, 1b ! yes, try again 6177c478bd9Sstevel@tonic-gate mov %o5, %o4 ! %o4 = old value 6187c478bd9Sstevel@tonic-gate2: 6197c478bd9Sstevel@tonic-gate retl 6207c478bd9Sstevel@tonic-gate srl %o4, %g1, %o0 ! %o0 = old value 6217c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ushort) 6227c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_16) 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_32) 6257c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_uint) 6267c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ptr) 6277c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ulong) 6287c478bd9Sstevel@tonic-gate cas [%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_uint) 6347c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_32) 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_64) 6377c478bd9Sstevel@tonic-gate sllx %o1, 32, %o1 ! cmp's upper 32 in %o1, lower in %o2 6387c478bd9Sstevel@tonic-gate srl %o2, 0, %o2 ! convert 2 32-bit args into 1 64-bit 6397c478bd9Sstevel@tonic-gate add %o1, %o2, %o1 6407c478bd9Sstevel@tonic-gate sllx %o3, 32, %o2 ! newval upper 32 in %o3, lower in %o4 6417c478bd9Sstevel@tonic-gate srl %o4, 0, %o4 ! setup %o2 to have newval 6427c478bd9Sstevel@tonic-gate add %o2, %o4, %o2 6437c478bd9Sstevel@tonic-gate casx [%o0], %o1, %o2 6447c478bd9Sstevel@tonic-gate srl %o2, 0, %o1 ! return lower 32-bits in %o1 6457c478bd9Sstevel@tonic-gate retl 6467c478bd9Sstevel@tonic-gate srlx %o2, 32, %o0 ! return upper 32-bits in %o0 6477c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_64) 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_8) 6507c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_uchar) 6517c478bd9Sstevel@tonic-gate and %o0, 0x3, %o4 ! %o4 = byte offset, left-to-right 6527c478bd9Sstevel@tonic-gate xor %o4, 0x3, %g1 ! %g1 = byte offset, right-to-left 6537c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 6547c478bd9Sstevel@tonic-gate set 0xff, %o3 ! %o3 = mask 6557c478bd9Sstevel@tonic-gate sll %o3, %g1, %o3 ! %o3 = shifted to bit offset 6567c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 6577c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single byte value 6587c478bd9Sstevel@tonic-gate andn %o0, 0x3, %o0 ! %o0 = word address 6597c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 6607c478bd9Sstevel@tonic-gate1: 6617c478bd9Sstevel@tonic-gate andn %o2, %o3, %o5 ! clear target bits 6627c478bd9Sstevel@tonic-gate or %o5, %o1, %o5 ! insert the new value 6637c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 6647c478bd9Sstevel@tonic-gate cmp %o2, %o5 6657c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 6667c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 6677c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 6687c478bd9Sstevel@tonic-gate retl 6697c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = old value 6707c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_uchar) 6717c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_8) 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_16) 6747c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ushort) 6757c478bd9Sstevel@tonic-gate and %o0, 0x2, %o4 ! %o4 = byte offset, left-to-right 6767c478bd9Sstevel@tonic-gate xor %o4, 0x2, %g1 ! %g1 = byte offset, right-to-left 6777c478bd9Sstevel@tonic-gate sll %o4, 3, %o4 ! %o4 = bit offset, left-to-right 6787c478bd9Sstevel@tonic-gate sll %g1, 3, %g1 ! %g1 = bit offset, right-to-left 6797c478bd9Sstevel@tonic-gate sethi %hi(0xffff0000), %o3 ! %o3 = mask 6807c478bd9Sstevel@tonic-gate srl %o3, %o4, %o3 ! %o3 = shifted to bit offset 6817c478bd9Sstevel@tonic-gate sll %o1, %g1, %o1 ! %o1 = shifted to bit offset 6827c478bd9Sstevel@tonic-gate and %o1, %o3, %o1 ! %o1 = single short value 6837c478bd9Sstevel@tonic-gate andn %o0, 0x2, %o0 ! %o0 = word address 6847c478bd9Sstevel@tonic-gate ! if low-order bit is 1, we will properly get an alignment fault here 6857c478bd9Sstevel@tonic-gate ld [%o0], %o2 ! read old value 6867c478bd9Sstevel@tonic-gate1: 6877c478bd9Sstevel@tonic-gate andn %o2, %o3, %o5 ! clear target bits 6887c478bd9Sstevel@tonic-gate or %o5, %o1, %o5 ! insert the new value 6897c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o5 6907c478bd9Sstevel@tonic-gate cmp %o2, %o5 6917c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 6927c478bd9Sstevel@tonic-gate mov %o5, %o2 ! %o2 = old value 6937c478bd9Sstevel@tonic-gate and %o5, %o3, %o5 6947c478bd9Sstevel@tonic-gate retl 6957c478bd9Sstevel@tonic-gate srl %o5, %g1, %o0 ! %o0 = old value 6967c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ushort) 6977c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_16) 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_32) 7007c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_uint) 7017c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ptr) 7027c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ulong) 7037c478bd9Sstevel@tonic-gate ld [%o0], %o2 7047c478bd9Sstevel@tonic-gate1: 7057c478bd9Sstevel@tonic-gate mov %o1, %o3 7067c478bd9Sstevel@tonic-gate cas [%o0], %o2, %o3 7077c478bd9Sstevel@tonic-gate cmp %o2, %o3 7087c478bd9Sstevel@tonic-gate bne,a,pn %icc, 1b 7097c478bd9Sstevel@tonic-gate mov %o3, %o2 7107c478bd9Sstevel@tonic-gate retl 7117c478bd9Sstevel@tonic-gate mov %o3, %o0 7127c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ulong) 7137c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ptr) 7147c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_uint) 7157c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_32) 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_64) 7187c478bd9Sstevel@tonic-gate sllx %o1, 32, %o1 ! upper 32 in %o1, lower in %o2 7197c478bd9Sstevel@tonic-gate srl %o2, 0, %o2 7207c478bd9Sstevel@tonic-gate add %o1, %o2, %o1 ! convert 2 32-bit args into 1 64-bit 7217c478bd9Sstevel@tonic-gate ldx [%o0], %o2 7227c478bd9Sstevel@tonic-gate1: 7237c478bd9Sstevel@tonic-gate mov %o1, %o3 7247c478bd9Sstevel@tonic-gate casx [%o0], %o2, %o3 7257c478bd9Sstevel@tonic-gate cmp %o2, %o3 7267c478bd9Sstevel@tonic-gate bne,a,pn %xcc, 1b 7277c478bd9Sstevel@tonic-gate mov %o3, %o2 7287c478bd9Sstevel@tonic-gate srl %o3, 0, %o1 ! return lower 32-bits in %o1 7297c478bd9Sstevel@tonic-gate retl 7307c478bd9Sstevel@tonic-gate srlx %o3, 32, %o0 ! return upper 32-bits in %o0 7317c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_64) 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate ENTRY(atomic_set_long_excl) 7347c478bd9Sstevel@tonic-gate mov 1, %o3 7357c478bd9Sstevel@tonic-gate slln %o3, %o1, %o3 7367c478bd9Sstevel@tonic-gate ldn [%o0], %o2 7377c478bd9Sstevel@tonic-gate1: 7387c478bd9Sstevel@tonic-gate andcc %o2, %o3, %g0 ! test if the bit is set 7397c478bd9Sstevel@tonic-gate bnz,a,pn %ncc, 2f ! if so, then fail out 7407c478bd9Sstevel@tonic-gate mov -1, %o0 7417c478bd9Sstevel@tonic-gate or %o2, %o3, %o4 ! set the bit, and try to commit it 7427c478bd9Sstevel@tonic-gate casn [%o0], %o2, %o4 7437c478bd9Sstevel@tonic-gate cmp %o2, %o4 7447c478bd9Sstevel@tonic-gate bne,a,pn %ncc, 1b ! failed to commit, try again 7457c478bd9Sstevel@tonic-gate mov %o4, %o2 7467c478bd9Sstevel@tonic-gate mov %g0, %o0 7477c478bd9Sstevel@tonic-gate2: 7487c478bd9Sstevel@tonic-gate retl 7497c478bd9Sstevel@tonic-gate nop 7507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_set_long_excl) 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate ENTRY(atomic_clear_long_excl) 7537c478bd9Sstevel@tonic-gate mov 1, %o3 7547c478bd9Sstevel@tonic-gate slln %o3, %o1, %o3 7557c478bd9Sstevel@tonic-gate ldn [%o0], %o2 7567c478bd9Sstevel@tonic-gate1: 7577c478bd9Sstevel@tonic-gate andncc %o3, %o2, %g0 ! test if the bit is clear 7587c478bd9Sstevel@tonic-gate bnz,a,pn %ncc, 2f ! if so, then fail out 7597c478bd9Sstevel@tonic-gate mov -1, %o0 7607c478bd9Sstevel@tonic-gate andn %o2, %o3, %o4 ! clear the bit, and try to commit it 7617c478bd9Sstevel@tonic-gate casn [%o0], %o2, %o4 7627c478bd9Sstevel@tonic-gate cmp %o2, %o4 7637c478bd9Sstevel@tonic-gate bne,a,pn %ncc, 1b ! failed to commit, try again 7647c478bd9Sstevel@tonic-gate mov %o4, %o2 7657c478bd9Sstevel@tonic-gate mov %g0, %o0 7667c478bd9Sstevel@tonic-gate2: 7677c478bd9Sstevel@tonic-gate retl 7687c478bd9Sstevel@tonic-gate nop 7697c478bd9Sstevel@tonic-gate SET_SIZE(atomic_clear_long_excl) 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate#if !defined(_KERNEL) 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate /* 7747c478bd9Sstevel@tonic-gate * Spitfires and Blackbirds have a problem with membars in the 7757c478bd9Sstevel@tonic-gate * delay slot (SF_ERRATA_51). For safety's sake, we assume 7767c478bd9Sstevel@tonic-gate * that the whole world needs the workaround. 7777c478bd9Sstevel@tonic-gate */ 7787c478bd9Sstevel@tonic-gate ENTRY(membar_enter) 7797c478bd9Sstevel@tonic-gate membar #StoreLoad|#StoreStore 7807c478bd9Sstevel@tonic-gate retl 7817c478bd9Sstevel@tonic-gate nop 7827c478bd9Sstevel@tonic-gate SET_SIZE(membar_enter) 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate ENTRY(membar_exit) 7857c478bd9Sstevel@tonic-gate membar #LoadStore|#StoreStore 7867c478bd9Sstevel@tonic-gate retl 7877c478bd9Sstevel@tonic-gate nop 7887c478bd9Sstevel@tonic-gate SET_SIZE(membar_exit) 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate ENTRY(membar_producer) 7917c478bd9Sstevel@tonic-gate membar #StoreStore 7927c478bd9Sstevel@tonic-gate retl 7937c478bd9Sstevel@tonic-gate nop 7947c478bd9Sstevel@tonic-gate SET_SIZE(membar_producer) 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate ENTRY(membar_consumer) 7977c478bd9Sstevel@tonic-gate membar #LoadLoad 7987c478bd9Sstevel@tonic-gate retl 7997c478bd9Sstevel@tonic-gate nop 8007c478bd9Sstevel@tonic-gate SET_SIZE(membar_consumer) 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate#endif /* !_KERNEL */ 803