arch-gcn3: Add handling for Inf/overflow in CVT insts
authorChow, Marcus <marcus.chow@amd.com>
Mon, 10 Dec 2018 20:40:39 +0000 (15:40 -0500)
committerAnthony Gutierrez <anthony.gutierrez@amd.com>
Thu, 16 Jul 2020 20:37:22 +0000 (20:37 +0000)
Change-Id: I0fddffdeaebd9f45fe89f44d536f80a43de63ff5
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29953
Maintainer: Anthony Gutierrez <anthony.gutierrez@amd.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com>
src/arch/gcn3/insts/instructions.cc

index e93278ab703d2e3d16f516c69c5e4d3e3d227c03..a7b89234a1c0877ab5757dfc9bc31b6cfb441f54 100644 (file)
@@ -7260,8 +7260,16 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane]) || exp > 30) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = INT_MIN;
+                    } else {
+                        vdst[lane] = INT_MAX;
+                    }
                 } else {
                     vdst[lane] = (VecElemI32)src[lane];
                 }
@@ -7386,8 +7394,18 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane])) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = 0;
+                    } else {
+                        vdst[lane] = UINT_MAX;
+                    }
+                } else if (exp > 31) {
+                    vdst[lane] = UINT_MAX;
                 } else {
                     vdst[lane] = (VecElemU32)src[lane];
                 }
@@ -7422,8 +7440,16 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane]) || exp > 30) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = INT_MIN;
+                    } else {
+                        vdst[lane] = INT_MAX;
+                    }
                 } else {
                     vdst[lane] = (VecElemI32)src[lane];
                 }
@@ -7772,8 +7798,18 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane])) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = 0;
+                    } else {
+                        vdst[lane] = UINT_MAX;
+                    }
+                } else if (exp > 31) {
+                    vdst[lane] = UINT_MAX;
                 } else {
                     vdst[lane] = (VecElemU32)src[lane];
                 }
@@ -25075,8 +25111,16 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane]) || exp > 30) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = INT_MIN;
+                    } else {
+                        vdst[lane] = INT_MAX;
+                    }
                 } else {
                     vdst[lane] = (VecElemI32)src[lane];
                 }
@@ -25235,8 +25279,18 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane])) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = 0;
+                    } else {
+                        vdst[lane] = UINT_MAX;
+                    }
+                } else if (exp > 31) {
+                    vdst[lane] = UINT_MAX;
                 } else {
                     vdst[lane] = (VecElemU32)src[lane];
                 }
@@ -25287,8 +25341,16 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
+                int exp;
+                std::frexp(src[lane],&exp);
                 if (std::isnan(src[lane])) {
                     vdst[lane] = 0;
+                } else if (std::isinf(src[lane]) || exp > 30) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = INT_MIN;
+                    } else {
+                        vdst[lane] = INT_MAX;
+                    }
                 } else {
                     vdst[lane] = (VecElemI32)src[lane];
                 }
@@ -25725,7 +25787,21 @@ namespace Gcn3ISA
 
         for (int lane = 0; lane < NumVecElemPerVecReg; ++lane) {
             if (wf->execMask(lane)) {
-                vdst[lane] = (VecElemU32)src[lane];
+                int exp;
+                std::frexp(src[lane],&exp);
+                if (std::isnan(src[lane])) {
+                    vdst[lane] = 0;
+                } else if (std::isinf(src[lane])) {
+                    if (std::signbit(src[lane])) {
+                        vdst[lane] = 0;
+                    } else {
+                        vdst[lane] = UINT_MAX;
+                    }
+                } else if (exp > 31) {
+                    vdst[lane] = UINT_MAX;
+                } else {
+                    vdst[lane] = (VecElemU32)src[lane];
+                }
             }
         }