Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 117 - Program using core.simd does not compile
Summary: Program using core.simd does not compile
Status: RESOLVED WONTFIX
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: 4.8.x
Hardware: x86_64 Linux
: --- normal
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2014-04-08 13:30 CEST by jens.k.mueller
Modified: 2014-05-14 10:45 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jens.k.mueller 2014-04-08 13:30:28 CEST
The following program

void main(string[] args)
{
	import core.simd;
	float4 a = 1, b = 2;
	float4 c = __simd(XMM.ADDSS, a, b);
}

fails to compile with gdc. The compiler aborts with

test.d:5: error: undefined identifier __simd
test.d:5: error: undefined identifier XMM

My running gdc on Linux.
gdc (crosstool-NG hg+unknown-20131212.080758) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How do I generate SSE instructions with gdc?
Comment 1 Iain Buclaw 2014-04-08 13:45:07 CEST
__simd requires the compiler to expose D_SIMD.  Which is not implemented in GDC. And given the nature of the intrinsic, I can't see it ever being introduced.


To access SIMD instructions, instead use the gcc.builtins module.

---
  import gcc.builtins;
  float4 a = 1, b = 2;
  float4 c = __builtin_ia32_addps(a, b);
---


You can get a list of all builtins gdc exposes using:

echo "module gcc.builtins;" > builtins.d && gdc -fsyntax-only -fintfc builtins.d

Then open the file 'builtins.di' for viewing.  There is currently no maintained list of this because what is generated for gcc.builtins may change depending on target or optimisation flags passed to gdc.
Comment 2 jens.k.mueller 2014-05-13 15:32:38 CEST
There is no __builtin_ia32_loadaps with my gdc. I'm using the latest binaries. Is this to be expected? Probably I'm doing something wrong. I cannot find it in the generated builtins.di and gdc says
error: undefined identifier __builtin_ia32_loadaps, did you mean function __builtin_ia32_loadhps.
Comment 3 Iain Buclaw 2014-05-13 18:13:23 CEST
There is no __builtin_ia32_loadaps in GCC either.
Comment 4 Iain Buclaw 2014-05-13 18:24:04 CEST
Quote from (Updated code example for D) https://gcc.gnu.org/ml/gcc-help/2011-06/msg00237.html

"""
The __builtin_ia32_loadaps builtin function was removed and the
documentation is out of date.  The movaps instruction from memory is
easily generated using code like

import core.simd;

float4 loadaps(float4 *p)
{
  return *p;
}
"""
Comment 5 Manu 2014-05-14 03:57:33 CEST
Might I suggest that std.simd exists to wrangle the difference between compilers (and arch/platforms).
It's on dub, or my github. I'll finish it up when I have all the tools required and ideally include in phobos, but what's there is usable now.
Comment 6 Iain Buclaw 2014-05-14 07:41:27 CEST
(In reply to Manu from comment #5)
> Might I suggest that std.simd exists to wrangle the difference between
> compilers (and arch/platforms).
> It's on dub, or my github. I'll finish it up when I have all the tools
> required and ideally include in phobos, but what's there is usable now.

Nice to see that it's well tested too. :)

https://github.com/TurkeyMan/simd/blob/master/std/simd.d#L4224
Comment 7 jens.k.mueller 2014-05-14 08:48:20 CEST
Thanks for the reply. Sorry I'm fairly new to this low-level programming.

I'm looking forward to std.simd. Currently I familiarize myself with this kind of programming. I believe std.simd will be a huge relief. But first I have to feel the "real" pain. Makes me appreciate your work even more and gives me some numbers regarding possible overheads.
Comment 8 Manu 2014-05-14 10:34:48 CEST
Fair enough. Although it's a direct abstraction for most operations, so no overheads. Some algorithms which aren't supported by certain architectures need to be emulated however.
Comment 9 jens.k.mueller 2014-05-14 10:45:15 CEST
Do you have some timeline? I'd like to see it reviewed.