KhronosGroup / KhronosGroup/SPIRV-Tools

spirv-fuzz: Split bit instructions into most fundamental operations

Open
#3,557 0 comments 0 reactions 1 assignee Claimed by @andreperezmaselco View on GitHub
component:fuzzer
Dominant language
C++
Stars
1.4k
Forks
709
Avg merge
1d 22h
Merged PRs (30d)
28

Description

Instructions like `OpBitwiseOr` operates on corresponding pairs of bits from the operands.
A transformation could split these bit instructions into instructions that extracts the corresponding bits from the operands, evaluates them and builds the result. The following is an example.



Reference shader


Variant shader




        

OpCapability Shader
OpCapability Int8
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %7 "main"


; Types
%2 = OpTypeInt 8 0
%3 = OpTypeVoid
%4 = OpTypeFunction %3


; Constants
%5 = OpConstant %2 0
%6 = OpConstant %2 1


; main function
%7 = OpFunction %3 None %4
%8 = OpLabel
%9 = OpBitwiseOr %2 %5 %6
OpReturn
OpFunctionEnd




        

OpCapability Shader
OpCapability Int8
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %7 "main"


; Types
%2 = OpTypeInt 8 0
%3 = OpTypeVoid
%4 = OpTypeFunction %3


; Constants
%5 = OpConstant %2 0
%6 = OpConstant %2 1
%10 = OpConstant %2 2
%11 = OpConstant %2 3
%12 = OpConstant %2 4
%13 = OpConstant %2 5
%14 = OpConstant %2 6
%15 = OpConstant %2 7



; main function
%7 = OpFunction %3 None %4
%8 = OpLabel


%16 = OpBitFieldUExtract %2 %5 %5 %6 ; extracts bit 0 from %5
%17 = OpBitFieldUExtract %2 %6 %5 %6 ; extracts bit 0 from %6
%18 = OpBitwiseOr %2 %16 %17


%19 = OpBitFieldUExtract %2 %5 %6 %6 ; extracts bit 1 from %5
%20 = OpBitFieldUExtract %2 %6 %6 %6 ; extracts bit 1 from %6
%21 = OpBitwiseOr %2 %19 %20


%22 = OpBitFieldUExtract %2 %5 %10 %6 ; extracts bit 2 from %5
%23 = OpBitFieldUExtract %2 %6 %10 %6 ; extracts bit 2 from %6
%24 = OpBitwiseOr %2 %22 %23


%25 = OpBitFieldUExtract %2 %5 %11 %6 ; extracts bit 3 from %5
%26 = OpBitFieldUExtract %2 %6 %11 %6 ; extracts bit 3 from %6
%27 = OpBitwiseOr %2 %25 %26


%28 = OpBitFieldUExtract %2 %5 %12 %6 ; extracts bit 4 from %5
%29 = OpBitFieldUExtract %2 %6 %12 %6 ; extracts bit 4 from %6
%30 = OpBitwiseOr %2 %28 %29


%31 = OpBitFieldUExtract %2 %5 %13 %6 ; extracts bit 5 from %5
%32 = OpBitFieldUExtract %2 %6 %13 %6 ; extracts bit 5 from %6
%33 = OpBitwiseOr %2 %31 %32


%34 = OpBitFieldUExtract %2 %5 %14 %6 ; extracts bit 6 from %5
%35 = OpBitFieldUExtract %2 %6 %14 %6 ; extracts bit 6 from %6
%36 = OpBitwiseOr %2 %34 %35


%37 = OpBitFieldUExtract %2 %5 %15 %6 ; extracts bit 7 from %5
%38 = OpBitFieldUExtract %2 %6 %15 %6 ; extracts bit 7 from %6
%39 = OpBitwiseOr %2 %37 %38


%40 = OpBitFieldInsert %2 %5 %18 %5 %6 ; inserts bit 0
%41 = OpBitFieldInsert %2 %40 %21 %6 %6 ; inserts bit 1
%42 = OpBitFieldInsert %2 %41 %24 %10 %6 ; inserts bit 2
%43 = OpBitFieldInsert %2 %42 %27 %11 %6 ; inserts bit 3
%44 = OpBitFieldInsert %2 %43 %30 %12 %6 ; inserts bit 4
%45 = OpBitFieldInsert %2 %44 %33 %13 %6 ; inserts bit 5
%46 = OpBitFieldInsert %2 %45 %36 %14 %6 ; inserts bit 6
%9 = OpBitFieldInsert %2 %46 %39 %15 %6 ; inserts bit 7

OpReturn
OpFunctionEnd



Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.