Author Topic: MOVBE missing  (Read 383 times)

jj2007

  • Member
  • *****
  • Posts: 8896
  • Assembler is fun ;-)
    • MasmBasic
MOVBE missing
« on: November 17, 2018, 02:13:45 PM »
UAsm, AsmC, MASM version 10 and lower:
Code: [Select]
int 3
movbe eax, [edi+5]
db 0Fh, 38h, 0F0h, 47h, 05h     ; movbe eax, [edi+5]
mov eax, [edi+5]

Produces error A2008: syntax error : movbe

In case somebody wants to time it and has a Haswell+ CPU: exe + source attached. I can't give you results because my CPU is too old :(
Don't be surprised if it crashes with an exception - it just means your hardware sucks like mine :greensml:

Strangely enough, MOVBE is almost absent in the forum. It gets mentioned in the Comprehensive x86 instruction set for MSVS2010? thread, but that one is more about the Pope and his role in assembly programming 8)

fearless

  • Member
  • ***
  • Posts: 366
    • LetTheLightIn
Re: MOVBE missing
« Reply #1 on: November 17, 2018, 04:16:19 PM »
Code: [Select]
Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz (SSE4

35      cycles for 100 * mov+bswap
20      cycles for 100 * movbe

33      cycles for 100 * mov+bswap
20      cycles for 100 * movbe

33      cycles for 100 * mov+bswap
22      cycles for 100 * movbe

33      cycles for 100 * mov+bswap
25      cycles for 100 * movbe

35      cycles for 100 * mov+bswap
31      cycles for 100 * movbe

9       bytes for mov+bswap
9       bytes for movbe


--- ok ---
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

www.LetTheLight.in  My Github  Twitter

mabdelouahab

  • Member
  • ***
  • Posts: 397
Re: MOVBE missing
« Reply #2 on: November 17, 2018, 04:42:32 PM »
Code: [Select]
Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz (SSE4)

21      cycles for 100 * mov+bswap
10      cycles for 100 * movbe

25      cycles for 100 * mov+bswap
10      cycles for 100 * movbe

23      cycles for 100 * mov+bswap
66      cycles for 100 * movbe

40      cycles for 100 * mov+bswap
24      cycles for 100 * movbe

76      cycles for 100 * mov+bswap
69      cycles for 100 * movbe

9       bytes for mov+bswap
9       bytes for movbe


--- ok ---

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5945
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MOVBE missing
« Reply #3 on: November 17, 2018, 07:04:10 PM »
This works on my Haswell E/EP.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

 entry_point proc

    USING r12
    LOCAL var   :QWORD

    SaveRegs

    mov r12, 1133557799BBDDFFh

    conout hex$(r12),lf

    movbe var, r12

    conout hex$(var),lf

    waitkey
    RestoreRegs
    .exit

 entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end


OUTPUT


1133557799BBDDFF
FFDDBB9977553311
Press any key to continue...
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

LiaoMi

  • Member
  • ***
  • Posts: 329
Re: MOVBE missing
« Reply #4 on: November 17, 2018, 07:59:34 PM »
Hi  :P,

Code: [Select]
Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz (SSE4)

22      cycles for 100 * mov+bswap
11      cycles for 100 * movbe

23      cycles for 100 * mov+bswap
37      cycles for 100 * movbe

23      cycles for 100 * mov+bswap
8       cycles for 100 * movbe

21      cycles for 100 * mov+bswap
16      cycles for 100 * movbe

35      cycles for 100 * mov+bswap
18      cycles for 100 * movbe

9       bytes for mov+bswap
9       bytes for movbe


--- ok ---

habran

  • Member
  • *****
  • Posts: 1179
    • uasm
Re: MOVBE missing
« Reply #5 on: November 17, 2018, 08:00:26 PM »
MOVBE is now implemented in UASM and I hope John will include it in this release 8)
Cod-Father

johnsa

  • Member
  • ****
  • Posts: 714
    • Uasm
Re: MOVBE missing
« Reply #6 on: November 17, 2018, 09:01:41 PM »
Now included, packages coming shortly :)

jj2007

  • Member
  • *****
  • Posts: 8896
  • Assembler is fun ;-)
    • MasmBasic
Re: MOVBE missing
« Reply #7 on: November 17, 2018, 09:06:49 PM »
MOVBE is now implemented in UASM and I hope John will include it in this release 8)

A winning team :t

habran

  • Member
  • *****
  • Posts: 1179
    • uasm
Re: MOVBE missing
« Reply #8 on: November 17, 2018, 09:38:05 PM »
It can be quite useful, here is an example:
Code: [Select]
.data
szReplace db 'Replaced',0

.code

   mov          rdx,qword ptr szReplace
   movbe rax,qword ptr szReplace
output:

RAX = 5265706C61636564
RDX = 646563616C706552

Cod-Father

jj2007

  • Member
  • *****
  • Posts: 8896
  • Assembler is fun ;-)
    • MasmBasic
Re: MOVBE missing
« Reply #9 on: November 17, 2018, 10:00:25 PM »
Yes indeed! If I ever encounter an application with an innermost time-critical loop where bswap is too slow, I will use it as a justification to get the ok for new hardware from my wife. Any ideas?

habran

  • Member
  • *****
  • Posts: 1179
    • uasm
Re: MOVBE missing
« Reply #10 on: November 17, 2018, 11:51:43 PM »
 .if (hardware == old)
    bswap eax
 .else
   movbe rax, qword ptr wife
 .endif
 ;)
Cod-Father

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5945
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MOVBE missing
« Reply #11 on: November 17, 2018, 11:58:22 PM »
From memory there is an SSE4 instruction where you use a mask to determine the altered order of data and from memory it was a lot faster than BSWAP.

> I will use it as a justification to get the ok for new hardware from my wife. Any ideas?

Best of luck with that one, it sounds like an attempt to wring blood out of a stone.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

AW

  • Member
  • *****
  • Posts: 1608
  • Let's Make ASM Great Again!
Re: MOVBE missing
« Reply #12 on: November 18, 2018, 12:37:11 AM »

GabrielRavier

  • Regular Member
  • *
  • Posts: 12
Re: MOVBE missing
« Reply #13 on: December 05, 2018, 10:07:38 PM »
Code: [Select]
Intel(R) Atom(TM) CPU  Z3735F @ 1.33GHz (SSE4)

95      cycles for 100 * mov+bswap
85      cycles for 100 * movbe

98      cycles for 100 * mov+bswap
85      cycles for 100 * movbe

95      cycles for 100 * mov+bswap
88      cycles for 100 * movbe

98      cycles for 100 * mov+bswap
86      cycles for 100 * movbe

116     cycles for 100 * mov+bswap
83      cycles for 100 * movbe

9       bytes for mov+bswap
9       bytes for movbe


--- ok ---


Results on my laptop with a shitty silvermont CPU (I think those were the first with MOVBE apart from bonnell