davereg, I would love to see how you could use the XS1 intrinsics in C/C++ do you have a simple example?
PS Obviously XC is a good example of adding the intrinsics to C, what I actually mean is how does one add intrinsics to say C/C++.
regards
Al
OCCAM to XC - Source to Source translator
-
- XCore Legend
- Posts: 1274
- Joined: Thu Dec 10, 2009 10:20 pm
-
- Member++
- Posts: 28
- Joined: Thu Dec 10, 2009 7:25 pm
There are two separate things here:Folknology wrote:davereg, I would love to see how you could use the XS1 intrinsics in C/C++ do you have a simple example?
PS Obviously XC is a good example of adding the intrinsics to C, what I actually mean is how does one add intrinsics to say C/C++.
regards
Al
- llvm-gcc frontend intrinsics
- LLVM backend intrinsics
The llvm-gcc frontend allows you to map what look like function calls into calls to LLVM backend intrinsics, which in general then map to one or a few instructions. The intrinsics we have added to support the XC resources are LLVM backend intrinsics and they have not yet been added to the llvm-gcc frontend; however, it should be straightforward to add these.
Side note : The current C/C++ compiler uses quite an old version of LLVM now, so we won't be able to add the intrinsics to llvm-gcc until we update the LLVM backend which the C/C++ compiler uses. I'm not sure if or when this would happen, but all the source is available so anyone with sufficient llvm-gcc knowledge would be able to add them.
There is also a page on the LLVM wiki which describes a simple way to get intrinsic calls into C code : http://wiki.llvm.org/HowTo:_Call_LLVM_i ... rom_C_code
However, using intrinsics will make portability a problem (of course) and will tie the code to a particular version of the LLVM backend, as there are no guarantees that the intrinsics available will be at all stable.
I wouldn't expect people to use the intrinsics in this way for C/C++ code (because of the portability concerns), but for languages targetting the architecture it's currently the only way to get a compiler to generate code via LLVM to use these features.
-
- Member++
- Posts: 28
- Joined: Thu Dec 10, 2009 7:25 pm
Intrinsics are really just a mapping to a single instruction which otherwise the LLVM bitcode can't really express, so they are building blocks on which the language constructs like par, select and other resource operations are built. They don't give you anything of the syntax, so XC is more different than just C+intrinsics (otherwise adding XC as a language for say the clang frontend would be straightforward, which unfortunately it isn't).Folknology wrote:PS Obviously XC is a good example of adding the intrinsics to C, what I actually mean is how does one add intrinsics to say C/C++.
-
- XCore Legend
- Posts: 1274
- Joined: Thu Dec 10, 2009 10:20 pm
Thanks Dave, I figured there might be a catch. I would love to for example add such XC intrinsics to objective C. How difficult would creating and Objective XC be out of interest?
Update better still "Objective X" or even better "ObjX" ;-)
regards
Al
Update better still "Objective X" or even better "ObjX" ;-)
regards
Al
-
- Member++
- Posts: 28
- Joined: Thu Dec 10, 2009 7:25 pm
For things like channel and port usage, making a thin wrapper around the intrinsics would be pretty straightforward. Par and select are somewhat more complicated since they're not just a one-to-one mapping with intrinsics.Folknology wrote:Thanks Dave, I figured there might be a catch. I would love to for example add such XC intrinsics to objective C. How difficult would creating and Objective XC be out of interest?
Update better still "Objective X" or even better "ObjX" ;-)
regards
Al
Also note that XC does a fair amount of checking at compile-time to ensure that what you are trying to do is safe, so you'd need to replicate that kind of checking. In an environment with pointers and aliasing (which XC lacks) then this is a considerably more difficult problem.
If you stick to the par and select chunks being in XC then it should be doable to use other languages which can target LLVM pretty easily. It really depends what you are trying to achieve with this as to how much effort and the language features you'd push into another language. As mentioned earlier, if you want to do things which are outside the scope of the semantics of XC, such as having dynamically-created threads, then you'll have to create this from scratch using the getr/msync and such intrinsics. The available LLVM sources allow you to play around with this already, and the architecture manual should contain all you need to know about how to set up/break down threads and resources (as well as by building simple examples using the current compilers to look at the generated assembly).
(This is more a general languages question/discussion than the original Occam to XC question now, mind)
-
- XCore Legend
- Posts: 1274
- Joined: Thu Dec 10, 2009 10:20 pm
Thanks Dave
I would like to use the intrinsics/builtins from C (gcc-llvm) can you point me at some documentation so I can do this please?
I have re asked this question in a more appropriate place rather than hijack Jonathan's Occam thread - https://www.xcore.com/forum/viewtopic.p ... sics#p8677
regards
Al
I would like to use the intrinsics/builtins from C (gcc-llvm) can you point me at some documentation so I can do this please?
I have re asked this question in a more appropriate place rather than hijack Jonathan's Occam thread - https://www.xcore.com/forum/viewtopic.p ... sics#p8677
regards
Al