SAL?

How is SAL supposed to work? How does it differ from SHL?

Comments

  • On some CPUs it would trigger overflow conditions when appropriate, where SHL would not.
    Not sure in the case of the P2.
  • SAL shifts the result n bits just like SHL except the original Bit0 is used as the shifted in bit instead of 0.
  • Huh. So it does.

    What's the use case for this?
  • ElectrodudeElectrodude Posts: 1,328
    edited 2015-10-22 - 03:54:14
    There might not be a use case. It might just be that that slot would have been otherwise unused:

    Note that the binary values of the opcodes of ROR, ROL, SHR, SHL, RCR, RCL, SAR, and SAL. They are all the same except for bits 23-21. Bit 21 means L if 1 and R if 0. Bits 23 and 22 presumably go to a mux or something which decides where the new bits that get shifted in come from. The meanings of bits 23-22 are as follows: (0) whatever got shifted out (rotate), (1) all 0 (shift), (2) the value of the C flag (RCx), or (3) the value of result[31] for R or result[0] for L (sign-extend shift).

    Removing the SAL instruction would mean telling the instruction decoder that if the instruction matched %CCCC_0000111_CZI_DDDDDDDDD_SSSSSSSSS it should disregard the output of the shifter and instead do something undefined.
  • I can't think of any myself.
    What would be more useful would be a sign extend instruction IMHO. :)
        EXTS   D,#S    'where bit S of D is copied up to bit 31
    or
        EXTB  D,#S   'sign extend byte
        EXTW  D,#S   'sign extend word
    
  • Peter JakackiPeter Jakacki Posts: 8,980
    edited 2015-10-22 - 04:05:12
    Just doing some testing but it is strange. SCRUB THAT, wrong test, fix up in a few minutes fixed
    TF2# ASM
     00.2E4D             $2.0000 org
     02.0000 F0E7.2001   sal 1st , # 1
     02.0004 FD60.002D   ret
     02.0008             end ok
    TF2# !SP $8000.0013  ok
    TF2# EXEC  0001 [0000.0027 0000.01A5 0000.01A5 0000.01A5 ]  ok
    TF2# EXEC  0001 [0000.004F 0000.01A5 0000.01A5 0000.01A5 ]  ok
    TF2# EXEC  0001 [0000.009F 0000.01A5 0000.01A5 0000.01A5 ]  ok
    TF2# EXEC  0001 [0000.013F 0000.01A5 0000.01A5 0000.01A5 ]  ok
    TF2# EXEC  0001 [0000.027F 0000.01A5 0000.01A5 0000.01A5 ]  ok
    TF2# 16 FOR CR EXEC NEXT
     0001 [0000.04FF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0000.09FF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0000.13FF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0000.27FF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0000.4FFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0000.9FFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0001.3FFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0002.7FFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0004.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0009.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0013.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [0027.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [004F.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [009F.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [013F.FFFF 0000.01A5 0000.01A5 0000.01A5 ]
     0001 [027F.FFFF 0000.01A5 0000.01A5 0000.01A5 ]  ok
    TF2#
    
  • It's like SAR, but in the opposite direction.

    It may have no mathematical purpose, but could find use somewhere.

    It was free, anyway.
  • If it does work that way, it shouldn't be called SAL, because that implies that it would be like other SAL instructions. It works very different than anyone would expect SAL to work.

    Not sure what it should be called, but definitely not SAL.

  • re:It's like SAR, but in the opposite direction.

    It should be called NOTSAR :)
  • OSAR - Opposite of SAR, but not really SAL.

  • potatohead wrote: »
    OSAR - Opposite of SAR, but not really SAL.

    I like "RAS" better. :)
  • cgraceycgracey Posts: 12,628
    edited 2015-10-22 - 17:20:12
    Seairth wrote: »
    potatohead wrote: »
    OSAR - Opposite of SAR, but not really SAL.

    I like "RAS" better. :)

    I agree.

    Would could just stop using 'A'rithmetic in 'SAR' and, instead, have some mnemonics that mean 'extend'.

    SER - shift extend right
    SEL - shift extend left

    -or-

    SMR - smear right
    SML - smear left
  • I like SER, SEL the most. Smear is fun, and I'm happy to help write docs that make sense and are entertaining, if we really want "smear" :)

  • However, SAR does have arithmetic importance, and is standard.
    Why can't we keep SAR, and just rename SAL?
  • Roy Eltham wrote: »
    However, SAR does have arithmetic importance, and is standard.
    Why can't we keep SAR, and just rename SAL?

    What should we call it?
  • SLL - Shift Left Lower bit in?

  • jmgjmg Posts: 14,278
    ozpropdev wrote: »
    SAL shifts the result n bits just like SHL except the original Bit0 is used as the shifted in bit instead of 0.
    cgracey wrote: »
    What should we call it?

    So that could be Shift Left duplicating b0 = SL0
    Of course, many may misread 0 as O, so it could also be
    Shift Left duplicating Lowest = SLL
    It is still Clearly a Shift Left operation.


  • potatohead wrote: »
    SLL - Shift Left Lower bit in?

    Or maybe SLR for shift left replicate LSB.

    I kind of like SMR/SML the best, because a child could understand them.
  • jmgjmg Posts: 14,278
    You could simply alias SAR, as Roy has a point about that being standard.
    ie SMR/SML and also SAR work.
  • SLE, Shift Left Extend?

    SEL also works.


    Also, I still can't think of a real use case for it...
  • RaymanRayman Posts: 10,465
    edited 2015-10-22 - 22:06:50
    I think SAL should fill in with zeros and preserve the MSBit...

    Then, it's multiplication by power of 2 for signed numbers...

    I guess it should set a flag if msb would have otherwise changed
  • Rayman, that is essentially the same as SHL, except when it overflows it produces odd results in some cases.
  • RaymanRayman Posts: 10,465
    edited 2015-10-22 - 23:51:34
    I think it's just how it handles a change in MSbit that is different...

    A change would indicate overflow, I think...
  • Here's a use case for SAL
    Right justified masks can be built of varied lengths
    shift number of bits - 1
    	mov	myreg,#1
    	sal	myreg,#11	'myreg = $00000FFF
    or
    	not	myreg,#1
    	sal	myreg,#11	'myreg = $FFFFF000
    
    :)

  • Roy Eltham wrote: »
    ... it shouldn't be called SAL, because that implies that it would be like other SAL instructions. ...
    I found this to be a very odd statement since I'd never heard of any SAL instruction ever before. So, I went a searching ... and found that x86 machine code has a redundant "SAL" that is 100% SHL. It's a total oddity.

    So, I guess the answer is still, there is no such thing as a real SAL instruction.
  • After a bit more reading it would seem it's not actually a separate opcode at all but rather just an assembly level duplication. So, there never was any SAL even for x86.
  • There are some SAL implementations that treat overflow differently than SHL.
Sign In or Register to comment.