1

I've been working on something and run into another couple of problems. First off:

ROR64 macro a, rot
; Result := (A shl (64-rot)) xor (A shr rot);
  MOV     EAX, 64
  SUB     EAX, rot
  PSLLQ   a, EAX
  MOVQ    mm6, a
  PSRLQ   mm6, rot
  PXOR    a, mm6
endm

I've been attempting the process using QWords per the last question (I'll probably attempt it with DWords to learn, too). All I have access to on the dev machine I'm using is MMX instructions, so I've been going there. The problem has been handling the values that come from "rot", since I've determined the MMX ops only work on those registers via the errors I get from MASM32. But when I attempt to put "rot" and "64-rot" into a MMX register, I get more errors. How do I resolve this?

Also I will need to be adding MMX registers as QWords. I do not see an instruction in the references to do this. Will I need to be splitting those up into the regular registers anyway or pushing them through the FP instructions?

Mysticial
  • 464,885
  • 45
  • 335
  • 332
Glenn1234
  • 2,542
  • 1
  • 16
  • 21
  • 2
    "All I have access to on the dev machine I'm using is MMX instructions" - wow, that must be an insanely old machine. I doubt any machine with only MMX can run any modern browser used to post this question. :P Is this just an artificial limitation? – Mysticial Oct 24 '12 at 03:19
  • 2
    In any case, I'm not familiar with MMX since it's well before my time. But I think both operands of `PSRLQ` need to be `mm` registers (if you're not using a constant shift amount). So you'll need to move `rot` from into an `mm` register. – Mysticial Oct 24 '12 at 03:24
  • 1
    @Mysticial Oh, you are that young :-) In short MMX can do everything SSE1 can do, but no floating point and only at half the width. – Gunther Piez Oct 24 '12 at 11:59
  • Believe it or not, my dev machine only supports MMX (and 3DNow! but that's another kettle of fish I'm not going to get into because it got phased out entirely). If it did support more, I'd still probably want to look into it just to learn what it is. And it's been a benefit, before this I really never knew what the supposed benefit of MMX or SSE was, despite being exposed to all the marketing materials over the years. – Glenn1234 Oct 24 '12 at 14:30

1 Answers1

3

MMX is meant for SIMD programming (it was not meant for 64 Bit operation in general).

See wikipedia .. "The main usage of the MMX instruction set is based on the concept of packed data types, which means that instead of using the whole register for a single 64-bit integer, two 32-bit integers, four 16-bit integers, or eight 8-bit integers may be processed concurrently."

Nowadays it is obsolete because of the SSEx technology. Sorry, but there is no instruction like PADDQ (take a look PADDx) in the specification.

The Shift-Instruction only accept 8Bit displacement or an other MMX Register to hold the amount of shifts. This means you cannot use a register like eax to do the job. Nice try but sometimes wishes have nothing to do with the real world.

By the way, please take a close look to your posted macro. Anyway, i think it seems not to be correct. Please think about the order of operation you want to do and the result you expect.

Because you use a macro which will emit code at any time you use it you can try (untested):

TEST macro a, rot
; Result := (A shl (64-rot)) xor (A shr rot);
  MOVQ    mm6, a
  PSLLQ   a, 64-rot
  PSRLQ   mm6, rot
  PXOR    a, mm6
endm
David J
  • 1,554
  • 9
  • 15
  • The reference I found on MMX showed a PADDQ instruction. Part of the challenge of this, I guess, is to find good accurate instruction material and references that weren't written in the days when DOS was common. – Glenn1234 Oct 24 '12 at 14:26
  • As harold said, there is an instruction called PADDQ in the SSE instruction set (it makes sense to have it here). For MMX there is no such instruction. And to be honest it would not make much sense. Please note PADDQ stands for **P** acked **ADD** of **Q** WORDS, but you cannot pack multiple 64 Bit numbers into a MMX register because it is only 64 Bit. The shift commands are full 64 Bit because it will help you to arrange the data in the MMX register. – David J Oct 25 '12 at 02:36
  • 1
    @Fermat2357 that argument makes `0F D4 /r` sad :( – harold Oct 26 '12 at 08:23
  • Yes you are right. I can find [here](http://courses.engr.illinois.edu/ece390/books/labmanual/inst-ref-simd.html) what you are pointing out. I really cannot remember for that :). It seems Im wrong in this point. – David J Oct 26 '12 at 08:45
  • @DavidJ `paddq mm, mm/m64` does actually exist. It's just not part of MMX but of SSE2. Remember that until SSE3 (I think) all SSE instructions also worked on MMX registers. – fuz Apr 15 '19 at 08:09