TweetFollow Us on Twitter

Mar 91 Letters
Volume Number:7
Issue Number:3
Column Tag:Letters

THINK C and Benchmarks

By Kirk Chase, Editor

Objective-C® Oversight

Sarah C. Bell

The Stepstone Corporation

75 Glen Road

Sandy Hook, CT 06482

I object to Mr. C. Keith Ray’s article, “NeXT for Mac Programmers”, (MacTutor, Dec. ’90). This article dealt with the Objective-C® programming environment marketed by the Stepstone Corporation. At the end of his article, he listed all the trademarks that were included in the article. He failed to mention that Objective-C is a trademark of the Stepstone Corp.

Since the column was centered around our product, we would appreciate it if you made mention of this fact in the next issue of MacTutor.

[Consider it done - ed]

Taming The THINK C Debugger

Rex Reinhart

Irvine, CA

Here’s a simple workaround to setting and keeping breakpoints in THINK C.

Define the following macro:

/* 1 */

#define HALT asm{_Debugger}

Then simply put HALT in your code wherever you want a breakpoint (anywhere but in the middle of an expression). Then run the program under the THINK C debugger. When execution of your code reaches the HALT, your program will stop, the debugger will become active, and your source code will appear with the current line pointer at the HALT. From there you may step at your leisure.

For low level debugging, try it with MACSBUG. Compile your program and run it on its own.

Another useful variation is

/* 2 */

#define CONDHALT(Condition) if(Condition) asm {_Debugger};

The Mac has a current debugger pointer which a debugger may set to point to itself. I don’t know if this pointer is in a global, or directly in the trap dispatch table. _Debugger is a little known (not in IM I-V) trap A9FF which transfers execution to wherever this pointer points to. The THINK C debugger sets this pointer correctly. I haven’t tried this with other debuggers, but if the set this pointer it should work.

Good Luck.

Benchmark Challenge Revisited

John W. Baxter

Port Ludow, WA

This is a response to the letter “Benchmark Challenge” published in the September 1990 issue.

A significant problem exists with the benchmark source code (both C and Pascal) as printed in the September issue: the local variable b controls the flow of the program, and the letter states that it ranges from 1 to 20. However, b is neither initialized to anything, nor adjusted during the loop. Therefore, the value of b will be whatever is left over in the stack frame locations or register the compiler uses for storing b. That could, for example, mean that the value of b in the Pascal case happens to be 1 (causing execution of only one comparison per loop) while the C case it might be 100,572, causing many comparisons per loop. To fix this problem, I would suggest initializing b to 1 at the beginning of each of the test functions (procedures), and in each conditional just advance it to the next value. So the Pascal TestCase procedure would look something like:

 
begin
 b := 1;
 case b of
 1: begin
 b:=2;
 end;
 

Another pitfall to watch out for in designing benchmark code is code optimization performed by the compiler. Looking at the code as presented in the magazine, we find that in fact regardless of the of b, the code to be executed by the conditional structure is the same (nothing). In both C and Pascal, the compiler has the “right” in such a case to optimize the conditional structure totally out of existence in the final object code (there are no called function or procedure side effects to worry about). As it happens, fixing the undefined state of the variable b as above will prevent such optimization in this benchmark. And, I doubt that either compiler used actually goes that far in its optimization process.

Yet another potential problem is the fact that the Pascal version using a 2-byte b, while the C version happens to be using a 4-byte b. In this case, the time difference introduced by this difference should be vanishingly small (on the 68xxx family). The same benchmarks moved to the Apple IIgs, and continuing to suffer the problem (they wouldn’t as printed because the available C compilers on the IIgs use a 2-byte int), would favor the Pascal significantly, since the 2-byte arithmetic is much faster than is 4-byte arithmetic on the 65816 (which is why int is 2 bytes in those C compilers). To go a step further, C would allow the use of an unsigned 2-byte b, while Pascal does not. For best C performance on the 65816 chip, everything which CAN be unsigned SHOULD be. That leads to the question: “Does a fair benchmark comparing 2 languages and their implementations use the same data type each, or use the most efficient available data type?”

Unfortunately, the answer to that is “Yes.” It depends upon what one wishes to compare. When ignored, this issue invalidates carelessly-written benchmark articles, including the original Byte magazine Sieve benchmark, which made UCSD Pascal look much worse than it needed to. For the Apple II version, about a 40% speed improvement was produced in the Byte Sieve simply by (a) turning off range checking, and (b) defining the variables with the big array last, so that the other variables could be reached by more efficient p-code. A benchmark needs to make clear whether it is comparing the best source found for a given language/implementation/ platform, or a direct translation.

