GSaha567/seq_level_training_data
052
1text,length,is_long_context,metric_val,label_metric2"----3 4Integer Integer FP5 6funct3 funct3 funct37OPIVV V OPMVV V OPFVV V8OPIVX X OPMVX X OPFVF F9OPIVI I10 11funct6 funct6 funct612000000 VXI vadd 000000 V vredsum 000000 VF vfadd13000001 000001 V vredand 000001 V vfredsum14000010 VX vsub 000010 V vredor 000010 VF vfsub15000011 XI vrsub 000011 V vredxor 000011 V vfredosum16000100 VX vminu 000100 V vredminu 000100 VF vfmin17000101 VX vmin 000101 V vredmin 000101 V vfredmin18000110 VX vmaxu 000110 V vredmaxu 000110 VF vfmax19000111 VX vmax 000111 V vredmax 000111 V vfredmax20001000 001000 001000 VF vfsgnj21001001 VXI vand 001001 001001 VF vfsgnn22001010 VXI vor 001010 001010 VF vfsgnx23001011 VXI vxor 001011 00101124001100 VXI vrgather 001100 V vext.x.v 001100 V vfmv.f.s25001101 001101 X vmv.s.x 001101 F vfmv.s.f26001110 XI vslideup 001110 X vslide1up 00111027001111 XI vslidedown 001111 X vslide1down 00111128 29010000 VXI vadc 010000 010000 30010001 010001 010001 31010010 VX vsbc 010010 010010 32010011 010011 01001133010100 010100 V vmpopc 01010034010101 010101 V vmfirst 01010135010110 010110 V VMUNARY0 01011036010111 VXI vmerge 010111 V vcompress 010111 F vfmerge.vf37011000 VXI vseq 011000 V vmandnot 011000 VF vfeq38011001 VXI vsne 011001 V vmand 011001 VF vflte39011010 VX vsltu 011010 V vmor 011010 VF vford40011011 VX vslt 011011 V vmxor 011011 VF vflt41011100 VXI vsleu 011100 V vmornot 011100 VF vfne42011101 VXI vsle 011101 V vmnand 011101 F vfgt43011110 XI vsgtu 011110 V vmnor 01111044011111 XI vsgt 011111 V vmxnor 011111 F vfgte45 46100000 VXI vsaddu 100000 VX vdivu 100000 VF vfdiv 47100001 VXI vsadd 100001 VX vdiv 100001 F vfrdiv 48100010 VX vssubu 100010 VX vremu 100010 V VFUNARY049100011 VX vssub 100011 VX vrem 100011 V VFUNARY150100100 VXI vaadd 100100 VX vmulhu 100100 VF vfmul51100101 VXI vsll 100101 VX vmul 100101 52100110 VX vasub 100110 VX vmulhsu 100110 53100111 VX vsmul 100111 VX vmulh 100111 54101000 VXI vsrl 101000 101000 VF vfmadd55101001 VXI vsra 101001 VX vmadd 101001 VF vfnmadd56101010 VXI vssrl 101010 101010 VF vfmsub57101011 VXI vssra 101011 VX vmsub 101011 VF vfnmsub58101100 VXI vnsrl 101100 101100 VF vfmacc59101101 VXI vnsra 101101 VX vmacc 101101 VF vfnmacc60101110 VXI vnclipu 101110 101110 VF vfmsac61101111 VXI vnclip 101111 VX vmsac 101111 VF vfnmsac62 63110000 V vwredsumu 110000 VX vwaddu 110000 VF vfwadd64110001 V vwredsum 110001 VX vwadd 110001 V vfwredsum65110010 110010 VX vwsubu 110010 VF vfwsub66110011 110011 VX vwsub 110011 V vfwredosum67110100 110100 VX vwaddu.w 110100 VF vfwadd.w68110101 110101 VX vwadd.w 11010169110110 110110 VX vwsubu.w 110110 VF vfwsub.w70110111 110111 VX vwsub.w 11011171111000 V vdotu 111000 VX vwmulu 111000 VF vfwmul72111001 V vdot 111001 111001 V vfdot73111010 111010 VX vwmulsu 11101074111011 111011 VX vwmul 11101175111100 VX vwsmaccu 111100 VX vwmaccu 111100 VF vfwmacc76111101 VX vwsmacc 111101 VX vwmacc 111101 VF vfwnmacc77111110 VX vwsmsacu 111110 VX vwmsacu 111110 VF vfwmsac78111111 VX vwsmsac 111111 VX vwmsac 111111 VF vfwnmsac79----80 81----82VFUNARY0 encoding space83 vs184 single-width converts8500000 vfcvt.xu.f.v8600001 vfcvt.x.f.v8700010 vfcvt.f.xu.v8800011 vfcvt.f.x.v89 90 widening converts9101000 vfwcvt.xu.f.v9201001 vfwcvt.x.f.v9301010 vfwcvt.f.xu.v9401011 vfwcvt.f.x.v9501100 vfwcvt.f.f.v96 97 narrowing converts9810000 vfncvt.xu.f.v9910001 vfncvt.x.f.v10010010 vfncvt.f.xu.v10110011 vfncvt.f.x.v10210100 vfncvt.f.f.v103----104 105----106VFUNARY1 encoding space107 vs110800000 vfsqrt.v10910000 vfclass.v110----111 112----113VMUNARY0 encoding space114 vs111500001 vmsbf11600010 vmsof11700011 vmsif11810000 vmiota11910001 vid120----121 122 123////124.Vector Unit-Stride Load/Store Instruction Listing125[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]126|========================127|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode128 129|off[1:0]|000|vm|00000|rs1|000 2+|vd|0000111|VLBU.V130|off[1:0]|000|vm|00000|rs1|101 2+|vd|0000111|VLHU.V131|off[1:0]|000|vm|00000|rs1|110 2+|vd|0000111|VLWU.V132|off[1:0]|000|vm|00000|rs1|111 2+|vd|0000111|VLE.V133|off[1:0]|100|vm|00000|rs1|000 2+|vd|0000111|VLB.V134|off[1:0]|100|vm|00000|rs1|101 2+|vd|0000111|VLH.V135|off[1:0]|100|vm|00000|rs1|110 2+|vd|0000111|VLW.V1362+|vs3|vm|00000|rs1|000|off[1:0]|000|0100111|VSB.V1372+|vs3|vm|00000|rs1|101|off[1:0]|000|0100111|VSH.V1382+|vs3|vm|00000|rs1|110|off[1:0]|000|0100111|VSW.V1392+|vs3|vm|00000|rs1|111|off[1:0]|000|0100111|VSE.V140|========================141 142 143.Vector Unit-Stride Fault-First Load Instruction Listing144[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]145|========================146|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode147 148|off[1:0]|000|vm|10000|rs1|000 2+|vd|0000111|VLBUFF.V149|off[1:0]|000|vm|10000|rs1|101 2+|vd|0000111|VLHUFF.V150|off[1:0]|000|vm|10000|rs1|110 2+|vd|0000111|VLWUFF.V151|off[1:0]|000|vm|10000|rs1|111 2+|vd|0000111|VLEFF.V152|off[1:0]|100|vm|10000|rs1|000 2+|vd|0000111|VLBFF.V153|off[1:0]|100|vm|10000|rs1|101 2+|vd|0000111|VLHFF.V154|off[1:0]|100|vm|10000|rs1|110 2+|vd|0000111|VLWFF.V155 156|========================157 158.Vector Strided Load/Store Instruction Listing159[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]160|========================161|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode162 163|off[1:0]|010|vm|rs2|rs1|000 2+|vd|0000111|VLSBU.V164|off[1:0]|010|vm|rs2|rs1|101 2+|vd|0000111|VLSHU.V165|off[1:0]|010|vm|rs2|rs1|110 2+|vd|0000111|VLSWU.V166|off[1:0]|010|vm|rs2|rs1|111 2+|vd|0000111|VLSE.V167|off[1:0]|110|vm|rs2|rs1|000 2+|vd|0000111|VLSB.V168|off[1:0]|110|vm|rs2|rs1|101 2+|vd|0000111|VLSH.V169|off[1:0]|110|vm|rs2|rs1|110 2+|vd|0000111|VLSW.V1702+|vs3|vm|rs2|rs1|000|off[1:0]|010|0100111|VSSB.V1712+|vs3|vm|rs2|rs1|101|off[1:0]|010|0100111|VSSH.V1722+|vs3|vm|rs2|rs1|110|off[1:0]|010|0100111|VSSW.V1732+|vs3|vm|rs2|rs1|111|off[1:0]|010|0100111|VSSE.V174 175|========================176 177 178.Vector Indexed Load/Store Instruction Listing179[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]180|========================181|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode182 183|off[1:0]|011|vm|vs2|rs1|000 2+|vd|0000111|VLXBU.V184|off[1:0]|011|vm|vs2|rs1|101 2+|vd|0000111|VLXHU.V185|off[1:0]|011|vm|vs2|rs1|110 2+|vd|0000111|VLXWU.V186|off[1:0]|011|vm|vs2|rs1|111 2+|vd|0000111|VLXE.V187|off[1:0]|111|vm|vs2|rs1|000 2+|vd|0000111|VLXB.V188|off[1:0]|111|vm|vs2|rs1|101 2+|vd|0000111|VLXH.V189|off[1:0]|111|vm|vs2|rs1|110 2+|vd|0000111|VLXW.V1902+|vs3|vm|vs2|rs1|000|off[1:0]|011|0100111|VSXB.V1912+|vs3|vm|vs2|rs1|101|off[1:0]|011|0100111|VSXH.V1922+|vs3|vm|vs2|rs1|110|off[1:0]|011|0100111|VSXW.V1932+|vs3|vm|vs2|rs1|111|off[1:0]|011|0100111|VSXE.V1942+|vs3|vm|vs2|rs1|000|off[1:0]|111|0100111|VSUXB.V1952+|vs3|vm|vs2|rs1|101|off[1:0]|111|0100111|VSUXH.V1962+|vs3|vm|vs2|rs1|110|off[1:0]|111|0100111|VSUXW.V1972+|vs3|vm|vs2|rs1|111|off[1:0]|111|0100111|VSUXE.V198 199|========================200////201 202 203 204////205 206X vsgteu207 X vsgte208 209 210vx4muladd211vx4mulsub212 213 214.Vector Table215[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]216|========================2172+|31 27|26 25 |24 20 |19 15 |14 12 2+|11 7 |6 0 |Opcode218 2192+|00000|vm |vs2 |vs1 |001 2+|vd |1010111|VADD.VV2202+|00000|vm |vs2 |vs1 |000 2+|vd |1010111|VADD.VS2212+|00000|vm |vs2 |rs1 |010 2+|vd |1010111|VADD.VX2222+|00000|vm |vs2 |simm[4:0]|011 2+|vd |1010111|VADD.VI223|========================224 225.Vector Table226[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]227|========================228|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode229 2302+|00000|vm|vs2|vs1|000 2+|vd|1010111|VADD.VV2312+|00000|vm|vs2|vs1|100 2+|vd|1010111|VADD.VS2322+|00000|vm|imm[4:0]|vs1|101 2+|vd|1010111|VADD.VI2332+|00000|vm|vs2|vs1|010 2+|vd|1010111|VADDW.VV2342+|00000|vm|vs2|vs1|110 2+|vd|1010111|VADDW.VS2352+|00000|vm|vs2|vs1|011 2+|vd|1010111|VADDW.WV2362+|00000|vm|vs2|vs1|111 2+|vd|1010111|VADDW.WS2372+|00001|vm|vs2|vs1|000 2+|vd|1010111|VSUB.VV2382+|00001|vm|vs2|vs1|100 2+|vd|1010111|VSUB.VS2392+|00001|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSUB.VI2402+|00001|vm|vs2|vs1|000 2+|vd|1010111|VSUB.VV2412+|00001|vm|vs2|vs1|100 2+|vd|1010111|VSUB.VS2422+|00001|vm|vs2|vs1|011 2+|vd|1010111|VSUBW.WV2432+|00001|vm|vs2|vs1|111 2+|vd|1010111|VSUBW.WS2442+|01000|vm|vs2|vs1|000 2+|vd|1010111|VMUL.VV2452+|01000|vm|vs2|vs1|100 2+|vd|1010111|VMUL.VS2462+|01000|vm|imm[4:0]|vs1|101 2+|vd|1010111|VMUL.VI2472+|01000|vm|vs2|vs1|000 2+|vd|1010111|VMUL.VV2482+|01000|vm|vs2|vs1|100 2+|vd|1010111|VMUL.VS2492+|01000|vm|vs2|vs1|011 2+|vd|1010111|VMULW.WV2502+|01000|vm|vs2|vs1|111 2+|vd|1010111|VMULW.WS2512+|01001|vm|vs2|vs1|000 2+|vd|1010111|VMULU.VV2522+|01001|vm|vs2|vs1|100 2+|vd|1010111|VMULU.VS2532+|01001|vm|imm[4:0]|vs1|101 2+|vd|1010111|VMULU.VI2542+|01001|vm|vs2|vs1|000 2+|vd|1010111|VMULU.VV2552+|01001|vm|vs2|vs1|100 2+|vd|1010111|VMULU.VS2562+|01001|vm|vs2|vs1|011 2+|vd|1010111|VMULUW.WV2572+|01001|vm|vs2|vs1|111 2+|vd|1010111|VMULUW.WS2582+|01010|vm|vs2|vs1|000 2+|vd|1010111|VMULSU.VV2592+|01010|vm|vs2|vs1|100 2+|vd|1010111|VMULSU.VS2602+|01010|vm|imm[4:0]|vs1|101 2+|vd|1010111|VMULSU.VI2612+|01010|vm|vs2|vs1|000 2+|vd|1010111|VMULSU.VV2622+|01010|vm|vs2|vs1|100 2+|vd|1010111|VMULSU.VS2632+|01010|vm|vs2|vs1|011 2+|vd|1010111|VMULSUW.WV2642+|01010|vm|vs2|vs1|111 2+|vd|1010111|VMULSUW.WS265 266|========================267 268 269.Vector Table270[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]271|========================272|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode273 2742+|00100|vm|vs2|vs1|000 2+|vd|1010111|VSRLN.VV2752+|00100|vm|vs2|vs1|100 2+|vd|1010111|VSRLN.VS2762+|00100|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSRLN.VI2772+|00100|vm|vs2|vs1|010 2+|vd|1010111|VSRLN.WV2782+|00100|vm|vs2|vs1|110 2+|vd|1010111|VSRLN.WS2792+|00100|vm|vs2|vs1|111 2+|vd|1010111|VSRLN.WI2802+|00101|vm|vs2|vs1|000 2+|vd|1010111|VSRAN.VV2812+|00101|vm|vs2|vs1|100 2+|vd|1010111|VSRAN.VS2822+|00101|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSRAN.VI2832+|00101|vm|vs2|vs1|010 2+|vd|1010111|VSRAN.WV2842+|00101|vm|vs2|vs1|110 2+|vd|1010111|VSRAN.WS2852+|00101|vm|vs2|vs1|111 2+|vd|1010111|VSRAN.WI2862+|00110|vm|vs2|vs1|000 2+|vd|1010111|VCLIPN.VV2872+|00110|vm|vs2|vs1|100 2+|vd|1010111|VCLIPN.VS2882+|00110|vm|imm[4:0]|vs1|101 2+|vd|1010111|VCLIPN.VI2892+|00110|vm|vs2|vs1|010 2+|vd|1010111|VCLIPN.WV2902+|00110|vm|vs2|vs1|110 2+|vd|1010111|VCLIPN.WS2912+|00110|vm|vs2|vs1|111 2+|vd|1010111|VCLIPN.WI2922+|00111|vm|vs2|vs1|000 2+|vd|1010111|VCLIPUN.VV2932+|00111|vm|vs2|vs1|100 2+|vd|1010111|VCLIPUN.VS2942+|00111|vm|imm[4:0]|vs1|101 2+|vd|1010111|VCLIPUN.VI2952+|00111|vm|vs2|vs1|010 2+|vd|1010111|VCLIPUN.WV2962+|00111|vm|vs2|vs1|110 2+|vd|1010111|VCLIPUN.WS2972+|00111|vm|vs2|vs1|111 2+|vd|1010111|VCLIPUN.WI2982+|10000|vm|vs2|vs1|000 2+|vd|1010111|VAND.VV2992+|10000|vm|vs2|vs1|100 2+|vd|1010111|VAND.VS3002+|10000|vm|imm[4:0]|vs1|101 2+|vd|1010111|VAND.VI3012+|10000|vm|vs2|vs1|010 2+|vd|1010111|VOR.VV3022+|10000|vm|vs2|vs1|110 2+|vd|1010111|VOR.VS3032+|10000|vm|imm[4:0]|vs1|111 2+|vd|1010111|VOR.VI3042+|10001|vm|vs2|vs1|000 2+|vd|1010111|VXOR.VV3052+|10001|vm|vs2|vs1|100 2+|vd|1010111|VXOR.VS3062+|10001|vm|imm[4:0]|vs1|101 2+|vd|1010111|VXOR.VI3072+|10010|vm|vs2|vs1|000 2+|vd|1010111|VSLL.VV3082+|10010|vm|vs2|vs1|100 2+|vd|1010111|VSLL.VS3092+|10010|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSLL.VI3102+|10011|vm|vs2|vs1|000 2+|vd|1010111|VSRL.VV3112+|10011|vm|vs2|vs1|100 2+|vd|1010111|VSRL.VS3122+|10011|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSRL.VI3132+|10011|vm|vs2|vs1|010 2+|vd|1010111|VSRA.VV3142+|10011|vm|vs2|vs1|110 2+|vd|1010111|VSRA.VS3152+|10011|vm|imm[4:0]|vs1|111 2+|vd|1010111|VSRA.VI3162+|10100|vm|vs2|vs1|000 2+|vd|1010111|VSEQ.VV3172+|10100|vm|vs2|vs1|100 2+|vd|1010111|VSEQ.VS3182+|10100|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSEQ.VI3192+|10100|vm|vs2|vs1|010 2+|vd|1010111|VSNE.VV3202+|10100|vm|vs2|vs1|110 2+|vd|1010111|VSNE.VS3212+|10100|vm|imm[4:0]|vs1|111 2+|vd|1010111|VSNE.VI3222+|10101|vm|vs2|vs1|000 2+|vd|1010111|VSLT.VV3232+|10101|vm|vs2|vs1|100 2+|vd|1010111|VSLT.VS3242+|10101|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSLT.VI3252+|10101|vm|vs2|vs1|010 2+|vd|1010111|VSLTU.VV3262+|10101|vm|vs2|vs1|110 2+|vd|1010111|VSLTU.VS3272+|10101|vm|imm[4:0]|vs1|111 2+|vd|1010111|VSLTU.VI3282+|10110|vm|vs2|vs1|000 2+|vd|1010111|VSLE.VV3292+|10110|vm|vs2|vs1|100 2+|vd|1010111|VSLE.VS3302+|10110|vm|imm[4:0]|vs1|101 2+|vd|1010111|VSLE.VI3312+|10110|vm|vs2|vs1|010 2+|vd|1010111|VSLEU.VV3322+|10110|vm|vs2|vs1|110 2+|vd|1010111|VSLEU.VS3332+|10110|vm|imm[4:0]|vs1|111 2+|vd|1010111|VSLEU.VI3342+|11000|vm|vs2|vs1|000 2+|vd|1010111|VMULH.VV3352+|11000|vm|vs2|vs1|100 2+|vd|1010111|VMULH.VS3362+|11000|vm|imm[4:0]|vs1|101 2+|vd|1010111|VMULH.VI3372+|11001|vm|vs2|vs1|000 2+|vd|1010111|VDIV.VV3382+|11001|vm|vs2|vs1|100 2+|vd|1010111|VDIV.VS3392+|11001|vm|imm[4:0]|vs1|101 2+|vd|1010111|VDIV.VI3402+|11001|vm|vs2|vs1|010 2+|vd|1010111|VDIVU.VV3412+|11001|vm|vs2|vs1|110 2+|vd|1010111|VDIVU.VS3422+|11001|vm|imm[4:0]|vs1|111 2+|vd|1010111|VDIVU.VI3432+|11010|vm|vs2|vs1|000 2+|vd|1010111|VREM.VV3442+|11010|vm|vs2|vs1|100 2+|vd|1010111|VREM.VS3452+|11010|vm|imm[4:0]|vs1|101 2+|vd|1010111|VREM.VI3462+|11010|vm|vs2|vs1|010 2+|vd|1010111|VREMU.VV3472+|11010|vm|vs2|vs1|110 2+|vd|1010111|VREMU.VS3482+|11010|vm|imm[4:0]|vs1|111 2+|vd|1010111|VREMU.VI3492+|11011|vm|00000|vs1|000 2+|vd|1010111|VSQRT.VV3502+|11011|vm|00000|vs1|100 2+|vd|1010111|VSQRT.VS3512+|11011|vm|00000|vs1|101 2+|vd|1010111|VSQRT.VI3522+|11011|vm|00001|vs1|000 2+|vd|1010111|VFCLASS.VV3532+|11011|vm|00001|vs1|100 2+|vd|1010111|VFCLASS.VS3542+|11011|vm|00001|vs1|101 2+|vd|1010111|VFCLASS.VI3552+|11100|vm|vs2|vs1|000 2+|vd|1010111|VFSGNJ.VV3562+|11100|vm|vs2|vs1|100 2+|vd|1010111|VFSGNJ.VS3572+|11100|vm|imm[4:0]|vs1|101 2+|vd|1010111|VFSGNJ.VI3582+|11100|vm|vs2|vs1|010 2+|vd|1010111|VFSGNJN.VV3592+|11100|vm|vs2|vs1|110 2+|vd|1010111|VFSGNJN.VS3602+|11100|vm|imm[4:0]|vs1|111 2+|vd|1010111|VFSGNJN.VI3612+|11101|vm|vs2|vs1|000 2+|vd|1010111|VFSGNJX.VV3622+|11101|vm|vs2|vs1|100 2+|vd|1010111|VFSGNJX.VS3632+|11101|vm|imm[4:0]|vs1|101 2+|vd|1010111|VFSGNJX.VI3642+|11110|vm|vs2|vs1|000 2+|vd|1010111|VFMIN.VV3652+|11110|vm|vs2|vs1|100 2+|vd|1010111|VFMIN.VS3662+|11110|vm|imm[4:0]|vs1|101 2+|vd|1010111|VFMIN.VI3672+|11110|vm|vs2|vs1|010 2+|vd|1010111|VFMAX.VV3682+|11110|vm|vs2|vs1|110 2+|vd|1010111|VFMAX.VS3692+|11110|vm|imm[4:0]|vs1|111 2+|vd|1010111|VFMAX.VI370 371|========================372 373 374.Vector Table375[width=""100%"",cols=""^3,^3,^3,^4,^4,^3,^3,^3,^7,<10""]376|========================377|31 30 |29 27 |26 25 |24 20 |19 15 |14 12 |11 10 |9 7 |6 0 |Opcode378 3792+|11011|vm|00000|vs1|010 2+|rd|1010111|VMPOPC3802+|11011|vm|00001|vs1|010 2+|rd|1010111|VMFIRST3812+|11011|vm|00000|vs1|011 2+|vd|1010111|VMSBF.V3822+|11011|vm|00001|vs1|011 2+|vd|1010111|VMSIF.V3832+|11011|vm|00010|vs1|011 2+|vd|1010111|VMSOF.V3842+|11011|vm|11111|00000|000 2+|vd|1010111|VIOTA.V3852+|11111|vm|vs2|vs1|000 2+|vd|1010111|VMERGE.VV3862+|11111|vm|vs2|vs1|100 2+|vd|1010111|VMERGE.VS3872+|11111|vm|imm[4:0]|vs1|101 2+|vd|1010111|VMERGE.VI3882+|01101|00|rs2|vs1|000 2+|rd|1010111|VMV.X.V3892+|01101|01|rs2|rs1|000 2+|vd|1010111|VMV.V.X3902+|01101|10|rs2|vs1|000 2+|vd|1010111|VMV.S.V3912+|01101|11|rs2|vs1|000 2+|vd|1010111|VMV.V.S3922+|01101|vm|vs2|vs1|011 2+|vd|1010111|VRGATHER.VV3932+|01101|vm|vs2|vs1|100 2+|vd|1010111|VSLIDEUP.VS3942+|01101|vm|imm[4:0]|00000|101 2+|vd|1010111|VSLIDEUP.VI3952+|01101|vm|vs2|vs1|110 2+|vd|1010111|VSLIDEDOWN.VS3962+|01101|vm|imm[4:0]|vs1|111 2+|vd|1010111|VSLIDEDOWN.VI3972+|01110|vm|vs2|vs1|000 2+|vd|1010111|VREDSUM.V3982+|01110|vm|vs2|vs1|010 2+|vd|1010111|VREDSUMW.V3992+|01110|vm|vs2|vs1|001 2+|vd|1010111|VREDMAX.V4002+|01110|vm|vs2|vs1|011 2+|vd|1010111|VREDMAXU.V4012+|01110|vm|vs2|vs1|100 2+|vd|1010111|VREDMIN.V4022+|01110|vm|vs2|vs1|110 2+|vd|1010111|VREDMINU.V4032+|01111|vm|vs2|vs1|000 2+|vd|1010111|VREDAND.V4042+|01111|vm|vs2|vs1|001 2+|vd|1010111|VREDOR.V4052+|01111|vm|vs2|vs1|010 2+|vd|1010111|VREDXOR.V4062+|vs3|vm|vs2|vs1|101 2+|vd|1000011|VMADD.VVV4072+|vs3|vm|vs2|vs1|110 2+|vd|1000011|VMADD.VVS4082+|vs3|vm|vs2|vs1|101 2+|vd|1000111|VMSUB.VVV4092+|vs3|vm|vs2|vs1|110 2+|vd|1000111|VMSUB.VVS4102+|vs3|vm|vs2|vs1|101 2+|vd|1001011|VMADDW.VVV4112+|vs3|vm|vs2|vs1|110 2+|vd|1001011|VMADDW.VVS4122+|vs3|vm|vs2|vs1|101 2+|vd|1001111|VMSUBW.VVV4132+|vs3|vm|vs2|vs1|110 2+|vd|1001111|VMSUBW.VVS414 415|========================416////417",12122,True,2962.4384085451757,median418"// Copyright (c) 2014 The Bitcoin Core developers419// Copyright (c) 2019 The quirkyturtcoin developers420// Distributed under the MIT/X11 software license, see the accompanying421// file COPYING or http://www.opensource.org/licenses/mit-license.php.422 423#include ""crypto/aes.h""424#include ""crypto/rfc6979_hmac_sha256.h""425#include ""crypto/chacha20.h""426#include ""crypto/ripemd160.h""427#include ""crypto/sha1.h""428#include ""crypto/sha256.h""429#include ""crypto/sha512.h""430#include ""crypto/hmac_sha256.h""431#include ""crypto/hmac_sha512.h""432#include ""random.h""433#include ""utilstrencodings.h""434#include ""test/test_quirkyturtcoin.h""435 436#include <vector>437 438#include <boost/test/unit_test.hpp>439 440BOOST_FIXTURE_TEST_SUITE(crypto_tests, BasicTestingSetup)441 442template<typename Hasher, typename In, typename Out>443void TestVector(const Hasher &h, const In &in, const Out &out) {444 Out hash;445 BOOST_CHECK(out.size() == h.OUTPUT_SIZE);446 hash.resize(out.size());447 {448 // Test that writing the whole input string at once works.449 Hasher(h).Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);450 BOOST_CHECK(hash == out);451 }452 for (int i=0; i<32; i++) {453 // Test that writing the string broken up in random pieces works.454 Hasher hasher(h);455 size_t pos = 0;456 while (pos < in.size()) {457 size_t len = InsecureRandRange((in.size() - pos + 1) / 2 + 1);458 hasher.Write((unsigned char*)&in[pos], len);459 pos += len;460 if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {461 // Test that writing the rest at once to a copy of a hasher works.462 Hasher(hasher).Write((unsigned char*)&in[pos], in.size() - pos).Finalize(&hash[0]);463 BOOST_CHECK(hash == out);464 }465 }466 hasher.Finalize(&hash[0]);467 BOOST_CHECK(hash == out);468 }469}470 471void TestSHA1(const std::string &in, const std::string &hexout) { TestVector(CSHA1(), in, ParseHex(hexout));}472void TestSHA256(const std::string &in, const std::string &hexout) { TestVector(CSHA256(), in, ParseHex(hexout));}473void TestSHA512(const std::string &in, const std::string &hexout) { TestVector(CSHA512(), in, ParseHex(hexout));}474void TestRIPEMD160(const std::string &in, const std::string &hexout) { TestVector(CRIPEMD160(), in, ParseHex(hexout));}475 476void TestHMACSHA256(const std::string &hexkey, const std::string &hexin, const std::string &hexout) {477 std::vector<unsigned char> key = ParseHex(hexkey);478 TestVector(CHMAC_SHA256(&key[0], key.size()), ParseHex(hexin), ParseHex(hexout));479}480 481void TestHMACSHA512(const std::string &hexkey, const std::string &hexin, const std::string &hexout) {482 std::vector<unsigned char> key = ParseHex(hexkey);483 TestVector(CHMAC_SHA512(&key[0], key.size()), ParseHex(hexin), ParseHex(hexout));484}485 486void TestChaCha20(const std::string &hex_message, const std::string &hexkey, uint64_t nonce, uint64_t seek, const std::string& hexout)487{488 std::vector<unsigned char> key = ParseHex(hexkey);489 std::vector<unsigned char> m = ParseHex(hex_message);490 ChaCha20 rng(key.data(), key.size());491 rng.SetIV(nonce);492 rng.Seek(seek);493 std::vector<unsigned char> out = ParseHex(hexout);494 std::vector<unsigned char> outres;495 outres.resize(out.size());496 assert(hex_message.empty() || m.size() == out.size());497 498 // perform the ChaCha20 round(s), if message is provided it will output the encrypted ciphertext otherwise the keystream499 if (!hex_message.empty()) {500 rng.Crypt(m.data(), outres.data(), outres.size());501 } else {502 rng.Keystream(outres.data(), outres.size());503 }504 BOOST_CHECK(out == outres);505 if (!hex_message.empty()) {506 // Manually XOR with the keystream and compare the output507 rng.SetIV(nonce);508 rng.Seek(seek);509 std::vector<unsigned char> only_keystream(outres.size());510 rng.Keystream(only_keystream.data(), only_keystream.size());511 for (size_t i = 0; i != m.size(); i++) {512 outres[i] = m[i] ^ only_keystream[i];513 }514 BOOST_CHECK(out == outres);515 }516}517 518void TestAES128(const std::string &hexkey, const std::string &hexin, const std::string &hexout)519{520 std::vector<unsigned char> key = ParseHex(hexkey);521 std::vector<unsigned char> in = ParseHex(hexin);522 std::vector<unsigned char> correctout = ParseHex(hexout);523 std::vector<unsigned char> buf, buf2;524 525 assert(key.size() == 16);526 assert(in.size() == 16);527 assert(correctout.size() == 16);528 AES128Encrypt enc(&key[0]);529 buf.resize(correctout.size());530 buf2.resize(correctout.size());531 enc.Encrypt(&buf[0], &in[0]);532 BOOST_CHECK_EQUAL(HexStr(buf), HexStr(correctout));533 AES128Decrypt dec(&key[0]);534 dec.Decrypt(&buf2[0], &buf[0]);535 BOOST_CHECK_EQUAL(HexStr(buf2), HexStr(in));536}537 538void TestAES256(const std::string &hexkey, const std::string &hexin, const std::string &hexout)539{540 std::vector<unsigned char> key = ParseHex(hexkey);541 std::vector<unsigned char> in = ParseHex(hexin);542 std::vector<unsigned char> correctout = ParseHex(hexout);543 std::vector<unsigned char> buf;544 545 assert(key.size() == 32);546 assert(in.size() == 16);547 assert(correctout.size() == 16);548 AES256Encrypt enc(&key[0]);549 buf.resize(correctout.size());550 enc.Encrypt(&buf[0], &in[0]);551 BOOST_CHECK(buf == correctout);552 AES256Decrypt dec(&key[0]);553 dec.Decrypt(&buf[0], &buf[0]);554 BOOST_CHECK(buf == in);555}556 557void TestAES128CBC(const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout)558{559 std::vector<unsigned char> key = ParseHex(hexkey);560 std::vector<unsigned char> iv = ParseHex(hexiv);561 std::vector<unsigned char> in = ParseHex(hexin);562 std::vector<unsigned char> correctout = ParseHex(hexout);563 std::vector<unsigned char> realout(in.size() + AES_BLOCKSIZE);564 565 // Encrypt the plaintext and verify that it equals the cipher566 AES128CBCEncrypt enc(&key[0], &iv[0], pad);567 int size = enc.Encrypt(&in[0], in.size(), &realout[0]);568 realout.resize(size);569 BOOST_CHECK(realout.size() == correctout.size());570 BOOST_CHECK_MESSAGE(realout == correctout, HexStr(realout) + std::string("" != "") + hexout);571 572 // Decrypt the cipher and verify that it equals the plaintext573 std::vector<unsigned char> decrypted(correctout.size());574 AES128CBCDecrypt dec(&key[0], &iv[0], pad);575 size = dec.Decrypt(&correctout[0], correctout.size(), &decrypted[0]);576 decrypted.resize(size);577 BOOST_CHECK(decrypted.size() == in.size());578 BOOST_CHECK_MESSAGE(decrypted == in, HexStr(decrypted) + std::string("" != "") + hexin);579 580 // Encrypt and re-decrypt substrings of the plaintext and verify that they equal each-other581 for(std::vector<unsigned char>::iterator i(in.begin()); i != in.end(); ++i)582 {583 std::vector<unsigned char> sub(i, in.end());584 std::vector<unsigned char> subout(sub.size() + AES_BLOCKSIZE);585 int size = enc.Encrypt(&sub[0], sub.size(), &subout[0]);586 if (size != 0)587 {588 subout.resize(size);589 std::vector<unsigned char> subdecrypted(subout.size());590 size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]);591 subdecrypted.resize(size);592 BOOST_CHECK(decrypted.size() == in.size());593 BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + std::string("" != "") + HexStr(sub));594 }595 }596}597 598void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout)599{600 std::vector<unsigned char> key = ParseHex(hexkey);601 std::vector<unsigned char> iv = ParseHex(hexiv);602 std::vector<unsigned char> in = ParseHex(hexin);603 std::vector<unsigned char> correctout = ParseHex(hexout);604 std::vector<unsigned char> realout(in.size() + AES_BLOCKSIZE);605 606 // Encrypt the plaintext and verify that it equals the cipher607 AES256CBCEncrypt enc(&key[0], &iv[0], pad);608 int size = enc.Encrypt(&in[0], in.size(), &realout[0]);609 realout.resize(size);610 BOOST_CHECK(realout.size() == correctout.size());611 BOOST_CHECK_MESSAGE(realout == correctout, HexStr(realout) + std::string("" != "") + hexout);612 613 // Decrypt the cipher and verify that it equals the plaintext614 std::vector<unsigned char> decrypted(correctout.size());615 AES256CBCDecrypt dec(&key[0], &iv[0], pad);616 size = dec.Decrypt(&correctout[0], correctout.size(), &decrypted[0]);617 decrypted.resize(size);618 BOOST_CHECK(decrypted.size() == in.size());619 BOOST_CHECK_MESSAGE(decrypted == in, HexStr(decrypted) + std::string("" != "") + hexin);620 621 // Encrypt and re-decrypt substrings of the plaintext and verify that they equal each-other622 for(std::vector<unsigned char>::iterator i(in.begin()); i != in.end(); ++i)623 {624 std::vector<unsigned char> sub(i, in.end());625 std::vector<unsigned char> subout(sub.size() + AES_BLOCKSIZE);626 int size = enc.Encrypt(&sub[0], sub.size(), &subout[0]);627 if (size != 0)628 {629 subout.resize(size);630 std::vector<unsigned char> subdecrypted(subout.size());631 size = dec.Decrypt(&subout[0], subout.size(), &subdecrypted[0]);632 subdecrypted.resize(size);633 BOOST_CHECK(decrypted.size() == in.size());634 BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + std::string("" != "") + HexStr(sub));635 }636 }637}638 639std::string LongTestString(void) {640 std::string ret;641 for (int i=0; i<200000; i++) {642 ret += (unsigned char)(i);643 ret += (unsigned char)(i >> 4);644 ret += (unsigned char)(i >> 8);645 ret += (unsigned char)(i >> 12);646 ret += (unsigned char)(i >> 16);647 }648 return ret;649}650 651const std::string test1 = LongTestString();652 653BOOST_AUTO_TEST_CASE(ripemd160_testvectors) {654 TestRIPEMD160("""", ""9c1185a5c5e9fc54612808977ee8f548b2258d31"");655 TestRIPEMD160(""abc"", ""8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"");656 TestRIPEMD160(""message digest"", ""5d0689ef49d2fae572b881b123a85ffa21595f36"");657 TestRIPEMD160(""secure hash algorithm"", ""20397528223b6a5f4cbc2808aba0464e645544f9"");658 TestRIPEMD160(""RIPEMD160 is considered to be safe"", ""a7d78608c7af8a8e728778e81576870734122b66"");659 TestRIPEMD160(""abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"",660 ""12a053384a9c0c88e405a06c27dcf49ada62eb2b"");661 TestRIPEMD160(""For this sample, this 63-byte string will be used as input data"",662 ""de90dbfee14b63fb5abf27c2ad4a82aaa5f27a11"");663 TestRIPEMD160(""This is exactly 64 bytes long, not counting the terminating byte"",664 ""eda31d51d3a623b81e19eb02e24ff65d27d67b37"");665 TestRIPEMD160(std::string(1000000, 'a'), ""52783243c1697bdbe16d37f97f68f08325dc1528"");666 TestRIPEMD160(test1, ""464243587bd146ea835cdf57bdae582f25ec45f1"");667}668 669BOOST_AUTO_TEST_CASE(sha1_testvectors) {670 TestSHA1("""", ""da39a3ee5e6b4b0d3255bfef95601890afd80709"");671 TestSHA1(""abc"", ""a9993e364706816aba3e25717850c26c9cd0d89d"");672 TestSHA1(""message digest"", ""c12252ceda8be8994d5fa0290a47231c1d16aae3"");673 TestSHA1(""secure hash algorithm"", ""d4d6d2f0ebe317513bbd8d967d89bac5819c2f60"");674 TestSHA1(""SHA1 is considered to be safe"", ""f2b6650569ad3a8720348dd6ea6c497dee3a842a"");675 TestSHA1(""abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"",676 ""84983e441c3bd26ebaae4aa1f95129e5e54670f1"");677 TestSHA1(""For this sample, this 63-byte string will be used as input data"",678 ""4f0ea5cd0585a23d028abdc1a6684e5a8094dc49"");679 TestSHA1(""This is exactly 64 bytes long, not counting the terminating byte"",680 ""fb679f23e7d1ce053313e66e127ab1b444397057"");681 TestSHA1(std::string(1000000, 'a'), ""34aa973cd4c4daa4f61eeb2bdbad27316534016f"");682 TestSHA1(test1, ""b7755760681cbfd971451668f32af5774f4656b5"");683}684 685BOOST_AUTO_TEST_CASE(sha256_testvectors) {686 TestSHA256("""", ""e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"");687 TestSHA256(""abc"", ""ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"");688 TestSHA256(""message digest"",689 ""f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650"");690 TestSHA256(""secure hash algorithm"",691 ""f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d"");692 TestSHA256(""SHA256 is considered to be safe"",693 ""6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630"");694 TestSHA256(""abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"",695 ""248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"");696 TestSHA256(""For this sample, this 63-byte string will be used as input data"",697 ""f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342"");698 TestSHA256(""This is exactly 64 bytes long, not counting the terminating byte"",699 ""ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8"");700 TestSHA256(""As Bitcoin relies on 80 byte header hashes, we want to have an example for that."",701 ""7406e8de7d6e4fffc573daef05aefb8806e7790f55eab5576f31349743cca743"");702 TestSHA256(std::string(1000000, 'a'),703 ""cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"");704 TestSHA256(test1, ""a316d55510b49662420f49d145d42fb83f31ef8dc016aa4e32df049991a91e26"");705}706 707BOOST_AUTO_TEST_CASE(sha512_testvectors) {708 TestSHA512("""",709 ""cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce""710 ""47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"");711 TestSHA512(""abc"",712 ""ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a""713 ""2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"");714 TestSHA512(""message digest"",715 ""107dbf389d9e9f71a3a95f6c055b9251bc5268c2be16d6c13492ea45b0199f33""716 ""09e16455ab1e96118e8a905d5597b72038ddb372a89826046de66687bb420e7c"");717 TestSHA512(""secure hash algorithm"",718 ""7746d91f3de30c68cec0dd693120a7e8b04d8073cb699bdce1a3f64127bca7a3""719 ""d5db502e814bb63c063a7a5043b2df87c61133395f4ad1edca7fcf4b30c3236e"");720 TestSHA512(""SHA512 is considered to be safe"",721 ""099e6468d889e1c79092a89ae925a9499b5408e01b66cb5b0a3bd0dfa51a9964""722 ""6b4a3901caab1318189f74cd8cf2e941829012f2449df52067d3dd5b978456c2"");723 TestSHA512(""abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"",724 ""204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c335""725 ""96fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445"");726 TestSHA512(""For this sample, this 63-byte string will be used as input data"",727 ""b3de4afbc516d2478fe9b518d063bda6c8dd65fc38402dd81d1eb7364e72fb6e""728 ""6663cf6d2771c8f5a6da09601712fb3d2a36c6ffea3e28b0818b05b0a8660766"");729 TestSHA512(""This is exactly 64 bytes long, not counting the terminating byte"",730 ""70aefeaa0e7ac4f8fe17532d7185a289bee3b428d950c14fa8b713ca09814a38""731 ""7d245870e007a80ad97c369d193e41701aa07f3221d15f0e65a1ff970cedf030"");732 TestSHA512(""abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno""733 ""ijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"",734 ""8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018""735 ""501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909"");736 TestSHA512(std::string(1000000, 'a'),737 ""e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb""738 ""de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b"");739 TestSHA512(test1,740 ""40cac46c147e6131c5193dd5f34e9d8bb4951395f27b08c558c65ff4ba2de594""741 ""37de8c3ef5459d76a52cedc02dc499a3c9ed9dedbfb3281afd9653b8a112fafc"");742}743 744BOOST_AUTO_TEST_CASE(hmac_sha256_testvectors) {745 // test cases 1, 2, 3, 4, 6 and 7 of RFC 4231746 TestHMACSHA256(""0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"",747 ""4869205468657265"",748 ""b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"");749 TestHMACSHA256(""4a656665"",750 ""7768617420646f2079612077616e7420666f72206e6f7468696e673f"",751 ""5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"");752 TestHMACSHA256(""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"",753 ""dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd""754 ""dddddddddddddddddddddddddddddddddddd"",755 ""773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe"");756 TestHMACSHA256(""0102030405060708090a0b0c0d0e0f10111213141516171819"",757 ""cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd""758 ""cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"",759 ""82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b"");760 TestHMACSHA256(""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""761 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""762 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""763 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""764 ""aaaaaa"",765 ""54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a""766 ""65204b6579202d2048617368204b6579204669727374"",767 ""60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54"");768 TestHMACSHA256(""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""769 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""770 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""771 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""772 ""aaaaaa"",773 ""5468697320697320612074657374207573696e672061206c6172676572207468""774 ""616e20626c6f636b2d73697a65206b657920616e642061206c61726765722074""775 ""68616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565""776 ""647320746f20626520686173686564206265666f7265206265696e6720757365""777 ""642062792074686520484d414320616c676f726974686d2e"",778 ""9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2"");779}780 781BOOST_AUTO_TEST_CASE(hmac_sha512_testvectors) {782 // test cases 1, 2, 3, 4, 6 and 7 of RFC 4231783 TestHMACSHA512(""0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"",784 ""4869205468657265"",785 ""87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cde""786 ""daa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854"");787 TestHMACSHA512(""4a656665"",788 ""7768617420646f2079612077616e7420666f72206e6f7468696e673f"",789 ""164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea250554""790 ""9758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737"");791 TestHMACSHA512(""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"",792 ""dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd""793 ""dddddddddddddddddddddddddddddddddddd"",794 ""fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39""795 ""bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb"");796 TestHMACSHA512(""0102030405060708090a0b0c0d0e0f10111213141516171819"",797 ""cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd""798 ""cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"",799 ""b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3db""800 ""a91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd"");801 TestHMACSHA512(""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""802 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""803 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""804 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""805 ""aaaaaa"",806 ""54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a""807 ""65204b6579202d2048617368204b6579204669727374"",808 ""80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f352""809 ""6b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598"");810 TestHMACSHA512(""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""811 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""812 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""813 ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""814 ""aaaaaa"",815 ""5468697320697320612074657374207573696e672061206c6172676572207468""816 ""616e20626c6f636b2d73697a65206b657920616e642061206c61726765722074""817 ""68616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565""818 ""647320746f20626520686173686564206265666f7265206265696e6720757365""819 ""642062792074686520484d414320616c676f726974686d2e"",820 ""e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944""821 ""b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58"");822}823 824void TestRFC6979(const std::string& hexkey, const std::string& hexmsg, const std::vector<std::string>& hexout)825{826 std::vector<unsigned char> key = ParseHex(hexkey);827 std::vector<unsigned char> msg = ParseHex(hexmsg);828 RFC6979_HMAC_SHA256 rng(&key[0], key.size(), &msg[0], msg.size());829 830 for (unsigned int i = 0; i < hexout.size(); i++) {831 std::vector<unsigned char> out = ParseHex(hexout[i]);832 std::vector<unsigned char> gen;833 gen.resize(out.size());834 rng.Generate(&gen[0], gen.size());835 BOOST_CHECK(out == gen);836 }837}838 839BOOST_AUTO_TEST_CASE(rfc6979_hmac_sha256)840{841 TestRFC6979(842 ""0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f00"",843 ""4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a"",844 {""4fe29525b2086809159acdf0506efb86b0ec932c7ba44256ab321e421e67e9fb"",845 ""2bf0fff1d3c378a22dc5de1d856522325c65b504491a0cbd01cb8f3aa67ffd4a"",846 ""f528b410cb541f77000d7afb6c5b53c5c471eab43e466d9ac5190c39c82fd82e""});847 848 TestRFC6979(849 ""FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"",850 ""e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"",851 {""9c236c165b82ae0cd590659e100b6bab3036e7ba8b06749baf6981e16f1a2b95"",852 ""df471061625bc0ea14b682feee2c9c02f235da04204c1d62a1536c6e17aed7a9"",853 ""7597887cbd76321f32e30440679a22cf7f8d9d2eac390e581fea091ce202ba94""});854}855 856 857BOOST_AUTO_TEST_CASE(chacha20_testvector)858{859 // Test vector from RFC 7539860 861 // test encryption862 TestChaCha20(""4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756""863 ""c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e""864 ""20776f756c642062652069742e"",865 ""000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"", 0x4a000000UL, 1,866 ""6e2e359a2568f98041ba0728dd0d6981e97e7aec1d4360c20a27afccfd9fae0bf91b65c5524733ab8f593dabcd62b3571639d""867 ""624e65152ab8f530c359f0861d807ca0dbf500d6a6156a38e088a22b65e52bc514d16ccf806818ce91ab77937365af90bbf74""868 ""a35be6b40b8eedf2785e42874d""869 );870 871 // test keystream output872 TestChaCha20("""", ""000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"", 0x4a000000UL, 1,873 ""224f51f3401bd9e12fde276fb8631ded8c131f823d2c06e27e4fcaec9ef3cf788a3b0aa372600a92b57974cded2b9334794cb""874 ""a40c63e34cdea212c4cf07d41b769a6749f3f630f4122cafe28ec4dc47e26d4346d70b98c73f3e9c53ac40c5945398b6eda1a""875 ""832c89c167eacd901d7e2bf363"");876 877 // Test vectors from https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7878 TestChaCha20("""", ""0000000000000000000000000000000000000000000000000000000000000000"", 0, 0,879 ""76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b""880 ""8f41518a11cc387b669b2ee6586"");881 TestChaCha20("""", ""0000000000000000000000000000000000000000000000000000000000000001"", 0, 0,882 ""4540f05a9f1fb296d7736e7b208e3c96eb4fe1834688d2604f450952ed432d41bbe2a0b6ea7566d2a5d1e7e20d42af2c53d79""883 ""2b1c43fea817e9ad275ae546963"");884 TestChaCha20("""", ""0000000000000000000000000000000000000000000000000000000000000000"", 0x0100000000000000ULL, 0,885 ""de9cba7bf3d69ef5e786dc63973f653a0b49e015adbff7134fcb7df137821031e85a050278a7084527214f73efc7fa5b52770""886 ""62eb7a0433e445f41e3"");887 TestChaCha20("""", ""0000000000000000000000000000000000000000000000000000000000000000"", 1, 0,888 ""ef3fdfd6c61578fbf5cf35bd3dd33b8009631634d21e42ac33960bd138e50d32111e4caf237ee53ca8ad6426194a88545ddc4""889 ""97a0b466e7d6bbdb0041b2f586b"");890 TestChaCha20("""", ""000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"", 0x0706050403020100ULL, 0,891 ""f798a189f195e66982105ffb640bb7757f579da31602fc93ec01ac56f85ac3c134a4547b733b46413042c9440049176905d3b""892 ""e59ea1c53f15916155c2be8241a38008b9a26bc35941e2444177c8ade6689de95264986d95889fb60e84629c9bd9a5acb1cc1""893 ""18be563eb9b3a4a472f82e09a7e778492b562ef7130e88dfe031c79db9d4f7c7a899151b9a475032b63fc385245fe054e3dd5""894 ""a97a5f576fe064025d3ce042c566ab2c507b138db853e3d6959660996546cc9c4a6eafdc777c040d70eaf46f76dad3979e5c5""895 ""360c3317166a1c894c94a371876a94df7628fe4eaaf2ccb27d5aaae0ad7ad0f9d4b6ad3b54098746d4524d38407a6deb3ab78""896 ""fab78c9"");897}898 899BOOST_AUTO_TEST_CASE(countbits_tests)900{901 FastRandomContext ctx;902 for (int i = 0; i <= 64; ++i) {903 if (i == 0) {904 // Check handling of zero.905 BOOST_CHECK_EQUAL(CountBits(0), 0);906 } else if (i < 10) {907 for (uint64_t j = 1 << (i - 1); (j >> i) == 0; ++j) {908 // Exhaustively test up to 10 bits909 BOOST_CHECK_EQUAL(CountBits(j), i);910 }911 } else {912 for (int k = 0; k < 1000; k++) {913 // Randomly test 1000 samples of each length above 10 bits.914 uint64_t j = ((uint64_t)1) << (i - 1) | ctx.randbits(i - 1);915 BOOST_CHECK_EQUAL(CountBits(j), i);916 }917 }918 }919}920 921BOOST_AUTO_TEST_CASE(aes_testvectors) {922 // AES test vectors from FIPS 197.923 TestAES128(""000102030405060708090a0b0c0d0e0f"", ""00112233445566778899aabbccddeeff"", ""69c4e0d86a7b0430d8cdb78070b4c55a"");924 TestAES256(""000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"", ""00112233445566778899aabbccddeeff"", ""8ea2b7ca516745bfeafc49904b496089"");925 926 // AES-ECB test vectors from NIST sp800-38a.927 TestAES128(""2b7e151628aed2a6abf7158809cf4f3c"", ""6bc1bee22e409f96e93d7e117393172a"", ""3ad77bb40d7a3660a89ecaf32466ef97"");928 TestAES128(""2b7e151628aed2a6abf7158809cf4f3c"", ""ae2d8a571e03ac9c9eb76fac45af8e51"", ""f5d3d58503b9699de785895a96fdbaaf"");929 TestAES128(""2b7e151628aed2a6abf7158809cf4f3c"", ""30c81c46a35ce411e5fbc1191a0a52ef"", ""43b1cd7f598ece23881b00e3ed030688"");930 TestAES128(""2b7e151628aed2a6abf7158809cf4f3c"", ""f69f2445df4f9b17ad2b417be66c3710"", ""7b0c785e27e8ad3f8223207104725dd4"");931 TestAES256(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", ""6bc1bee22e409f96e93d7e117393172a"", ""f3eed1bdb5d2a03c064b5a7e3db181f8"");932 TestAES256(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", ""ae2d8a571e03ac9c9eb76fac45af8e51"", ""591ccb10d410ed26dc5ba74a31362870"");933 TestAES256(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", ""30c81c46a35ce411e5fbc1191a0a52ef"", ""b6ed21b99ca6f4f9f153e7b1beafed1d"");934 TestAES256(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", ""f69f2445df4f9b17ad2b417be66c3710"", ""23304b7a39f9f3ff067d8d8f9e24ecc7"");935}936 937BOOST_AUTO_TEST_CASE(aes_cbc_testvectors) {938 939 // NIST AES CBC 128-bit encryption test-vectors940 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""000102030405060708090A0B0C0D0E0F"", false, \\941 ""6bc1bee22e409f96e93d7e117393172a"", ""7649abac8119b246cee98e9b12e9197d"");942 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""7649ABAC8119B246CEE98E9B12E9197D"", false, \\943 ""ae2d8a571e03ac9c9eb76fac45af8e51"", ""5086cb9b507219ee95db113a917678b2"");944 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""5086cb9b507219ee95db113a917678b2"", false, \\945 ""30c81c46a35ce411e5fbc1191a0a52ef"", ""73bed6b8e3c1743b7116e69e22229516"");946 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""73bed6b8e3c1743b7116e69e22229516"", false, \\947 ""f69f2445df4f9b17ad2b417be66c3710"", ""3ff1caa1681fac09120eca307586e1a7"");948 949 // The same vectors with padding enabled950 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""000102030405060708090A0B0C0D0E0F"", true, \\951 ""6bc1bee22e409f96e93d7e117393172a"", ""7649abac8119b246cee98e9b12e9197d8964e0b149c10b7b682e6e39aaeb731c"");952 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""7649ABAC8119B246CEE98E9B12E9197D"", true, \\953 ""ae2d8a571e03ac9c9eb76fac45af8e51"", ""5086cb9b507219ee95db113a917678b255e21d7100b988ffec32feeafaf23538"");954 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""5086cb9b507219ee95db113a917678b2"", true, \\955 ""30c81c46a35ce411e5fbc1191a0a52ef"", ""73bed6b8e3c1743b7116e69e22229516f6eccda327bf8e5ec43718b0039adceb"");956 TestAES128CBC(""2b7e151628aed2a6abf7158809cf4f3c"", ""73bed6b8e3c1743b7116e69e22229516"", true, \\957 ""f69f2445df4f9b17ad2b417be66c3710"", ""3ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012"");958 959 // NIST AES CBC 256-bit encryption test-vectors960 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\961 ""000102030405060708090A0B0C0D0E0F"", false, ""6bc1bee22e409f96e93d7e117393172a"", \\962 ""f58c4c04d6e5f1ba779eabfb5f7bfbd6"");963 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\964 ""F58C4C04D6E5F1BA779EABFB5F7BFBD6"", false, ""ae2d8a571e03ac9c9eb76fac45af8e51"", \\965 ""9cfc4e967edb808d679f777bc6702c7d"");966 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\967 ""9CFC4E967EDB808D679F777BC6702C7D"", false, ""30c81c46a35ce411e5fbc1191a0a52ef"",968 ""39f23369a9d9bacfa530e26304231461"");969 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\970 ""39F23369A9D9BACFA530E26304231461"", false, ""f69f2445df4f9b17ad2b417be66c3710"", \\971 ""b2eb05e2c39be9fcda6c19078c6a9d1b"");972 973 // The same vectors with padding enabled974 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\975 ""000102030405060708090A0B0C0D0E0F"", true, ""6bc1bee22e409f96e93d7e117393172a"", \\976 ""f58c4c04d6e5f1ba779eabfb5f7bfbd6485a5c81519cf378fa36d42b8547edc0"");977 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\978 ""F58C4C04D6E5F1BA779EABFB5F7BFBD6"", true, ""ae2d8a571e03ac9c9eb76fac45af8e51"", \\979 ""9cfc4e967edb808d679f777bc6702c7d3a3aa5e0213db1a9901f9036cf5102d2"");980 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\981 ""9CFC4E967EDB808D679F777BC6702C7D"", true, ""30c81c46a35ce411e5fbc1191a0a52ef"",982 ""39f23369a9d9bacfa530e263042314612f8da707643c90a6f732b3de1d3f5cee"");983 TestAES256CBC(""603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"", \\984 ""39F23369A9D9BACFA530E26304231461"", true, ""f69f2445df4f9b17ad2b417be66c3710"", \\985 ""b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644"");986}987 988BOOST_AUTO_TEST_SUITE_END()989",16182,True,3087.206155315729,median990"/*991Bullet Continuous Collision Detection and Physics Library992Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/993 994This software is provided 'as-is', without any express or implied warranty.995In no event will the authors be held liable for any damages arising from the use of this software.996Permission is granted to anyone to use this software for any purpose,997including commercial applications, and to alter it and redistribute it freely,998subject to the following restrictions:999 10001. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.10012. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.10023. This notice may not be removed or altered from any source distribution.1003*/1004 1005#include ""btCollisionWorld.h""1006#include ""btCollisionDispatcher.h""1007#include ""BulletCollision/CollisionDispatch/btCollisionObject.h""1008#include ""BulletCollision/CollisionShapes/btCollisionShape.h""1009#include ""BulletCollision/CollisionShapes/btConvexShape.h""1010#include ""BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h""1011#include ""BulletCollision/CollisionShapes/btSphereShape.h"" //for raycasting1012#include ""BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"" //for raycasting1013#include ""BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"" //for raycasting1014#include ""BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"" //for raycasting1015#include ""BulletCollision/NarrowPhaseCollision/btRaycastCallback.h""1016#include ""BulletCollision/CollisionShapes/btCompoundShape.h""1017#include ""BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h""1018#include ""BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h""1019#include ""BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h""1020#include ""BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h""1021#include ""BulletCollision/BroadphaseCollision/btBroadphaseInterface.h""1022#include ""BulletCollision/BroadphaseCollision/btDbvt.h""1023#include ""LinearMath/btAabbUtil2.h""1024#include ""LinearMath/btQuickprof.h""1025#include ""LinearMath/btSerializer.h""1026#include ""BulletCollision/CollisionShapes/btConvexPolyhedron.h""1027#include ""BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h""1028 1029//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION1030 1031//#define USE_BRUTEFORCE_RAYBROADPHASE 11032//RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation' or 'updateAabbs' before using a rayTest1033//#define RECALCULATE_AABB_RAYCAST 11034 1035//When the user doesn't provide dispatcher or broadphase, create basic versions (and delete them in destructor)1036#include ""BulletCollision/CollisionDispatch/btCollisionDispatcher.h""1037#include ""BulletCollision/BroadphaseCollision/btSimpleBroadphase.h""1038#include ""BulletCollision/CollisionDispatch/btCollisionConfiguration.h""1039 1040///for debug drawing1041 1042//for debug rendering1043#include ""BulletCollision/CollisionShapes/btBoxShape.h""1044#include ""BulletCollision/CollisionShapes/btCapsuleShape.h""1045#include ""BulletCollision/CollisionShapes/btCompoundShape.h""1046#include ""BulletCollision/CollisionShapes/btConeShape.h""1047#include ""BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h""1048#include ""BulletCollision/CollisionShapes/btCylinderShape.h""1049#include ""BulletCollision/CollisionShapes/btMultiSphereShape.h""1050#include ""BulletCollision/CollisionShapes/btPolyhedralConvexShape.h""1051#include ""BulletCollision/CollisionShapes/btSphereShape.h""1052#include ""BulletCollision/CollisionShapes/btTriangleCallback.h""1053#include ""BulletCollision/CollisionShapes/btTriangleMeshShape.h""1054#include ""BulletCollision/CollisionShapes/btStaticPlaneShape.h""1055 1056btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher, btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration)1057 : m_dispatcher1(dispatcher),1058 m_broadphasePairCache(pairCache),1059 m_debugDrawer(0),1060 m_forceUpdateAllAabbs(true)1061{1062}1063 1064btCollisionWorld::~btCollisionWorld()1065{1066 //clean up remaining objects1067 int i;1068 for (i = 0; i < m_collisionObjects.size(); i++)1069 {1070 btCollisionObject* collisionObject = m_collisionObjects[i];1071 1072 btBroadphaseProxy* bp = collisionObject->getBroadphaseHandle();1073 if (bp)1074 {1075 //1076 // only clear the cached algorithms1077 //1078 getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bp, m_dispatcher1);1079 getBroadphase()->destroyProxy(bp, m_dispatcher1);1080 collisionObject->setBroadphaseHandle(0);1081 }1082 }1083}1084 1085void btCollisionWorld::refreshBroadphaseProxy(btCollisionObject* collisionObject)1086{1087 if (collisionObject->getBroadphaseHandle())1088 {1089 int collisionFilterGroup = collisionObject->getBroadphaseHandle()->m_collisionFilterGroup;1090 int collisionFilterMask = collisionObject->getBroadphaseHandle()->m_collisionFilterMask;1091 1092 getBroadphase()->destroyProxy(collisionObject->getBroadphaseHandle(), getDispatcher());1093 1094 //calculate new AABB1095 btTransform trans = collisionObject->getWorldTransform();1096 1097 btVector3 minAabb;1098 btVector3 maxAabb;1099 collisionObject->getCollisionShape()->getAabb(trans, minAabb, maxAabb);1100 1101 int type = collisionObject->getCollisionShape()->getShapeType();1102 collisionObject->setBroadphaseHandle(getBroadphase()->createProxy(1103 minAabb,1104 maxAabb,1105 type,1106 collisionObject,1107 collisionFilterGroup,1108 collisionFilterMask,1109 m_dispatcher1));1110 }1111}1112 1113void btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject, int collisionFilterGroup, int collisionFilterMask)1114{1115 btAssert(collisionObject);1116 1117 //check that the object isn't already added1118 btAssert(m_collisionObjects.findLinearSearch(collisionObject) == m_collisionObjects.size());1119 btAssert(collisionObject->getWorldArrayIndex() == -1); // do not add the same object to more than one collision world1120 1121 collisionObject->setWorldArrayIndex(m_collisionObjects.size());1122 m_collisionObjects.push_back(collisionObject);1123 1124 //calculate new AABB1125 btTransform trans = collisionObject->getWorldTransform();1126 1127 btVector3 minAabb;1128 btVector3 maxAabb;1129 collisionObject->getCollisionShape()->getAabb(trans, minAabb, maxAabb);1130 1131 int type = collisionObject->getCollisionShape()->getShapeType();1132 collisionObject->setBroadphaseHandle(getBroadphase()->createProxy(1133 minAabb,1134 maxAabb,1135 type,1136 collisionObject,1137 collisionFilterGroup,1138 collisionFilterMask,1139 m_dispatcher1));1140}1141 1142void btCollisionWorld::updateSingleAabb(btCollisionObject* colObj)1143{1144 btVector3 minAabb, maxAabb;1145 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb, maxAabb);1146 //need to increase the aabb for contact thresholds1147 btVector3 contactThreshold(gContactBreakingThreshold, gContactBreakingThreshold, gContactBreakingThreshold);1148 minAabb -= contactThreshold;1149 maxAabb += contactThreshold;1150 1151 if (getDispatchInfo().m_useContinuous && colObj->getInternalType() == btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())1152 {1153 btVector3 minAabb2, maxAabb2;1154 colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(), minAabb2, maxAabb2);1155 minAabb2 -= contactThreshold;1156 maxAabb2 += contactThreshold;1157 minAabb.setMin(minAabb2);1158 maxAabb.setMax(maxAabb2);1159 }1160 1161 btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;1162 1163 //moving objects should be moderately sized, probably something wrong if not1164 if (colObj->isStaticObject() || ((maxAabb - minAabb).length2() < btScalar(1e12)))1165 {1166 bp->setAabb(colObj->getBroadphaseHandle(), minAabb, maxAabb, m_dispatcher1);1167 }1168 else1169 {1170 //something went wrong, investigate1171 //this assert is unwanted in 3D modelers (danger of loosing work)1172 colObj->setActivationState(DISABLE_SIMULATION);1173 1174 static bool reportMe = true;1175 if (reportMe && m_debugDrawer)1176 {1177 reportMe = false;1178 m_debugDrawer->reportErrorWarning(""Overflow in AABB, object removed from simulation"");1179 m_debugDrawer->reportErrorWarning(""If you can reproduce this, please email bugs@continuousphysics.com\\n"");1180 m_debugDrawer->reportErrorWarning(""Please include above information, your Platform, version of OS.\\n"");1181 m_debugDrawer->reportErrorWarning(""Thanks.\\n"");1182 }1183 }1184}1185 1186void btCollisionWorld::updateAabbs()1187{1188 BT_PROFILE(""updateAabbs"");1189 1190 btTransform predictedTrans;1191 for (int i = 0; i < m_collisionObjects.size(); i++)1192 {1193 btCollisionObject* colObj = m_collisionObjects[i];1194 btAssert(colObj->getWorldArrayIndex() == i);1195 1196 //only update aabb of active objects1197 if (m_forceUpdateAllAabbs || colObj->isActive())1198 {1199 updateSingleAabb(colObj);1200 }