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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:19:58+00:00 2026-06-09T04:19:58+00:00

I am working on and ios project compiling with Apple LLVM 4.0 with optimizations.

  • 0

I am working on and ios project compiling with Apple LLVM 4.0 with optimizations. I implemented two different versions of a function, one in C and one in NEON. I wanted to test their performance against one another. My idea was to call them both the same amount of times and then look them up in Time Profiler to see the relative time spent in each. Originally my code looked like

used_value = score_squareNEON(patch, image, current_pos);
used_value = score_squareC(patch, image, current_pos);

When I profiled the time the NEON code did not appear at all. Next I tried

for(int i = 0; i < successively_bigger_numbers; i++)
{
    used_value = score_squareNEON(patch, image, current_pos);
{
used_value = score_squareC(patch, image, current_pos);

Still no contribution from NEON code. Next was

used_value = score_squareNEON(patch, image, current_pos);
test = score_squareC(patch, image, current_pos);

where test never got read. Nothing. Then

test = score_squareNEON(patch, image, current_pos);
test = 0;
other_used_variable += test;
used_value = score_squareC(patch, image, current_pos);

Still nothing. What finally made it execute both functions was

value = score_squareNEON(patch, image, current_pos);
test = score_squareC(patch, image, current_pos);
...
min = (value+test)/2; //before it was min=value;

Also very important. The functions were both defined in the same file in which I was calling them. When I tried moving the function declarations to a different file both of them are called in every example.

First off, I have gained a lot of respect for compilers. Second, what exactly do I have to do to make sure a function is called? This has made me start to question all the things I have timed before. What if in the normal pattern of

timerStart();
functionCall();
timerEnd();

the function in the middle gets optimized out completely? Do I need to start checking for this somehow every time or is there a trick I can use? What are the rules governing when a compiler can optimize out an entire function call?

  • 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-09T04:19:59+00:00Added an answer on June 9, 2026 at 4:19 am

    Also very important. The functions were both defined in the same file in which I was calling them. When I tried moving the function declarations to a different file both of them are called in every example.

    When the compiler can prove that a function call has no side effect, and its result is not used, it can remove the call. If it can’t prove that, the call cannot be removed because as far as the compiler can tell, the function may have side effects, and those mustn’t be eliminated.

    Declaring the variable the result of the function call is assigned to¹ should be enough to force the compiler to leave the function call in the program (6.7.3, paragraph 7 in N1570):

    An object that has volatile-qualified type may be modified in ways unknown to the
    implementation or have other unknown side effects. Therefore any expression referring
    to such an object shall be evaluated strictly according to the rules of the abstract machine,
    as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the
    object shall agree with that prescribed by the abstract machine, except as modified by the
    unknown factors mentioned previously. What constitutes an access to an object that
    has volatile-qualified type is implementation-defined.

    For C++ the guarantees are a little less unambiguous, as far as I can tell, but I think 1.9 should take precedence:

    Program execution, 1.9 (6) and (7):

    The observable behavior of the abstract machine is its sequence of reads and writes to volatile data and
    calls to library I/O functions.6)

    Accessing an object designated by a volatile lvalue (3.10), modifying an object, calling a library I/O
    function, or calling a function that does any of those operations are all side effects, which are changes in the
    state of the execution environment. Evaluation of an expression might produce side effects. At certain
    specified points in the execution sequence called sequence points, all side effects of previous evaluations
    shall be complete and no side effects of subsequent evaluations shall have taken place.

    And in 7.1.5.1:

    [Note: volatile is a hint to the implementation to avoid aggressive optimization involving the object
    because the value of the object might be changed by means undetectable by an implementation. See 1.9 for
    detailed semantics. In general, the semantics of volatile are intended to be the same in C++ as they are
    in C. ]

    ¹ That doesn’t work with void fun(), of course.

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

Sidebar

Related Questions

I'm getting the hang of iOS and working with the different frameworks. My project
i'm currently working on an ios project with some people, one of us decided
I'm working on an iOS project in xcode and I'd like to include different
I'm working on some project for iOS 5 using Xcode 4.2. I have one
I'm working on an iOS project that has to work from iOS4. I have
I am doing iOS project in Xcode . It was working properly but now
I am working on a iOS 5 iPhone project where users can choose an
Currently my project is working perfectly on IOS development target 3.2 But as soon
I'm currently working on a project in iOS where I want the UItouch command
I have been working on an opencv project for iOS. I was given a

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.