1.\" 2.\" This file and its contents are supplied under the terms of the 3.\" Common Development and Distribution License ("CDDL"), version 1.0. 4.\" You may only use this file in accordance with the terms of version 5.\" 1.0 of the CDDL. 6.\" 7.\" A full copy of the text of the CDDL should have accompanied this 8.\" source. A copy of the CDDL is also available via the Internet at 9.\" http://www.illumos.org/license/CDDL. 10.\" 11.\" 12.\" Copyright 2024 Oxide Computer Company 13.\" 14.Dd October 27, 2024 15.Dt STDC_FIRST_TRAILING_ONE 9F 16.Os 17.Sh NAME 18.Nm stdc_first_trailing_one , 19.Nm stdc_first_trailing_one_uc , 20.Nm stdc_first_trailing_one_us , 21.Nm stdc_first_trailing_one_ui , 22.Nm stdc_first_trailing_one_ul , 23.Nm stdc_first_trailing_one_ull 24.Nd find index of least significant one bit 25.Sh SYNOPSIS 26.In sys/stdbit.h 27.Ft "unsigned int" 28.Fo stdc_first_trailing_one 29.Fa "generic_value_type value" 30.Fc 31.Ft "unsigned int" 32.Fo stdc_first_trailing_one_uc 33.Fa "unsigned char value" 34.Fc 35.Ft "unsigned int" 36.Fo stdc_first_trailing_one_us 37.Fa "unsigned short value" 38.Fc 39.Ft "unsigned int" 40.Fo stdc_first_trailing_one_ui 41.Fa "unsigned int value" 42.Fc 43.Ft "unsigned int" 44.Fo stdc_first_trailing_one_ul 45.Fa "unsigned long value" 46.Fc 47.Ft "unsigned int" 48.Fo stdc_first_trailing_one_ull 49.Fa "unsigned long long value" 50.Fc 51.Sh DESCRIPTION 52The 53.Fn stdc_first_trailing_one 54family of functions returns the 1s-based index of the first one bit in 55.Fa value 56starting at the least significant bit. 57If there is no one bit in 58.Fa value 59then zero is returned. 60.Pp 61These functions are sometimes called 62.Dq find first set 63and signed equivalents exist with 64.Xr ddi_ffs 9F . 65.Pp 66The 67.Fn stdc_first_trailing_one 68function is generic and will operate on all 8, 16, 32, and 64-bit 69unsigned integers; however, it is only available in C23. 70The other functions all operate on a specific integer type, but 71otherwise behave the same and are available regardless of the C language 72version. 73.Sh CONTEXT 74These functions may be called from 75.Sy user , 76.Sy kernel , 77or 78.Sy interrupt 79context. 80.Sh RETURN VALUES 81The functions in the 82.Fn stdc_first_trailing_one 83family always return the index of the first trailing 84one bit in 85.Fa value 86plus one. 87Otherwise, if there are no one bits in 88.Fa value , 890 will be returned. 90These functions cannot fail. 91.Sh INTERFACE STABILITY 92.Sy Committed 93.Sh SEE ALSO 94.Xr stdc_first_trailing_one 3C , 95.Xr ddi_ffs 9F , 96.Xr stdc_bit_ceil 9F , 97.Xr stdc_bit_floor 9F , 98.Xr stdc_bit_width 9F , 99.Xr stdc_count_ones 9F , 100.Xr stdc_count_zeros 9F , 101.Xr stdc_first_leading_one 9F , 102.Xr stdc_first_leading_zero 9F , 103.Xr stdc_first_trailing_zero 9F , 104.Xr stdc_has_single_bit 9F , 105.Xr stdc_leading_ones 9F , 106.Xr stdc_leading_zeros 9F , 107.Xr stdc_trailing_ones 9F , 108.Xr stdc_trailing_zeros 9F 109