SAL shift arithmetic left
ManAtWork
Posts: 2,176
in Propeller 2
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.
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
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.
That should detect overflow, right?
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.
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?
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...
We could emulate that behaviour with something like 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)
[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]
EDIT: Hmm, nope that wasn't it.
Quoting: EDIT2: Weird.
TJV saves an instruction and avoids use of Z:
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.
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.
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 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.
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...)
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.
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?
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
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)
Sadly, I think all of the newer GUIs will struggle, speed wise, with that.
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.