Page MenuHomeFreeBSD

sys/libkern.h: Add type conversion helpers
ClosedPublic

Authored by hum_semihalf.com on Nov 29 2021, 12:29 PM.

Details

Summary

Add helper functions for 32 and 64 bit unsigned to signed integers
conversions.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I would prefer shorter names. signed_extend32 is really unwieldy. Also, the name does not really explain that the operation is really about extracting from bitfields.

How about mirroring the ARM instructions these are based on? I.e. sbfx32 and sbfx64.

Change function's names to more self-descriptive, reflecting followed ARM instructions behavior.

sbfx32 means nothing to me, signed_extend32 was way more clear to what it does.

How about extract_s32/extract_s64?

I like the idea but would reduce it to sextract32 and sextract64. Or just leave the underscore out. Alternative: extractl and extractll (with corresponding unsigned functions extractul and extractull).

This revision was not accepted when it landed; it landed in state Needs Review.Dec 2 2021, 9:00 AM
This revision was automatically updated to reflect the committed changes.

I agree with @manu These functions are going to be used extremely rarely and imo the more meaningful name the better.