From owner-freebsd-questions@freebsd.org Wed Jun 19 10:04:22 2019 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B162D15B309A for ; Wed, 19 Jun 2019 10:04:22 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) Received: from s1-b0c6.socketlabs.email-od.com (s1-b0c6.socketlabs.email-od.com [142.0.176.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B0C1385D6D for ; Wed, 19 Jun 2019 10:04:21 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) DKIM-Signature: v=1; a=rsa-sha256; d=email-od.com;i=@email-od.com;s=dkim; c=relaxed/relaxed; q=dns/txt; t=1560938662; x=1563530662; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to:message-id:subject:cc:to:from:date:x-thread-info; bh=kaBNX338vapA7x5F5IiJg+aZJHZT1Gr3mY9d+F/n4YE=; b=Hh0EcEPOy8N+K/9g/0aZnSaa0pOr1W8KeRtUV9kQ6KxQ5jvCrwqJ94ApU+8YH/klzl+325SQQObbu8KVIj7kcFizzdb6Fu2fq+3HHUPUlY+SEFQWDucAfLZeYrkKpvcCynZhqMePtG1O4PjzKn9U2shpTOh9gZno1pHPyZC4UEU= X-Thread-Info: NDI1MC4xMi4xYjMwMDAwMDExYjQ3MDEuZnJlZWJzZC1xdWVzdGlvbnM9ZnJlZWJzZC5vcmc= Received: from r5.us-east.aws.in.socketlabs.com (r5.us-east.aws.in.socketlabs.com [52.204.195.176]) by mxsg2.email-od.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Wed, 19 Jun 2019 05:04:09 -0400 Received: from smtp.lan.sohara.org (EMTPY [185.202.17.215]) by r5.us-east.aws.in.socketlabs.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Wed, 19 Jun 2019 05:04:09 -0400 Received: from [192.168.63.1] (helo=steve.lan.sohara.org) by smtp.lan.sohara.org with smtp (Exim 4.91 (FreeBSD)) (envelope-from ) id 1hdWVj-000JdI-ID; Wed, 19 Jun 2019 10:04:07 +0100 Date: Wed, 19 Jun 2019 10:04:07 +0100 From: Steve O'Hara-Smith To: mayuresh@kathe.in Cc: freebsd-questions@freebsd.org Subject: Re: How are modern processor instructions exposed to userland? Message-Id: <20190619100407.2e730ae147d87894e9479e23@sohara.org> In-Reply-To: <4b320042bd82ffe9b7793b62719d06f0@kathe.in> References: <4b320042bd82ffe9b7793b62719d06f0@kathe.in> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; amd64-portbld-freebsd12.0) X-Clacks-Overhead: "GNU Terry Pratchett" Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: B0C1385D6D X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=email-od.com header.s=dkim header.b=Hh0EcEPO; spf=pass (mx1.freebsd.org: domain of 4250.10.freebsd-questions=freebsd.org@email-od.com designates 142.0.176.198 as permitted sender) smtp.mailfrom=4250.10.freebsd-questions=freebsd.org@email-od.com X-Spamd-Result: default: False [-1.22 / 15.00]; R_SPF_ALLOW(-0.20)[+ip4:142.0.176.0/20]; MV_CASE(0.50)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[email-od.com:+]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.01)[mxbh.socketlabs.com,mxbsg.socketlabs.com]; FORGED_SENDER(0.00)[steve@sohara.org,4250.10.freebsd-questions=freebsd.org@email-od.com]; IP_SCORE(-0.21)[ip: (-0.57), ipnet: 142.0.176.0/22(-0.26), asn: 7381(-0.19), country: US(-0.06)]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:7381, ipnet:142.0.176.0/22, country:US]; MIME_TRACE(0.00)[0:+]; FROM_NEQ_ENVFROM(0.00)[steve@sohara.org,4250.10.freebsd-questions=freebsd.org@email-od.com]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.98)[-0.976,0]; R_DKIM_ALLOW(-0.20)[email-od.com:s=dkim]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_SHORT(-0.02)[-0.023,0]; NEURAL_HAM_LONG(-0.99)[-0.992,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[sohara.org]; FORGED_SENDER_VERP_SRS(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[198.176.0.142.list.dnswl.org : 127.0.15.0]; ENVFROM_VERP(0.00)[]; RCVD_TLS_LAST(0.00)[] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jun 2019 10:04:22 -0000 On Wed, 19 Jun 2019 11:58:23 +0530 Mayuresh Kathe wrote: > Hello, > > I have been wondering about this, and couldn't find an answer on the Web > because I didn't know what to search for. > > Let's think about the AVX-512 instruction introduced with the latest > Intel Core i9 Skylake-X processor. > I wanted to know how one could use such capabilities via regular C. The usual way that processor features get exposed is by being used in the implementation of low level routines. Depending on the application there may be run or compile time detection of CPU and choice of implementation (mplayer/mencoder offers both in its build). > There should be some way, someone working on the FreeBSD core who would > expose that instruction capability to the userland via libc, right? Not necessarily libc and not usually the instruction directly, but if it is worthwhile some functions may grow implementation versions based on the new instruction to be used when that CPU is available. Other approaches are used sometimes, for example the hardware crypto engine in some processors is exposed via a device with a fallback software implementation in the kernel. Kernel code and a user/kernel interface will be needed whenever the instruction is privileged. The principle is the same the new feature is used to conditionally implement an API for which there are fallback implementations for CPUs without the new feature. The fine details vary feature by feature. > If my assumption is correct, may I know who does that? And, how do they > go about doing it? Either by writing assembler that implements entry points with the C calling conventions or using the C extensions that allow embedded assembler. > Obviously, knowledge of x86-64 assembler would be a must, so would > knowledge of C89; right? Yep. -- Steve O'Hara-Smith