brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.6 KiB · 2ae4bc8 Raw
127 lines · c
1// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s2// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s3// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s4// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror | FileCheck %s5 6// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s7// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s8// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s9// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin -target-feature +f16c -emit-llvm -o - -Wall -Werror -fexperimental-new-constant-interpreter | FileCheck %s10 11 12#include <immintrin.h>13#include "builtin_test_helpers.h"14 15float test_cvtsh_ss(unsigned short a) {16  // CHECK-LABEL: test_cvtsh_ss17  // CHECK: [[CONV:%.*]] = fpext half %{{.*}} to float18  // CHECK: ret float [[CONV]]19  return _cvtsh_ss(a);20}21 22TEST_CONSTEXPR(_cvtsh_ss(0x0000) == 0.0f);23TEST_CONSTEXPR(_cvtsh_ss(0x4500) == 5.0f);24TEST_CONSTEXPR(_cvtsh_ss(0xC000) == -2.0f);25 26unsigned short test_cvtss_sh(float a) {27  // CHECK-LABEL: test_cvtss_sh28  // CHECK: insertelement <4 x float> poison, float %{{.*}}, i32 029  // CHECK: insertelement <4 x float> %{{.*}}, float 0.000000e+00, i32 130  // CHECK: insertelement <4 x float> %{{.*}}, float 0.000000e+00, i32 231  // CHECK: insertelement <4 x float> %{{.*}}, float 0.000000e+00, i32 332  // CHECK: call <8 x i16> @llvm.x86.vcvtps2ph.128(<4 x float> %{{.*}}, i32 0)33  // CHECK: extractelement <8 x i16> %{{.*}}, i32 034  return _cvtss_sh(a, 0);35}36 37TEST_CONSTEXPR(match_m128(38    _mm_cvtph_ps(_mm_setr_epi16(0x3C00, 0x4000, 0x4200, 0x4400, 0, 0, 0, 0)), 39    1.0f, 2.0f, 3.0f, 4.0f40));41 42__m128 test_mm_cvtph_ps(__m128i a) {43  // CHECK-LABEL: test_mm_cvtph_ps44  // CHECK: shufflevector <8 x i16> %{{.*}}, <8 x i16> %{{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>45  // CHECK: fpext <4 x half> %{{.*}} to <4 x float>46  return _mm_cvtph_ps(a);47}48 49// A value exactly halfway between 1.0 and the next representable FP16 number.50// In binary, its significand ends in ...000, followed by a tie-bit 1.51#define POS_HALFWAY (1.0f + 0.00048828125f) // 1.0 + 2^-11, a tie-breaking case52 53//54// _mm_cvtps_ph (128-bit, 4 floats -> 8 shorts, 4 are zero-padded)55//56// Test values: -2.5f, 1.123f, POS_HALFWAY57TEST_CONSTEXPR(match_v8hi(58  _mm_cvtps_ph(_mm_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_NEAREST_INT),59  0xC100, 0x3C7E, 0x3C00, 0x0000, 0, 0, 0, 060));61TEST_CONSTEXPR(match_v8hi(62  _mm_cvtps_ph(_mm_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_NEG_INF),63  0xC100, 0x3C7D, 0x3C00, 0x0000, 0, 0, 0, 064));65TEST_CONSTEXPR(match_v8hi(66  _mm_cvtps_ph(_mm_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_POS_INF),67  0xC100, 0x3C7E, 0x3C01, 0x0000, 0, 0, 0, 068));69TEST_CONSTEXPR(match_v8hi(70  _mm_cvtps_ph(_mm_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_ZERO),71  0xC100, 0x3C7D, 0x3C00, 0x0000, 0, 0, 0, 072));73 74__m256 test_mm256_cvtph_ps(__m128i a) {75  // CHECK-LABEL: test_mm256_cvtph_ps76  // CHECK: fpext <8 x half> %{{.*}} to <8 x float>77  return _mm256_cvtph_ps(a);78}79TEST_CONSTEXPR(match_m256(80    _mm256_cvtph_ps(_mm_setr_epi16(0x3C00, 0x4000, 0x4200, 0x4400, 0x4500, 0x3800, 0xC000, 0x0000)), 81    1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 0.5f, -2.0f, 0.0f82));83 84//85// _mm256_cvtps_ph (256-bit, 8 floats -> 8 shorts)86//87// Test values: -2.5f, 1.123f, POS_HALFWAY88TEST_CONSTEXPR(match_v8hi(89  _mm256_cvtps_ph(_mm256_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f, -2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_NEAREST_INT),90  0xC100, 0x3C7E, 0x3C00, 0x0000, 0xC100, 0x3C7E, 0x3C00, 0x000091));92TEST_CONSTEXPR(match_v8hi(93  _mm256_cvtps_ph(_mm256_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f, -2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_NEG_INF),94  0xC100, 0x3C7D, 0x3C00, 0x0000, 0xC100, 0x3C7D, 0x3C00, 0x000095));96TEST_CONSTEXPR(match_v8hi(97  _mm256_cvtps_ph(_mm256_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f, -2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_POS_INF),98  0xC100, 0x3C7E, 0x3C01, 0x0000, 0xC100, 0x3C7E, 0x3C01, 0x000099));100TEST_CONSTEXPR(match_v8hi(101  _mm256_cvtps_ph(_mm256_setr_ps(-2.5f, 1.123f, POS_HALFWAY, 0.0f, -2.5f, 1.123f, POS_HALFWAY, 0.0f), _MM_FROUND_TO_ZERO),102  0xC100, 0x3C7D, 0x3C00, 0x0000, 0xC100, 0x3C7D, 0x3C00, 0x0000103));104 105__m128i test_mm_cvtps_ph(__m128 a) {106  // CHECK-LABEL: test_mm_cvtps_ph107  // CHECK: call <8 x i16> @llvm.x86.vcvtps2ph.128(<4 x float> %{{.*}}, i32 0)108  return _mm_cvtps_ph(a, 0);109}110 111//112// Tests for Exact Dynamic Rounding113//114// Test that dynamic rounding SUCCEEDS for exactly representable values.115// We use _MM_FROUND_CUR_DIRECTION (value 4) to specify dynamic rounding.116// Inputs: -2.5f, 0.125f, -16.0f are all exactly representable in FP16.117TEST_CONSTEXPR(match_v8hi(118  __builtin_ia32_vcvtps2ph256(_mm256_setr_ps(-2.5f, 0.125f, -16.0f, 0.0f, -2.5f, 0.125f, -16.0f, 0.0f), _MM_FROUND_CUR_DIRECTION),119  0xC100, 0x3000, 0xCC00, 0x0000, 0xC100, 0x3000, 0xCC00, 0x0000120));121 122__m128i test_mm256_cvtps_ph(__m256 a) {123  // CHECK-LABEL: test_mm256_cvtps_ph124  // CHECK: call <8 x i16> @llvm.x86.vcvtps2ph.256(<8 x float> %{{.*}}, i32 0)125  return _mm256_cvtps_ph(a, 0);126}127