Browse Source

fix armv7 roundmode (#3176)

tags/20211122
nihui GitHub 4 years ago
parent
commit
e9b5bbcd2d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions
  1. +31
    -0
      src/layer/arm/arm_usability.h
  2. +2
    -0
      src/layer/arm/quantize_arm.cpp
  3. +2
    -0
      src/layer/arm/requantize_arm.cpp

+ 31
- 0
src/layer/arm/arm_usability.h View File

@@ -15,6 +15,37 @@
#ifndef ARM_USABILITY_H
#define ARM_USABILITY_H

class FPSCRGuard
{
#if !__aarch64__
public:
FPSCRGuard()
{
// set round mode to round to nearest for armv7
// this impacts all vcvtr instructions in guarded scope
asm volatile(
"vmrs %0, FPSCR \n"
"bic r10, %0, #0x00c00000 \n"
"vmsr FPSCR, r10 \n"
: "=r"(FPSCR_value)
:
: "memory", "r10");
}

~FPSCRGuard()
{
asm volatile(
"vmsr FPSCR, %0 \n"
:
: "r"(FPSCR_value)
: "memory");
}

private:
int FPSCR_value;
#endif // !__aarch64__
};

static inline signed char float2int8(float v)
{
int int32 = round(v);


+ 2
- 0
src/layer/arm/quantize_arm.cpp View File

@@ -41,6 +41,8 @@ Quantize_arm::Quantize_arm()

int Quantize_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
{
FPSCRGuard fpscr_guard;

int elembits = bottom_blob.elembits();

#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC


+ 2
- 0
src/layer/arm/requantize_arm.cpp View File

@@ -42,6 +42,8 @@ Requantize_arm::Requantize_arm()

int Requantize_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const
{
FPSCRGuard fpscr_guard;

int dims = bottom_blob.dims;
int elempack = bottom_blob.elempack;



Loading…
Cancel
Save