Unknown instruction: xor, sub

22 views
Skip to first unread message

itre...@gmail.com

unread,
May 9, 2011, 5:42:41 PM5/9/11
to asmjit-dev
Hello again—I finally realized I should be zeroing out any variables
in order to use them, but trying to generate a xor or sub results in
an Unknown instruction (3) error, which seems odd. Doing something as
simple as this causes this error:

c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder2<Void, long*,
long*>());
c.getFunction()->setHint(FUNCTION_HINT_NAKED, true);

// function arguments
GPVar stack(c.argGP(0));
GPVar memory(c.argGP(1));

GPVar x1(c.newGP(VARIABLE_TYPE_GPQ));
c.xor_(x1, x1);

For what it's worth, I'm using trunk 1.0, on OS X 64-bit. Any
suggestions? Thanks so much again for this wonderful project!

; Function Prototype:
;
; IDX| Type | Sz | Home |
; ---+----------+----+----------------+
; 0 | GP.Q | 8 | rdi |
; 1 | GP.Q | 8 | rsi |
;
; Variables:
;
; ID | Type | Sz | Home | Register Access | Memory
Access |
; ---+----------+----+----------------+-------------------
+-------------------+
; 0 | GP.Q | 8 | [None] | r=2 w=0 x=0 | r=0
w=0 x=0 |
; 1 | GP.Q | 8 | [None] | r=0 w=0 x=0 | r=0
w=0 x=0 |
; 2 | GP.Q | 8 | [None] | r=1 w=0 x=1 | r=0
w=0 x=0 |
;
; Modified registers (3):
; GP : rcx, rsi, rdi
; MM :
; XMM:

L.0:
; Prolog
; Body
*** ASSEMBLER ERROR: Unknown instruction (3).
L.1:
; Epilog
*** COMPILER ERROR: Unknown instruction (3).
Error making jit function (3).

Petr Kobalíček

unread,
May 9, 2011, 7:10:50 PM5/9/11
to asmji...@googlegroups.com
Hi,

I tested your code under 64-bit Linux and it works for me, the output:

; Function Prototype:
;
; IDX| Type | Sz | Home |
; ---+----------+----+----------------+
; 0 | GP.Q | 8 | rdi |
; 1 | GP.Q | 8 | rsi |
;
; Variables:
;
; ID | Type | Sz | Home | Register Access | Memory Access |
; ---+----------+----+----------------+-------------------+-------------------+

; 0 | GP.Q | 8 | [None] | r=0 w=0 x=0 | r=0 w=0 x=0 |


; 1 | GP.Q | 8 | [None] | r=0 w=0 x=0 | r=0 w=0 x=0 |

; 2 | GP.Q | 8 | [None] | r=0 w=0 x=1 | r=0 w=0 x=0 |


;
; Modified registers (3):
; GP : rcx, rsi, rdi
; MM :
; XMM:

L.0:
; Prolog
; Body
xor rcx, rcx
L.1:
; Epilog
ret
*** COMPILER SUCCESS - Wrote 4 bytes, code: 4, trampolines: 0.

Could you post your full code please? Maybe there is something else wrong.

Best regards
Petr Kobalicek

Petr Kobalíček

unread,
May 9, 2011, 7:12:58 PM5/9/11
to asmji...@googlegroups.com
Btw, my testing code (from skeleton):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <AsmJit/Compiler.h>
#include <AsmJit/Logger.h>
#include <AsmJit/MemoryManager.h>

// This is type of function we will generate
typedef void (*MyFn)(long*, long*);

int main(int argc, char* argv[])
{
using namespace AsmJit;

// Create compiler.
Compiler c;

// Log compiler output.
FileLogger logger(stderr);
c.setLogger(&logger);

c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder2<Void, long*, long*>());
c.getFunction()->setHint(FUNCTION_HINT_NAKED, true);

GPVar stack(c.argGP(0));
GPVar memory(c.argGP(1));

GPVar x1(c.newGP(VARIABLE_TYPE_GPQ));
c.xor_(x1, x1);
c.endFunction();

// Make the function.
MyFn fn = function_cast<MyFn>(c.make());

// Call it.
// printf("Result %llu\n", (unsigned long long)fn());

// Free the generated function if it's not needed anymore.
MemoryManager::getGlobal()->free((void*)fn);

return 0;
}

Best regards
Petr Kobalicek

