[pixel shader]
uniform float2 a;

float4 main() : SV_TARGET
{
    float x = +a.x;
    float y = a.y;
    return float4(x + y, x - y, x * y, -y);
}

[test]
uniform 0 float4 0.05 0.15 0.0 0.0
draw quad
probe (0, 0) rgba (0.20, -0.10, 0.0075, -0.15) 1


% 1.x has no division or modulo.
[pixel shader notimpl(sm<2)]
uniform float2 a;

float4 main() : SV_TARGET
{
    float x = a.x;
    float y = a.y;
    return float4(x / y, -x / y, x / -y, -x / -y);
}

[test]
uniform 0 float4 42.0 5.0 0.0 0.0
draw quad
probe (0, 0) rgba (8.4, -8.4, -8.4, 8.4) 16


[pixel shader fail(sm<2)]
uniform float2 a;

float4 main() : SV_TARGET
{
    float x = a.x;
    float y = a.y;
    return float4(x % y, -x % y, x % -y, -x % -y);
}

[test]
uniform 0 float4 42.0 5.0 0.0 0.0
draw quad
probe (0, 0) f32(2.0, -2.0, 2.0, -2.0) 16

[pixel shader fail(sm<2)]
uniform float2 a;

float4 main() : SV_TARGET
{
    float x = a.x;
    float y = a.y;
    return float4(x % y, -x % y, x % -y, -x % -y);
}

[test]
uniform 0 float4 45.0 5.0 0.0 0.0
draw quad
probe (0, 0) f32(0.0, 0.0, 0.0, 0.0)

[pixel shader fail(sm<2)]
float4 x, y;

float4 main() : sv_target
{
    return x % y;
}

[test]
uniform 0 float4 5.0 -42.1 4.0 45.0
uniform 4 float4 15.0 -5.0 4.1 5.0
draw quad
probe (0, 0) f32(5.0, -2.1, 4.0, 0.0) 6

[pixel shader notimpl(sm<2)]
uniform float2 a;

float4 main() : SV_TARGET
{
    float x = a.x;
    float y = a.y;
    return x / y;
}

[test]
uniform 0 float4 1.0 0.0 0.0 0.0
draw quad
probe (0, 0) f32(inf, inf, inf, inf)

% d3dx9/d3dcompiler < 41 does not have mad().
[pixel shader fail(sm<2)]
uniform float4 a, b, c;

float4 main() : sv_target
{
    return mad(a, b, c);
}

[test]
uniform 0 float4 1.00000007 -42.1 4.0 45.0
uniform 4 float4 1.625 -5.0 4.125 5.0
uniform 8 float4 1.00000007 -1.0 0.5 -0.5
draw quad
probe (0, 0) rgba (2.62500024, 209.5, 17.0, 224.5) 1

% precise mad() is not allowed to fuse, even though unfused is less precise.
[pixel shader fail(sm<2)]
uniform float4 a, b, c;

float4 main() : sv_target
{
    precise float4 ret = mad(a, b, c);
    return ret;
}

[test]
uniform 0 float4 1.00000007 -42.1 4.0 45.0
uniform 4 float4 1.625 -5.0 4.125 5.0
uniform 8 float4 1.00000007 -1.0 0.5 -0.5
todo(msl & sm>=6) draw quad
probe (0, 0) rgba (2.62500048, 209.5, 17.0, 224.5) 1

[pixel shader]
uniform float4 a;

float4 main() : sv_target
{
    return float4(abs(abs(a.x)), abs(-a.y), -(-a.z), 0);
}

[test]
uniform 0 float4 -1.0 -2.0 -3.0 0.0
draw quad
probe (0, 0) f32(1.0, 2.0, -3.0, 0.0)

[pixel shader]
uniform float4 a;

float4 main() : sv_target
{
    float4 ret;
    ret.x = floor(floor(a.x));
    ret.y = floor(ceil(a.y));
    ret.z = ceil(floor(a.z));
    ret.w = ceil(ceil(a.w));
    return ret;
}

[test]
uniform 0 float4 1.5 1.5 -1.5 -1.5
draw quad
probe (0, 0) f32(1.0, 2.0, -2.0, -1.0)

% precise mad() where the first component is not x.
[pixel shader fail(sm<2)]
uniform float4 a, b, c;

float4 main() : sv_target
{
    precise float4 r = float4(c.zw * c.zw, mad(b.xy, b.zw, c.xy));

    return r * a;
}

[test]
uniform 0 float4 1.5 1.5 1.5 1.5
uniform 4 float4 1.00000007 -42.1 1.625 -5.0
uniform 8 float4 1.00000007 -1.0 2.0 2.0
todo(msl & sm>=6) draw quad
probe (0, 0) f32(6.0, 6.0, 3.93750072, 314.25) 1

