1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
.\"
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source. A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.\"
.\"
.\" Copyright 2022 Oxide Computer Company
.\"
.Dd April 12, 2022
.Dt BITX64 9F
.Os
.Sh NAME
.Nm bitx8 ,
.Nm bitx16 ,
.Nm bitx32 ,
.Nm bitx64
.Nd extract bits from an integer
.Sh SYNOPSIS
.In sys/bitext.h
.Ft uint8_t
.Fo bitx8
.Fa "uint8_t value"
.Fa "uint_t high"
.Fa "uint_t low"
.Fc
.Ft uint16_t
.Fo bitx16
.Fa "uint16_t value"
.Fa "uint_t high"
.Fa "uint_t low"
.Fc
.Ft uint32_t
.Fo bitx32
.Fa "uint32_t value"
.Fa "uint_t high"
.Fa "uint_t low"
.Fc
.Ft uint64_t
.Fo bitx64
.Fa "uint64_t value"
.Fa "uint_t high"
.Fa "uint_t low"
.Fc
.Sh INTERFACE LEVEL
.Sy Volatile -
This interface is still evolving in illumos.
API and ABI stability is not guaranteed.
.Sh PARAMETERS
.Bl -tag -width Fa
.It Fa value
An integer to extract a value from.
.It Fa high
The high end, inclusive, of the bit range to extract from
.Fa value .
.It Fa low
The low end, inclusive, of the bit range to extract from
.Fa value .
.El
.Sh DESCRIPTION
The
.Fn bitx8 ,
.Fn bitx16 ,
.Fn bitx32 ,
and
.Fn bitx64
functions are used to extract a range of bits from on an 8, 16, 32, and
64-bit value respectively.
These functions are all implementations of a classical application of a
bitwise-AND of a mask and a logical right shift.
More specifically, the arguments
.Fa high
and
.Fa low
describe an inclusive range of bits
.Po
.Pf [ Fa low ,
.Fa high ]
.Pc
to extract from
.Fa value .
The extracted bits are all shifted right such that the resulting value
starts at bit 0
.Po that is, shifted over by
.Fa low
.Pc .
.Pp
Each of the variants here operates on a specifically sized integer.
.Fa high
and
.Fa low
must fit within the bit range that the integer implies.
For example, the valid range for
.Fa bitx32
is from 0 to 31.
.Fa high
must not be less than
.Fa low .
.Sh CONTEXT
These functions may be called in all contexts,
.Sy user ,
.Sy kernel ,
and
.Sy interrupt .
.Sh RETURN VALUES
Upon successful completion, the
.Fn bitx8 ,
.Fn bitx16 ,
.Fn bitx32 ,
and
.Fn bitx64
functions all return the indicated portion of
.Fa val .
.Sh SEE ALSO
.Xr bitdel64 9F ,
.Xr bitset64 9F
|