// Copyright 2024 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/lang/core/fluent_types.h"
#include "src/tint/lang/core/ir/function.h"
#include "src/tint/lang/core/number.h"
#include "src/tint/lang/hlsl/writer/helper_test.h"

#include "gtest/gtest.h"

using namespace tint::core::fluent_types;     // NOLINT
using namespace tint::core::number_suffixes;  // NOLINT

namespace tint::hlsl::writer {
namespace {

TEST_F(HlslWriterTest, BitcastIdentityNumeric) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", 1_i);
        b.Let("bc", b.Bitcast<i32>(b.Load(a)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
void foo() {
  int a = 1;
  int bc = a;
}

)");
}

TEST_F(HlslWriterTest, BitcastIdentityVec) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", b.Construct<vec2<f32>>(1_f, 2_f));
        b.Let("bc", b.Bitcast<vec2<f32>>(b.Load(a)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
void foo() {
  float2 a = float2(1.0f, 2.0f);
  float2 bc = a;
}

)");
}

TEST_F(HlslWriterTest, BitcastToFloat) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", 1_i);
        b.Let("bc", b.Bitcast<f32>(b.Load(a)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
void foo() {
  int a = 1;
  float bc = asfloat(a);
}

)");
}

TEST_F(HlslWriterTest, BitcastToInt) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", 1_u);
        b.Let("bc", b.Bitcast<i32>(b.Load(a)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
void foo() {
  uint a = 1u;
  int bc = asint(a);
}

)");
}

TEST_F(HlslWriterTest, BitcastToUint) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", 1_i);
        b.Let("bc", b.Bitcast<u32>(b.Load(a)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
void foo() {
  int a = 1;
  uint bc = asuint(a);
}

)");
}

TEST_F(HlslWriterTest, BitcastFromVec2F16) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", b.Construct<vec2<f16>>(1_h, 2_h));
        auto* z = b.Load(a);
        b.Let("b", b.Bitcast<i32>(z));
        b.Let("c", b.Bitcast<f32>(z));
        b.Let("d", b.Bitcast<u32>(z));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
uint tint_bitcast_from_f16_2(vector<float16_t, 2> src) {
  uint2 r = f32tof16(float2(src));
  return ((r.x & 65535u) | ((r.y & 65535u) << 16u));
}

float tint_bitcast_from_f16_1(vector<float16_t, 2> src) {
  uint2 r = f32tof16(float2(src));
  return asfloat(((r.x & 65535u) | ((r.y & 65535u) << 16u)));
}

int tint_bitcast_from_f16(vector<float16_t, 2> src) {
  uint2 r = f32tof16(float2(src));
  return asint(((r.x & 65535u) | ((r.y & 65535u) << 16u)));
}

void foo() {
  vector<float16_t, 2> a = vector<float16_t, 2>(float16_t(1.0h), float16_t(2.0h));
  int b = tint_bitcast_from_f16(a);
  float c = tint_bitcast_from_f16_1(a);
  uint d = tint_bitcast_from_f16_2(a);
}

)");
}

TEST_F(HlslWriterTest, BitcastToVec2F16) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", 1_i);
        b.Let("b", b.Bitcast<vec2<f16>>(b.Load(a)));

        auto* c = b.Var("c", 1_f);
        b.Let("d", b.Bitcast<vec2<f16>>(b.Load(c)));

        auto* e = b.Var("e", 1_u);
        b.Let("f", b.Bitcast<vec2<f16>>(b.Load(e)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
vector<float16_t, 2> tint_bitcast_to_f16_2(uint src) {
  uint v = src;
  float t_low = f16tof32((v & 65535u));
  float t_high = f16tof32(((v >> 16u) & 65535u));
  return vector<float16_t, 2>(t_low.x, t_high.x);
}

vector<float16_t, 2> tint_bitcast_to_f16_1(float src) {
  uint v = asuint(src);
  float t_low = f16tof32((v & 65535u));
  float t_high = f16tof32(((v >> 16u) & 65535u));
  return vector<float16_t, 2>(t_low.x, t_high.x);
}

vector<float16_t, 2> tint_bitcast_to_f16(int src) {
  uint v = asuint(src);
  float t_low = f16tof32((v & 65535u));
  float t_high = f16tof32(((v >> 16u) & 65535u));
  return vector<float16_t, 2>(t_low.x, t_high.x);
}

void foo() {
  int a = 1;
  vector<float16_t, 2> b = tint_bitcast_to_f16(a);
  float c = 1.0f;
  vector<float16_t, 2> d = tint_bitcast_to_f16_1(c);
  uint e = 1u;
  vector<float16_t, 2> f = tint_bitcast_to_f16_2(e);
}

)");
}

