ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

intrinsics.c (2096B)


      1 #define FORCE_INLINE inline __attribute__((always_inline))
      2 
      3 /* TODO(rnp): msvc probably won't build this but there are other things preventing that as well */
      4 #define clz_u32(a)  __builtin_clz(a)
      5 #define ctz_u32(a)  __builtin_ctz(a)
      6 #define sqrt_f32(a) __builtin_sqrtf(a)
      7 
      8 #ifdef __ARM_ARCH_ISA_A64
      9 /* TODO? debuggers just loop here forever and need a manual PC increment (step over) */
     10 #define debugbreak() asm volatile ("brk 0xf000")
     11 
     12 /* NOTE(rnp): we are only doing a handful of f32x4 operations so we will just use NEON and do
     13  * the macro renaming thing. If you are implementing a serious wide vector operation you should
     14  * use SVE(2) instead. The semantics are different however and the code will be written for an
     15  * arbitrary vector bit width. In that case you will also need x86_64 code for determining
     16  * the supported vector width (ideally at runtime though that may not be possible).
     17  */
     18 #include <arm_neon.h>
     19 typedef float32x4_t f32x4;
     20 typedef int32x4_t   i32x4;
     21 
     22 #define cvt_i32x4_f32x4(a)    vcvtq_f32_s32(a)
     23 #define cvt_f32x4_i32x4(a)    vcvtq_s32_f32(a)
     24 #define dup_f32x4(f)          vdupq_n_f32(f)
     25 #define load_f32x4(a)         vld1q_f32(a)
     26 #define load_i32x4(a)         vld1q_s32(a)
     27 #define mul_f32x4(a, b)       vmulq_f32(a, b)
     28 #define set_f32x4(a, b, c, d) vld1q_f32((f32 []){d, c, b, a})
     29 #define sqrt_f32x4(a)         vsqrtq_f32(a)
     30 #define store_f32x4(a, o)     vst1q_f32(o, a)
     31 #define store_i32x4(a, o)     vst1q_s32(o, a)
     32 
     33 #elif __x86_64__
     34 #include <immintrin.h>
     35 typedef __m128  f32x4;
     36 typedef __m128i i32x4;
     37 
     38 #define cvt_i32x4_f32x4(a)    _mm_cvtepi32_ps(a)
     39 #define cvt_f32x4_i32x4(a)    _mm_cvtps_epi32(a)
     40 #define dup_f32x4(f)          _mm_set1_ps(f)
     41 #define load_f32x4(a)         _mm_loadu_ps(a)
     42 #define load_i32x4(a)         _mm_loadu_si128((i32x4 *)a)
     43 #define mul_f32x4(a, b)       _mm_mul_ps(a, b)
     44 #define set_f32x4(a, b, c, d) _mm_set_ps(a, b, c, d)
     45 #define sqrt_f32x4(a)         _mm_sqrt_ps(a)
     46 #define store_f32x4(a, o)     _mm_storeu_ps(o, a)
     47 #define store_i32x4(a, o)     _mm_storeu_si128((i32x4 *)o, a)
     48 
     49 #define debugbreak() asm volatile ("int3; nop")
     50 
     51 #endif