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 7061645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:29:58+00:00 2026-05-28T04:29:58+00:00

Can someone tell me a fast function to find the square of each pixel

  • 0

Can someone tell me a fast function to find the square of each pixel of an int image. I need it for iOS app dev. I am working directly on the memory of the image defined as

int *image_sqr_Baseaaddr = (int *) malloc(noOfPixels * sizeof(int));

for (int i=0; i<newNoOfPixels; i++)
     image_sqr_Baseaaddr[i] = (int) image_scaled_Baseaaddr[i] * (int) image_scaled_Baseaaddr[i];

This is obviously the slowest function possible. I heard that ARM Neon intrinsics on the iOS can be used to make several operations in 1 cycle. Maybe that’s the way to go ?

The problem is that I am not very familiar and don’t have enough time to learn assembly language at the moment. So it would be great if anyone can post a Neon intrinsics code for the problem mentioned above or any other fast implementation in C/C++.

The only code in NEON intrinsics that I am able to find online is the code for RGB to gray http://computer-vision-talks.com/2011/02/a-very-fast-bgra-to-grayscale-conversion-on-iphone/

  • 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-05-28T04:29:58+00:00Added an answer on May 28, 2026 at 4:29 am

    Here’s a simple NEON implementation:

    #include <arm_neon.h>
    
    // ...
    
    int i;
    
    for (i = 0; i <= newNoOfPixels - 16; i += 16)           // SIMD loop
    {
        uint8x16_t v = vld1q_u8(&image_scaled_Baseaaddr[i]);// load 16 x 8 bit pixels
    
        int16x8_t vl = (int16x8_t)vmovl_u8(vget_low_u8(v)); // unpack into 2 x 16 bit vectors
        int16x8_t vh = (int16x8_t)vmovl_u8(vget_high_u8(v));
    
        vl = vmulq_s16(vl, vl);                             // square them
        vh = vmulq_s16(vh, vh);
    
        int32x4_t vll = vmovl_s16(vget_low_s16(vl));        // unpack to 4 x 32 bit vectors
        int32x4_t vlh = vmovl_s16(vget_high_s16(vl));
        int32x4_t vhl = vmovl_s16(vget_low_s16(vh));
        int32x4_t vhh = vmovl_s16(vget_high_s16(vh));
    
        vst1q_s32(&image_sqr_Baseaaddr[i], vll);            // store 32 bit squared values
        vst1q_s32(&image_sqr_Baseaaddr[i + 4], vlh);
        vst1q_s32(&image_sqr_Baseaaddr[i + 8], vhl);
        vst1q_s32(&image_sqr_Baseaaddr[i + 12], vhh);
    }
    for ( ; i < newNoOfPixels; ++i)                         // scalar clean up loop
    {
        int32_t p = (int32_t)image_scaled_Baseaaddr[i];
        image_sqr_Baseaaddr[i] = p * p;
    }
    

    Note that this will perform best if both image_scaled_Baseaaddr and image_sqr_Baseaaddr are 16 byte aligned.

    Note also that the above code is untested and may need some further work.

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

Sidebar

Related Questions

Can someone tell me a fast function to find the gaussian blur of an
Can someone tell me why I'm getting successCallback is not a function in my
Can someone tell me the difference between: $(document).ready(function() { }); and: var someVar =
Can someone tell me which one is more efficient between List<int> and int[] .
Can someone tell me how does the imdb app manage to play trailers on
Can someone tell me the code to convert image into byte array and that
Can someone tell me the difference between these two queries? db.foo.find({ $and: [{a: 1},
Can someone tell me why creating a new project with an iOS Deployment Target
I'm new here and I'm very stuck. I need help. Hopefully someone can tell
Can someone tell me where can I find the latest Python bindings for Apache

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.