Comments (15)
#if defined(_M_X64) || defined(__amd64__) // 64-bit
typedef XmmReg FloatingReg;
#else // not 64-bit (hopefully 32-bit)
typedef FpReg FloatingReg;
#endif
from asmjit.
Unfortunately, it goes a lot deeper than that. You have to call completely different methods depending on what type of registers you're using. For example, if you're using Fp registers then you call fadd() to do addition, but if you're using Xmm registers then you call addsd().
from asmjit.
#if defined(_M_X64) || defined(__amd64__) // 64-bit
typedef XmmReg FloatingReg;
inline void addf(X86Assembler& a, FloatingReg& dst, FloatingReg& src) { a.addsd(dst, src); }
// repeat for other operations
#else // not 64-bit (hopefully 32-bit)
typedef FpReg FloatingReg;
inline void addf(X86Assembler& a, FloatingReg& dst, FloatingReg& src) { a.fadd(dst, src); }
// repeat for other operations
#endif
from asmjit.
Yes, I could write a completely new API that wraps AsmJit and provides an ABI agnostic interface. I was hoping there was a way to accomplish this without having to do that. :)
from asmjit.
I would go with SSE2 plus handling only differences in ABI. Asmjit::Compiler can help with that, but it's also fine in raw Assembler mode.
You can probably write your own abstractions on top of asmjit, which can help you with FPU/SSE, but such abstractions are not trivial as FPU provides a lot of things SSE doesn't and vice versa.
I'm currently not planning to develop any abstractions on top of asmjit as there is already LLVM, which does nice job when it comes to universality.
I think that x87 FPU is deprecated anyway, it's maybe a huge waste of time to even think of it :-)
from asmjit.
I would go with SSE2 plus handling only differences in ABI.
Could you explain what you mean? For example, if I tell it to use SSE registers for floating point values but I compile in 32 bit mode, then arguments don't get passed correctly to functions. How do I make that happen correctly?
from asmjit.
Well, this is what I meant by handling ABI differences. There is a class in asmjit called X86FuncDecl
, which can be used to map argument to register or stack location. If you use only SSE2 the only problem would be to handle functions returning floating point (xmm0
in 64-bit mode and fp0
in 32-bit mode).
from asmjit.
How do I do that? To give a concrete example, here's a utility function I've written. It generates calls to functions that take a double as their argument and return a double.
void generateSingleArgCall(X86Compiler& c, X86XmmVar& dest, X86XmmVar& arg, double (*function)(double)) {
X86GpVar fn(c, kVarTypeIntPtr);
c.mov(fn, imm_ptr((void*) function));
X86CallNode* call = c.call(fn, kFuncConvHost, FuncBuilder1<double, double>());
call->setArg(0, arg);
call->setRet(0, dest);
}
I see that X86Compiler::call() returns an X86CallNode, whose getDecl() method returns an X86FuncDecl. So I take it that it's already handling the arguments correctly? What do I need to add to get the return value into dest?
from asmjit.
Actually returning a float/double is still an issue in 32-bit mode, the oldest open Issue #3 is not closed by because of this. I didn't fix this simply because I have never needed to return float/double from Compiler, but yeah, I should finally fix this one.
However, function parameters (float / double) should be handled properly in both 32-bit and 64-bit modes.
from asmjit.
If you can make returning floating point values work, that would be awesome. My application is all about floating point. More specifically, I'm adding JIT support to Lepton (https://simtk.org/home/lepton) for use in OpenMM (https://simtk.org/home/openmm).
from asmjit.
Yeah, I will definitely take a look and update the issue
from asmjit.
Peastman: Returning is now supported, I'm closing this for now as there is currently nothing to fix.
from asmjit.
That's great news! I'll give it a try.
from asmjit.
Using the latest version of asmjit from the repository and compiling in 32 bit mode, my program crashes when I try to execute the compiled code. If I compile in 64 bit mode it still works fine.
Is identical code supposed to work in both modes? Or do I need to do something differently in 32 bit mode?
from asmjit.
It should work the same, it's a bug if it doesn't.
I have just added this feature recently so it's possible it's still buggy, if you have any code that crashes fill a new issue and I will try to fix it.
from asmjit.
Related Issues (20)
- How can I convert a byte array to assembly code? HOT 3
- parse "faddp st1, st0" and "fsubp st1, st0" instruction failed HOT 1
- Unexpected error when load label address to register in AArch64 HOT 3
- InvalidDisplacement error when use loop instruction HOT 3
- Calling void function on a64 (android) not working HOT 2
- LAHF issue with x86_64 compiler HOT 2
- Return "Segmentation fault" when use std instruction HOT 4
- Jmp to label size HOT 3
- How to load the address of a label to a register? HOT 1
- "memfd_create() called without MFD_EXEC or MFD_NOEXEC_SEAL set" HOT 9
- No matter what I do. I am not able to get it working in my C++ CLI project. HOT 3
- Build Problem: Android Ndk build failed HOT 1
- Invalid movzx instruction generated by x86 EmitHelper::emitArgMove HOT 8
- Liveness analysis differs in Release mode vs Debug mode HOT 19
- calling names when use call instruction HOT 2
- Are the generated ISA databases still in the public domain? HOT 3
- Ports Meta Issue
- mov eax,[r11+rcx*4+00004C28] how? HOT 2
- [BUG] jmp far & call far (FF25 00000000 ptr & FF15 02000000 ptr) HOT 7
- The correctness question of InstInfo for sub and sub instructions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asmjit.