More pet ALC tricks... 
Author Message
 More pet ALC tricks...

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;



Mon, 19 Apr 1993 21:27:00 GMT  
 More pet ALC tricks...

Quote:
>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



Mon, 19 Apr 1993 07:36:00 GMT  
 More pet ALC tricks...

Quote:
>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




Mon, 19 Apr 1993 22:16:00 GMT  
 More pet ALC tricks...

        Shikmoni) writes

Quote:
>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




Mon, 19 Apr 1993 22:16:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. A Neat ALC Trick

2. PETS

3. More about OFF, ON, and Pet words

4. PET protocol

5. Survey: Pet Forth words.

6. LOGO-L> Digital Pets

7. Pet C+@s and DO0Gs.

8. PP, PET, PMMA scrap

9. FREE VIRTUAL PETS!

10. sample pets callback

11. Pet hates

12. CL version of (Java) Pet Store?

 

 
Powered by phpBB® Forum Software