Path: csiph.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: naked switches
Date: Thu, 30 Sep 2021 06:09:37 -0700
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <86sfxmtdke.fsf@linuxsc.com>
References: <06a0049a-2d7d-40f0-899a-fb35c9a15d5fn@googlegroups.com> <255c09e7-2365-4983-ad4d-3bfc83cf04e7n@googlegroups.com> <31342574-cb69-4ad6-8576-387dcf9caf70n@googlegroups.com> <7e094b82-01be-4d7f-9793-4eeda725ca0en@googlegroups.com> <20210708103653.702@kylheku.com> <9a999021-6733-4d00-91fb-9797570a1328n@googlegroups.com> <87czrr3ics.fsf@bsb.me.uk> <865yxh8fkf.fsf@linuxsc.com> <3WCGI.8419$rr3.5144@fx34.iad> <864kcu7cnx.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d4788905ada0446dfc3ae6b02ecc1355"; logging-data="28032"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18787lbj56CzNLdTSwnAxF6ZQ+bteIYfx0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:UkBzJFr+9Sq/z8bYXRrxMZfWi2I= sha1:e365Fa0WwCoegyDqwwL497y0PBQ=
Xref: csiph.com comp.lang.c:162877
scott@slp53.sl.home (Scott Lurndal) writes:
> Tim Rentsch writes:
>
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>
>>>
>>> uint64_t registervalue, field;
>>> int64_t field1;
>>>
>>> field = bit::extract(registervalue, 15, 0); /* Extract <15:0> and zero-extend */
>>> field1 = bit::extracts((int64_t)registervalue, 20, 16); /* Extract and sign-extend */
>>>
>>> registervalue = bit::insert(registervalue, 0xff, 16, 4); /* Set bits<19:16> == 0xff */
>>
>> Ahh, rather like using an elephant gun to shoot a field mouse.
>
> The compiler generates optimal code[*].
Perhaps some compilers do, but it's more likely that fast code
will result from a purely functional expression that computes
the desired result directly. Not that code quality had anything to
do with my earlier comments.
> The source is descriptive and far more readable (and less subject
> to error) than manual bit shifting/masking.
That's funny. Reminds me of things I used to hear 50 years ago when
people would say assembly language is easier to understand than the
high-level languages of the day.
> I don't see a problem.
To me it looks like you're confusing length and verbosity with
comprehensibility.