<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>I do agree that populating the carry bit is not that
straightforward, especially on processors that don't have an
explicit carry.</p>
<p>An alternative approach is to go for something similar to the
SHRD instruction, that pulls in bits from another register rather
than the carry bit - <a class="moz-txt-link-freetext" href="https://www.felixcloutier.com/x86/shrd">https://www.felixcloutier.com/x86/shrd</a> - then
again, this might be overkill when you want to rotate with a
single carry bit, which is effectively akin to rotating a register
that is 1 bit larger than the normal word size.</p>
<p>Gareth aka. Kit<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 11/01/2021 18:53, Karoly Balogh via
fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:alpine.DEB.2.02.2101111919470.3100@scenergy.dfmk.hu">
<pre class="moz-quote-pre" wrap="">Hi,
On Mon, 11 Jan 2021, Sven Barth via fpc-devel wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">So the idea is to add support for ROL/ROR with Carry support as the
current Rol*/Ror* functions don't support that. Florian then said that
he's open to suggestions under some restrictions. Considering that the
current Rol*/Ror* intrinsics aren't available for all platforms as
intrinsics either, but as functions then, this could be done to support
CPUs without suitable Carry support as well. And the code snippet that
jamie showed would be a nice base:
=== code begin ===
Function ROLByteWithCarry(Const AByte:Byte; Var ACarry:Boolean):Byte;Inline;
var
LocalIn:Boolean;
Begin
LocalIN := Acarry;
ACarry := ShortInt(Abyte) < 0;
Result := (AByte shl 1);
IF LocalIn then Result := Result or 1;
End;
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
We can name it rolx/rorx... I don't think such a long name is a good idea,
because such construct will be used a lot in longer formulas?
Btw, as the code, what's wrong with:
begin
result:=(abyte shl 1) or ord(acarry);
acarry:=shortint(abyte) < 0;
end;
No local var, no branches...
The problem is with this ROL-with-carry as library function approach, that
it tries to mimic internal working of some CPU, so it inherently leads to
less efficient code, because it's very difficult to actually map this into
a CPU instruction... Even when we provide an instrinsic for it, because
how on earth you populate the carry flag first based on that boolean
coming from that argument? So I feel people will try to use this for
"smart" algos and optimization, while it's totally counterproductive in a
high level language.
It's much better to write such code as <value * 2> + previous carry then
clamp it, then let the compiler optimize it, rather than trying to mess
with a rorx/rolx function.
I think whoever wants such a ching is just better off extending their byte
to a word, doing the shift/rotate, and masking the carry off as needed.
My 2 cents.
Charlie</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #D3D4DE;">
<tr>
<td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
<td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>
</td>
</tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>