More on Benchmarks

Tom Pittman

Spreckels, CA

Davis and Bayer have some interesting figures, but their conclusions are misinformed.

First (and trivially), the “assembly language” put out by the compiler has nothing to do with the speed of the compiled code, since most compilers (and THINK in particular) don’t put out assembly language at all, but go directly to native machine code. I consider this point trivial, as I assume that is what they would have intended to say, anyway. But the point as corrected is still misleading, since the quality of the machine code generated by a compiler is largely affected by the nature of the source language, as their benchmarks clearly show.

If you ask experienced compiler people (not just run-of-the-mill programmers), you will get an entirely different answer concerning the relative merits of C and Pascal. You see, compiler people know that C is a low-level language designed to fit the PDP-11 very well; to the extent that other computers are similar in architecture to the PDP-11, it’s possible to generate correspondingly good code for them. But as machine design moves away from that obsolete architecture, compiler designers have a harder and harder time of undoing all those low-level optimizations that C encourages the programmers to write, in order to generate the correct and optimal code that a Pascal compiler can do with ease. For some C constructs it’s utterly impossible; any self-respecting compiler just throws up its metaphorical hands and puts out something that works somehow, never mind how slowly or awkwardly. Pascal, by distancing itself from the low-level machine details, does the compiler writer a favor. Pascal compilers on the Macintosh still put out some rotten code; they have not even begun to show what Pascal is capable of. The C compilers on the other hand, are pretty much maxed out. Draw your own conclusions.

So why do programmers all think C is so much better? It’s widely recognized to be a religious issue. That does not mean, as is commonly believed, that there are no right answers (for the benchmarks tell us otherwise), but only that bringing evidence to the discussion will not change anybody’s mind. As interesting as the Davis and Bayer benchmarks are, I doubt they will change any C hackers into Pascal programmers. More’s the pity.

[I didn’t change over. C is still my language of preference to code in. I do code in Pascal, but I find C an easier one to code in. This “preference” benchmark can go a long way. Code optimization is nice, but I feel that developers, programmers, hackers, and hobbyists should be familiar with many languages and do their work with the best language for the need of the job. At some point, C and Pascal will reach a point where they are nearly equal in code generated. - ed]

Bypassing SANE

Michael J. Gibbs

Surprise, AZ

In response to Martin E. Huber’s letter (September 1990):

Radius includes some nice software with their monitors, including an INIT called Radius Math. Radius Math speeds up floating point by bypassing SANE.

On machines with FPUs, SANE uses the floating point unit for most operations but not transcendental or trigonometric functions. The reason for this is that the 68881/882 does not provide the accuracy for these functions that SANE requires, so they are done in software. Apparently the last 4 or 5 bit positions are inaccurate on the FPU (not important for most applications).

Radius Math patches SANE to use FPU for all floating point operations, including those mentioned above. This is not as fast as inline floating point instructions for the FPU, but it does work for all applications that use SANE.

I ran the following benchmarks using Radius Math version 1.4 and THINK Pascal 3.0.1 on my Macintosh IIcx:

Trig Test

Radius Math Generate FPU instructions Time(ticks)

NO NO 875

YES NO 38

NO YES 16

YES YES 16

Arithmetic Test

Radius Math Generate FPU instructions Time(ticks)

NO NO 54

YES NO 28

NO YES 6

YES YES 6

It appears that THINK Pascal generates inline floating point instructions, since the presence of Radius Math has no effect on performance with 881/882 code generation turned on. Notice that for applications that use SANE, Radius Math speeds normal operations by a factor of 2, and trig by a factor of 23.

Remember to use extended precision for all floating point that uses SANE. SANE converts single and double precision numbers to extended precision for calculations, then back again to store the results, so you will get better performance by avoiding the conversion. For inline FPU code, there is not much difference, except for double precision (64 bit), which is considerably slower than extended (80 or 96 bit) and single (32 bit) precision.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more
Hopper Disassembler 5.14.1 - Binary disa...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more

Latest Forum Discussions

See All

Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »
TouchArcade Game of the Week: ‘Vroomies’
So here’s a thing: Vroomies from developer Alex Taber aka Unordered Games is the Game of the Week! Except… Vroomies came out an entire month ago. It wasn’t on my radar until this week, which is why I included it in our weekly new games round-up, but... | Read more »
SwitchArcade Round-Up: ‘MLB The Show 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for March 15th, 2024. We’re closing out the week with a bunch of new games, with Sony’s baseball franchise MLB The Show up to bat yet again. There are several other interesting games to... | Read more »
Steam Deck Weekly: WWE 2K24 and Summerho...
Welcome to this week’s edition of the Steam Deck Weekly. The busy season has begun with games we’ve been looking forward to playing including Dragon’s Dogma 2, Horizon Forbidden West Complete Edition, and also console exclusives like Rise of the... | Read more »
Steam Spring Sale 2024 – The 10 Best Ste...
The Steam Spring Sale 2024 began last night, and while it isn’t as big of a deal as say the Steam Winter Sale, you may as well take advantage of it to save money on some games you were planning to buy. I obviously recommend checking out your own... | Read more »
New ‘SaGa Emerald Beyond’ Gameplay Showc...
Last month, Square Enix posted a Let’s Play video featuring SaGa Localization Director Neil Broadley who showcased the worlds, companions, and more from the upcoming and highly-anticipated RPG SaGa Emerald Beyond. | Read more »
Choose Your Side in the Latest ‘Marvel S...
Last month, Marvel Snap (Free) held its very first “imbalance" event in honor of Valentine’s Day. For a limited time, certain well-known couples were given special boosts when conditions were right. It must have gone over well, because we’ve got a... | Read more »
Warframe welcomes the arrival of a new s...
As a Warframe player one of the best things about it launching on iOS, despite it being arguably the best way to play the game if you have a controller, is that I can now be paid to talk about it. To whit, we are gearing up to receive the first... | Read more »
Apple Arcade Weekly Round-Up: Updates an...
Following the new releases earlier in the month and April 2024’s games being revealed by Apple, this week has seen some notable game updates and events go live for Apple Arcade. What The Golf? has an April Fool’s Day celebration event going live “... | Read more »

Price Scanner via MacPrices.net

Apple Education is offering $100 discounts on...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take $100 off the price of a new M3 MacBook Air.... Read more
Apple Watch Ultra 2 with Blood Oxygen feature...
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
New promo at Sams Club: Apple HomePods for $2...
Sams Club has Apple HomePods on sale for $259 through March 31, 2024. Their price is $40 off Apple’s MSRP, and both Space Gray and White colors are available. Sale price is for online orders only, in... Read more
Get Apple’s 2nd generation Apple Pencil for $...
Apple’s Pencil (2nd generation) works with the 12″ iPad Pro (3rd, 4th, 5th, and 6th generation), 11″ iPad Pro (1st, 2nd, 3rd, and 4th generation), iPad Air (4th and 5th generation), and iPad mini (... Read more
10th generation Apple iPads on sale for $100...
Best Buy has Apple’s 10th-generation WiFi iPads back on sale for $100 off MSRP on their online store, starting at only $349. With the discount, Best Buy’s prices are the lowest currently available... Read more
iPad Airs on sale again starting at $449 on B...
Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices again for $150 off Apple’s MSRP, starting at $449. Sale prices for online orders only, in-store price may vary. Order online, and choose... Read more
Best Buy is blowing out clearance 13-inch M1...
Best Buy is blowing out clearance Apple 13″ M1 MacBook Airs this weekend for only $649.99, or $350 off Apple’s original MSRP. Sale prices for online orders only, in-store prices may vary. Order... Read more
Low price alert! You can now get a 13-inch M1...
Walmart has, for the first time, begun offering new Apple MacBooks for sale on their online store, albeit clearance previous-generation models. They now have the 13″ M1 MacBook Air (8GB RAM, 256GB... Read more
Best Apple MacBook deal this weekend: Get the...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New 15-inch M3 MacBook Air (Midnight) on sale...
Amazon has the new 15″ M3 MacBook Air (8GB RAM/256GB SSD/Midnight) in stock and on sale today for $1249.99 including free shipping. Their price is $50 off MSRP, and it’s the lowest price currently... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-350696 **Updated:** Mon Mar 11 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill WellSpan Medical Group, York, PA | Nursing | Nursing Support | FTE: 1 | Regular | Tracking Code: 200555 Apply Now Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.