From owner-freebsd-current@FreeBSD.ORG Sun Aug 2 09:53:19 2009 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4DE70106564A for ; Sun, 2 Aug 2009 09:53:19 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outG.internet-mail-service.net (outg.internet-mail-service.net [216.240.47.230]) by mx1.freebsd.org (Postfix) with ESMTP id 383BF8FC22 for ; Sun, 2 Aug 2009 09:53:19 +0000 (UTC) (envelope-from julian@elischer.org) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id EF6FDB3F80 for ; Sun, 2 Aug 2009 02:53:18 -0700 (PDT) X-Client-Authorized: MaGic Cook1e Received: from julian-mac.elischer.org (home.elischer.org [216.240.48.38]) by idiom.com (Postfix) with ESMTP id AD6582D600E for ; Sun, 2 Aug 2009 02:53:18 -0700 (PDT) Message-ID: <4A756214.8010002@elischer.org> Date: Sun, 02 Aug 2009 02:53:24 -0700 From: Julian Elischer User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 To: FreeBSD Current Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: puzzling code in pcpu stuff X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Aug 2009 09:53:19 -0000 I simplified the output of the preprocessor for a PCPU_SET(xx, newval) (to look at it). I came down to: (after formatting) for i386.. { __typeof(((struct pcpu *)0)->pc_xx) __val; struct __s { u_char __b[(((sizeof(__val)) < (4)) ? (sizeof(__val)) : (4))]; } __s; __val = (newval); /* aligned */ if (sizeof(__val) == 1 || sizeof(__val) == 2 || sizeof(__val) == 4) { __s = *(struct __s *)(void *)&__val; __asm volatile("mov %1,%%fs:%0" : "=m" (*(struct __s *)(__builtin_offsetof( struct pcpu, pc_xx))) : "r" (__s)); } else { *__extension__ ( { __typeof(__val) *__p; __asm volatile("movl %%fs:%1,%0; addl %2,%0" : "=r" (__p) : "m" (*(struct pcpu *)(__builtin_offsetof(struct pcpu, pc_prvspace))), "i" (__builtin_offsetof(struct pcpu, pc_xx))); __p; }) = __val; } } having had my brain explode on this several times, I can't figure out exactly what teh clause after the else is doing. anyone better at reading __asm better than me care to explain it in simple words?