Re: Integer Do's And Don'ts

From: Gerald Hernandez (Cablewizard_at_spam_remove@Yahoo.com)
Date: 10/18/04


Date: Sun, 17 Oct 2004 21:05:58 -0600

Thanks, that is a good read.
While I hadn't really considered Integer being Int64 on 64 bit processors in
the near future, it does look like there are some things to consider. It
does look like 2 Int32's will be packed nicely into an Int64, which we all
would expect now. This is a nice change from past platform differences where
a whole Int64 might be allocated for 1 Int32. Guess we need to be aware of
the size of the pointers, which we also knew, but looks like it could raise
it's head in unexpected ways. Gotta watch out how much memory we consume.
Would be a shame to waste half of it due to unneccessary boxing.

I haven't paid much attention to the x64 vs Itanium stuff. But as I
understand it, the x64 is kind of a hybrid processor. It has the 32 Bit
instructions as well as the 64 Bit instructions. Also supports both memory
pipelines. The Itanium has it's own set of 64 Bit instructions, and only
those. So in the long run it looks like it might die due to compatibility
issues.

Gerald

"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:OszJX1KtEHA.3972@TK2MSFTNGP15.phx.gbl...
> Herfried,
> "vbc /help" in .NET 2.0 beta 1 gives:
>
> /platform:<string> Limit which platforms this code can run
> on;
> must be x86, x64, Itanium or anycpu
> (default).
>
> Which is what http://blogs.msdn.com/joshwil/ suggested C# does.
>
> Within VS.NET (beta 1) you can use "Project - Properties - Compile -
> Advanced - Target CPU" to change the above setting.
>
> Compiling the following with Target CPU = Itanium (Intel's 64-bit CPU):
>
> Public Class MainForm
>
> Public Shared Sub Main()
> Dim index As Integer = 10
> index *= 100
> End Sub
>
> End Class
>
> Gives the following IL.
> .method public static void Main() cil managed
> {
> .entrypoint
> .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = (
01
> 00 00 00 )
> // Code size 11 (0xb)
> .maxstack 2
> .locals init ([0] int32 index)
> .language '{3A12D0B8-C26C-11D0-B442-00A0244A1DD2}',
> '{994B45C4-E6E9-11D2-903F-00C04FA302A1}',
> '{00000000-0000-0000-0000-000000000000}'
> // Source File 'C:\Documents and Settings\Jay\My Documents\Visual
> Studio\Projects\Windows 64 Application\Windows 64 Application\MainForm.vb'
> //000009: Public Shared Sub Main()
> IL_0000: nop
> //000010: Dim index As Integer = 10
> IL_0001: ldc.i4.s 10
> IL_0003: stloc.0
> //000011: index *= 100
> IL_0004: ldloc.0
> IL_0005: ldc.i4.s 100
> IL_0007: mul.ovf
> IL_0008: stloc.0
> //000012: End Sub
> IL_0009: nop
> IL_000a: ret
> } // end of method MainForm::Main
>
> Which demonstrates, as I was saying: VB.NET defines Integer as an alias
for
> Sytem.Int32.
>
> Of course I need a Win64 machine to actually execute the above program :-)
>
>
> Note: The default of AnyCPU for Platform allows your single executable to
> run as a 32-bit app on Win32 & a (full!) 64-bit app on Win64! Which IMHO
> reinforces the notion that "Integer is an alias for System.Int32" even on
> the 64-bit edition of .NET.
>
>
> Of course if one really needs a platform specific Int, then one could use
a
> variation of Gerald earlier post.
>
> Something like:
>
> #If Is64BitSystem Then
> Imports Int = System.Int64
> #Else
> Imports Int = System.Int32
> #End If
>
> Public Shared Sub Main()
> Dim index As Int = 10
> index *= 100
> End Sub
>
> Of course then you need to be careful of literals (100I verses 100L) and
> public methods into & out of your assembly... (all the pain we learned
from
> C :-))
>
> Alternatively I would consider defining Int as a structure and overload
all
> the operators. Then compile 3 versions of the assembly with the Int
> structure, one for each Target CPU. Which may introduce its own
performance
> issues, however like System.IntPtr I would only use Int for Interop...
>
>
> I'm really not sure why there are 2 64-bit targets (x64 & Itanium). I
would
> expected only one...
>
> Hope this helps
> Jay
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:Ok0e0OJtEHA.2128@TK2MSFTNGP11.phx.gbl...
> > Jay,
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> schrieb:
> >> This does raise an interesting question. We all seem to be
> >> assuming that there will be a 32-bit compiler & a 64-bit
> >> compiler in .NET 2.0. I suspect there will be a single
> >> VB.NET compiler (vbc.exe)
> >
> > I suspect that too. Only one compiler is needed.
> >
> >> as I understand there is going to be a single 32-bit
> >> VS.NET, based on the video I posted or an MSDN article or MSDN Magazine
> >> article.
> >
> > ACK. From what I have heard, there will be a 32-bit VS 2005 only.
> >
> >> I know the JIT changes based on what platform is deployed, however as
you
> >
> >> Thinking about it, I see no real need for a 32-bit specific
> >> compiler (C# or VB.NET) & a specific 64-bit (C# or
> >> VB.NET) compiler, as both would simply create IL for
> >> the Framework. I do see a need for a 64-bit JIT & a 32-bit JIT as the
> >> machine instructions needed change. I also see a
> >> need for (parts of) the runtime assemblies changing, as you
> >> may need to call a 32-bit or 64-bit unmanaged API...
> >
> > That's what I think too, and that's the reason why I doubt that there
will
> > be a change in the mapping between 'Integer' and 'Int32'.
> >
> >> I'll look around the beta to see what I can find...
> >
> > :-)
> >
> > --
> > Herfried K. Wagner [MVP]
> > <URL:http://dotnet.mvps.org/>
>
>



Relevant Pages

  • Re: function returning __int32 in place of __int64
    ... > number (assigned to a __int64 var). ... function returns an int, which is 32 bits on your platform. ... Then include "my_header.h" in all the source files. ... to be an int value, if it fits in an int, or a long value. ...
    (comp.dsp)
  • Re: Proposal: New types in C++0x
    ... > is unsigned int16 to be the same as unsigned int and unsigned, ... > and unsigned int64 is the unsigned type. ... If, for example, there exists a platform that ... then replacing int's representation with a 16 bit representation would break ...
    (comp.lang.cpp)
  • Re: Moving from C++ to VC++
    ... >>> At least your code would then capture your requirement for the type. ... Using __int64 just means that int and long wasn't enough, ... We just get yet another long type problem! ...
    (microsoft.public.vc.language)
  • Re: C and only C language has a standard 64 bit integer type ?
    ... > a new keyword, it's a correction in the grammar. ... int16 is introduced and is an exact 16-bit type (of course additional ... int and short become equivalent of it. ... int64 is introduced and holds 64-bit values. ...
    (comp.lang.cpp)

Loading