Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Dec 2021 09:00:28 GMT
From:      Wojciech Macek <wma@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: efa5d3831b0f - main - sys/libkern.h: Add type conversion helpers
Message-ID:  <202112020900.1B290SgE091636@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wma:

URL: https://cgit.FreeBSD.org/src/commit/?id=efa5d3831b0f0938115436be78f173366330a2ca

commit efa5d3831b0f0938115436be78f173366330a2ca
Author:     Hubert Mazur <hum@semihalf.com>
AuthorDate: 2021-11-26 09:20:04 +0000
Commit:     Wojciech Macek <wma@FreeBSD.org>
CommitDate: 2021-12-02 08:18:48 +0000

    sys/libkern.h: Add type conversion helpers
    
    Add helper functions for 32 and 64 bit unsigned to signed integers
    conversions.
    
    Reviewed by:
    Sponsored by:           Alstom
    Obtained from:          Semihalf
    Differential revision:  https://reviews.freebsd.org/D33162
---
 sys/sys/libkern.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h
index 147eba9bd1bd..41844fa7490e 100644
--- a/sys/sys/libkern.h
+++ b/sys/sys/libkern.h
@@ -226,6 +226,22 @@ rindex(const char *p, int ch)
 	return (strrchr(p, ch));
 }
 
+static __inline int64_t
+signed_extend64(uint64_t bitmap, int lsb, int width)
+{
+
+	return ((int64_t)(bitmap << (63 - lsb - (width - 1)))) >>
+	    (63 - (width - 1));
+}
+
+static __inline int32_t
+signed_extend32(uint32_t bitmap, int lsb, int width)
+{
+
+	return ((int32_t)(bitmap << (31 - lsb - (width - 1)))) >>
+	    (31 - (width - 1));
+}
+
 /* fnmatch() return values. */
 #define	FNM_NOMATCH	1	/* Match failed. */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202112020900.1B290SgE091636>