Revision 2dedf314 target-sparc/vis_helper.c
b/target-sparc/vis_helper.c | ||
---|---|---|
417 | 417 |
|
418 | 418 |
return sum; |
419 | 419 |
} |
420 |
|
|
421 |
uint32_t helper_fpack16(uint64_t gsr, uint64_t rs2) |
|
422 |
{ |
|
423 |
int scale = (gsr >> 3) & 0xf; |
|
424 |
uint32_t ret = 0; |
|
425 |
int byte; |
|
426 |
|
|
427 |
for (byte = 0; byte < 4; byte++) { |
|
428 |
uint32_t val; |
|
429 |
int16_t src = rs2 >> (byte * 16); |
|
430 |
int32_t scaled = src << scale; |
|
431 |
int32_t from_fixed = scaled >> 7; |
|
432 |
|
|
433 |
val = (from_fixed < 0 ? 0 : |
|
434 |
from_fixed > 255 ? 255 : from_fixed); |
|
435 |
|
|
436 |
ret |= val << (8 * byte); |
|
437 |
} |
|
438 |
|
|
439 |
return ret; |
|
440 |
} |
|
441 |
|
|
442 |
uint64_t helper_fpack32(uint64_t gsr, uint64_t rs1, uint64_t rs2) |
|
443 |
{ |
|
444 |
int scale = (gsr >> 3) & 0x1f; |
|
445 |
uint64_t ret = 0; |
|
446 |
int word; |
|
447 |
|
|
448 |
ret = (rs1 << 8) & ~(0x000000ff000000ffULL); |
|
449 |
for (word = 0; word < 2; word++) { |
|
450 |
uint64_t val; |
|
451 |
int32_t src = rs2 >> (word * 32); |
|
452 |
int64_t scaled = (int64_t)src << scale; |
|
453 |
int64_t from_fixed = scaled >> 23; |
|
454 |
|
|
455 |
val = (from_fixed < 0 ? 0 : |
|
456 |
(from_fixed > 255) ? 255 : from_fixed); |
|
457 |
|
|
458 |
ret |= val << (32 * word); |
|
459 |
} |
|
460 |
|
|
461 |
return ret; |
|
462 |
} |
|
463 |
|
|
464 |
uint32_t helper_fpackfix(uint64_t gsr, uint64_t rs2) |
|
465 |
{ |
|
466 |
int scale = (gsr >> 3) & 0x1f; |
|
467 |
uint32_t ret = 0; |
|
468 |
int word; |
|
469 |
|
|
470 |
for (word = 0; word < 2; word++) { |
|
471 |
uint32_t val; |
|
472 |
int32_t src = rs2 >> (word * 32); |
|
473 |
int64_t scaled = src << scale; |
|
474 |
int64_t from_fixed = scaled >> 16; |
|
475 |
|
|
476 |
val = (from_fixed < -32768 ? -32768 : |
|
477 |
from_fixed > 32767 ? 32767 : from_fixed); |
|
478 |
|
|
479 |
ret |= (val & 0xffff) << (word * 16); |
|
480 |
} |
|
481 |
|
|
482 |
return ret; |
|
483 |
} |
Also available in: Unified diff