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 27*9a70fc3bSMark 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 /* 337c478bd9Sstevel@tonic-gate * Legacy kernel interfaces; they will go away (eventually). 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(cas8,atomic_cas_8,function) 367c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(cas32,atomic_cas_32,function) 377c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(cas64,atomic_cas_64,function) 387c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(caslong,atomic_cas_ulong,function) 397c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(casptr,atomic_cas_ptr,function) 407c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(atomic_and_long,atomic_and_ulong,function) 417c478bd9Sstevel@tonic-gate ANSI_PRAGMA_WEAK2(atomic_or_long,atomic_or_ulong,function) 427c478bd9Sstevel@tonic-gate#endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_8) 457c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uchar) 467c478bd9Sstevel@tonic-gate lock 477c478bd9Sstevel@tonic-gate incb (%rdi) 487c478bd9Sstevel@tonic-gate ret 497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uchar) 507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_8) 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_16) 537c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ushort) 547c478bd9Sstevel@tonic-gate lock 557c478bd9Sstevel@tonic-gate incw (%rdi) 567c478bd9Sstevel@tonic-gate ret 577c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ushort) 587c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_16) 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_32) 617c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uint) 627c478bd9Sstevel@tonic-gate lock 637c478bd9Sstevel@tonic-gate incl (%rdi) 647c478bd9Sstevel@tonic-gate ret 657c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uint) 667c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_32) 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_64) 697c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ulong) 707c478bd9Sstevel@tonic-gate lock 717c478bd9Sstevel@tonic-gate incq (%rdi) 727c478bd9Sstevel@tonic-gate ret 737c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ulong) 747c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_64) 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_8_nv) 777c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uchar_nv) 787c478bd9Sstevel@tonic-gate movb (%rdi), %al / %al = old value 797c478bd9Sstevel@tonic-gate1: 807c478bd9Sstevel@tonic-gate leaq 1(%rax), %rcx / %cl = new value 817c478bd9Sstevel@tonic-gate lock 827c478bd9Sstevel@tonic-gate cmpxchgb %cl, (%rdi) / try to stick it in 837c478bd9Sstevel@tonic-gate jne 1b 847c478bd9Sstevel@tonic-gate movzbl %cl, %eax / return new value 857c478bd9Sstevel@tonic-gate ret 867c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uchar_nv) 877c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_8_nv) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_16_nv) 907c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ushort_nv) 917c478bd9Sstevel@tonic-gate movw (%rdi), %ax / %ax = old value 927c478bd9Sstevel@tonic-gate1: 937c478bd9Sstevel@tonic-gate leaq 1(%rax), %rcx / %cx = new value 947c478bd9Sstevel@tonic-gate lock 957c478bd9Sstevel@tonic-gate cmpxchgw %cx, (%rdi) / try to stick it in 967c478bd9Sstevel@tonic-gate jne 1b 977c478bd9Sstevel@tonic-gate movzwl %cx, %eax / return new value 987c478bd9Sstevel@tonic-gate ret 997c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ushort_nv) 1007c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_16_nv) 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_32_nv) 1037c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_uint_nv) 1047c478bd9Sstevel@tonic-gate movl (%rdi), %eax / %eax = old value 1057c478bd9Sstevel@tonic-gate1: 1067c478bd9Sstevel@tonic-gate leaq 1(%rax), %rcx / %ecx = new value 1077c478bd9Sstevel@tonic-gate lock 1087c478bd9Sstevel@tonic-gate cmpxchgl %ecx, (%rdi) / try to stick it in 1097c478bd9Sstevel@tonic-gate jne 1b 1107c478bd9Sstevel@tonic-gate movl %ecx, %eax / return new value 1117c478bd9Sstevel@tonic-gate ret 1127c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_uint_nv) 1137c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_32_nv) 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate ENTRY(atomic_inc_64_nv) 1167c478bd9Sstevel@tonic-gate ALTENTRY(atomic_inc_ulong_nv) 1177c478bd9Sstevel@tonic-gate movq (%rdi), %rax / %rax = old value 1187c478bd9Sstevel@tonic-gate1: 1197c478bd9Sstevel@tonic-gate leaq 1(%rax), %rcx / %rcx = new value 1207c478bd9Sstevel@tonic-gate lock 1217c478bd9Sstevel@tonic-gate cmpxchgq %rcx, (%rdi) / try to stick it in 1227c478bd9Sstevel@tonic-gate jne 1b 1237c478bd9Sstevel@tonic-gate movq %rcx, %rax / return new value 1247c478bd9Sstevel@tonic-gate ret 1257c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_ulong_nv) 1267c478bd9Sstevel@tonic-gate SET_SIZE(atomic_inc_64_nv) 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_8) 1297c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uchar) 1307c478bd9Sstevel@tonic-gate lock 1317c478bd9Sstevel@tonic-gate decb (%rdi) 1327c478bd9Sstevel@tonic-gate ret 1337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uchar) 1347c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_8) 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_16) 1377c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ushort) 1387c478bd9Sstevel@tonic-gate lock 1397c478bd9Sstevel@tonic-gate decw (%rdi) 1407c478bd9Sstevel@tonic-gate ret 1417c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ushort) 1427c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_16) 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_32) 1457c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uint) 1467c478bd9Sstevel@tonic-gate lock 1477c478bd9Sstevel@tonic-gate decl (%rdi) 1487c478bd9Sstevel@tonic-gate ret 1497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uint) 1507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_32) 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_64) 1537c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ulong) 1547c478bd9Sstevel@tonic-gate lock 1557c478bd9Sstevel@tonic-gate decq (%rdi) 1567c478bd9Sstevel@tonic-gate ret 1577c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ulong) 1587c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_64) 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_8_nv) 1617c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uchar_nv) 1627c478bd9Sstevel@tonic-gate movb (%rdi), %al / %al = old value 1637c478bd9Sstevel@tonic-gate1: 1647c478bd9Sstevel@tonic-gate leaq -1(%rax), %rcx / %cl = new value 1657c478bd9Sstevel@tonic-gate lock 1667c478bd9Sstevel@tonic-gate cmpxchgb %cl, (%rdi) / try to stick it in 1677c478bd9Sstevel@tonic-gate jne 1b 1687c478bd9Sstevel@tonic-gate movzbl %cl, %eax / return new value 1697c478bd9Sstevel@tonic-gate ret 1707c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uchar_nv) 1717c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_8_nv) 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_16_nv) 1747c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ushort_nv) 1757c478bd9Sstevel@tonic-gate movw (%rdi), %ax / %ax = old value 1767c478bd9Sstevel@tonic-gate1: 1777c478bd9Sstevel@tonic-gate leaq -1(%rax), %rcx / %cx = new value 1787c478bd9Sstevel@tonic-gate lock 1797c478bd9Sstevel@tonic-gate cmpxchgw %cx, (%rdi) / try to stick it in 1807c478bd9Sstevel@tonic-gate jne 1b 1817c478bd9Sstevel@tonic-gate movzwl %cx, %eax / return new value 1827c478bd9Sstevel@tonic-gate ret 1837c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ushort_nv) 1847c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_16_nv) 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_32_nv) 1877c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_uint_nv) 1887c478bd9Sstevel@tonic-gate movl (%rdi), %eax / %eax = old value 1897c478bd9Sstevel@tonic-gate1: 1907c478bd9Sstevel@tonic-gate leaq -1(%rax), %rcx / %ecx = new value 1917c478bd9Sstevel@tonic-gate lock 1927c478bd9Sstevel@tonic-gate cmpxchgl %ecx, (%rdi) / try to stick it in 1937c478bd9Sstevel@tonic-gate jne 1b 1947c478bd9Sstevel@tonic-gate movl %ecx, %eax / return new value 1957c478bd9Sstevel@tonic-gate ret 1967c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_uint_nv) 1977c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_32_nv) 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate ENTRY(atomic_dec_64_nv) 2007c478bd9Sstevel@tonic-gate ALTENTRY(atomic_dec_ulong_nv) 2017c478bd9Sstevel@tonic-gate movq (%rdi), %rax / %rax = old value 2027c478bd9Sstevel@tonic-gate1: 2037c478bd9Sstevel@tonic-gate leaq -1(%rax), %rcx / %rcx = new value 2047c478bd9Sstevel@tonic-gate lock 2057c478bd9Sstevel@tonic-gate cmpxchgq %rcx, (%rdi) / try to stick it in 2067c478bd9Sstevel@tonic-gate jne 1b 2077c478bd9Sstevel@tonic-gate movq %rcx, %rax / return new value 2087c478bd9Sstevel@tonic-gate ret 2097c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_ulong_nv) 2107c478bd9Sstevel@tonic-gate SET_SIZE(atomic_dec_64_nv) 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate ENTRY(atomic_add_8) 2137c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_char) 2147c478bd9Sstevel@tonic-gate lock 2157c478bd9Sstevel@tonic-gate addb %sil, (%rdi) 2167c478bd9Sstevel@tonic-gate ret 2177c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_char) 2187c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_8) 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate ENTRY(atomic_add_16) 2217c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_short) 2227c478bd9Sstevel@tonic-gate lock 2237c478bd9Sstevel@tonic-gate addw %si, (%rdi) 2247c478bd9Sstevel@tonic-gate ret 2257c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_short) 2267c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_16) 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate ENTRY(atomic_add_32) 2297c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_int) 2307c478bd9Sstevel@tonic-gate lock 2317c478bd9Sstevel@tonic-gate addl %esi, (%rdi) 2327c478bd9Sstevel@tonic-gate ret 2337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_int) 2347c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_32) 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate ENTRY(atomic_add_64) 2377c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_ptr) 2387c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_long) 2397c478bd9Sstevel@tonic-gate lock 2407c478bd9Sstevel@tonic-gate addq %rsi, (%rdi) 2417c478bd9Sstevel@tonic-gate ret 2427c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_long) 2437c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_ptr) 2447c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_64) 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate ENTRY(atomic_or_8) 2477c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uchar) 2487c478bd9Sstevel@tonic-gate lock 2497c478bd9Sstevel@tonic-gate orb %sil, (%rdi) 2507c478bd9Sstevel@tonic-gate ret 2517c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uchar) 2527c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_8) 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate ENTRY(atomic_or_16) 2557c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ushort) 2567c478bd9Sstevel@tonic-gate lock 2577c478bd9Sstevel@tonic-gate orw %si, (%rdi) 2587c478bd9Sstevel@tonic-gate ret 2597c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ushort) 2607c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_16) 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate ENTRY(atomic_or_32) 2637c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uint) 2647c478bd9Sstevel@tonic-gate lock 2657c478bd9Sstevel@tonic-gate orl %esi, (%rdi) 2667c478bd9Sstevel@tonic-gate ret 2677c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uint) 2687c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_32) 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate ENTRY(atomic_or_64) 2717c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ulong) 2727c478bd9Sstevel@tonic-gate lock 2737c478bd9Sstevel@tonic-gate orq %rsi, (%rdi) 2747c478bd9Sstevel@tonic-gate ret 2757c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ulong) 2767c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_64) 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate ENTRY(atomic_and_8) 2797c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uchar) 2807c478bd9Sstevel@tonic-gate lock 2817c478bd9Sstevel@tonic-gate andb %sil, (%rdi) 2827c478bd9Sstevel@tonic-gate ret 2837c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar) 2847c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8) 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate ENTRY(atomic_and_16) 2877c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ushort) 2887c478bd9Sstevel@tonic-gate lock 2897c478bd9Sstevel@tonic-gate andw %si, (%rdi) 2907c478bd9Sstevel@tonic-gate ret 2917c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ushort) 2927c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_16) 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate ENTRY(atomic_and_32) 2957c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uint) 2967c478bd9Sstevel@tonic-gate lock 2977c478bd9Sstevel@tonic-gate andl %esi, (%rdi) 2987c478bd9Sstevel@tonic-gate ret 2997c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uint) 3007c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_32) 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate ENTRY(atomic_and_64) 3037c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ulong) 3047c478bd9Sstevel@tonic-gate lock 3057c478bd9Sstevel@tonic-gate andq %rsi, (%rdi) 3067c478bd9Sstevel@tonic-gate ret 3077c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ulong) 3087c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_64) 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate ENTRY(atomic_add_8_nv) 3117c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_char_nv) 3127c478bd9Sstevel@tonic-gate movb (%rdi), %al / %al = old value 3137c478bd9Sstevel@tonic-gate1: 3147c478bd9Sstevel@tonic-gate movb %sil, %cl 3157c478bd9Sstevel@tonic-gate addb %al, %cl / %cl = new value 3167c478bd9Sstevel@tonic-gate lock 3177c478bd9Sstevel@tonic-gate cmpxchgb %cl, (%rdi) / try to stick it in 3187c478bd9Sstevel@tonic-gate jne 1b 3197c478bd9Sstevel@tonic-gate movzbl %cl, %eax / return new value 3207c478bd9Sstevel@tonic-gate ret 3217c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_char_nv) 3227c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_8_nv) 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate ENTRY(atomic_add_16_nv) 3257c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_short_nv) 3267c478bd9Sstevel@tonic-gate movw (%rdi), %ax / %ax = old value 3277c478bd9Sstevel@tonic-gate1: 3287c478bd9Sstevel@tonic-gate movw %si, %cx 3297c478bd9Sstevel@tonic-gate addw %ax, %cx / %cx = new value 3307c478bd9Sstevel@tonic-gate lock 3317c478bd9Sstevel@tonic-gate cmpxchgw %cx, (%rdi) / try to stick it in 3327c478bd9Sstevel@tonic-gate jne 1b 3337c478bd9Sstevel@tonic-gate movzwl %cx, %eax / return new value 3347c478bd9Sstevel@tonic-gate ret 3357c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_short_nv) 3367c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_16_nv) 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate ENTRY(atomic_add_32_nv) 3397c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_int_nv) 3407c478bd9Sstevel@tonic-gate movl (%rdi), %eax 3417c478bd9Sstevel@tonic-gate1: 3427c478bd9Sstevel@tonic-gate movl %esi, %ecx 3437c478bd9Sstevel@tonic-gate addl %eax, %ecx 3447c478bd9Sstevel@tonic-gate lock 3457c478bd9Sstevel@tonic-gate cmpxchgl %ecx, (%rdi) 3467c478bd9Sstevel@tonic-gate jne 1b 3477c478bd9Sstevel@tonic-gate movl %ecx, %eax 3487c478bd9Sstevel@tonic-gate ret 3497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_int_nv) 3507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_32_nv) 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate ENTRY(atomic_add_64_nv) 3537c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_ptr_nv) 3547c478bd9Sstevel@tonic-gate ALTENTRY(atomic_add_long_nv) 3557c478bd9Sstevel@tonic-gate movq (%rdi), %rax 3567c478bd9Sstevel@tonic-gate1: 3577c478bd9Sstevel@tonic-gate movq %rsi, %rcx 3587c478bd9Sstevel@tonic-gate addq %rax, %rcx 3597c478bd9Sstevel@tonic-gate lock 3607c478bd9Sstevel@tonic-gate cmpxchgq %rcx, (%rdi) 3617c478bd9Sstevel@tonic-gate jne 1b 3627c478bd9Sstevel@tonic-gate movq %rcx, %rax 3637c478bd9Sstevel@tonic-gate ret 3647c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_long_nv) 3657c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_ptr_nv) 3667c478bd9Sstevel@tonic-gate SET_SIZE(atomic_add_64_nv) 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate ENTRY(atomic_and_8_nv) 3697c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uchar_nv) 3707c478bd9Sstevel@tonic-gate movb (%rdi), %al / %al = old value 3717c478bd9Sstevel@tonic-gate1: 3727c478bd9Sstevel@tonic-gate movb %sil, %cl 3737c478bd9Sstevel@tonic-gate andb %al, %cl / %cl = new value 3747c478bd9Sstevel@tonic-gate lock 3757c478bd9Sstevel@tonic-gate cmpxchgb %cl, (%rdi) / try to stick it in 3767c478bd9Sstevel@tonic-gate jne 1b 3777c478bd9Sstevel@tonic-gate movzbl %cl, %eax / return new value 3787c478bd9Sstevel@tonic-gate ret 3797c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar_nv) 3807c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8_nv) 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate ENTRY(atomic_and_16_nv) 3837c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ushort_nv) 3847c478bd9Sstevel@tonic-gate movw (%rdi), %ax / %ax = old value 3857c478bd9Sstevel@tonic-gate1: 3867c478bd9Sstevel@tonic-gate movw %si, %cx 3877c478bd9Sstevel@tonic-gate andw %ax, %cx / %cx = new value 3887c478bd9Sstevel@tonic-gate lock 3897c478bd9Sstevel@tonic-gate cmpxchgw %cx, (%rdi) / try to stick it in 3907c478bd9Sstevel@tonic-gate jne 1b 3917c478bd9Sstevel@tonic-gate movzwl %cx, %eax / return new value 3927c478bd9Sstevel@tonic-gate ret 3937c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ushort_nv) 3947c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_16_nv) 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate ENTRY(atomic_and_32_nv) 3977c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_uint_nv) 3987c478bd9Sstevel@tonic-gate movl (%rdi), %eax 3997c478bd9Sstevel@tonic-gate1: 4007c478bd9Sstevel@tonic-gate movl %esi, %ecx 4017c478bd9Sstevel@tonic-gate andl %eax, %ecx 4027c478bd9Sstevel@tonic-gate lock 4037c478bd9Sstevel@tonic-gate cmpxchgl %ecx, (%rdi) 4047c478bd9Sstevel@tonic-gate jne 1b 4057c478bd9Sstevel@tonic-gate movl %ecx, %eax 4067c478bd9Sstevel@tonic-gate ret 4077c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uint_nv) 4087c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_32_nv) 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate ENTRY(atomic_and_64_nv) 4117c478bd9Sstevel@tonic-gate ALTENTRY(atomic_and_ulong_nv) 4127c478bd9Sstevel@tonic-gate movq (%rdi), %rax 4137c478bd9Sstevel@tonic-gate1: 4147c478bd9Sstevel@tonic-gate movq %rsi, %rcx 4157c478bd9Sstevel@tonic-gate andq %rax, %rcx 4167c478bd9Sstevel@tonic-gate lock 4177c478bd9Sstevel@tonic-gate cmpxchgq %rcx, (%rdi) 4187c478bd9Sstevel@tonic-gate jne 1b 4197c478bd9Sstevel@tonic-gate movq %rcx, %rax 4207c478bd9Sstevel@tonic-gate ret 4217c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_ulong_nv) 4227c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_64_nv) 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate ENTRY(atomic_or_8_nv) 4257c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uchar_nv) 4267c478bd9Sstevel@tonic-gate movb (%rdi), %al / %al = old value 4277c478bd9Sstevel@tonic-gate1: 4287c478bd9Sstevel@tonic-gate movb %sil, %cl 4297c478bd9Sstevel@tonic-gate orb %al, %cl / %cl = new value 4307c478bd9Sstevel@tonic-gate lock 4317c478bd9Sstevel@tonic-gate cmpxchgb %cl, (%rdi) / try to stick it in 4327c478bd9Sstevel@tonic-gate jne 1b 4337c478bd9Sstevel@tonic-gate movzbl %cl, %eax / return new value 4347c478bd9Sstevel@tonic-gate ret 4357c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_uchar_nv) 4367c478bd9Sstevel@tonic-gate SET_SIZE(atomic_and_8_nv) 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate ENTRY(atomic_or_16_nv) 4397c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ushort_nv) 4407c478bd9Sstevel@tonic-gate movw (%rdi), %ax / %ax = old value 4417c478bd9Sstevel@tonic-gate1: 4427c478bd9Sstevel@tonic-gate movw %si, %cx 4437c478bd9Sstevel@tonic-gate orw %ax, %cx / %cx = new value 4447c478bd9Sstevel@tonic-gate lock 4457c478bd9Sstevel@tonic-gate cmpxchgw %cx, (%rdi) / try to stick it in 4467c478bd9Sstevel@tonic-gate jne 1b 4477c478bd9Sstevel@tonic-gate movzwl %cx, %eax / return new value 4487c478bd9Sstevel@tonic-gate ret 4497c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ushort_nv) 4507c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_16_nv) 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate ENTRY(atomic_or_32_nv) 4537c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_uint_nv) 4547c478bd9Sstevel@tonic-gate movl (%rdi), %eax 4557c478bd9Sstevel@tonic-gate1: 4567c478bd9Sstevel@tonic-gate movl %esi, %ecx 4577c478bd9Sstevel@tonic-gate orl %eax, %ecx 4587c478bd9Sstevel@tonic-gate lock 4597c478bd9Sstevel@tonic-gate cmpxchgl %ecx, (%rdi) 4607c478bd9Sstevel@tonic-gate jne 1b 4617c478bd9Sstevel@tonic-gate movl %ecx, %eax 4627c478bd9Sstevel@tonic-gate ret 4637c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_uint_nv) 4647c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_32_nv) 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate ENTRY(atomic_or_64_nv) 4677c478bd9Sstevel@tonic-gate ALTENTRY(atomic_or_ulong_nv) 4687c478bd9Sstevel@tonic-gate movq (%rdi), %rax 4697c478bd9Sstevel@tonic-gate1: 4707c478bd9Sstevel@tonic-gate movq %rsi, %rcx 4717c478bd9Sstevel@tonic-gate orq %rax, %rcx 4727c478bd9Sstevel@tonic-gate lock 4737c478bd9Sstevel@tonic-gate cmpxchgq %rcx, (%rdi) 4747c478bd9Sstevel@tonic-gate jne 1b 4757c478bd9Sstevel@tonic-gate movq %rcx, %rax 4767c478bd9Sstevel@tonic-gate ret 4777c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_ulong_nv) 4787c478bd9Sstevel@tonic-gate SET_SIZE(atomic_or_64_nv) 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_8) 4817c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_uchar) 4827c478bd9Sstevel@tonic-gate movzbl %sil, %eax 4837c478bd9Sstevel@tonic-gate lock 4847c478bd9Sstevel@tonic-gate cmpxchgb %dl, (%rdi) 4857c478bd9Sstevel@tonic-gate ret 4867c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_uchar) 4877c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_8) 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_16) 4907c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ushort) 4917c478bd9Sstevel@tonic-gate movzwl %si, %eax 4927c478bd9Sstevel@tonic-gate lock 4937c478bd9Sstevel@tonic-gate cmpxchgw %dx, (%rdi) 4947c478bd9Sstevel@tonic-gate ret 4957c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ushort) 4967c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_16) 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_32) 4997c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_uint) 5007c478bd9Sstevel@tonic-gate movl %esi, %eax 5017c478bd9Sstevel@tonic-gate lock 5027c478bd9Sstevel@tonic-gate cmpxchgl %edx, (%rdi) 5037c478bd9Sstevel@tonic-gate ret 5047c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_uint) 5057c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_32) 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate ENTRY(atomic_cas_64) 5087c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ulong) 5097c478bd9Sstevel@tonic-gate ALTENTRY(atomic_cas_ptr) 5107c478bd9Sstevel@tonic-gate movq %rsi, %rax 5117c478bd9Sstevel@tonic-gate lock 5127c478bd9Sstevel@tonic-gate cmpxchgq %rdx, (%rdi) 5137c478bd9Sstevel@tonic-gate ret 5147c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ptr) 5157c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_ulong) 5167c478bd9Sstevel@tonic-gate SET_SIZE(atomic_cas_64) 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_8) 5197c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_uchar) 5207c478bd9Sstevel@tonic-gate movzbl %sil, %eax 5217c478bd9Sstevel@tonic-gate lock 5227c478bd9Sstevel@tonic-gate xchgb %al, (%rdi) 5237c478bd9Sstevel@tonic-gate ret 5247c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_uchar) 5257c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_8) 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_16) 5287c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ushort) 5297c478bd9Sstevel@tonic-gate movzwl %si, %eax 5307c478bd9Sstevel@tonic-gate lock 5317c478bd9Sstevel@tonic-gate xchgw %ax, (%rdi) 5327c478bd9Sstevel@tonic-gate ret 5337c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ushort) 5347c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_16) 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_32) 5377c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_uint) 5387c478bd9Sstevel@tonic-gate movl %esi, %eax 5397c478bd9Sstevel@tonic-gate lock 5407c478bd9Sstevel@tonic-gate xchgl %eax, (%rdi) 5417c478bd9Sstevel@tonic-gate ret 5427c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_uint) 5437c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_32) 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate ENTRY(atomic_swap_64) 5467c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ulong) 5477c478bd9Sstevel@tonic-gate ALTENTRY(atomic_swap_ptr) 5487c478bd9Sstevel@tonic-gate movq %rsi, %rax 5497c478bd9Sstevel@tonic-gate lock 5507c478bd9Sstevel@tonic-gate xchgq %rax, (%rdi) 5517c478bd9Sstevel@tonic-gate ret 5527c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ptr) 5537c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_ulong) 5547c478bd9Sstevel@tonic-gate SET_SIZE(atomic_swap_64) 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate ENTRY(atomic_set_long_excl) 5577c478bd9Sstevel@tonic-gate xorl %eax, %eax 5587c478bd9Sstevel@tonic-gate lock 5597c478bd9Sstevel@tonic-gate btsq %rsi, (%rdi) 5607c478bd9Sstevel@tonic-gate jnc 1f 5617c478bd9Sstevel@tonic-gate decl %eax / return -1 5627c478bd9Sstevel@tonic-gate1: 5637c478bd9Sstevel@tonic-gate ret 5647c478bd9Sstevel@tonic-gate SET_SIZE(atomic_set_long_excl) 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate ENTRY(atomic_clear_long_excl) 5677c478bd9Sstevel@tonic-gate xorl %eax, %eax 5687c478bd9Sstevel@tonic-gate lock 5697c478bd9Sstevel@tonic-gate btrq %rsi, (%rdi) 5707c478bd9Sstevel@tonic-gate jc 1f 5717c478bd9Sstevel@tonic-gate decl %eax / return -1 5727c478bd9Sstevel@tonic-gate1: 5737c478bd9Sstevel@tonic-gate ret 5747c478bd9Sstevel@tonic-gate SET_SIZE(atomic_clear_long_excl) 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate#if !defined(_KERNEL) 5777c478bd9Sstevel@tonic-gate 578dfb96a4fSab196087 /* 579dfb96a4fSab196087 * NOTE: membar_enter, and membar_exit are identical routines. 580dfb96a4fSab196087 * We define them separately, instead of using an ALTENTRY 581dfb96a4fSab196087 * definitions to alias them together, so that DTrace and 582dfb96a4fSab196087 * debuggers will see a unique address for them, allowing 583dfb96a4fSab196087 * more accurate tracing. 584dfb96a4fSab196087 */ 585dfb96a4fSab196087 5867c478bd9Sstevel@tonic-gate ENTRY(membar_enter) 587dfb96a4fSab196087 mfence 588dfb96a4fSab196087 ret 589dfb96a4fSab196087 SET_SIZE(membar_enter) 590dfb96a4fSab196087 591dfb96a4fSab196087 ENTRY(membar_exit) 5927c478bd9Sstevel@tonic-gate mfence 5937c478bd9Sstevel@tonic-gate ret 5947c478bd9Sstevel@tonic-gate SET_SIZE(membar_exit) 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate ENTRY(membar_producer) 5977c478bd9Sstevel@tonic-gate sfence 5987c478bd9Sstevel@tonic-gate ret 5997c478bd9Sstevel@tonic-gate SET_SIZE(membar_producer) 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate ENTRY(membar_consumer) 6027c478bd9Sstevel@tonic-gate lfence 6037c478bd9Sstevel@tonic-gate ret 6047c478bd9Sstevel@tonic-gate SET_SIZE(membar_consumer) 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate#endif /* !_KERNEL */ 607