views:

91

answers:

2

Hi, couldn't seem to find anything besides opinion questions on 64/32 bit stuff when I searched.

__asm__ {
  mov rbx, 0xFFFFffffFFFFffffull
  movq mm2, rbx 
}

After these 2 instructions the mm2 register holds the value 0x30500004ffffffff according to my xcode debugger (this is inline asm in C++). Now I am new to x86 assembly and my assembly class was taught in MIPS which I took forever ago, but I suppose this isn't working because I am compiling (this is a part of a photoshop plugin) in 32 bit mode and rbx (the 64 bit version of ebx, bx etc, right?) probably doesn't technically exist. I tried other methods to get all 1's like loading 0xfffffffful into mm2 and another register and multiplying but that also didn't seem to work.

I'm fixing to optimize my plugin with some SIMD instructions but I can't seem to figure it out or find any documentation that doesn't make my eyes hurt. Any help is much appreciated!

+1  A: 

You can't run 64-bit assembly code in a 32-bit program. You can either read the value into the MMX register from a memory location, or use something like this:

mov ebx, 0xffffffff
movd mm2, ebx       //copy value to lower 32 bits
punpckldq mm2, mm2  //copy lower 32-bits to upper 32 bits
interjay
Thanks for the answer, really appreciate it! Do you have any recommendations for good documentation? The manual like ones from intel started to give me a headache and I never found punpckldq =/
Tom
@Tom: It's not great, but [this site](http://www.tommesani.com/MMXPrimer.html) has an overview and a list of MMX instructions. In the [Intel manual](http://www.intel.com/products/processor/manuals/), volume 1 has a description and a list of MMX instructions, and volume 2 describes each intruction in detail.
interjay
+1 for mentioning the 64-bit code vs. 32-bit code issue, but -1 for suggesting such a clunky solution of 3 instructions vs. just one in the other answers. On balance, I simply didn't vote.
Nathan Fellman
+6  A: 

Although interjay's code does what you want, there's an easier way to set an MMX register (or XMM register, for that matter) to all-1's (here for mm2):

pcmpeqw mm2, mm2
PhiS
good one! assembly is fun.
Tom