This is an archive of the discontinued LLVM Phabricator instance.

[HLSL] add max/min library functions
ClosedPublic

Authored by bob80905 on Feb 17 2023, 5:22 PM.

Details

Summary

This change exposes the max and min library functions for HLSL, excluding long, and long long doubles.
The max / min functions are supported for all scalar, vector, and matrix types.
Long and long long double support is missing in this patch because those types
don't exist in HLSL.

The full documentation of the HLSL max / min functions are available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-max
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-min

Diff Detail

Event Timeline

bob80905 created this revision.Feb 17 2023, 5:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 5:22 PM
Herald added a subscriber: Anastasia. · View Herald Transcript
bob80905 requested review of this revision.Feb 17 2023, 5:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2023, 5:22 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
bob80905 retitled this revision from add max/min lib fxns to [HLSL] add max/min library functions.Feb 17 2023, 5:22 PM
bob80905 edited the summary of this revision. (Show Details)
bob80905 added inline comments.
clang/test/CodeGenHLSL/builtins/min.hlsl
11

I had to add a 0 here for the NO_HALF case for all these tests, which is unlike what I had to do for previous tests. Not sure why, but thought I would point it out.

max/min does work on integers in HLSL.
And __builtin_elementwise_max/min support both integers and floats.

bob80905 updated this revision to Diff 500953.Feb 27 2023, 3:48 PM

add int support for max/min.

bob80905 edited the summary of this revision. (Show Details)Feb 27 2023, 3:49 PM

add int support for max/min.

Sorry didn't check more :(.

Now i16/u16/i32/u32/i64/u64/f16/f32/f64 are all supported for min/max in hlsl.

bob80905 updated this revision to Diff 501248.Feb 28 2023, 11:46 AM
  • add support for these types: i16/u16/i32/u32/i64/u64/f16/f32/f64
bob80905 updated this revision to Diff 501250.Feb 28 2023, 11:57 AM
  • ushort is now unsigned
  • ushort is now unsigned

Use uint16_t/int16_t/uint64_t/int64_t for 16/64 bit integers.

bob80905 updated this revision to Diff 501963.Mar 2 2023, 1:37 PM
  • use already defined hlsl types
python3kgae added inline comments.Mar 2 2023, 1:41 PM
clang/test/CodeGenHLSL/builtins/max.hlsl
13

Just guard 16bit integer tests with #ifdef __HLSL_ENABLE_16_BIT.

bob80905 updated this revision to Diff 502009.Mar 2 2023, 3:14 PM
  • only run tests if 16 bit is enabled
python3kgae accepted this revision.Mar 2 2023, 4:05 PM
This revision is now accepted and ready to land.Mar 2 2023, 4:05 PM
This revision was automatically updated to reflect the committed changes.