From owner-svn-src-all@FreeBSD.ORG Fri Nov 7 20:10:10 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 99D0B813; Fri, 7 Nov 2014 20:10:10 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6C16B6C8; Fri, 7 Nov 2014 20:10:10 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sA7KAAZs026434; Fri, 7 Nov 2014 20:10:10 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sA7KAAkp026433; Fri, 7 Nov 2014 20:10:10 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201411072010.sA7KAAkp026433@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 7 Nov 2014 20:10:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274250 - head/sys/dev/random X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Nov 2014 20:10:10 -0000 Author: kib Date: Fri Nov 7 20:10:09 2014 New Revision: 274250 URL: https://svnweb.freebsd.org/changeset/base/274250 Log: Simplify assembler in ivy.c. Move the copying of the random bits into buffer from asm to C, which reduces amount of arguments for inline asm and simplifies constraints. Use unsigned types consistently. Submitted by: bde Approved by: secteam (delphij) Reviewed by: markm MFC after: 1 week Modified: head/sys/dev/random/ivy.c Modified: head/sys/dev/random/ivy.c ============================================================================== --- head/sys/dev/random/ivy.c Fri Nov 7 19:34:10 2014 (r274249) +++ head/sys/dev/random/ivy.c Fri Nov 7 20:10:09 2014 (r274250) @@ -61,42 +61,41 @@ static struct live_entropy_source random }; static inline int -ivy_rng_store(long *buf) +ivy_rng_store(u_long *buf) { #ifdef __GNUCLIKE_ASM - long tmp; + u_long rndval; int retry; retry = RETRY_COUNT; __asm __volatile( "1:\n\t" - "rdrand %2\n\t" /* read randomness into tmp */ - "jb 2f\n\t" /* CF is set on success, exit retry loop */ + "rdrand %1\n\t" /* read randomness into tmp */ + "jc 2f\n\t" /* CF is set on success, exit retry loop */ "dec %0\n\t" /* otherwise, retry-- */ "jne 1b\n\t" /* and loop if retries are not exhausted */ - "jmp 3f\n" /* failure, retry is 0, used as return value */ - "2:\n\t" - "mov %2,%1\n\t" /* *buf = tmp */ - "3:" - : "+q" (retry), "=m" (*buf), "+q" (tmp) : : "cc"); + "2:" + : "+r" (retry), "=r" (rndval) : : "cc"); + *buf = rndval; return (retry); #else /* __GNUCLIKE_ASM */ return (0); #endif } -/* It is specifically allowed that buf is a multiple of sizeof(long) */ +/* It is required that buf length is a multiple of sizeof(u_long). */ static u_int random_ivy_read(void *buf, u_int c) { - long *b; + u_long *b, rndval; u_int count; KASSERT(c % sizeof(*b) == 0, ("partial read %d", c)); b = buf; for (count = c; count > 0; count -= sizeof(*b)) { - if (ivy_rng_store(b++) == 0) + if (ivy_rng_store(&rndval) == 0) break; + *b++ = rndval; } return (c - count); }