[require]
shader model >= 5.0
shader model < 5.1

[pixel shader dxbc-tpf-hex]
% precise mad() where the first component is not x.
43425844 94c81680 cb1272b3 157657b2 1c94b136 00000001 00000120          % DXBC header
00000003 0000002c 0000003c 00000070                                     %
4e475349 00000008 00000000 00000008                                     % .input
4e47534f 0000002c 00000001 00000008                                     % .output
00000020 00000000 00000000 00000003 00000000 0000000f                   % .param sv_target.xyzw, o0.xyzw, float, TARGET
745f7673 65677261 abab0074                                              %
58454853 000000a8 00000050 0000002a                                     % .text ps_5_0
0100086a                                                                % dcl_globalFlags refactoringAllowed
04000059 00208e46 00000000 00000003                                     % dcl_constantBuffer cb0[1], immediateIndexed
03000065 001020f2 00000000                                              % dcl_output o0.xyzw
02000068 00000001                                                       % dcl_temps 1
09180038 00100032 00000000 00208ae6 00000000 00000002                   % mul [precise(xy)] r0.xy, cb0[2].zwzz,
         00208ae6 00000000 00000002                                     %                   cb0[2].zwzz
0c600032 001000c2 00000000 00208406 00000000 00000001                   % mad [precise(zw)] r0.zw, cb0[1].xxxy,
         00208ea6 00000000 00000001 00208406 00000000 00000002          %                   cb0[1].zzzw, cb0[2].xxxy
08000038 001020f2 00000000 00100e46 00000000 00208e46 00000000 00000000 % mul o0.xyzw, r0.xyzw, cb0[0].xyzw
0100003e                                                                % ret

[test]
uniform 0 float4 1.5 1.5 1.5 1.5
uniform 4 float4 1.00000007 -42.1 1.625 -5.0
uniform 8 float4 1.00000007 -1.0 2.0 2.0
todo(glsl | msl) draw quad
probe (0, 0) f32(6.0, 6.0, 3.93750072, 314.25) 1

[require]
shader model >= 5.0
float64

[pixel shader todo]
uniform double2 a;

float4 main() : SV_TARGET
{
    double x = a.x;
    double y = a.y;
    return float4(x + y, x - y, x * y, x / y);
}

[test]
uniform 0 double2 7.5 -2.5
todo(sm<6) draw quad
probe (0, 0) rgba (5.0, 10.0, -18.75, -3.0)

[pixel shader todo]
uniform double2 a;

float4 main() : SV_TARGET
{
    double x = a.x;
    double y = a.y;
    return x * y;
}

[test]
uniform 0 double2 3.0e-300 2.5e300
todo(sm<6) draw quad
probe (0, 0) rgba (7.5, 7.5, 7.5, 7.5)

% Note: DXC does not support modulo on doubles.
[pixel shader todo]
uniform double2 a;

float4 main() : SV_TARGET
{
    double x = a.x;
    double y = a.y;
    return x / y;
}

[test]
uniform 0 double2 1.5e300 2.0e299
todo(sm<6) draw quad
probe (0, 0) rgba (7.5, 7.5, 7.5, 7.5)

[pixel shader todo]
uniform double2 a, b, c;

float4 main() : sv_target
{
    return float4(fma(a, b, c), 0, 0);
}

[test]
uniform 0 double2 1.00000007 -42.1
uniform 4 double2 1.625 -5.0
uniform 8 double2 1.00000007 -1.0
todo(sm<6) draw quad
probe (0, 0) rgba (2.62500024, 209.5, 0.0, 0.0)


% Test result when instructions might be removed because they are identities such as (+0) or (*1).
[pixel shader]
float4 a;

float4 main() : sv_target
{
    float4 zero = {0, 0, 0, 0};
    float4 one = {1, 1, 1, 1};

    return a + zero + a * one + zero * one;
}

[test]
uniform 0 float4 0.2 0.3 9.1 3.2
draw quad
probe (0, 0) rgba (0.4, 0.6, 18.2, 6.4)

[rtv 0]
format r32g32b32a32-uint
size (2d, 640, 480)

[pixel shader todo]
uniform double2 a, b, c, d;

% Return bool4 to ensure that non-trivial destination swizzling happens on the
% DLT instruction, rather than on the instruction to convert the result.
bool4 main() : SV_TARGET
{
    bool2 first = a < b;
    bool2 second = c < d;
    return bool4(first.x, second.x, second.y, first.y);
}

[test]
uniform 0 double2 1.0 3.0
uniform 4 double2 2.0 4.0
uniform 8 double2 5.0 7.0
uniform 12 double2 6.0 8.0
todo(sm<6) draw quad
if(sm<6) probe (0, 0) u32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff)
if(sm>=6) probe (0, 0) u32(1, 1, 1, 1)

