[comp.lang.asm370] More pet ALC tricks...

ASPRMH@UOFT01.BITNET (Rob Hamilton) (11/13/89)

I was a little off in my description of the TR/TRT thing; what I do when
I want to find the last nonblank character in a character string is to
use TR to reverse the string, and then use TRT to calculate the offset
from the beginning of the translated string (end of the original string)
of the last character.  Whew!!!  It looks kinda like this

.
...
.
    MVC  STRING(256),BLANKS       blank out string to be xlated
    MVC  STRING(L'INPUT),INPUT    insert string to be checked
    TR   TRTAB(256),STRING        use the string as the translation table
    TRT  TRTAB(256),NONBLANK      find the first nonblank
    LA   R2,TRTAB+256             calculate where that is...
    SR   R2,R1                    ...and that address is in R2
.
...
.
*  TRTAB is collating sequence in reverse order
TRTAB    DC   256AL1(TRTAB+255-*)
*  NONBLANK is a TRT table for finding anything but a blank
NONBLANK DC   C' ',255AL1(*-NONBLANK)
         ORG  NONBLANK+C' '
         DC   X'00'
         ORG
.
...
.

This has worked for me before; I picked this up 8 years or so ago and
tried it then and didn't have any trouble.  Note that you have to
reinitialize the TRTAB table each time through, but if it's in dynamic
storage, you have to initialize it anyway. . .Let me know if this doesn't
work because I have it in a program somewhere and I'm in serious trouble
if it doesn't.

About that BXLE thing, I just think it's handy for doing just what it says;
Add two registers, compare two registers, and branch if the sum isn't bigger
than the comparand register.  Usually we use this instruction and its
brother-in-law, BXH, for handling simple looping.  Usually.  As pointed
out by this particular discussion, there are no REAL rules about where these
things are to be used....

Thanks, Valdis and Doron, for your info on CS and CDS.  Somehow, I had a
mental block for those guys, and a few others as well.  Also, I agree
that there must be something similar for AP and MP environments.  Any
clues yet???

R;

P85025@BARILVM.BITNET (Doron Shikmoni) (11/13/89)

>Thanks, Valdis and Doron, for your info on CS and CDS.  Somehow, I had a
>mental block for those guys, and a few others as well.  Also, I agree
>that there must be something similar for AP and MP environments.  Any
>clues yet???

What do you mean? CS and CDS *are* for AP and MP, exactly. The whole
idea of "Compare-and-Swap" is that the action can be seen as "atomic",
in the aspect of storage references; the system control ensures that
all storage accesses are serialized before and after CS, CDS, TS etc.
- that is, no other processor can interfere with this action, or fetch
an operand between the "Compare" and the "Swap". (Mind you, this is far
from being a simple task, if you take into account central storage caching
and pre-fetch pipelining). This *is* the way to serialize in an AP/MP
environment, virtual or real.

Note, that CS/CDS/TS should be used only if you really need to serialize;
if you just want to compare-and-then-swap, and think of using these since
"It's one instruction", in a simple "application" program, don't; these
instructions are expensive.

Doron

cet1@UUNET.UU.NET ("C.E. Thompson") (11/15/89)

In article <8911131336.AA27002@brazos.rice.edu>,P85025@BARILVM.BITNET (Doron
        Shikmoni) writes
>Note, that CS/CDS/TS should be used only if you really need to serialize;
>if you just want to compare-and-then-swap, and think of using these since
>"It's one instruction", in a simple "application" program, don't; these
>instructions are expensive.

Well, they are not as cheap as L and C, say, but you shouldn't be paranoid
about using them, either. On CPUs with write-in caches, the overheads are
not that bad. It makes sense to use CS/CDS to synchronise between a program
and an asynchronous exit, for example, using them for their non-divisibility
rather than their MP-storage-consistency.

Chris Thompson
JANET:    cet1@uk.ac.cam.phx
Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk

cet1@cl.cam.ac.uk (C.E. Thompson) (11/15/89)

In article <8911131336.AA27002@brazos.rice.edu>,P85025@BARILVM.BITNET (Doron Shikmoni) writes
>Note, that CS/CDS/TS should be used only if you really need to serialize;
>if you just want to compare-and-then-swap, and think of using these since
>"It's one instruction", in a simple "application" program, don't; these
>instructions are expensive.

Well, they are not as cheap as L and C, say, but you shouldn't be paranoid
about using them, either. On CPUs with write-in caches, the overheads are
not that bad. It makes sense to use CS/CDS to synchronise between a program
and an asynchronous exit, for example, using them for their non-divisibility
rather than their MP-storage-consistency. 

Chris Thompson
JANET:    cet1@uk.ac.cam.phx
Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk