@@ -330,7 +330,104 @@ class InternalAddress: public Address {
330330};
331331
332332class Assembler : public AbstractAssembler {
333- public:
333+ protected:
334+
335+ static int zfa_zli_lookup_double (uint64_t value) {
336+ switch (value) {
337+ case 0xbff0000000000000 : return 0 ;
338+ case 0x0010000000000000 : return 1 ;
339+ case 0x3ef0000000000000 : return 2 ;
340+ case 0x3f00000000000000 : return 3 ;
341+ case 0x3f70000000000000 : return 4 ;
342+ case 0x3f80000000000000 : return 5 ;
343+ case 0x3fb0000000000000 : return 6 ;
344+ case 0x3fc0000000000000 : return 7 ;
345+ case 0x3fd0000000000000 : return 8 ;
346+ case 0x3fd4000000000000 : return 9 ;
347+ case 0x3fd8000000000000 : return 10 ;
348+ case 0x3fdc000000000000 : return 11 ;
349+ case 0x3fe0000000000000 : return 12 ;
350+ case 0x3fe4000000000000 : return 13 ;
351+ case 0x3fe8000000000000 : return 14 ;
352+ case 0x3fec000000000000 : return 15 ;
353+ case 0x3ff0000000000000 : return 16 ;
354+ case 0x3ff4000000000000 : return 17 ;
355+ case 0x3ff8000000000000 : return 18 ;
356+ case 0x3ffc000000000000 : return 19 ;
357+ case 0x4000000000000000 : return 20 ;
358+ case 0x4004000000000000 : return 21 ;
359+ case 0x4008000000000000 : return 22 ;
360+ case 0x4010000000000000 : return 23 ;
361+ case 0x4020000000000000 : return 24 ;
362+ case 0x4030000000000000 : return 25 ;
363+ case 0x4060000000000000 : return 26 ;
364+ case 0x4070000000000000 : return 27 ;
365+ case 0x40e0000000000000 : return 28 ;
366+ case 0x40f0000000000000 : return 29 ;
367+ case 0x7ff0000000000000 : return 30 ;
368+ case 0x7ff8000000000000 : return 31 ;
369+ default : break ;
370+ }
371+ return -1 ;
372+ }
373+
374+
375+ static int zfa_zli_lookup_float (uint32_t value) {
376+ switch (value) {
377+ case 0xbf800000 : return 0 ;
378+ case 0x00800000 : return 1 ;
379+ case 0x37800000 : return 2 ;
380+ case 0x38000000 : return 3 ;
381+ case 0x3b800000 : return 4 ;
382+ case 0x3c000000 : return 5 ;
383+ case 0x3d800000 : return 6 ;
384+ case 0x3e000000 : return 7 ;
385+ case 0x3e800000 : return 8 ;
386+ case 0x3ea00000 : return 9 ;
387+ case 0x3ec00000 : return 10 ;
388+ case 0x3ee00000 : return 11 ;
389+ case 0x3f000000 : return 12 ;
390+ case 0x3f200000 : return 13 ;
391+ case 0x3f400000 : return 14 ;
392+ case 0x3f600000 : return 15 ;
393+ case 0x3f800000 : return 16 ;
394+ case 0x3fa00000 : return 17 ;
395+ case 0x3fc00000 : return 18 ;
396+ case 0x3fe00000 : return 19 ;
397+ case 0x40000000 : return 20 ;
398+ case 0x40200000 : return 21 ;
399+ case 0x40400000 : return 22 ;
400+ case 0x40800000 : return 23 ;
401+ case 0x41000000 : return 24 ;
402+ case 0x41800000 : return 25 ;
403+ case 0x43000000 : return 26 ;
404+ case 0x43800000 : return 27 ;
405+ case 0x47000000 : return 28 ;
406+ case 0x47800000 : return 29 ;
407+ case 0x7f800000 : return 30 ;
408+ case 0x7fc00000 : return 31 ;
409+ default : break ;
410+ }
411+ return -1 ;
412+ }
413+
414+ public:
415+
416+ static bool can_zfa_zli_float (jfloat f) {
417+ if (!UseZfa) {
418+ return false ;
419+ }
420+ uint32_t f_bits = (uint32_t )jint_cast (f);
421+ return zfa_zli_lookup_float (f_bits) != -1 ;
422+ }
423+
424+ static bool can_zfa_zli_double (jdouble d) {
425+ if (!UseZfa) {
426+ return false ;
427+ }
428+ uint64_t d_bits = (uint64_t )julong_cast (d);
429+ return zfa_zli_lookup_double (d_bits) != -1 ;
430+ }
334431
335432 enum {
336433 instruction_size = 4 ,
@@ -972,6 +1069,13 @@ enum operand_size { int8, int16, int32, uint32, int64 };
9721069 fp_base<Fmt, funct5>(Rd->raw_encoding (), Rs1->raw_encoding (), Rs2, (RoundingMode)rm);
9731070 }
9741071
1072+ template <FmtPrecision Fmt, uint8_t funct5>
1073+ void fp_base (FloatRegister Rd, uint8_t Rs1, uint8_t Rs2, int8_t rm) {
1074+ guarantee (is_uimm5 (Rs1), " Rs1 is out of validity" );
1075+ guarantee (is_uimm5 (Rs2), " Rs2 is out of validity" );
1076+ fp_base<Fmt, funct5>(Rd->raw_encoding (), Rs1, Rs2, (RoundingMode)rm);
1077+ }
1078+
9751079 public:
9761080
9771081 enum FClassBits {
@@ -1293,6 +1397,18 @@ enum operand_size { int8, int16, int32, uint32, int64 };
12931397 fp_base<H_16_hp, 0b11100 >(Rd, Rs1, 0b00000 , 0b000 );
12941398 }
12951399
1400+ // -------------- ZFA Instruction Definitions --------------
1401+ // Zfa Extension for Additional Floating-Point Instructions
1402+ void _fli_s (FloatRegister Rd, uint8_t Rs1) {
1403+ assert_cond (UseZfa);
1404+ fp_base<S_32_sp, 0b11110 >(Rd, Rs1, 0b00001 , 0b000 );
1405+ }
1406+
1407+ void _fli_d (FloatRegister Rd, uint8_t Rs1) {
1408+ assert_cond (UseZfa);
1409+ fp_base<D_64_dp, 0b11110 >(Rd, Rs1, 0b00001 , 0b000 );
1410+ }
1411+
12961412// ==========================
12971413// RISC-V Vector Extension
12981414// ==========================
0 commit comments