Skip to content

[LA64_DYNAREC] Close the fastnan path for MINSS/MAXSS/VMINSS/VMAXSS to correct NaN semantics.#3486

Merged
ptitSeb merged 1 commit intoptitSeb:mainfrom
yzewei:vmax/min_ss
Feb 10, 2026
Merged

[LA64_DYNAREC] Close the fastnan path for MINSS/MAXSS/VMINSS/VMAXSS to correct NaN semantics.#3486
ptitSeb merged 1 commit intoptitSeb:mainfrom
yzewei:vmax/min_ss

Conversation

@yzewei
Copy link
Copy Markdown
Contributor

@yzewei yzewei commented Feb 10, 2026

Problem:
LoongArch's FMIN_S/FMAX_S rules for determining NaN are inconsistent with x86's MINSS/MAXSS.

This causes NaN handling errors when dynarec_fastnan=1 (error scenario observed: numpy max/argmax returns 1.0 instead of nan).

Test Code:

#gcc -O0 -mavx -o test test.c 
#include <immintrin.h>
#include <stdio.h>
#include <math.h>

int main() {
    float a = 1.0f;
    float b = NAN;

    __m128 va = _mm_set_ss(a);   // dest
    __m128 vb = _mm_set_ss(b);   // src
    __m128 vc = _mm_max_ss(va, vb); 

    float out;
    _mm_store_ss(&out, vc);
    printf("vmaxss out=%f\n", out);
    return 0;
}

If we need to check whether d0/d1 is NaN in order to preserve fastnan(FMAX_S), it might actually be slower.

…o correct NaN semantics.

Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
@ptitSeb ptitSeb merged commit 4f01e75 into ptitSeb:main Feb 10, 2026
27 checks passed
@ptitSeb
Copy link
Copy Markdown
Owner

ptitSeb commented Feb 10, 2026

This is in par with ARM64 backend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants