Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:17:09+00:00 2026-06-02T22:17:09+00:00

There is a big (~100 000) array of floating point variables, and there is

  • 0

There is a big (~100 000) array of floating point variables, and there is a threshold (also floating point).

The problem is that I have to compare each one variable from the array with a threshold, but NEON flags transfer takes a really long time (~20 cycles in accordance to a profiler).

Is there any efficient way to compare these values?

NOTE: As rounding error doesn’t matter, I tried the following:

float arr[10000];
float threshold; 
....

int a = arr[20]; // e.g.
int t = threshold;
if (t > a) {....}

But in this case I getting the following processor command sequence:

vldr.32        s0, [r0]
vcvt.s32.f32   s0, s0
vmov           r0, s0    <--- takes 20 cycles as `vmrs APSR_nzcv, fpscr` in case of 
cmp            r0, r1         floating point comparison

As conversion happens at NEON, there is no matter if I compare integers, by described way or floats.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:17:11+00:00Added an answer on June 2, 2026 at 10:17 pm

    If floats are 32-bit IEEE-754 and ints are 32-bit too and if there are no +infinity, -infinity and NaN values, we can compare floats as ints with a little trick:

    #include <stdio.h>
    #include <limits.h>
    #include <assert.h>
    
    #define C_ASSERT(expr) extern char CAssertExtern[(expr)?1:-1]
    C_ASSERT(sizeof(int) == sizeof(float));
    C_ASSERT(sizeof(int) * CHAR_BIT == 32);
    
    int isGreater(float* f1, float* f2)
    {
      int i1, i2, t1, t2;
    
      i1 = *(int*)f1;
      i2 = *(int*)f2;
    
      t1 = i1 >> 31;
      i1 = (i1 ^ t1) + (t1 & 0x80000001);
    
      t2 = i2 >> 31;
      i2 = (i2 ^ t2) + (t2 & 0x80000001);
    
      return i1 > i2;
    }
    
    int main(void)
    {
      float arr[9] = { -3, -2, -1.5, -1, 0, 1, 1.5, 2, 3 };
      float thr;
      int i;
    
      // Make sure floats are 32-bit IEE754 and
      // reinterpreted as integers as we want/expect
      {
        static const float testf = 8873283.0f;
        unsigned testi = *(unsigned*)&testf;
        assert(testi == 0x4B076543);
      }
    
      thr = -1.5;
      for (i = 0; i < 9; i++)
      {
        printf("%f %s %f\n", arr[i], "<=\0> " + 3*isGreater(&arr[i], &thr), thr);
      }
    
      thr = 1.5;
      for (i = 0; i < 9; i++)
      {
        printf("%f %s %f\n", arr[i], "<=\0> " + 3*isGreater(&arr[i], &thr), thr);
      }
    
      return 0;
    }
    

    Output:

    -3.000000 <= -1.500000
    -2.000000 <= -1.500000
    -1.500000 <= -1.500000
    -1.000000 >  -1.500000
    0.000000 >  -1.500000
    1.000000 >  -1.500000
    1.500000 >  -1.500000
    2.000000 >  -1.500000
    3.000000 >  -1.500000
    -3.000000 <= 1.500000
    -2.000000 <= 1.500000
    -1.500000 <= 1.500000
    -1.000000 <= 1.500000
    0.000000 <= 1.500000
    1.000000 <= 1.500000
    1.500000 <= 1.500000
    2.000000 >  1.500000
    3.000000 >  1.500000
    

    Of course, it makes sense to precalculate that final integer value in isGreater() that’s used in the comparison operator if your threshold doesn’t change.

    If you are afraid of undefined behavior in C/C++ in the above code, you can rewrite the code in assembly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big repository, 100,000+ revisions with a very high branching factor. The
I have a div. When there is a big text then scroller comes on
If there is a process that reads a big file and saves it in
With a seriously big .NET site/solution (100's of assemblies), are there any tools available
I am going to develop a web site will have 80,000 to 100,000 views
I have a big table (200'000'000 rows); declared like this thread( forum_id tinyint, thread_id
I have a big database that has fields of paragraphs that are formatted like
Assume that I have one big table with three columns: user_name, user_property, value_of_property. Lat's
I have the following <div id=big style=width:100%> <div id=slider> <div class=item id=item1><img src=some50x50.jpg /></div>
I have a relational database with about 100 tables. Each table has unique, numerical,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.