TEST_F(HlslWriterTest, BitcastFromVec4F16) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", b.Construct<vec4<f16>>(1_h, 2_h, 3_h, 4_h));
        auto* z = b.Load(a);
        b.Let("b", b.Bitcast<vec2<i32>>(z));
        b.Let("c", b.Bitcast<vec2<f32>>(z));
        b.Let("d", b.Bitcast<vec2<u32>>(z));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
uint2 tint_bitcast_from_f16_2(vector<float16_t, 4> src) {
  uint4 r = f32tof16(float4(src));
  return uint2(((r.x & 65535u) | ((r.y & 65535u) << 16u)), ((r.z & 65535u) | ((r.w & 65535u) << 16u)));
}

float2 tint_bitcast_from_f16_1(vector<float16_t, 4> src) {
  uint4 r = f32tof16(float4(src));
  return asfloat(uint2(((r.x & 65535u) | ((r.y & 65535u) << 16u)), ((r.z & 65535u) | ((r.w & 65535u) << 16u))));
}

int2 tint_bitcast_from_f16(vector<float16_t, 4> src) {
  uint4 r = f32tof16(float4(src));
  return asint(uint2(((r.x & 65535u) | ((r.y & 65535u) << 16u)), ((r.z & 65535u) | ((r.w & 65535u) << 16u))));
}

void foo() {
  vector<float16_t, 4> a = vector<float16_t, 4>(float16_t(1.0h), float16_t(2.0h), float16_t(3.0h), float16_t(4.0h));
  int2 b = tint_bitcast_from_f16(a);
  float2 c = tint_bitcast_from_f16_1(a);
  uint2 d = tint_bitcast_from_f16_2(a);
}

)");
}

TEST_F(HlslWriterTest, BitcastToVec4F16) {
    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
    b.Append(func->Block(), [&] {
        auto* a = b.Var("a", b.Construct<vec2<i32>>(1_i, 2_i));
        b.Let("b", b.Bitcast<vec4<f16>>(b.Load(a)));

        auto* c = b.Var("c", b.Construct<vec2<f32>>(1_f, 2_f));
        b.Let("d", b.Bitcast<vec4<f16>>(b.Load(c)));

        auto* e = b.Var("e", b.Construct<vec2<u32>>(1_u, 2_u));
        b.Let("f", b.Bitcast<vec4<f16>>(b.Load(e)));
        b.Return(func);
    });

    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
    EXPECT_EQ(output_.hlsl, R"(
vector<float16_t, 4> tint_bitcast_to_f16_2(uint2 src) {
  uint2 v = src;
  uint2 mask = (65535u).xx;
  uint2 shift = (16u).xx;
  float2 t_low = f16tof32((v & mask));
  float2 t_high = f16tof32(((v >> shift) & mask));
  return vector<float16_t, 4>(t_low.x, t_high.x, t_low.y, t_high.y);
}

vector<float16_t, 4> tint_bitcast_to_f16_1(float2 src) {
  uint2 v = asuint(src);
  uint2 mask = (65535u).xx;
  uint2 shift = (16u).xx;
  float2 t_low = f16tof32((v & mask));
  float2 t_high = f16tof32(((v >> shift) & mask));
  return vector<float16_t, 4>(t_low.x, t_high.x, t_low.y, t_high.y);
}

vector<float16_t, 4> tint_bitcast_to_f16(int2 src) {
  uint2 v = asuint(src);
  uint2 mask = (65535u).xx;
  uint2 shift = (16u).xx;
  float2 t_low = f16tof32((v & mask));
  float2 t_high = f16tof32(((v >> shift) & mask));
  return vector<float16_t, 4>(t_low.x, t_high.x, t_low.y, t_high.y);
}

void foo() {
  int2 a = int2(1, 2);
  vector<float16_t, 4> b = tint_bitcast_to_f16(a);
  float2 c = float2(1.0f, 2.0f);
  vector<float16_t, 4> d = tint_bitcast_to_f16_1(c);
  uint2 e = uint2(1u, 2u);
  vector<float16_t, 4> f = tint_bitcast_to_f16_2(e);
}

)");
}

}  // namespace
}  // namespace tint::hlsl::writer
