Monday, November 28, 2016

Dear Mr(s) President, I want to be the Ambassador to Ghana.

To current, past and future presidents: I want to become the Ambassador to Ghana. I would be an excellent candidate for the job because I am a skilled political manager. (anyone who gets their Ph.D. has this skill). Primarily, I have found that most Ambassadors are a bit removed from the countries where they are representing the USA. As a fluent Japanese speaker, I would be more qualified for Ambassador to Japan, but if you look at the link, you will find that it's the award for campaign contributions. I'm really unable to find someone in recent years that I could be proud from the standpoint of increasing mutual cooperation. In an effort to be appropriate for Ghana, my Twi is not yet fluent, but it will be.

So why Ghana?
It's refreshing to find a country in Africa that has its act together. I read The Economist every week, and have been to Ghana multiple times. Ghana is one of those places where the people are proud of their achievements and government, and in 50 years I imagine it to be a powerhouse of industry like Japan or China (their VAT is a bit of an issue, but...) The people are hard working and industrious. A good example of the quality of the populous is that the country remained stable during power transition after President Mills died in office. All in all, it's a great country and it would be a privilege to be part of its international rise.

Sunday, November 20, 2016

68060 for the NeXT.

Although this is completely worthless as far as real-world item, I really want to get back to making a 68060 socket for the NeXT Slab. I got up to the point where I reverse engineered the Nitro board, ordered the logic, but I never sent out the board. Maybe one day I can justify the time, but I doubt that day will come. :(

Friday, November 18, 2016

Gate Equivalents (GE) and why you should not use them.

I was introduced to Gate Equivalents (GEs) from using Xilinx layout tools, where the routed graph estimates how many NAND gates would be required for an implementation of a circuit. I keep reading papers were people use GEs as a comparison between designs, but it seems that the GE does not seem to have a standard definition. In many cryptography papers, the GE is used as an area comparison; however, this can be misleading. Let's say that you have a standard cell library with a large NAND gate, which is one GE. Now let's say that you have an XOR that is heavily optimized for area, and in this case, the XOR could have the same area of a NAND gate even though it requires more transistors.

Here is how people seem to game the system when GE is used as area. I make a NAND that is very large. This makes my total design take much less area in GEs for the other optimized cells. I just saw a design on 130nm that has fewer transistors with a higher GE than a design that has more transistors and a lower GE.

Instead of GEs, use transistor count. This just make sense. Here's an example of the layout of 8 transistors in a commercially available 14nm process:


This layout is substantially different from a 130nm equivalent. The attempt to compare different layouts and feature sizes with GEs is just worthless. Just don't do it.

Monday, November 14, 2016

Logic with large numbers in Bash

I found that I was losing information when passing information between commands via bash. Bash cannot seem to deal with numbers larger than 64-bits. The solution was for me to change everything into an ASCII series of 0's and 1's and then run logic on the strings. The code below takes a hexadecimal number, 549b93563bfa04fb, splits it in two, and XOR's the halves. I tried the code on a 4096-bit number and it worked well.
 #!/bin/sh  
 #Before anything else, set the PATH_SCRIPT variable  
      pushd `dirname $0` > /dev/null; PATH_SCRIPT=`pwd -P`; popd > /dev/null  
      PROGNAME=${0##*/}; PROGVERSION=0.1.0   

 lowercase(){  
 # convert the uppercase to lowercase  
   echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"  
 }  
 bashhex2bin()  
 {  
 # Take a value as a hex number and convert it to a binary string  
 #  
  HEXVAL=$1  
  #echo "$@"  
  #echo "$#"  
  if [ "$#" -lt 1 ]; then  
   # this means that the function was run without any arguments  
   : #null command to make BASH happy  
  else  
   #echo "bashhex2bin(): total args passed to me $#"  
   STRSIZE=${#HEXVAL} #the string length of the argument  
   for ((COUNTER1=0; COUNTER1 < STRSIZE ; COUNTER1++))  
   do  
    #echo "Welcome $COUNTER1 times"  
    CHARATINDEX=${HEXVAL:$COUNTER1:1}  
    #convert the hex value to binary  
    bashchar2bin $CHARATINDEX  
   done   
  fi  
 }  
 bashchar2bin()  
 {  
 # Take a nibble as an argument, and return a binary represntation  
 #  
  NIB=$1 #this should be 0 to F  
  NIB=$(lowercase $NIB)  
  case $NIB in  
   "0" )  
     printf "0000" ;;  
   "1" )  
     printf "0001" ;;  
   "2" )  
     printf "0010" ;;  
   "3" )  
     printf "0011" ;;       
   "4" )  
     printf "0100" ;;  
   "5" )  
     printf "0101" ;;  
   "6" )  
     printf "0110" ;;                  
   "7" )  
     printf "0111" ;;   
   "8" )  
     printf "1000" ;;  
   "9" )  
     printf "1001" ;;  
   "a" )  
     printf "1010" ;;  
   "b" )  
     printf "1011" ;;       
   "c" )  
     printf "1100" ;;  
   "d" )  
     printf "1101" ;;  
   "e" )  
     printf "1110" ;;   
   *)   
     printf "1111" ;;   
  esac  
 }  
 xor()   
 {  
      if (( $1 ^ $2 )) ;then  
           printf "1"  
      else  
           printf "0"  
      fi  
 }  
 bashXORbinstring()  
 {  
 # Take a string, such as arguments 1, 2:  
 # 10100001  
 # 10100000  
 # and return the XOR result  
 STRBIN1=$1  
 STRBIN2=$2  
 if [ ${#STRBIN1} -eq ${#STRBIN2} ]; then  
   STRSIZE=${#STRBIN1} #the string length of the argument  
   for ((COUNTER1=0; COUNTER1 < STRSIZE ; COUNTER1++))  
   do  
    xor ${STRBIN1:$COUNTER1:1} ${STRBIN2:$COUNTER1:1}  
   done   
 else  
  echo "ERROR, XOR failed due to different lengths $STRBIN1, $STRBIN2"   
 fi  
 }  

 CMDRESULT=549b93563bfa04fb
 # at this point, CMDRESULT should have a key, such as:  
 # 549b93563bfa04fb  
 #  
 # now need to split the key into two.  
 STRSIZE=${#CMDRESULT}   
 STRHALFSIZE=$(($STRSIZE / 2)) #divide by two  
 #now use BASH to split the string  
 #echo $CMDRESULT  
 XORARG1=${CMDRESULT:0:$STRHALFSIZE}  
 XORARG2=${CMDRESULT:$STRHALFSIZE:STRHALFSIZE}  
 #echo $XORARG1  
 #echo $XORARG2  
 #convert the strings into binary as a string  
 BINARG1=$(bashhex2bin $XORARG1)  
 BINARG2=$(bashhex2bin $XORARG2)  
 #use the XOR function to XOR the ASCII strings  
 RESULTXOR=$(bashXORbinstring $BINARG1 $BINARG2)  
 echo $BINARG1  
 echo $BINARG2  
 echo $RESULTXOR  

Friday, November 11, 2016

Referencing the RFID Gen2 document via BibTeX

One would not think that it would be difficult to reference a document in BibTeX, but there's strangeness when you don't do it just right. I found this link on referencing the CD4007 via bibtex. In the same vein, I came up with:

\usepackage{url} %for the _ in the URL

@misc{EPCglobalGen2-2013,
  author={EPCglobal Inc.},
  title={{EPC}$^{TM}$  {Radio-Frequency Identity Protocols
Generation-2 UHF RFID}},
  howpublished = "\url{http://www.gs1.org/sites/default/files/docs/epc/uhfc1g2_2_0_0_standard_20131101.pdf}",
  publisher={EPCglobal Inc.},
  year={2013}
}
The {} around the author make sure that it doesn't become E. Inc. The resulting render:

Tuesday, November 8, 2016

Merge PDFs with MacOS and the command line.

I use the command line to merge PDFs all of the time, but I have found that with every MacOS release, things move. I made a script, PDFconcatenator.sh, that finds the script join.py in /System/Library and then passes arguments to join.py. join.py seems to move with every MacOS release and this script works as long as you have join.py on the system.

Ad example of three files:
PDFconcatenator.sh -o merged.pdf ../../file1..pdf file3pdf /off/root/3.pdf
#!/bin/bash
#Before anything else, set the PATH_SCRIPT variable
    pushd `dirname $0` > /dev/null; PATH_SCRIPT=`pwd -P`; popd > /dev/null
    PROGNAME=${0##*/}; PROGVERSION=0.1.0
# WHAT DOES THIS DO?
# This script looks at MacOS distribution and tries to find the python script to merge
# pdfs files. It tends to move depending on MacOS releases.

HUNT_DIR="/System/Library/"

usage(){
    echo "$PROGNAME"
    echo "This program finds the PDF concatenation script on MacOS "
    echo "example:"
    echo "$PROGNAME -o PATH/TO/YOUR/MERGED/FILE.pdf /PATH/TO/1.pdf /PATH/TO/2.pdf /3.pdf"
    echo ""
}

# lowercase makes things lowercase. This is an issue because sometime different OS
# have different conventions. bsd and BSD or FreeBSD and freebsd
lowercase(){
    echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}

# This is my canned script to determine the OS
#
getOS(){
OS=`lowercase \`uname\``
KERNEL=`uname -r`
MACH=`uname -m`

if [ "${OS}" = "windowsnt" ]; then
    OS=windows
elif [ "${OS}" = "darwin" ]; then
    OS=mac
else
    OS=`uname`
    if [ "${OS}" = "SunOS" ] ; then
OS=Solaris
ARCH=`uname -p`
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
    elif [ "${OS}" = "AIX" ] ; then
OSSTR="${OS} `oslevel` (`oslevel -r`)"
    elif [ "${OS}" = "Linux" ] ; then
if [ -f /etc/redhat-release ] ; then
DistroBasedOn='RedHat'
DIST=`cat /etc/redhat-release |sed s/\ release.*//`
PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn='SuSe'
PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
elif [ -f /etc/mandrake-release ] ; then
DistroBasedOn='Mandrake'
PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/debian_version ] ; then
DistroBasedOn='Debian'
DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'`
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
fi
OS=`lowercase $OS`
DistroBasedOn=`lowercase $DistroBasedOn`
readonly OS
readonly DIST
readonly DistroBasedOn
readonly PSUEDONAME
readonly REV
readonly KERNEL
readonly MACH
fi
fi
}

# start by getting the OS to be sure we can run
getOS

if [ "mac" != "$OS" ]; then
    echo "This script only works on MacOS"
    exit 1
fi

SCRIPT=$(find $HUNT_DIR -name join.py 2>/dev/null)
SCRIPT=$( echo "$SCRIPT" | sed 's/ /\\ /g')

if [ "$#" -eq 0 ]; then
    usage
    exit 2
fi

#run the concatenation
echo "Executing the following command:"
echo "$SCRIPT $@"
#execute the actual command
eval "$SCRIPT $@"