flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > Shouldn't "movq r64,xmm" be legal? Goto page 1, 2 Next |
Author |
|
Madis731 06 Aug 2008, 12:45
I'm rementioning it because it seems to have been forgotten.
Some documents say that movd r64,(x)mm is legal, but even that doesn't work and I think its okay. movq r64,(x)mm is way more logical. Code: use64 movd eax,mm0 ;OK! movd eax,xmm0 ;OK! movq rax,mm0 ;OK! ;movq rax,xmm0 ;Why? Operand sized do not match ;Not even possible with some wierd formats: ;movd rax,mm0 ;OK! Invalid size of operand ;movd rax,xmm0 ;OK! Invalid size of operand ;movq eax,mm0 ;OK! Invalid size of operand ;movq eax,xmm0 ;OK! Invalid size of operand A rather simple, but ugly workaround is something like this: Code: db 66h movq rax,mm0 ;OK! |
|||
06 Aug 2008, 12:45 |
|
Tomasz Grysztar 06 Aug 2008, 12:59
OK, thanks - I have found the old thread and merged your new one into it - will look into the bug report later.
|
|||
06 Aug 2008, 12:59 |
|
lazer1 14 Aug 2008, 20:44
Tomasz Grysztar wrote: OK, thanks - I have found the old thread and merged your new one into it - will look into the bug report later. what is the URL? please see also my post: http://board.flatassembler.net/topic.php?p=80780#80780 the documentation for xmm I am using is from the AMD webpage: http://developer.amd.com/documentation/guides/Pages/default.aspx namely: http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/26568.pdf volume 4, 128 bit multimedia instructions. I need the following XMM and MMX instructions: Quote:
I dont know which of these are implemented as I got an error with the first one. for the moment I dont need any other MMX or XMM instructions, later I probably may need a few other ones. In order to conform with other fasm things: for the ones which dont change the remaining bits perhaps the way is to have eg xmm0h and xmm0l for the hi 64 and the lo 64 bits. eg "movsd xmm0l, xmm1l" and "movd rax, xmm0l" not sure how you would deal with "movd xmm0, rax" perhaps that should be like "movzx eax, bx" where the 2 operands are different sizes. |
|||
14 Aug 2008, 20:44 |
|
lazer1 14 Aug 2008, 20:52
one other thing, these xmm and mmx opcodes are IMPOSSIBLE
to remember, perhaps it is better to extend eg the definitions of mov and movzx: eg Quote:
that would be much more useful and easy to remember |
|||
14 Aug 2008, 20:52 |
|
revolution 14 Aug 2008, 21:49
lazer1 wrote: one other thing, these xmm and mmx opcodes are IMPOSSIBLE |
|||
14 Aug 2008, 21:49 |
|
Madis731 15 Aug 2008, 07:34
It won't be changed! The only thing needed is this bugfix, but we won't declare another syntax here. What you can do it use macros to make your life simpler, but I can tell you this: if you've coded in SSE for a few days you have a real "epiphany" Wow, this is so logical.
I can give you an example which is illogical: Code: use32 mov ax,bx ;okay 16-bit move mov eax,ebx ;okay 32-bit move use64 mov eax,ebx ;upper 32 bits are cleared mov rax,rbx ;okay 64-bit move ;Should is be more like this? movzx eax,ebx ;This is what it exactly means So SSE is pretty logical compared to this. |
|||
15 Aug 2008, 07:34 |
|
lazer1 15 Aug 2008, 15:59
revolution wrote:
fasm DOESNT follow intel syntax for operands, eg it is incompatible with most other assemblers and disassemblers. (and is better by breaking with convention) eg it doesnt accept the STANDARD syntax of segment:[register] fasm uses [ segment : register ] and later versions of fasm use different syntax from earlier ones, for 16 bit code earlier versions allow: jmp label later versions require: jmp dword label when the code is beyond the first 64K the above alternative I gave is a lot easier to remember as there is nothing to remember! merely: mov dest, source for a true mov (understand versus memorize) substitute whatever dest or source you want. and as madis points out for 64 bit mov eax, ebx is WRONG and should be movzx, that of course is AMD's fault. I'll probably create my own macros for such things. movlhps xmm0, xmm1 is an opcode syntax, but an operand syntax is logically more efficient: mov xmm0h, xmm1l implicit syntaxes are ALWAYS better than explicit syntaxes for humans: eg maths uses (sin( x ) + cos( x ))^2 instead of: square + sin x cos x or: x sin x cos + square the latter "stack" syntaxes are more efficient to implement (via stacks) but more difficult to read and less orthogonal: more difficult to cut and paste fragments, the implicit syntax (sin(x) + cos(x))^2 is much more difficult to implement the advantage of an operand syntax is you need less keywords and its more orthogonal. you can create new instructions without any new keywords. eg you can ask: does "mov xmm0h, xmm1h" exist? not sure if that does exist, the fact that it allows me to talk about things which arent invented yet proves its a good syntax. anything which zero extends should be movzx, Intel arent the mouthpiece of god! some of their ideas are good and some are rubbish Intel anyway globs opcodes, eg mov itself already is many different opcodes: 88 89 8A 8B 8C 8E A0 A1 A2 A3 B0 B8 C6 C7 can you imagine the HASSLE if those were 14 different opcodes? Intel are notorious for inefficiency, eg their crazy segment idea and prefices. thankfully AMD's long mode supercedes as many Intel inefficiencies as are feasible. segments superceded by the MMU, which other CPU's have been using for decades. AMD also have fully orthogonal multiprocessors, Intel multiprocessors can be fake multiprocessors, 1 cpu pretending to be 2. speaking as someone who used Motorola 68k and MIPS RISC years before learning x86. When you switch on a 68k or PPC or MIPS it STARTS in a state which takes a lot of work to reach with x86. switch on a 68k and you IMMEDIATELY have flat 32 bit addressing you arent stuck to the first 1mb one other thing: A LOT OF ASSEMBLERS accept synonyms, if there is only one possible interpretation of something they tend to accept it, perhaps with a warning. eg: jmp label ..... label: can only mean one thing! and is best interpreted as a rip-relative jmp just in case the code gets relocated. (all my own code DOES get relocated so absolute jmps are forbidden except via registers) in fact its an art allowing unambigous interpretations which are off the map HOWEVER label equ 12345678h jmp label where label isnt a code label but a const COULD be an error for 16 bit code. |
|||
15 Aug 2008, 15:59 |
|
revolution 15 Aug 2008, 17:14
Madis731 wrote:
Code: movzx rax,ebx |
|||
15 Aug 2008, 17:14 |
|
Madis731 15 Aug 2008, 17:57
oh yeah - sorry rax was meant to be there I got lost in this wierd syntax - though... isn't the very same line allowed ^o) ... hmm not exactly
Code: use64 movzx rax,bx ;allowed movzx rax,bl ;allowed ;movzx rax,ebx ; NOT allowed because: mov eax,ebx ; ...does the same thing erm, so I do partly agree with laser1 BUT the world is accustomed to Intel syntax and although you feel it sometimes too complicated, at the time of development they seeked for the best solution. Now that new technologies are coming and compatibility needs to remain...what's U gonna do? |
|||
15 Aug 2008, 17:57 |
|
lazer1 17 Aug 2008, 19:47
Madis731 wrote: oh yeah - sorry rax was meant to be there I got lost in this wierd syntax - though... isn't the very same line allowed ^o) ... hmm not exactly you can have it multiple ways: fasm -strict xyz.asm fasm -alternative xyz.asm fasm -generous xyz.asm -strict is the current approach, -alternative is where for use64 you disallow "mov eax,ebx" that has to be done as "movzx rax,ebx". -alternative removes all bug prone constructs -generous is where things which can have only one possible interpretation are done that way. eg "jmp label" has only one possible meaning. but: xyz equ 123456h jmp xyz could be an error for 16 bit. fasm needs to keep track of which definitions are labels and which are other. there are only a few things which are affected. most things are fine as they are. BTW is there any trick way for me to do "movd xmm1, rax" with fasm curently? can I do it with a define byte followed by some instruction which it currently accepts? |
|||
17 Aug 2008, 19:47 |
|
LocoDelAssembly 17 Aug 2008, 20:08
Quote:
I think you are right about this. For example, look this funny example Code: use64 virtual at $FFFFFFFFFFFFFF00 someLabel: end virtual someValue = $FFFFFFFFFFFFDEAD mov ebx, someLabel mov eax, someValue I think that fasm should either consider numbers negative ONLY when minus is found or consider labels as an special type of value (unsigned). |
|||
17 Aug 2008, 20:08 |
|
vid 17 Aug 2008, 21:10
same old "no-sign-bit" bug, in my opinion
|
|||
17 Aug 2008, 21:10 |
|
revolution 18 Aug 2008, 02:08
lazer1 wrote: fasm needs to keep track of which definitions are labels and which are other. |
|||
18 Aug 2008, 02:08 |
|
LocoDelAssembly 18 Aug 2008, 02:57
Quote:
But it already does it a little however, for example you are not allowed to XOR a label against a constant on a PE with fixups. I do understand that the XOR example is a sightly different category because the executable would randomly crash instead of having constant behavior (the crash depends on whether the expected virtual address space was satisfied or not), but since fasm already knows (internally) what is a label and what is not, why don't go a step further and add some extra checks and additionally give the programmer the opportunity to check if a symbol is a label or a value? Of course backward compatibility would be broken, but that happened before anyway and was for good. |
|||
18 Aug 2008, 02:57 |
|
revolution 18 Aug 2008, 03:00
Yes, it will do a little bit of hand holding but I meant not the expect it to always do it. One should try to write code/labels etc. in such a way that hand holding won't be needed.
|
|||
18 Aug 2008, 03:00 |
|
Tomasz Grysztar 18 Aug 2008, 06:49
LocoDelAssembly wrote:
This isn't knowing what is a label and what not. It is knowing which symbol is an absolute value, and which is not. Try: Code: symbol = $ for example. All numerical symbols in fasm have the same properties (not counting the ability to redefine the "=" ones), that's one of the principles. |
|||
18 Aug 2008, 06:49 |
|
lazer1 18 Aug 2008, 17:32
revolution wrote: Yes, it will do a little bit of hand holding but I meant not the expect it to always do it. One should try to write code/labels etc. in such a way that hand holding won't be needed. if it CAN hold your hand it SHOULD safe programming occurs at different levels: 1. safe language, well designed languages PREVENT you doing unsafe things, eg Modula 3 is very safe, 2. safe compilation, compiler actively warns on potential unsafe constructs eg "gcc -Wall" 3. programmer level safety: using naming conventions. the problem with long mode "mov eax,ebx" is that it is unsafe at the language level. Most people reading that will assume it just moves ebx to eax. with languages and compilation, THE MORE SAFETY THE BETTER. |
|||
18 Aug 2008, 17:32 |
|
lazer1 18 Aug 2008, 17:38
I have created my own fasm macro for "movd xmm,reg64"
if you want to do "movd xmm,mem64" you need to do it indirectly via a reg64, the macro leaves unchanged any movd which isnt of the above form. here is the macro: Quote:
I havent tried testing the code, but fasm accepts the macro. the bug at the top of the thread also can probably be done this way, as long as all operands are registers. for mem64 args I dont know if those are feasible via macros. |
|||
18 Aug 2008, 17:38 |
|
revolution 18 Aug 2008, 17:47
lazer1 wrote: if it CAN hold your hand it SHOULD Think of some of the seriously terrible HLL's that are hyper-restrictive about what you can and cannot do, they can become a real PItB to use for some tasks. |
|||
18 Aug 2008, 17:47 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.