<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Left shift by more than 32 bits--&amp;gt;undefined in DEC C? in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054229#M38008</link>
    <description>IIRC, the six-bit field is an Alpha instruction implementation; take a look at the LSL and ASL stuff.</description>
    <pubDate>Fri, 22 Jun 2007 15:49:38 GMT</pubDate>
    <dc:creator>Hoff</dc:creator>
    <dc:date>2007-06-22T15:49:38Z</dc:date>
    <item>
      <title>Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054212#M37991</link>
      <description>We're in the middle of migrating a C application built for Alpha to run on our VMS I64 systems. One of our developers recently came across some bit shifting code that didn't work the same on Alpha and I64.&lt;BR /&gt;&lt;BR /&gt;We've already fixed the broken code. In the process, though, we learned that in HP C the result is undefined if the shift amount is more than the number of bits in an int (= 32). (See section C.5.3 of the HP C Language Reference Manual at &lt;A href="http://h71000.www7.hp.com/commercial/c/docs/6180profile_017.html#index_x_593)" target="_blank"&gt;http://h71000.www7.hp.com/commercial/c/docs/6180profile_017.html#index_x_593)&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Both Alpha and I64 are 64 bit processors. I don't know about I64 but Alpha can do a 64 bit shift in one instruction. So why the 32 bit limit on shifts? Does some standard specify this limitation?&lt;BR /&gt;&lt;BR /&gt;Further, the result is different on I64 than on Alpha.&lt;BR /&gt;&lt;BR /&gt;See the attached file for sample code and output.&lt;BR /&gt;&lt;BR /&gt;If the shift amount is a constant &amp;gt;= 32 the compiler will catch it and give you the %CC-W-SHIFTCOUNT message. Obviously it can't do that when the shift amount is a variable.&lt;BR /&gt;&lt;BR /&gt;Comments are welcome.</description>
      <pubDate>Thu, 21 Jun 2007 08:05:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054212#M37991</guid>
      <dc:creator>Galen Tackett</dc:creator>
      <dc:date>2007-06-21T08:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054213#M37992</link>
      <description>My Itanium Architecture Software Developer's Manual (Revision 2.2), volume 3 says:&lt;BR /&gt;&lt;BR /&gt;Page 3:222 (index says 3:224)&lt;BR /&gt;&lt;BR /&gt;shl - Shift Left&lt;BR /&gt;&lt;BR /&gt;shl r1 = r2,r3&lt;BR /&gt;shl r1 = r2,count&lt;BR /&gt;&lt;BR /&gt;The value in r2 is shifted to the left with the vacated bit positions filled with zeroes, and placed in r1.  The shift count is interpreted as an unsigned number.  If the value is greater and 63, then the result is all zeroes.&lt;BR /&gt;&lt;BR /&gt;Though Alpha and Itanium are 64 bit machines, the VMS heritage comes from a 32 bit machine (VAX).  I believe that an int is still considered to be 32 bits and you have to declare the type of your variable as int64 to get a 64 bit value.</description>
      <pubDate>Thu, 21 Jun 2007 08:18:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054213#M37992</guid>
      <dc:creator>Richard Whalen</dc:creator>
      <dc:date>2007-06-21T08:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054214#M37993</link>
      <description>The C language lawyers in the C compiler group were pretty good, and if the operation is listed as undefined, they're quite free to return anything they want.&lt;BR /&gt;&lt;BR /&gt;From what I find, you got caught out by an "undefined".  Any shift past 31 is "undefined" for a 32-bit int value.&lt;BR /&gt;&lt;BR /&gt;The sign extension mentioned in your comments is likely unrelated, and appears part of the C argument (integral) promotion; it's in the C standard when converting.&lt;BR /&gt;&lt;BR /&gt;The C code that was posted is not the C code tested.&lt;BR /&gt;&lt;BR /&gt;The following result looks wrong (save via application of the "undefined" clause and the associated "anything goes" mentioned above):&lt;BR /&gt;1u &amp;lt;&amp;lt; 64 = 00000001&lt;BR /&gt;&lt;BR /&gt;This screams "undefined", as I'd expect a zero here if this actually performed a 64 bit shift on a 32-bit quantity.&lt;BR /&gt;&lt;BR /&gt;And it's also this case that's "different" in the source code posted...&lt;BR /&gt;&lt;BR /&gt;The first few entries are listed as 1u in the printf, I'd expect unsigned.  That's a display bug.&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Jun 2007 08:40:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054214#M37993</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2007-06-21T08:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054215#M37994</link>
      <description>&amp;gt; I believe that an int is still considered to be 32 bits and you have to declare&lt;BR /&gt;&amp;gt; the type of your variable as int64 to get a 64 bit value.&lt;BR /&gt;&lt;BR /&gt;You're right about an int still being 32 bits on Alpha and I64.&lt;BR /&gt;&lt;BR /&gt;But check my reference above to the C LRM for a specific statement that defines shift as having a limit of the size of an int (32 bits, of course.)&lt;BR /&gt;&lt;BR /&gt;That's what surprised me--the shift operator is defined to work only up to 32 bits even though both Alpha and I64 cpus can trivially  do a 64 bit shift.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But the value "1Lu" on the left of the &amp;lt;&amp;lt; in the last four lines of my example is a 64 bit unsigned integer constant with a value of 1. &lt;BR /&gt;&lt;BR /&gt;It works the same if you use a 64 bit unsigned integer variable. I just didn't show that in my code, for brevity.&lt;BR /&gt;&lt;BR /&gt;Plus the pseudo-"sign extension" performed on the result of "1Lu &amp;lt;&amp;lt; 31" seems pretty strange.</description>
      <pubDate>Thu, 21 Jun 2007 08:48:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054215#M37994</guid>
      <dc:creator>Galen Tackett</dc:creator>
      <dc:date>2007-06-21T08:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054216#M37995</link>
      <description>&lt;!--!*#--&gt;In the interest of beating a dead horse past&lt;BR /&gt;the point of diminishing returns, it appears&lt;BR /&gt;that on Alpha, the shift count is masked down&lt;BR /&gt;to six bits.  A longer test shows this (in&lt;BR /&gt;tedious detail):&lt;BR /&gt;&lt;BR /&gt;alp $ type shift.c&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;    int i;&lt;BR /&gt;    for (i = 0; i &amp;lt;= 128; i++)&lt;BR /&gt;    {&lt;BR /&gt;        printf( " %3d  %%x%03x  %%x%08x\n", i, i, (1&amp;lt;&amp;lt; i));&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;alp $ cc shift&lt;BR /&gt;alp $ link shift&lt;BR /&gt;alp $ run shift&lt;BR /&gt;   0  %x000  %x00000001&lt;BR /&gt;   1  %x001  %x00000002&lt;BR /&gt;   2  %x002  %x00000004&lt;BR /&gt;   3  %x003  %x00000008&lt;BR /&gt;   4  %x004  %x00000010&lt;BR /&gt;   5  %x005  %x00000020&lt;BR /&gt;   6  %x006  %x00000040&lt;BR /&gt;   7  %x007  %x00000080&lt;BR /&gt;   8  %x008  %x00000100&lt;BR /&gt;   9  %x009  %x00000200&lt;BR /&gt;  10  %x00a  %x00000400&lt;BR /&gt;  11  %x00b  %x00000800&lt;BR /&gt;  12  %x00c  %x00001000&lt;BR /&gt;  13  %x00d  %x00002000&lt;BR /&gt;  14  %x00e  %x00004000&lt;BR /&gt;  15  %x00f  %x00008000&lt;BR /&gt;  16  %x010  %x00010000&lt;BR /&gt;  17  %x011  %x00020000&lt;BR /&gt;  18  %x012  %x00040000&lt;BR /&gt;  19  %x013  %x00080000&lt;BR /&gt;  20  %x014  %x00100000&lt;BR /&gt;  21  %x015  %x00200000&lt;BR /&gt;  22  %x016  %x00400000&lt;BR /&gt;  23  %x017  %x00800000&lt;BR /&gt;  24  %x018  %x01000000&lt;BR /&gt;  25  %x019  %x02000000&lt;BR /&gt;  26  %x01a  %x04000000&lt;BR /&gt;  27  %x01b  %x08000000&lt;BR /&gt;  28  %x01c  %x10000000&lt;BR /&gt;  29  %x01d  %x20000000&lt;BR /&gt;  30  %x01e  %x40000000&lt;BR /&gt;  31  %x01f  %x80000000&lt;BR /&gt;  32  %x020  %x00000000&lt;BR /&gt;  33  %x021  %x00000000&lt;BR /&gt;  34  %x022  %x00000000&lt;BR /&gt;  35  %x023  %x00000000&lt;BR /&gt;  36  %x024  %x00000000&lt;BR /&gt;  37  %x025  %x00000000&lt;BR /&gt;  38  %x026  %x00000000&lt;BR /&gt;  39  %x027  %x00000000&lt;BR /&gt;  40  %x028  %x00000000&lt;BR /&gt;  41  %x029  %x00000000&lt;BR /&gt;  42  %x02a  %x00000000&lt;BR /&gt;  43  %x02b  %x00000000&lt;BR /&gt;  44  %x02c  %x00000000&lt;BR /&gt;  45  %x02d  %x00000000&lt;BR /&gt;  46  %x02e  %x00000000&lt;BR /&gt;  47  %x02f  %x00000000&lt;BR /&gt;  48  %x030  %x00000000&lt;BR /&gt;  49  %x031  %x00000000&lt;BR /&gt;  50  %x032  %x00000000&lt;BR /&gt;  51  %x033  %x00000000&lt;BR /&gt;  52  %x034  %x00000000&lt;BR /&gt;  53  %x035  %x00000000&lt;BR /&gt;  54  %x036  %x00000000&lt;BR /&gt;  55  %x037  %x00000000&lt;BR /&gt;  56  %x038  %x00000000&lt;BR /&gt;  57  %x039  %x00000000&lt;BR /&gt;  58  %x03a  %x00000000&lt;BR /&gt;  59  %x03b  %x00000000&lt;BR /&gt;  60  %x03c  %x00000000&lt;BR /&gt;  61  %x03d  %x00000000&lt;BR /&gt;  62  %x03e  %x00000000&lt;BR /&gt;  63  %x03f  %x00000000&lt;BR /&gt;  64  %x040  %x00000001  (Mom!  He's doing it again!)&lt;BR /&gt;  65  %x041  %x00000002&lt;BR /&gt;  66  %x042  %x00000004&lt;BR /&gt;  67  %x043  %x00000008&lt;BR /&gt;  68  %x044  %x00000010&lt;BR /&gt;  69  %x045  %x00000020&lt;BR /&gt;  70  %x046  %x00000040&lt;BR /&gt;  71  %x047  %x00000080&lt;BR /&gt;  72  %x048  %x00000100&lt;BR /&gt;  73  %x049  %x00000200&lt;BR /&gt;  74  %x04a  %x00000400&lt;BR /&gt;  75  %x04b  %x00000800&lt;BR /&gt;  76  %x04c  %x00001000&lt;BR /&gt;  77  %x04d  %x00002000&lt;BR /&gt;  78  %x04e  %x00004000&lt;BR /&gt;  79  %x04f  %x00008000&lt;BR /&gt;  80  %x050  %x00010000&lt;BR /&gt;  81  %x051  %x00020000&lt;BR /&gt;  82  %x052  %x00040000&lt;BR /&gt;  83  %x053  %x00080000&lt;BR /&gt;  84  %x054  %x00100000&lt;BR /&gt;  85  %x055  %x00200000&lt;BR /&gt;  86  %x056  %x00400000&lt;BR /&gt;  87  %x057  %x00800000&lt;BR /&gt;  88  %x058  %x01000000&lt;BR /&gt;  89  %x059  %x02000000&lt;BR /&gt;  90  %x05a  %x04000000&lt;BR /&gt;  91  %x05b  %x08000000&lt;BR /&gt;  92  %x05c  %x10000000&lt;BR /&gt;  93  %x05d  %x20000000&lt;BR /&gt;  94  %x05e  %x40000000&lt;BR /&gt;  95  %x05f  %x80000000&lt;BR /&gt;  96  %x060  %x00000000&lt;BR /&gt;  97  %x061  %x00000000&lt;BR /&gt;  98  %x062  %x00000000&lt;BR /&gt;  99  %x063  %x00000000&lt;BR /&gt; 100  %x064  %x00000000&lt;BR /&gt; 101  %x065  %x00000000&lt;BR /&gt; 102  %x066  %x00000000&lt;BR /&gt; 103  %x067  %x00000000&lt;BR /&gt; 104  %x068  %x00000000&lt;BR /&gt; 105  %x069  %x00000000&lt;BR /&gt; 106  %x06a  %x00000000&lt;BR /&gt; 107  %x06b  %x00000000&lt;BR /&gt; 108  %x06c  %x00000000&lt;BR /&gt; 109  %x06d  %x00000000&lt;BR /&gt; 110  %x06e  %x00000000&lt;BR /&gt; 111  %x06f  %x00000000&lt;BR /&gt; 112  %x070  %x00000000&lt;BR /&gt; 113  %x071  %x00000000&lt;BR /&gt; 114  %x072  %x00000000&lt;BR /&gt; 115  %x073  %x00000000&lt;BR /&gt; 116  %x074  %x00000000&lt;BR /&gt; 117  %x075  %x00000000&lt;BR /&gt; 118  %x076  %x00000000&lt;BR /&gt; 119  %x077  %x00000000&lt;BR /&gt; 120  %x078  %x00000000&lt;BR /&gt; 121  %x079  %x00000000&lt;BR /&gt; 122  %x07a  %x00000000&lt;BR /&gt; 123  %x07b  %x00000000&lt;BR /&gt; 124  %x07c  %x00000000&lt;BR /&gt; 125  %x07d  %x00000000&lt;BR /&gt; 126  %x07e  %x00000000&lt;BR /&gt; 127  %x07f  %x00000000&lt;BR /&gt; 128  %x080  %x00000001  (MOM!!!!!)&lt;BR /&gt;alp $&lt;BR /&gt;&lt;BR /&gt;So, shifting a 32-bit value by up to 63 bits&lt;BR /&gt;works right, and that probably covers the&lt;BR /&gt;vast majority of the lame code out there, but&lt;BR /&gt;apparently not absolutely all of it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I _loved_ the rich-text-format attachment,&lt;BR /&gt;by the way.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But the value "1Lu" on the left of the &amp;lt;&amp;lt;&lt;BR /&gt;&amp;gt; in the last four lines of my example is a&lt;BR /&gt;&amp;gt; 64 bit unsigned integer constant with a&lt;BR /&gt;&amp;gt; value of 1.&lt;BR /&gt;&lt;BR /&gt;Sure it is.&lt;BR /&gt;&lt;BR /&gt;alp $ type SIZX.C&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;    printf( " sizeof  1Lu = %d.\n", (sizeof 1Lu));&lt;BR /&gt;    printf( " sizeof 1LLu = %d.\n", (sizeof 1LLu));&lt;BR /&gt;}&lt;BR /&gt;alp $ cc SIZX&lt;BR /&gt;alp $ link SIZX&lt;BR /&gt;alp $ run SIZX&lt;BR /&gt; sizeof  1Lu = 4.&lt;BR /&gt; sizeof 1LLu = 8.&lt;BR /&gt;alp $&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;We're having fun now.&lt;BR /&gt;&lt;/STDIO.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Thu, 21 Jun 2007 11:44:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054216#M37995</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-21T11:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054217#M37996</link>
      <description>Hoff,&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The C code that was posted is not the C code tested.&lt;BR /&gt;&lt;BR /&gt;Thanks for catching my scribal errors. That was an attempt to transcribe from a classified system to an unclassified one, with the keyboard/monitor about 6 feet away.&lt;BR /&gt;&lt;BR /&gt;I've attached a corrected copy of the sample program.  Hope I haven't botched it again in the process of fixing it. :-)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The C language lawyers in the C compiler group were pretty good, and if the operation is listed as undefined, they're quite free to return anything they want.&lt;BR /&gt;&lt;BR /&gt;True, of course.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;From what I find, you got caught out by an "undefined". Any shift past 31 is "undefined" for a 32-bit int value.&lt;BR /&gt;&lt;BR /&gt;Yes. The original developer years back blindly relied on the undefined result of this code as it ran on the Alpha. The current maintainer/developer discovered that it ran differently on the I64 and came to me for help.&lt;BR /&gt;&lt;BR /&gt;I turned up the cited statement in the C LRM and pointed it out to him and our other developers. It was easy to fix the code once the problem was located and understood.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;The sign extension mentioned in your comments is likely unrelated, and appears part of the C argument (integral) promotion; it's in the C standard when converting.&lt;BR /&gt;&lt;BR /&gt;Is this really part of one or more C standards? I don't claim to know the innards of the C standards, but I wonder, because--&lt;BR /&gt;&lt;BR /&gt;How can you promote 1U (unsigned 64 bit) to another integral type? It's the largest one there is.&lt;BR /&gt;&lt;BR /&gt;And why would you "sign extend" from bit 31 of a 64 bit unsigned value?&lt;BR /&gt;&lt;BR /&gt;It looks more like the compiler was _de_moting the 64 bit unsigned value to a 32 bit signed value, then sign extending that. I don't know why it would do this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Jun 2007 11:54:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054217#M37996</guid>
      <dc:creator>Galen Tackett</dc:creator>
      <dc:date>2007-06-21T11:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054218#M37997</link>
      <description>And, by the way, sign extension is a&lt;BR /&gt;right-shift phenomenon, and is not involved&lt;BR /&gt;in any way in a left shift.  The confusing&lt;BR /&gt;stuff here is completely distinct from any&lt;BR /&gt;sign extension.</description>
      <pubDate>Thu, 21 Jun 2007 12:02:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054218#M37997</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-21T12:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054219#M37998</link>
      <description>All,&lt;BR /&gt;&lt;BR /&gt;I am SO sorry about posting the RTF attachment, and multiple times at that.&lt;BR /&gt;&lt;BR /&gt;I had somehow saved it in both plain text and RTF formats, and clicked the wrong one. If you're still interested, a plain text version is attached.&lt;BR /&gt;&lt;BR /&gt;I'd not knowingly post anything but plain text here.&lt;BR /&gt;&lt;BR /&gt;I blame it Gates, whose !&amp;amp;@#%@\]? OS is the one I used to create the file. And we know it's behind all the world's evils. I'll bet it was a WinSnake that tempted Eve in the first place!&lt;BR /&gt;&lt;BR /&gt;Galen</description>
      <pubDate>Thu, 21 Jun 2007 12:05:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054219#M37998</guid>
      <dc:creator>Galen Tackett</dc:creator>
      <dc:date>2007-06-21T12:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054220#M37999</link>
      <description>&amp;gt; I'd not knowingly post anything but plain&lt;BR /&gt;&amp;gt; text here.&lt;BR /&gt;&lt;BR /&gt;Oh, sure.  You'd say anything now.&lt;BR /&gt;&lt;BR /&gt;Any mystery remaining, or is all wonderfully&lt;BR /&gt;clear at last?</description>
      <pubDate>Thu, 21 Jun 2007 12:11:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054220#M37999</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-21T12:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054221#M38000</link>
      <description>Once again I have overwhelmed my actual question with sheer verbosity.&lt;BR /&gt;&lt;BR /&gt;The only real questions I have are:&lt;BR /&gt;&lt;BR /&gt;Do the C standards with which HP C V7.1 complies make any kind of statement that would limit the maximum supported shift to either "the number of bits in an int" or explicitly to 32 bits?&lt;BR /&gt;&lt;BR /&gt;If not, it seems to me a needless limitation to have no defined 64 bit shift on a 64 bit platform.&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Jun 2007 12:56:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054221#M38000</guid>
      <dc:creator>Galen Tackett</dc:creator>
      <dc:date>2007-06-21T12:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054222#M38001</link>
      <description>&lt;!--!*#--&gt;&amp;gt; Do the C standards with which HP C V7.1&lt;BR /&gt;&amp;gt; complies make any kind of statement that&lt;BR /&gt;&amp;gt; would limit the maximum supported shift to&lt;BR /&gt;&amp;gt; either "the number of bits in an int" or&lt;BR /&gt;&amp;gt; explicitly to 32 bits?&lt;BR /&gt;&lt;BR /&gt;Apparently, you can trust it up to 63 on&lt;BR /&gt;Alpha, for either a 32-bit or a 64-bit value.&lt;BR /&gt;On IA64, the implementation seems to allow&lt;BR /&gt;shift counts larger than 63.&lt;BR /&gt;&lt;BR /&gt;While the HP C document says:&lt;BR /&gt;&lt;BR /&gt;   The result of the shift operation is&lt;BR /&gt;   undefined if the right operand is negative&lt;BR /&gt;   or if its value is greater than the number&lt;BR /&gt;   of bits in an int.&lt;BR /&gt;&lt;BR /&gt;I assume that for "in an int" it really meant&lt;BR /&gt;"in the left operand", and I'll admit that&lt;BR /&gt;when you really _do_ have a 64-bit value,&lt;BR /&gt;I'd've expected a left shift by 64 to do&lt;BR /&gt;something (rather than nothing).&lt;BR /&gt;&lt;BR /&gt;However:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://c0x.coding-guidelines.com/6.5.7.html" target="_blank"&gt;http://c0x.coding-guidelines.com/6.5.7.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;says:&lt;BR /&gt;&lt;BR /&gt;   1175 If the value of the right operand is&lt;BR /&gt;   negative or is greater than or equal to&lt;BR /&gt;   the width of the promoted left operand,&lt;BR /&gt;   the behavior is undefined.&lt;BR /&gt;&lt;BR /&gt;And with that "greater than or equal to",&lt;BR /&gt;they pull the rug out from under a complaint&lt;BR /&gt;about a 64-bit shift on a 64-bit item.&lt;BR /&gt;&lt;BR /&gt;And RTF or not, your sample code is shifting&lt;BR /&gt;32-bit values, not 64-bit values.  If you&lt;BR /&gt;want to see what happens to actual 64-bit&lt;BR /&gt;values, you could use this:&lt;BR /&gt;&lt;BR /&gt;alp $ type shift64.c&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;    int i;&lt;BR /&gt;    for (i = 0; i &amp;lt;= 128; i++)&lt;BR /&gt;    {&lt;BR /&gt;        printf( " %3d  %%x%03x  %%x%016llx\n", i, i, (1LL&amp;lt;&amp;lt; i));&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;As before, shift counts on Alpha seem to be&lt;BR /&gt;masked at six bits, while on IA64 shift&lt;BR /&gt;counts bigger than 63 work as one might hope&lt;BR /&gt;(but apparently shouldn't expect).&lt;/STDIO.H&gt;</description>
      <pubDate>Thu, 21 Jun 2007 13:51:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054222#M38001</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-21T13:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054223#M38002</link>
      <description>There's a different variation of this one around, as Itanium (or it used to) happily process the whole of the shift value (rather than the low six bits Alpha looks at), and it takes a while to shift a huge number of bits.&lt;BR /&gt;&lt;BR /&gt;If this hasn't been tagged in the compiler (and it might have been), you could request a shift by a billion or so.  And wait for it.&lt;BR /&gt;&lt;BR /&gt;I'd prefer that anything past the scale of the value being shifted would cough up a zero and continue, or cough up an error, but that doesn't always happen.&lt;BR /&gt;&lt;BR /&gt;This made one of my hints-and-kinks presentations a while back.&lt;BR /&gt;</description>
      <pubDate>Thu, 21 Jun 2007 14:19:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054223#M38002</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2007-06-21T14:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054224#M38003</link>
      <description>From the C99 standard, section 6.5.7, Bitwise shift operators:&lt;BR /&gt;&lt;BR /&gt;Semantics&lt;BR /&gt;&lt;BR /&gt;The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.</description>
      <pubDate>Thu, 21 Jun 2007 14:39:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054224#M38003</guid>
      <dc:creator>John Reagan</dc:creator>
      <dc:date>2007-06-21T14:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054225#M38004</link>
      <description>You're welcome, I'm sure.</description>
      <pubDate>Fri, 22 Jun 2007 07:57:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054225#M38004</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-22T07:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054226#M38005</link>
      <description>Sorry for having abruptly closed the thread earlier with no explanation...&lt;BR /&gt;&lt;BR /&gt;I do appreciate everyone's comments and have awarded points to each of you.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;Galen&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Jun 2007 08:34:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054226#M38005</guid>
      <dc:creator>Galen Tackett</dc:creator>
      <dc:date>2007-06-22T08:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054227#M38006</link>
      <description>It was educational.  If anyone had asked me&lt;BR /&gt;what you'd get from a left-shift by 64 on an&lt;BR /&gt;Alpha, I wouldn't have hesitated before&lt;BR /&gt;saying "zero".  I hate educational.</description>
      <pubDate>Fri, 22 Jun 2007 08:42:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054227#M38006</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-22T08:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054228#M38007</link>
      <description>By the way, is the six-bit shift count an&lt;BR /&gt;Alpha hardware thing, or could the C&lt;BR /&gt;compiler/RTL be adjusted to let, say, seven&lt;BR /&gt;bits slip through?  Getting zero from&lt;BR /&gt;"1LL &amp;lt;&amp;lt; 64" would be much more satisfying&lt;BR /&gt;than the current result.  (Think of it as an&lt;BR /&gt;IA64-compatibility feature?)</description>
      <pubDate>Fri, 22 Jun 2007 15:40:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054228#M38007</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-22T15:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054229#M38008</link>
      <description>IIRC, the six-bit field is an Alpha instruction implementation; take a look at the LSL and ASL stuff.</description>
      <pubDate>Fri, 22 Jun 2007 15:49:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054229#M38008</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2007-06-22T15:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054230#M38009</link>
      <description>For PA-RISC, the shift register is 5 or 6 bits respectively.  Earlier for K&amp;amp;R, there was extra code to test the shift value.  Later we realized that ANSI C said it was unspecified, so this extra test was ripped out.&lt;BR /&gt;&lt;BR /&gt;As mentioned by Hoff, IPF will not mask the shift value and shift off to 0.  This is also allowed by the Standard.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;If the shift amount is a constant &amp;gt;= 32 the compiler will catch it &lt;BR /&gt;&lt;BR /&gt;That's correct.  Some compilers after they warn, set the value to 0, even if the hardware won't.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Steven: sign extension is a right-shift phenomenon, and is not involved in any way in a left shift.&lt;BR /&gt;&lt;BR /&gt;That's not quite true.  The HP3000 had a ASL, Arithmetic Left Shift instruction that would preserve the sign bit on overflow.</description>
      <pubDate>Fri, 22 Jun 2007 22:41:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054230#M38009</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-06-22T22:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Left shift by more than 32 bits--&gt;undefined in DEC C?</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054231#M38010</link>
      <description>&amp;gt;  The HP3000 had a ASL, [...]&lt;BR /&gt;&lt;BR /&gt;Yeah, and the IBM 1130 had a RTE (rotate&lt;BR /&gt;right accumulator and extension), but it was&lt;BR /&gt;just as hard to get to from C.  Maybe harder,&lt;BR /&gt;as I don't recall seeing a C compiler for the&lt;BR /&gt;1130.  (COBOL, FORTRAN, RPG, APL, and BASIC,&lt;BR /&gt;but not C.)&lt;BR /&gt;&lt;BR /&gt;Now, if you're looking for a machine with&lt;BR /&gt;minimal high-level language support, I&lt;BR /&gt;recommend the Univac 422.  Assembler and&lt;BR /&gt;ELTRAN.  (It's amazing what you can get into&lt;BR /&gt;512 15-bit words.)</description>
      <pubDate>Fri, 22 Jun 2007 23:13:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/left-shift-by-more-than-32-bits-gt-undefined-in-dec-c/m-p/5054231#M38010</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-06-22T23:13:38Z</dc:date>
    </item>
  </channel>
</rss>

