Is this am answer? ]c=:#:i.40 00 11 01 1 ]a=:0{"1 c0 0 1 1 ]b=:1{"1 c
]b=:1{"1 c0 1 0 1 {:a*b1 LindaSent from my Verizon, Samsung Galaxy
smartphone
-------- Original message --------From: Henry Rich <[email protected]> Date:
7/28/19 8:51 PM (GMT-05:00) To: [email protected] Subject:
[Jprogramming] A bit-twisting puzzle Many of the members of this Forum will
remember the days of assembler language ...and who could less than merry be
when writing out BXLE?AND, OR, XOR were our meat. Those days are returning.You
have two integer variables a and b and you want to do something if one or both
of them are 0. In C, you might write if(a==0 || b==0)stmt;but that will
generate the code cmp a,0 bz stmt cmp b,0 bnz
notstmtstmt:...notstmt:Here's the problem: your machine is very slow at branch
instructions. Each branch takes 30 times as long as a regular instruction. (I
am describing a state-of-the-art Intel CPU when it cannot predict the branches
effectively, perhaps because the data is... unpredictable).Obviously, you want
to use only one branch instruction. You may use as many arithmetic and logic
instructions as you like, but only one branch. The usual condition codes,
ZNCV, are available. How tight can you make the code?Example: suppose the
problem were to execute stmt if one or both of a and b is NOT zero. Then you
would simply write or a,b bnz notstmt...Checking for zero seems to be
harder.No hurry. I have pondered this problem for over a year, and just today
I found a solution I consider acceptable.Henry Rich---This email has been
checked for viruses by
AVG.https://www.avg.com----------------------------------------------------------------------For
information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] A bit-twisting puzzle
'lindaalvord' via Programming Mon, 29 Jul 2019 03:57:39 -0700
- Re: [Jprogramming] A bit-twisting puzzle Louis de Forcrand
- Re: [Jprogramming] A bit-twisting puzzle Roger Hui
- Re: [Jprogramming] A bit-twisting puzzl... Louis de Forcrand
- Re: [Jprogramming] A bit-twisting p... Henry Rich
- Re: [Jprogramming] A bit-twisting p... Henry Rich
- Re: [Jprogramming] A bit-twisti... Marshall Lochbaum
- Re: [Jprogramming] A bit-tw... Henry Rich
- Re: [Jprogramming] A bit-twisting puzzl... Richard Donovan
- Re: [Jprogramming] A bit-twisting puzzle Aai
- Re: [Jprogramming] A bit-twisting puzzle 'lindaalvord' via Programming
- Re: [Jprogramming] A bit-twisting puzzle 'lindaalvord' via Programming
- Re: [Jprogramming] A bit-twisting puzzle Linda Alvord
- Re: [Jprogramming] A bit-twisting puzzle Don Guinn
- Re: [Jprogramming] A bit-twisting puzzl... Henry Rich
- Re: [Jprogramming] A bit-twisting p... Raul Miller
- Re: [Jprogramming] A bit-twisti... Henry Rich
- Re: [Jprogramming] A bit-tw... Roger Hui
- Re: [Jprogramming] A b... Devon McCormick
- Re: [Jprogramming] A bit-twisting p... Don Guinn
- Re: [Jprogramming] A bit-twisti... Linda Alvord
- Re: [Jprogramming] A bit-tw... Linda Alvord