uniform 0 double2 1.0 4.0
uniform 4 double2 2.0 3.0
uniform 8 double2 5.0 8.0
uniform 12 double2 6.0 7.0
todo(sm<6) draw quad
if(sm<6) probe (0, 0) u32(0xffffffff, 0xffffffff, 0, 0)
if(sm>=6) probe (0, 0) u32(1, 1, 0, 0)

uniform 0 double2 1.0 4.0
uniform 4 double2 2.0 3.0
uniform 8 double2 6.0 7.0
uniform 12 double2 5.0 8.0
todo(sm<6) draw quad
if(sm<6) probe (0, 0) u32(0xffffffff, 0, 0xffffffff, 0)
if(sm>=6) probe (0, 0) u32(1, 0, 1, 0)

[rtv 0]
format r32g32b32a32-float
size (2d, 640, 480)

% Minimum precision vectors in constant buffers have inconsistent behavior with
% SM6 (see minimum-precision.shader_test), so we're reading with arrays instead.

[require]
shader model >= 4.0

[pixel shader]
uniform min16float u[4];

float4 main() : sv_target
{
    min16float n = -1.5, m = 65.0;
    return float4(u[0] + n, u[1] + m, u[2] + n, u[3] + m);
}

[test]
if(sm<6) uniform 0 float 0
if(sm<6) uniform 4 float 0
if(sm<6) uniform 8 float 2.75
if(sm<6) uniform 12 float 2.75
if(sm>=6) uniform 0 uint 0
if(sm>=6) uniform 4 uint 0
if(sm>=6) uniform 8 uint 0x4180
if(sm>=6) uniform 12 uint 0x4180
todo(msl & sm>=6) draw quad
todo(sm>=6) probe (0, 0) rgba(-1.5, 65.0, 1.25, 67.75)

[pixel shader]
uniform min16float u[2];
uniform uint i;

float4 main() : sv_target
{
    min16float arr[4] = {1.0, 2.0, 10.0, 0.5};
    return float4(u[0] + arr[i], u[1] + arr[i + 1], 0, 0);
}

[test]
if(sm<6) uniform 0 float 0.25
if(sm<6) uniform 4 float 3.0
if(sm>=6) uniform 0 uint 0x3400
if(sm>=6) uniform 4 uint 0x4200
% i is allocated differently between SM4-5 and SM6
uniform 5 uint 2
uniform 8 uint 2
todo(sm>=6) draw quad
% With the NVIDIA d3d11 driver `arr[x]' seems to evaluate to `arr[0]' independently of x.
if(!d3d11 | !nvidia) probe (0, 0) f32(10.25, 3.5, 0.0, 0.0)
uniform 0 uint 0
uniform 4 uint 0
uniform 5 uint 0
uniform 8 uint 0
todo(sm>=6) draw quad
if(!d3d11 | !nvidia) probe (0, 0) f32(1.0, 2.0, 0, 0)

[pixel shader]
uniform min16float u[4];

float4 main() : sv_target
{
    min16float n = -1.5, m = 5.5;
    return float4(u[0] * n, u[1] * m, u[2] * n, u[3] * m);
}

[test]
if(sm<6) uniform 0 float -2.5
if(sm<6) uniform 4 float 3.5
if(sm<6) uniform 8 float 0.5
if(sm<6) uniform 12 float -4.5
if(sm>=6) uniform 0 uint 0xc100
if(sm>=6) uniform 4 uint 0x4300
if(sm>=6) uniform 8 uint 0x3800
if(sm>=6) uniform 12 uint 0xc480
todo(msl & sm>=6) draw quad
todo(sm>=6) probe (0, 0) rgba(3.75, 19.25, -0.75, -24.75)

[pixel shader]
uniform min16float u[4];

float4 main() : sv_target
{
    min16float n = 655.0, m = -0.5;
    return float4(u[0] / n, u[1] / m, u[2] / n, u[3] / m);
}

[test]
if(sm<6) uniform 0 float 3.25
if(sm<6) uniform 4 float -1023.5
if(sm<6) uniform 8 float -7.5
if(sm<6) uniform 12 float 0.125
if(sm>=6) uniform 0 uint 0x4280
if(sm>=6) uniform 4 uint 0xe3ff
if(sm>=6) uniform 8 uint 0xc780
if(sm>=6) uniform 12 uint 0x3000
todo(msl & sm>=6) draw quad
% The computation is potentially done in f16, but ULPs are relative to the f32 result.
todo(sm>=6) probe (0, 0) rgba (0.004962, 2047.0, -0.011451, -0.25) 8192


[require]
shader model >= 6.2
native-16-bit

[pixel shader]
uniform half4 u;