itre...@gmail.com

unread,
May 10, 2011, 12:03:21 AM5/10/11
to asmjit-dev
Thank you for the example! I tried compiling it against trunk/1.0 on
my system, but I see a similar error as to my original issue. I'm
running on OS X, 64-bit, which doesn't seem to be a supported/test
platform, but I'm happy to dig through this issue. Could it be some
missing definitions in that the platform isn't correctly being
identified? I'll try my code in Linux 64-bit too, to see if that helps
resolve the issue.

Thanks again!

; Function Prototype:
;
; IDX| Type | Sz | Home |
; ---+----------+----+----------------+
; 0 | GP.Q | 8 | rdi |
; 1 | GP.Q | 8 | rsi |
;
; Variables:
;
; ID | Type | Sz | Home | Register Access | Memory
Access |
; ---+----------+----+----------------+-------------------
+-------------------+
; 0 | GP.Q | 8 | [None] | r=0 w=0 x=0 | r=0
w=0 x=0 |
; 1 | GP.Q | 8 | [None] | r=0 w=0 x=0 | r=0
w=0 x=0 |
; 2 | GP.Q | 8 | [None] | r=1 w=0 x=1 | r=0
w=0 x=0 |
;
; Modified registers (3):
; GP : rcx, rsi, rdi
; MM :
; XMM:

L.0:
; Prolog
; Body
*** ASSEMBLER ERROR: Unknown instruction (3).
L.1:
; Epilog
*** COMPILER ERROR: Unknown instruction (3).


> > ; ---+----------+----+----------------+-------------------+------------------ -+
> > ; 0  | GP.Q     | 8  | [None]         | r=0   w=0   x=0   | r=0   w=0   x=0   |
> > ; 1  | GP.Q     | 8  | [None]         | r=0   w=0   x=0   | r=0   w=0   x=0   |
> > ; 2  | GP.Q     | 8  | [None]         | r=0   w=0   x=1   | r=0   w=0   x=0   |
> > ;
> > ; Modified registers (3):
> > ; GP : rcx, rsi, rdi
> > ; MM :
> > ; XMM:
>
> > L.0:
> > ; Prolog
> > ; Body
> > xor rcx, rcx
> > L.1:
> > ; Epilog
> > ret
> > *** COMPILER SUCCESS - Wrote 4 bytes, code: 4, trampolines: 0.
>
> > Could you post your full code please? Maybe there is something else wrong.
>
> > Best regards
> > Petr Kobalicek
>

Petr Kobalíček

unread,
May 10, 2011, 3:59:44 AM5/10/11
to asmji...@googlegroups.com
Hi,

could you send me the output of this?

#if defined(ASMJIT_X86)
printf("x86\n");
#endif

#if defined(ASMJIT_X64)
printf("x64\n");
#endif

printf("%d", (int)sizeof(void*))

Maybe it's only 64-bit detection issue. I'm guessing only.

Best regards
Petr Kobalicek

itre...@gmail.com

unread,
May 10, 2011, 4:47:32 AM5/10/11
to asmjit-dev
Sure! That outputs "x64 8". I have just confirmed that the exact same
code works fine on 64-bit Linux, so it must be OS X related? If
there's any more debug information I can provide, I'm happy to. I'll
also keep poking around the source for more details. Thanks again!

On May 10, 12:59 am, Petr Kobalíček <kobalicek.p...@gmail.com> wrote:
> Hi,
>

Petr Kobalíček

unread,
May 10, 2011, 7:30:02 AM5/10/11
to asmji...@googlegroups.com
I'm going to test it under mac, but it will be tomorrow, so wait:)

BTW: It seems that you are using release build, maybe switching to
debug will trigger some assertion.

Best regards
Petr Kobalicek

itre...@gmail.com

unread,
May 10, 2011, 4:36:50 PM5/10/11
to asmjit-dev
Ooops. It turns out I have an older version in my path. Fixing for the
proper version fixes the problem. JITing is working just fine on 64-
bit OS X. Hope I didn't waste too much of your time! Thanks for the
help, and the project!

Petr Kobalíček

unread,
May 10, 2011, 5:10:01 PM5/10/11
to asmji...@googlegroups.com
Nice to hear,

so I can add mac-os-x 64 bit as a supported platform on the home-page ;-)

Thanks!
Petr Kobalicek

Reply all
Reply to author
Forward
0 new messages