Skip to content

Soft-Float Implementation #1

@Tilka

Description

@Tilka

This is what they probably use for constant propagation to match the hardware exactly. For basic arithmetic, it seems to follow IEEE 754 rules so far, but the transcendental functions will obviously be hardware-specific. The function parameters are actually all unsigned integers, I'm just making them floats where it matches IEEE 754 to make this easier to understand. Also, assume that implicit casts between integer and float are bit-casts.

uint32 exp_table[16] = {
    0x3F800000,
    0x3F85AAC3,
    0x3F8B95C2,
    0x3F91C3D3,
    0x3F9837F0,
    0x3F9EF532,
    0x3FA5FED7,
    0x3FAD583F,
    0x3FB504F3,
    0x3FBD08A4,
    0x3FC5672A,
    0x3FCE248C,
    0x3FD744FD,
    0x3FE0CCDF,
    0x3FEAC0C7,
    0x3FF5257D};

uint32 exp_table_low[16] = {
    0x00000000,
    0x38B0DA00,
    0x3860F200,
    0x38F4DD00,
    0x38FC1500,
    0x38193100,
    0x38B5AB00,
    0x36FBAA00,
    0x37F33400,
    0x37A3A000,
    0x38CA8500,
    0x378C1600,
    0x37FCCB00,
    0x37DEED00,
    0x37C6E800,
    0x383E8B00};

float _mali_clamp0_sf32(float x) { return clamp(x, 0, inf); } // NaN -> 0
float _mali_clamp1_sf32(float x) { return isnan(x) ? -1 : clamp(x, -1, 1); }
bool _mali_equal_sf32(float x, float y) { return x == y; } // -0 != +0 (?!)
bool _mali_equal_tb_sf32(float x, float y) { return x == y || (isnan(x) && isnan(y)); } // -0 != +0 (?!)
float _mali_suppress_inf_sf32(float x) { return isinf(x) ? copysign(FLT_MAX, x) : x; }
float _mali_suppress_nan_sf32(float x) { return isnan(x) ? 0 : x; }
float _mali_exp_table_sf32(uint4 i) { return exp_table[i]; }
float _mali_exp_table_low_sf32(uint4 i) { return exp_table_low[i]; }
float _mali_exp_table_small_sf32(uint4 i) { return exp_table[i] & 0xDFFFFFFF; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions