Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #21625 > unrolled thread

Slightly OT: speed of operation on a PC

Started byTim Wescott <seemywebsite@myfooter.really>
First post2015-08-04 12:59 -0500
Last post2015-08-06 12:56 +1000
Articles 20 on this page of 43 — 17 participants

Back to article view | Back to comp.arch.embedded


Contents

  Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 12:59 -0500
    Re: Slightly OT: speed of operation on a PC rickman <gnuarm@gmail.com> - 2015-08-04 14:06 -0400
    Re: Slightly OT: speed of operation on a PC Lanarcam <lanarcam1@yahoo.fr> - 2015-08-04 20:06 +0200
      Re: Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 13:27 -0500
        Re: Slightly OT: speed of operation on a PC Lanarcam <lanarcam1@yahoo.fr> - 2015-08-04 20:33 +0200
        Re: Slightly OT: speed of operation on a PC rickman <gnuarm@gmail.com> - 2015-08-04 17:05 -0400
          Re: Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 18:54 -0500
            Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-05 00:09 +0000
              Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 17:32 -0700
            Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-05 17:25 +1000
              Re: Slightly OT: speed of operation on a PC Anders.Montonen@kapsi.spam.stop.fi.invalid - 2015-08-05 08:34 +0000
      Re: Slightly OT: speed of operation on a PC Philipp Klaus Krause <pkk@spth.de> - 2015-08-11 11:04 +0200
    Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 11:07 -0700
      Re: Slightly OT: speed of operation on a PC Tim Wescott <seemywebsite@myfooter.really> - 2015-08-04 13:28 -0500
        Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 11:37 -0700
          Re: Slightly OT: speed of operation on a PC Tom Gardner <spamjunk@blueyonder.co.uk> - 2015-08-04 22:20 +0100
          Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-04 21:45 +0000
            Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 15:34 -0700
              Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-05 00:00 +0000
                Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-04 17:36 -0700
                  Re: Slightly OT: speed of operation on a PC glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-05 05:43 +0000
                    Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-05 00:44 -0700
                      Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-05 19:14 +1000
                        Re: Slightly OT: speed of operation on a PC Don Y <this@is.not.me.com> - 2015-08-05 08:04 -0700
        Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-05 17:28 +1000
    Re: Slightly OT: speed of operation on a PC Paul Rubin <no.email@nospam.invalid> - 2015-08-04 11:13 -0700
    Re: Slightly OT: speed of operation on a PC "Bill Davy" <Bill@SynectixLtd.com> - 2015-08-04 19:19 +0100
    Re: Slightly OT: speed of operation on a PC Tom Gardner <spamjunk@blueyonder.co.uk> - 2015-08-04 22:18 +0100
      Re: Slightly OT: speed of operation on a PC Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2015-08-05 10:25 +0000
        Re: Slightly OT: speed of operation on a PC Tom Gardner <spamjunk@blueyonder.co.uk> - 2015-08-05 11:42 +0100
          Re: Slightly OT: speed of operation on a PC Anders.Montonen@kapsi.spam.stop.fi.invalid - 2015-08-05 11:23 +0000
            Re: Slightly OT: speed of operation on a PC David Brown <david.brown@hesbynett.no> - 2015-08-05 13:58 +0200
            Re: Slightly OT: speed of operation on a PC Robert Wessel <robertwessel2@yahoo.com> - 2015-08-06 00:24 -0500
        Re: Slightly OT: speed of operation on a PC David Brown <david.brown@hesbynett.no> - 2015-08-05 12:59 +0200
    Re: Slightly OT: speed of operation on a PC Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2015-08-04 23:30 +0200
      Re: Slightly OT: speed of operation on a PC Philipp Klaus Krause <pkk@spth.de> - 2015-08-11 11:19 +0200
    Re: Slightly OT: speed of operation on a PC David Brown <david.brown@hesbynett.no> - 2015-08-05 08:32 +0200
    Re: Slightly OT: speed of operation on a PC Stefan Reuther <stefan.news@arcor.de> - 2015-08-05 18:43 +0200
    Re: Slightly OT: speed of operation on a PC edward.ming.lee@gmail.com - 2015-08-05 10:31 -0700
      Re: Slightly OT: speed of operation on a PC Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2015-08-05 20:11 +0200
      Re: Slightly OT: speed of operation on a PC rickman <gnuarm@gmail.com> - 2015-08-05 20:19 -0400
        Re: Slightly OT: speed of operation on a PC edward.ming.lee@gmail.com - 2015-08-05 19:45 -0700
          Re: Slightly OT: speed of operation on a PC Clifford Heath <no.spam@please.net> - 2015-08-06 12:56 +1000

Page 1 of 3  [1] 2 3  Next page →


#21625 — Slightly OT: speed of operation on a PC

FromTim Wescott <seemywebsite@myfooter.really>
Date2015-08-04 12:59 -0500
SubjectSlightly OT: speed of operation on a PC
Message-ID<juKdnf5uzZr0YF3InZ2dnUU7-YOdnZ2d@giganews.com>
Which do you think is quicker on a PC, with the latest gnu compiler:

double a = something;
double b = something else;

if (a >= 0.0 && b < 0.0)

>> or <<

if (a * b <= 0)

Thank you for your time.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [next] | [standalone]


#21626

Fromrickman <gnuarm@gmail.com>
Date2015-08-04 14:06 -0400
Message-ID<mpqura$ohu$1@dont-email.me>
In reply to#21625
On 8/4/2015 1:59 PM, Tim Wescott wrote:
> Which do you think is quicker on a PC, with the latest gnu compiler:
>
> double a = something;
> double b = something else;
>
> if (a >= 0.0 && b < 0.0)
>
>>> or <<
>
> if (a * b <= 0)
>
> Thank you for your time.

My guess would be the latter if any.  Why not write the code and look at 
what is generated?

-- 

Rick

[toc] | [prev] | [next] | [standalone]


#21627

FromLanarcam <lanarcam1@yahoo.fr>
Date2015-08-04 20:06 +0200
Message-ID<55c0ff2e$0$3060$426a34cc@news.free.fr>
In reply to#21625
Le 04/08/2015 19:59, Tim Wescott a écrit :
> Which do you think is quicker on a PC, with the latest gnu compiler:
>
> double a = something;
> double b = something else;
>
> if (a >= 0.0 && b < 0.0)
>
>>> or <<
>
> if (a * b <= 0)
>
> Thank you for your time.
>
if (a + b < a) would be quicker, I believe.

[toc] | [prev] | [next] | [standalone]


#21631

FromTim Wescott <seemywebsite@myfooter.really>
Date2015-08-04 13:27 -0500
Message-ID<juKdnfluzZq-mVzInZ2dnUU7-YOdnZ2d@giganews.com>
In reply to#21627
On Tue, 04 Aug 2015 20:06:35 +0200, Lanarcam wrote:

> Le 04/08/2015 19:59, Tim Wescott a écrit :
>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>
>> double a = something;
>> double b = something else;
>>
>> if (a >= 0.0 && b < 0.0)
>>
>>>> or <<
>>
>> if (a * b <= 0)
>>
>> Thank you for your time.
>>
> if (a + b < a) would be quicker, I believe.

I don't think that tests if a and b are of opposite sign.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#21633

FromLanarcam <lanarcam1@yahoo.fr>
Date2015-08-04 20:33 +0200
Message-ID<55c10574$0$2976$426a34cc@news.free.fr>
In reply to#21631
Le 04/08/2015 20:27, Tim Wescott a écrit :
> On Tue, 04 Aug 2015 20:06:35 +0200, Lanarcam wrote:
>
>> Le 04/08/2015 19:59, Tim Wescott a écrit :
>>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>>
>>> double a = something;
>>> double b = something else;
>>>
>>> if (a >= 0.0 && b < 0.0)
>>>
>>>>> or <<
>>>
>>> if (a * b <= 0)
>>>
>>> Thank you for your time.
>>>
>> if (a + b < a) would be quicker, I believe.
>
> I don't think that tests if a and b are of opposite sign.
>
That's right, my error.

You could try the macro signbit

if (signbit(a) != signbit(b))

[toc] | [prev] | [next] | [standalone]


#21635

Fromrickman <gnuarm@gmail.com>
Date2015-08-04 17:05 -0400
Message-ID<mpr9b1$5bn$1@dont-email.me>
In reply to#21631
On 8/4/2015 2:27 PM, Tim Wescott wrote:
> On Tue, 04 Aug 2015 20:06:35 +0200, Lanarcam wrote:
>
>> Le 04/08/2015 19:59, Tim Wescott a écrit :
>>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>>
>>> double a = something;
>>> double b = something else;
>>>
>>> if (a >= 0.0 && b < 0.0)
>>>
>>>>> or <<
>>>
>>> if (a * b <= 0)
>>>
>>> Thank you for your time.
>>>
>> if (a + b < a) would be quicker, I believe.
>
> I don't think that tests if a and b are of opposite sign.

Neither does your original code, either.

The first case only checks for 'a' positive and 'b' negative.  "Opposite 
sign" would include the case of 'a' negative and 'b' positive.  Your 
multiplication includes either one being zero the same as them being 
opposite sign.

Maybe you could explain is a bit more detail what the goal is.  Is the 
first code example sufficient for your needs and the domain excludes the 
problem areas where these two give different results?

In an HDL this may or may not produce comparators or multiplies.  I 
would have to try it to see, but I have seen the compiler be smart 
enough to realize that much of the logic was not important to the result 
and simplify it.

-- 

Rick

[toc] | [prev] | [next] | [standalone]


#21641

FromTim Wescott <seemywebsite@myfooter.really>
Date2015-08-04 18:54 -0500
Message-ID<EK2dnbDM9NYozVzInZ2dnUU7-LmdnZ2d@giganews.com>
In reply to#21635
On Tue, 04 Aug 2015 17:05:03 -0400, rickman wrote:

> On 8/4/2015 2:27 PM, Tim Wescott wrote:
>> On Tue, 04 Aug 2015 20:06:35 +0200, Lanarcam wrote:
>>
>>> Le 04/08/2015 19:59, Tim Wescott a écrit :
>>>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>>>
>>>> double a = something;
>>>> double b = something else;
>>>>
>>>> if (a >= 0.0 && b < 0.0)
>>>>
>>>>>> or <<
>>>>
>>>> if (a * b <= 0)
>>>>
>>>> Thank you for your time.
>>>>
>>> if (a + b < a) would be quicker, I believe.
>>
>> I don't think that tests if a and b are of opposite sign.
> 
> Neither does your original code, either.
> 
> The first case only checks for 'a' positive and 'b' negative.  "Opposite
> sign" would include the case of 'a' negative and 'b' positive.  Your
> multiplication includes either one being zero the same as them being
> opposite sign.
> 
> Maybe you could explain is a bit more detail what the goal is.  Is the
> first code example sufficient for your needs and the domain excludes the
> problem areas where these two give different results?
> 
> In an HDL this may or may not produce comparators or multiplies.  I
> would have to try it to see, but I have seen the compiler be smart
> enough to realize that much of the logic was not important to the result
> and simplify it.

I ended up finding a different solution to the top level problem, but 
yes, the curiosity was whether, with floating point hardware, it was 
quicker to do a bunch of compares (four I guess and not two) or one 
multiply and one compare.

I suppose that a good optimizing compiler that understands floating point 
sign bits would figure this out quickly.

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#21643

Fromglen herrmannsfeldt <gah@ugcs.caltech.edu>
Date2015-08-05 00:09 +0000
Message-ID<mprk86$g6e$1@speranza.aioe.org>
In reply to#21641
Tim Wescott <seemywebsite@myfooter.really> wrote:
> On Tue, 04 Aug 2015 17:05:03 -0400, rickman wrote:
 
(snip)
>>>>> if (a >= 0.0 && b < 0.0)

>>>>>>> or <<

>>>>> if (a * b <= 0)

(snip) 
>> Maybe you could explain is a bit more detail what the goal is.  Is the
>> first code example sufficient for your needs and the domain excludes the
>> problem areas where these two give different results?

Some time ago, I was doing a test to see if two points are on
the same of different sides of a line. Some similar tests ended
up in the result, and I believe I went for the a*b case.

For one, I wasn't doing it enough to really matter how long it took.
(It might have been thousands of points, maybe even millions, but
that doesn't matter today.) 

I believe the equal case occurs if one or both are on the line,
and in my case it didn't matter which way it went.  (And for random
(x,y) pairs was pretty unlikely.)
 
(snip) 
> I ended up finding a different solution to the top level problem, but 
> yes, the curiosity was whether, with floating point hardware, it was 
> quicker to do a bunch of compares (four I guess and not two) or one 
> multiply and one compare.
 
> I suppose that a good optimizing compiler that understands floating point 
> sign bits would figure this out quickly.

-- glen

[toc] | [prev] | [next] | [standalone]


#21644

FromDon Y <this@is.not.me.com>
Date2015-08-04 17:32 -0700
Message-ID<mprlit$ifp$1@speranza.aioe.org>
In reply to#21643
On 8/4/2015 5:09 PM, glen herrmannsfeldt wrote:

> Some time ago, I was doing a test to see if two points are on
> the same of different sides of a line. Some similar tests ended
> up in the result, and I believe I went for the a*b case.
>
> For one, I wasn't doing it enough to really matter how long it took.
> (It might have been thousands of points, maybe even millions, but
> that doesn't matter today.)
>
> I believe the equal case occurs if one or both are on the line,
> and in my case it didn't matter which way it went.  (And for random
> (x,y) pairs was pretty unlikely.)

I was looking for a quick/efficient test to ensure C2 continuity
(reason should be obvious -- if you think on it!) between "successive"
(concatenated) Bezier curves in my gesture recognizer.

I got fixated on the:
     dy/dx ?= dY/dX
issue -- how to avoid the (high precision) divide!  And, the inevitable
"comparing floats for equality" dilemma!

"Ah!  dy*dX ?= dx*dY does the trick!"

<frown>  No, imagine dy == 0 or dx == 0, etc.

After fretting about this (for TOO long!), I slapped myself
upside-da-head:  "You're solving the *wrong* problem!  E.g., C1
instead of C2!"   D'oh!

Hence the admonition not to get caught up in silly optimizations
at the expense of sorting out what you *really* are trying to do!

[toc] | [prev] | [next] | [standalone]


#21653

FromClifford Heath <no.spam@please.net>
Date2015-08-05 17:25 +1000
Message-ID<0Tiwx.77280$XZ5.45472@fx19.iad>
In reply to#21641
On 05/08/15 09:54, Tim Wescott wrote:
> On Tue, 04 Aug 2015 17:05:03 -0400, rickman wrote:
>> On 8/4/2015 2:27 PM, Tim Wescott wrote:
>>> On Tue, 04 Aug 2015 20:06:35 +0200, Lanarcam wrote:
>>>> Le 04/08/2015 19:59, Tim Wescott a écrit :
>>>>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>>>> double a = something;
>>>>> double b = something else;
>>>>> if (a >= 0.0 && b < 0.0)
>>>>>>> or <<
>>>>> if (a * b <= 0)
>>>>>>>>>> Thank you for your time.
> I suppose that a good optimizing compiler that understands floating point
> sign bits would figure this out quickly.


I would not have been a bit surprised if gcc did in fact figure this 
out, but it appears it does not. In any case, on a *86 machine, the time 
is entirely dominated by the time takes to load the two cache lines. 
Whether logical operations on the sign bits, or arithmetic comparisons, 
or the floating point multiplier is used to compute the result, all 
three will spend most of their time waiting for memory loads.

Try compiling the following file using "gcc -O6 -S foo.c":

int foo(double a, double b)
{
         return (a<0) != (b<0);
}

int bar(double a, double b)
{
         return a*b < 0;
}

and then read foo.s. You'll see that the second case uses a multiply.
Using my gcc 4.8.4 anyhow... and also with the Apple LLVM-based "gcc".

Clifford Heath.

[toc] | [prev] | [next] | [standalone]


#21656

FromAnders.Montonen@kapsi.spam.stop.fi.invalid
Date2015-08-05 08:34 +0000
Message-ID<mpshq4$6tb$1@speranza.aioe.org>
In reply to#21653
Clifford Heath <no.spam@please.net> wrote:
> Try compiling the following file using "gcc -O6 -S foo.c":

Just as a sidenote, GCC's optimization levels top out at -O3. The 
generated code will also depend on the used -march, -mtune, -mfpmath 
and other options.

-a

[toc] | [prev] | [next] | [standalone]


#21724

FromPhilipp Klaus Krause <pkk@spth.de>
Date2015-08-11 11:04 +0200
Message-ID<mqcdqs$a3j$1@solani.org>
In reply to#21627
On 04.08.2015 20:06, Lanarcam wrote:
> Le 04/08/2015 19:59, Tim Wescott a écrit :
>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>
>> double a = something;
>> double b = something else;
>>
>> if (a >= 0.0 && b < 0.0)
>>
>>>> or <<
>>
>> if (a * b <= 0)
>>
>> Thank you for your time.
>>
> if (a + b < a) would be quicker, I believe.

Why would it? Depending on the architecture, comparing with 0 is often
more efficient than with other values. Also multiplication is a much
simpler operation than addition for floating-point values.

Philipp

[toc] | [prev] | [next] | [standalone]


#21628

FromDon Y <this@is.not.me.com>
Date2015-08-04 11:07 -0700
Message-ID<mpqv0v$u2v$1@speranza.aioe.org>
In reply to#21625
On 8/4/2015 10:59 AM, Tim Wescott wrote:
> Which do you think is quicker on a PC, with the latest gnu compiler:
>
> double a = something;
> double b = something else;
>
> if (a >= 0.0 && b < 0.0)
>
>>> or <<
>
> if (a * b <= 0)
>
> Thank you for your time.

Do you really need to micro-optimize like this?
Why not just have the code *say* what you are trying to *do*?

[toc] | [prev] | [next] | [standalone]


#21632

FromTim Wescott <seemywebsite@myfooter.really>
Date2015-08-04 13:28 -0500
Message-ID<juKdnfhuzZr5mVzInZ2dnUU7-YOdnZ2d@giganews.com>
In reply to#21628
On Tue, 04 Aug 2015 11:07:49 -0700, Don Y wrote:

> On 8/4/2015 10:59 AM, Tim Wescott wrote:
>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>
>> double a = something;
>> double b = something else;
>>
>> if (a >= 0.0 && b < 0.0)
>>
>>>> or <<
>>
>> if (a * b <= 0)
>>
>> Thank you for your time.
> 
> Do you really need to micro-optimize like this?

Uh -- fun?

> Why not just have the code *say* what you are trying to *do*?

Where's the job security in that?

-- 

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

[toc] | [prev] | [next] | [standalone]


#21634

FromDon Y <this@is.not.me.com>
Date2015-08-04 11:37 -0700
Message-ID<mpr0ph$3gv$1@speranza.aioe.org>
In reply to#21632
On 8/4/2015 11:28 AM, Tim Wescott wrote:
> On Tue, 04 Aug 2015 11:07:49 -0700, Don Y wrote:
>
>> On 8/4/2015 10:59 AM, Tim Wescott wrote:
>>> Which do you think is quicker on a PC, with the latest gnu compiler:
>>>
>>> double a = something;
>>> double b = something else;
>>>
>>> if (a >= 0.0 && b < 0.0)
>>>
>>>>> or <<
>>>
>>> if (a * b <= 0)
>>>
>>> Thank you for your time.
>>
>> Do you really need to micro-optimize like this?
>
> Uh -- fun?

If you want to head down that path, there are lots of processor/compiler
specific "optimizations" that you can explore!  The problem then becomes
making sure you don't let some "clever trick" creep into your code at
a later date.

    Given a year expressed in packed BCD, indicate whether the year is a
    leap year.

Obviously, there is some merit in knowing this.  OTOH, the code only
has to execute VERY rarely!

[It's an interesting problem, though.  How many clock cycles will
it take to resolve?  :> ]

>> Why not just have the code *say* what you are trying to *do*?
>
> Where's the job security in that?

Do you *really* want to be tethered to "old projects"?  Or, would
you rather be free to explore *new* projects??  ;-)

[toc] | [prev] | [next] | [standalone]


#21637

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2015-08-04 22:20 +0100
Message-ID<50awx.82892$Ec3.47403@fx24.am4>
In reply to#21634
On 04/08/15 19:37, Don Y wrote:
> On 8/4/2015 11:28 AM, Tim Wescott wrote:
>> On Tue, 04 Aug 2015 11:07:49 -0700, Don Y wrote:
>>> Why not just have the code *say* what you are trying to *do*?
>>
>> Where's the job security in that?
>
> Do you *really* want to be tethered to "old projects"?  Or, would
> you rather be free to explore *new* projects??  ;-)

Precisely.

[toc] | [prev] | [next] | [standalone]


#21639

Fromglen herrmannsfeldt <gah@ugcs.caltech.edu>
Date2015-08-04 21:45 +0000
Message-ID<mprbpu$vnv$1@speranza.aioe.org>
In reply to#21634
Don Y <this@is.not.me.com> wrote:

(snip of other non-optimizations)

>    Given a year expressed in packed BCD, indicate whether the year is a
>    leap year.
 
> Obviously, there is some merit in knowing this.  OTOH, the code only
> has to execute VERY rarely!

Not so long ago, I had to test an odd integer for being 1 modulo 4.
Slightly different, but I did it with the S/360 MVO and TM 
instructions.

         MVO    ODD(4),J+6(2)
         TM     ODD+2,X'12'
         BM    LOOP5B

But only after I put in the usual (binary case) test for one bit,
and then realized that it didn't work. The first time I remember
using BM (branch mixed) for a TM (test under mask) instruction.

-- glen

[toc] | [prev] | [next] | [standalone]


#21640

FromDon Y <this@is.not.me.com>
Date2015-08-04 15:34 -0700
Message-ID<mprek7$5o0$1@speranza.aioe.org>
In reply to#21639
Hi Glen,

On 8/4/2015 2:45 PM, glen herrmannsfeldt wrote:
> Don Y <this@is.not.me.com> wrote:
>
> (snip of other non-optimizations)
>
>>     Given a year expressed in packed BCD, indicate whether the year is a
>>     leap year.
>
>> Obviously, there is some merit in knowing this.  OTOH, the code only
>> has to execute VERY rarely!
>
> Not so long ago, I had to test an odd integer for being 1 modulo 4.
> Slightly different, but I did it with the S/360 MVO and TM
> instructions.
>
>           MVO    ODD(4),J+6(2)
>           TM     ODD+2,X'12'
>           BM    LOOP5B
>
> But only after I put in the usual (binary case) test for one bit,
> and then realized that it didn't work. The first time I remember
> using BM (branch mixed) for a TM (test under mask) instruction.

"Too clever for your own good!"  :-)

I am retroactively embarrassed for many of the *little* clever
tricks I employed in designs early in my career.  In hindsight,
they're nothing more than ego-strokes -- the "savings" rarely
justified the time spent *thinking* about them!  (i.e., micro
optimizations)

E.g., I designed a "front panel replacement" for a minicomputer
in the 70's.  This allowed me to discard the little "bit switches"
that one would use to "toggle" a program into core (*real* core!),
examine memory locations, step the processor, etc.

Part of the design required some conditional logic to encode
certain "levels" on the O.C. bus.  So, conceptually, you had a
bit of "junk logic" feeding OC NAND's that, in turn, drove the bus.

Not content to live with this "obvious" implementation, I
realized that some of the "logic functions" coincided with
some of the "segment decoders" in common BCD->7segment display
decoders.  So, by twiddling the "BCD" inputs to the decoder,
I could get the logic function of the "junk logic" *and* the
bus driving capability of the NAND drivers -- all in one package!

Over the lifetime of the product, it *might* save a dozen DIPs
(total!!)  :-/

[But, solving the problem was truly *fun*!]

[toc] | [prev] | [next] | [standalone]


#21642

Fromglen herrmannsfeldt <gah@ugcs.caltech.edu>
Date2015-08-05 00:00 +0000
Message-ID<mprjn7$fb1$1@speranza.aioe.org>
In reply to#21640
Don Y <this@is.not.me.com> wrote:

(snip on different ways to do the same thing)
(then I wrote)
>> Not so long ago, I had to test an odd integer for being 1 modulo 4.
>> Slightly different, but I did it with the S/360 MVO and TM
>> instructions.

>>           MVO    ODD(4),J+6(2)
>>           TM     ODD+2,X'12'
>>           BM    LOOP5B

>> But only after I put in the usual (binary case) test for one bit,
>> and then realized that it didn't work. The first time I remember
>> using BM (branch mixed) for a TM (test under mask) instruction.
 
> "Too clever for your own good!"  :-)
 
> I am retroactively embarrassed for many of the *little* clever
> tricks I employed in designs early in my career.  In hindsight,
> they're nothing more than ego-strokes -- the "savings" rarely
> justified the time spent *thinking* about them!  (i.e., micro
> optimizations)

Most of the others that I thought of were enough more complicated.
The result is the exclusive OR of two different bits in two
different bytes. The less tricky way might be four bit tests
and four branch instructions.  Many ways to get it wrong.

For those who don't follow it, MVO is a memory to memory
move that shifts four bits. The high half of one byte, and
the low half of the one before it get written to one byte.
(For between 1 and 16 bytes.)

TM allows testing for some combination of bits in one
byte being all zero (BZ) all ones (BO) or mixed zeros 
and ones (BM).

Even more tricky by the designers of S/360, BO is the Branch
on Overflow test after arithmetic instructions, and BM is
the Branch if Minus test after arithmetic instructions!
 
(snip)

> Not content to live with this "obvious" implementation, I
> realized that some of the "logic functions" coincided with
> some of the "segment decoders" in common BCD->7segment display
> decoders.  So, by twiddling the "BCD" inputs to the decoder,
> I could get the logic function of the "junk logic" *and* the
> bus driving capability of the NAND drivers -- all in one package!

The 7447 has nice high current 15 volt OC drivers. 
Usual OC gates have 5V transistors.

-- glen

[toc] | [prev] | [next] | [standalone]


#21645

FromDon Y <this@is.not.me.com>
Date2015-08-04 17:36 -0700
Message-ID<mprlpm$is9$1@speranza.aioe.org>
In reply to#21642
On 8/4/2015 5:00 PM, glen herrmannsfeldt wrote:
>> Not content to live with this "obvious" implementation, I
>> realized that some of the "logic functions" coincided with
>> some of the "segment decoders" in common BCD->7segment display
>> decoders.  So, by twiddling the "BCD" inputs to the decoder,
>> I could get the logic function of the "junk logic" *and* the
>> bus driving capability of the NAND drivers -- all in one package!
>
> The 7447 has nice high current 15 volt OC drivers.
> Usual OC gates have 5V transistors.

The HV output wasn't required.  The silliness was the effort
to save a package of *gates* (or an AOI, etc.) -- at the expense
of puzzling anyone who had to look at the circuit thereafter
(Can you rattle off the decoding functions of any particular
7seg decoder, "off the top of your head"?  e.g., does 6 have a
tail?  9?  how are the non-decimal codes handled?  etc.  By
contrast, some *gates* wired together would be incredibly
obvious to damn near anyone looking at the schematic!)

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.arch.embedded


csiph-web