SAL shift arithmetic left

I just stumbled across the SAL instruction. The docs say: "Shift arithmetic left. D = [63:32] of ({D[31:0], {32{D[0]}}} << S[4:0]). C = last bit shifted out if S[4:0] > 0, else D[31]." Is that correct? It seems to repeat the LSB instead of keeping the sign (MSB) as I'd expect.

I'm looking for an operation like "multiply (signed) D with 2^S, set carry if overflow". On the P1 I did this by SHL, then SAR back into a temporary variable and then comparing the result to the original value of D. If it's different an overflow occured.

As there are so many new instructions that can be used for cool and clever shortcuts I thought there must also be a solution for this problem.

Comments

  • RaymanRayman Posts: 10,425
    edited 2020-02-10 - 17:37:17
    I remember a discussion about SAL here a few years ago...
    Edit: Found it here https://forums.parallax.com/discussion/162570/sal

    Wikipedia page has this footnote:
    The VHDL arithmetic left shift operator is unusual. Instead of filling the LSB of the result with zero, it copies the original LSB into the new LSB. While this is an exact mirror image of the arithmetic right shift, it is not the conventional definition of the operator, and is not equivalent to multiplication by a power of 2. In the VHDL 2008 standard this strange behavior was left unchanged (for backward compatibility) for argument types that do not have forced numeric interpretation (e.g., BIT_VECTOR) but 'SLA' for unsigned and signed argument types behaves in the expected way (i.e., rightmost positions are filled with zeros). VHDL's shift left logical (SLL) function does implement the aforementioned 'standard' arithmetic shift.
  • Regarding your problem, I guess I'd compare C with the D[31] after the operation to make sure they are the same.
    That should detect overflow, right?
  • cgraceycgracey Posts: 12,607
    edited 2020-02-10 - 20:12:09
    I had to think carefully about what you were getting at, where you expected the MSB to rotate into the LSB.

    Maybe SAL wasn't the best name for this instruction. Basically, it's SAR in the other direction, but that's not really "arithmetic", and maybe misleading. It just shifts the LSB left while maintaining it.
  • ManAtWork wrote: »
    I just stumbled across the SAL instruction. The docs say: "Shift arithmetic left. D = [63:32] of ({D[31:0], {32{D[0]}}} << S[4:0]). C = last bit shifted out if S[4:0] > 0, else D[31]." Is that correct? It seems to repeat the LSB instead of keeping the sign (MSB) as I'd expect.

    I'm looking for an operation like "multiply (signed) D with 2^S, set carry if overflow". On the P1 I did this by SHL, then SAR back into a temporary variable and then comparing the result to the original value of D. If it's different an overflow occured.

    As there are so many new instructions that can be used for cool and clever shortcuts I thought there must also be a solution for this problem.

    So, were you looking for an instruction to perform:

    D = [63:32] of ({D[31:0], 32'b0} << S[4:0]). C = D[31] XOR [63] if S[4:0] > 0, else D[31]

    That is, perform the left shift (multiply), and check for signed overflow by comparing pre-shift MSB to post-shift MSB, setting the C flag to indicate overflow, or just get D[31] if no shift occurs?

  • RaymanRayman Posts: 10,425
    edited 2020-02-11 - 00:44:13
    There is the "ENCOD" instruction... That should tell you beforehand if the shift is going to be OK...

    Was going to suggest "ENCOD", but that's the opposite of what you want... Still, if you could flip all the bits and then do encod, it could work...
  • On the Motorola 68k and Coldfire processors there was a ASL instruction (arithmetic shift left) that shifted only bits 30..0 and kept the sign unmodified. It's not much better than a simple SHL. As long as there's no overflow it does exactly the same. If there's an overflow the result is invalid anyway, so keeping the sign constant doesn't help much. But setting the C flag to the overflow condition (old b31 XOR last bit shifted out) does.

    We could emulate that behaviour with something like
    	testb D,#31 wc	' remember sign
    	shl	D,exp	' shift left by exponent
    	testb   D,#31 wz	' overflow if sign changed
      if_diff ... ' handle overflow
    
    On the P1 SHL did place the first bit shifted out in C. The P2 takes the last bit shifted out what makes the extra TESTB necessary. (in other cases the last bit is better)
  • TonyB_TonyB_ Posts: 1,456
    edited 2020-02-11 - 11:33:32
    TJV saves an instruction and avoids use of Z:

    [code]
    testb D,#31 wc ' remember sign
    shl D,exp ' shift left by exponent
    tjv D,#overflow ' jump to overflow if D[31] != C
    [/code]
  • TonyB_TonyB_ Posts: 1,456
    edited 2020-02-11 - 18:36:51
    I don't know why formatting is not right in previous post.
  • evanhevanh Posts: 8,955
    edited 2020-02-11 - 10:42:09
    You've got a couple spaces in front of the leading [ code ] ...
    with spaces
    
    without spaces
    
    EDIT: Hmm, nope that wasn't it.

    Quoting:
      	testb	D,#31	wc	' remember sign
      	shl	D,exp		' shift left by exponent
      	tjv	D,#overflow	' jump to overflow if D[31] != C
    
    EDIT2: Weird.

  • TonyB_TonyB_ Posts: 1,456
    edited 2020-02-11 - 11:42:44
    Try again:

    TJV saves an instruction and avoids use of Z:
      	testb	D,#31	wc	' remember sign
      	shl	D,exp		' shift left by exponent
      	tjv	D,#overflow	' jump to overflow if D[31] != C
    
  • TonyB_TonyB_ Posts: 1,456
    edited 2020-02-11 - 12:55:55
    Evan, thanks for quoting my post so @ManAtWork can see it properly. BBCode does not work for me now on the Mobile version of this website, but it did work fine with Firefox 3.6.28 a few months ago.

    I had a computer problem a week ago when Win XP stopped booting and I reverted to 98SE. Apart from accessing webpages, this was a massive performance upgrade.
  • TonyB, thanks for the hint with TJV. There are so many clever instructions. I just overlook most of them until someone displays an example because the current sparse documentation explains semantics but doesn't mention the intention behind it.

    BTW, I also have some PCs still running XP. It's a bit annoying that FlexGui doesn't run on XP. PNut does, I think.
  • Hehe, Tony is dis'ing the XP experience after only recently shifted off 98. He much prefers 98, and I don't blame him to be honest, but the web browsers that work on 98 are archaic.

    The drive toward XP back in the day is partly what gave me the impetus to stop dual booting with QNX and give Linux a whirl instead. Haven't looked back.

  • I think if Tony tried Linux Mint he would quite happy after a short learning period. After going from Win 3.1 through to Win 7 and finally Win 10 I switched to Linux and have absolutely no desire to go back.
  • ManAtWork wrote: »
    BTW, I also have some PCs still running XP. It's a bit annoying that FlexGui doesn't run on XP. PNut does, I think.

    I wasn't aware that FlexGUI doesn't run on XP. What are the symptoms? The command line tools (fastspin and loadp2) should work, I think, so I guess it's probably something in the Tcl/Tk interpreter that's causing a problem?
  • ersmith wrote: »
    ManAtWork wrote: »
    BTW, I also have some PCs still running XP. It's a bit annoying that FlexGui doesn't run on XP. PNut does, I think.

    I wasn't aware that FlexGUI doesn't run on XP. What are the symptoms? The command line tools (fastspin and loadp2) should work, I think, so I guess it's probably something in the Tcl/Tk interpreter that's causing a problem?

    With me it was something like "entry point XXXX not found in msvcrt.dll". I can't try it again as XP simply will not load and the drive has been removed. I could have reported this problem some months ago but as fastspin worked I felt that FlexGUI was not essential.
  • Wuerfel_21Wuerfel_21 Posts: 597
    edited 2020-02-11 - 17:45:36
    TonyB_ wrote: »
    "entry point XXXX not found in msvcrt.dll"

    Ah, ye olde MSVCRT.DLL. Can one just rename a more recent C runtime to MSVCRT.DLL and stick it in the application's directory? That might work?

    (The other obvious solution of course is to install Windows 7...)
  • kwinn wrote: »
    I think if Tony tried Linux Mint he would quite happy after a short learning period. After going from Win 3.1 through to Win 7 and finally Win 10 I switched to Linux and have absolutely no desire to go back.

    Is Linux Mint usable with a Celeron 1.2GHz, 512MB RAM & Intel 810E chipset? Wiping XP would bring me great joy and perhaps I could use the drive for Linux, about which I know nothing. A browser that supports more modern SSL/TSL would give me access to a lot more websites, such as https://forums.linuxmint.com !

    I am so glad that the Parallax forums are unsecured, otherwise I would not have been able to contribute to the P2, probably.
  • Wuerfel_21Wuerfel_21 Posts: 597
    edited 2020-02-11 - 18:58:33
    TonyB_ wrote: »
    Is Linux Mint usable with a Celeron 1.2GHz, 512MB RAM & Intel 810E chipset?

    Last I knew (2018?), it works on anything that's at least an i686 (Pentium Pro / AMD K6-III or newer, IIRC), but all web browsers (except an ancient-ish version of Opera) will require SSE2 instruction set support. (Which the AthlonXP machines I got a couple of don't have...). Although I think SSL and certificates are handled by the OS, for I don't recall running into SSL trouble with Opera.
    For such a low-end machine, be sure to choose the Xfce distro, it's the most lightweight.

    Have you maybe considered getting a new computer?
  • kwinnkwinn Posts: 8,509
    edited 2020-02-11 - 21:50:33
    Here is a link to some Linux Mint info, the minimum requirements, and the download link. https://www.appstosoft.com/blog/linux-mint-hardware-requirements/


    A summary of the requirements are:


    X86 processor, under this Linux Mint 64-bit, requires a 64-bit processor. But the Linux Mint 32-bit can easily run over the 32-bit or 64-bit processors.
    There is a requirement of 512 MB RAM. But for the comfortable usage, we suggest 1 GB.
    The demand for 5 GB disk space. For better result, we recommend 20 GB.
    Requirement of DVD drive or USB port
    The capability of 800*600 resolution for graphics card. At the same time, we propose 1027*768 resolution
  • Peter JakackiPeter Jakacki Posts: 8,980
    edited 2020-02-11 - 22:31:15
    I had an old slow single core Celeron laptop with 2GB of RAM that I loaded Minit onto about 10 years ago and ti is still going strong. Mind you, I never upgraded it after Mint 17 though. But then again a friend of mine had a whole stack of laptops he picked up from scavenging kerb-side collections where people throw out all their junk and furniture for yearly local council pickup (and scavengers). I picked one out of the bunch, it was an i5 Ultrabook with 6GB, a 256GB SSD, and a dead battery and no power supply. I grabbed a 15DC 2A power-pack I had in my junk box, plugged it in, and loaded Linux Mint onto it and after finding a random glitch I removed the RAM, wiped the contacts, put it back in, and it has been running like a dream ever since. (15V is fine if you are not charging batteries).

    I mention this since people are throwing out all kinds of newer computers these days for various reasons and I know that a lot of smaller laptops appeared to have "died" from various Win10 updates, but came to life as soon as I booted from a Live Linux USB Flash drive. I guess that's what they mean when they say "Live" :)

    So if you do persist with your old old PC and even without extra RAM, you can test it by booting from the USB with a Live Linux. While I favor Linux Mint with the Cinnamon desktop, I should also mention that I have been very happy too with MX Linux with the more efficient XFCE desktop that might be more suited in your case. But the main thing is to download the 32-bit ISO, "burn" it onto a USB Flash drive, and boot up your PC with it (you might have to change the boot order or hit F12 or something). Once it boots up you can use it and play with it etc but you should install it as it will run even faster from local storage and you can install extra software from the built-in software-center or directly etc.

    btw, to "burn" an ISO onto a Flash drive is a very easy thing when you are running Linux but you will have to Google up how to do it on XP (which I still run in VirtualBox for Protel99SE). I played with Linux for several years until I decided that enough is enough, I will take the plunge and "commit" to Linux. There was a learning curve for sure, but it was relatively easy and I was still able to do things from the word go. I don't worry about anti-virus software, although I consider that stuff a virus in itself in terms of slowing down the PC and hogging memory etc.

    My second keyring has two USB Flash drives on them, one with a Live Linux Mint, the other with MX Linux. Anytime I need to get into a troublesome PC, they are my "keys".
    P.S. I mentioned VirtualBox before but these days I can run most WIndows stuff directly in Wine, even Descent II (rebirth) games run gloriously)
  • these days I can run most WIndows stuff directly in Wine, even Descent II (rebirth) games run gloriously)
    These days, WINE often has better compatibility with old games than Windows 10. Direct3D 8 and non-32bpp DirectDraw just don't seem to work very well at all. I'd say it's pathetic on MS's part, but considering they literally shipped (to unsuspecting end users (but of course, not the "business" customers...), not as a beta!) a Win10 update once that was so buggy that it irrecoverably deleted all your files if you moved your user folders from the default location, I'll let them off the hook on that issue for now. Bring back the MIDI mapper though.
  • TonyB_ wrote: »
    ... Celeron 1.2GHz, 512MB RAM & Intel 810E chipset?
    I'm guessing a Pentium3 class instruction set - https://en.wikipedia.org/wiki/Celeron#Tualatin-256
    Sadly, I think all of the newer GUIs will struggle, speed wise, with that.

  • I don't worry about anti-virus software, although I consider that stuff a virus in itself in terms of slowing down the PC and hogging memory etc.

    So true! I have an interesting safety strategy that doesn't need anti-virus software at all:

    Only one single PC ("surfer") is connected to the internet. All my "productive" PCs for development, machine control, testing etc. can share files in the local network but are blocked from the outside world in the router so nothing can go in or out.

    If I want to surf the internet from any PC I open a remote desktop to the surfer PC. In the case the surfer gets infected (never happened though the last 10 years) by something I'll simply overwrite the hard drive with a new image. Takes 10 minutes and saves all the trouble with anti-virus software and frequent so called "safety" updates that actually only replace unsafe software with known bugs by unsafe software with unknown bugs.

Sign In or Register to comment.