float4 main() : sv_target
{
    half n = -1.5, m = 65504.0;
    return float4(u.x + n, u.y + m, u.z + n, u.w + m);
}

[test]
uniform 0 uint 0
uniform 1 uint 0x41804180  % 2.75 2.75
draw quad
probe (0, 0) rgba(-1.5, 65504.0, 1.25, 65504.0)

[pixel shader]
uniform half4 u;

float4 main() : sv_target
{
    half n = -1.5, m = 5.5;
    return float4(u.x * n, u.y * m, u.z * n, u.w * m);
}

[test]
uniform 0 uint 0xc1004300   %  3.5 -2.5
uniform 1 uint4 0x3800c480  % -4.5  0.5
draw quad
probe (0, 0) rgba(-5.25, -13.75, 6.75, 2.75)

[pixel shader]
uniform half4 u;

float4 main() : sv_target
{
    half n = 65504.0, m = -0.5;
    return float4(u.x / n, u.y / m, u.z / n, u.w / m);
}

[test]
uniform 0 uint 0x4280e3ff  % -1023.5 3.25
uniform 1 uint 0xc7803000  % 0.125 -7.5
draw quad
% The computation is done in f16, but ULPs are relative to the f32 result.
probe (0, 0) rgba(-0.0156173706, -6.5, 1.90734863e-06, 15.0) 16384

[require]
shader model >= 6.2

[pixel shader]
uniform float2 f;

float4 main() : SV_Target
{
    return float4(f.x, f.x / 100.0f, f.x * 100.0f, f.x / f.y);
}

% Some C libraries are unable to parse denormal numbers, so we bitcast to uint

[test]
denorm preserve
uniform 0 float4 1.0e-37 100.0 0.0 0.0
draw quad
todo probe (0, 0) u32(0x02081cea, 0x000ae398, 0x0554ad2e, 0x000ae398)  % f32(1.0e-37, 1.0e-39, 1.0e-35, 1.0e-39)
uniform 0 uint4 0x000ae398 0x3c23d70a 0 0                              % f32(1.0e-39, 0.01, 0, 0)
draw quad
todo probe (0, 0) u32(0x000ae398, 0x00001be0, 0x02081cec, 0x02081cec)  % f32(1.0e-39, 1.0e-41, 9.999989e-38, 9.999989e-38)

denorm ftz
uniform 0 float4 1.0e-37 100.0 0.0 0.0
draw quad
probe (0, 0) u32(0x02081cea, 0x00000000, 0x0554ad2e, 0x00000000)  % f32(1.0e-37, 0.0, 1.0e-35, 0.0)
uniform 0 uint4 0x000ae398 0x3c23d70a 0 0                         % f32(1.0e-39, 0.01, 0, 0)
draw quad
probe (0, 0) u32(0x000ae398, 0x00000000, 0x00000000, 0x00000000)  % f32(1.0e-39, 0.0, 0.0, 0.0)

[rtv 0]
format r32g32b32a32-uint
size (2d, 640, 480)

% Per the specification, the dernom mode only applies to f32;
% f64 and f16 are always supposed to preserve denormals. Tests agree.

[require]
shader model >= 6.2
float64

[pixel shader]
uniform double f;

uint4 main() : SV_Target
{
    uint4 ret;
    double2 d = double2(f / 100.0, f * 100.0);
    asuint(d.x, ret.x, ret.y);
    asuint(d.y, ret.z, ret.w);
    return ret;
}

[test]
denorm preserve
uniform 0 uint64_t2 0x0031fa182c40c60d 0                                 % f64(1e-307, 0)
draw quad
todo(llvmpipe) probe (0, 0) u64(0x0000b8157268fdaf, 0x009c16c5c5253574)  % f64(1e-309, 9.999999999999999e-306)

denorm ftz
uniform 0 uint64_t2 0x0031fa182c40c60d 0                                 % f64(1e-307, 0)
draw quad
todo(llvmpipe) probe (0, 0) u64(0x0000b8157268fdaf, 0x009c16c5c5253574)  % f64(1e-309, 9.999999999999999e-306)

[require]
shader model >= 6.2
native-16-bit

[pixel shader]
uniform half2 f;

float4 main() : SV_Target
{
    return half4(f.x, f.x / 100.0h, f.x * 100.0h, f.x / f.y);
}

[test]
denorm preserve
uniform 0 uint 0x5640068d    % half2 1e-4 100.0
draw quad
probe (0, 0) f32(9.99569893e-005, 1.01327896e-006, 9.99450684e-003, 1.01327896e-006)

denorm ftz
uniform 0 uint 0x5640068d    % half2 1e-4 100.0
draw quad
probe (0, 0) f32(9.99569893e-005, 1.01327896e-006, 9.99450684e-003, 1.01327896e-006)
