user2214913
user2214913

Reputation: 1501

how to make simple float4 add in gcc/mingw inline assembly

I need to get something like this probably but in strange GCC inline assembly

void add4(float* a, float* b, float* out) 
{ 
  mov edx, [esp+4] 
  movaps  xmm0, oword [edx+0]   
  mov edx, [esp+8] 
  movaps  xmm1, oword [edx+0]   
  addps  xmm0, xmm1 
  mov edx, [esp+12] 
  movaps oword [edx+0], xmm0 
  ret 
} 

1) one topic is how to pack this in gcc inline syntax 2) second topic is how to rewrite it (maybe getting rid of explicit memory access) to make such inlined routine well integrate with surrounding GCC (mingw32) code

Upvotes: 0

Views: 151

Answers (1)

Drew McGowen
Drew McGowen

Reputation: 11706

There are two ways to do this.

The first way would be to use the asm keyword to include inline assembly as a literal string. You can also pass in the function parameters, and GCC will generate the necessary code to access them. This will save you from having to manually use the memory accesses, especially when dealing with different calling convention. This is the general way for embedding assembly in C functions.

The second way, which is more specific to what you're trying to do, is to use SSE intrinsics (provided by <xmmintrin.h>. The resulting code looks like normal C function calls, but the compiler will generate the corresponding instructions instead of a bunch of function calls. See the Intel Intrinsics Guide for more info on how to use these intrinsics.

Upvotes: 1

Related Questions