Skip to content

Instantly share code, notes, and snippets.

@yongzhy
Created March 2, 2017 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongzhy/d65c26d39fe5d549d1b406c7c84eacd4 to your computer and use it in GitHub Desktop.
Save yongzhy/d65c26d39fe5d549d1b406c7c84eacd4 to your computer and use it in GitHub Desktop.
Simple code to debug JDK9 float point issue
// javac whetstc.java
// java whetstc
import java.util.*;
import java.io.*;
public class FloatDebug
{
private static double TimeUsed;
private static float x,y,z;
private static float[] e1 = new float[4];
private static float Check;
private static float mwips;
private static double[] loop_time = new double[9];
private static double[] loop_mops = new double[9];
private static double[] loop_mflops = new double[9];
private static float[] results = new float[9];
private static String[] titles = new String[9];
private static int[] num = new int[4];
private static int wwidth = 500;
private static int wheight = 325;
private static String xout;
private static double runTime;
private static double mflops;
private static int section ;
private static int runit = 1;
private static int printit = 0;
private static int x100 = 100;
public static void main(String[] args)
{
section = -1;
System.out.println("Float point debug code, get exit code using $? after execution");
if (runit == 1)
{
TimeUsed = 0.0;
for (section=1; section<9; section++)
{
whetstones();
}
}
}
public static void whetstones()
{
double startTime;
double endTime;
int i, j, k, l, ix, xtra, n1mult;
float t = 0.49999975f;
float t0 = t;
float t1 = 0.50000025f;
float t2 = 2.0f;
int n1 = 12*x100;
int n2 = 14*x100;
int n3 = 345*x100;
int n4 = 210*x100;
int n5 = 32*x100;
int n6 = 899*x100;
int n7 = 616*x100;
int n8 = 93*x100;
num[0] = 0;
num[1] = 1;
num[2] = 2;
num[3] = 3;
switch (section)
{
case 1:
// Section 1, Array elements
n1mult = 10;
e1[0] = 1.0f;
e1[1] = -1.0f;
e1[2] = -1.0f;
e1[3] = -1.0f;
runTime = 0.0;
xtra = 10;
do
{
if (runTime > 0.2)
{
xtra = xtra * 5;
}
else if (runTime > 0.5)
{
xtra = xtra * 2;
}
else
{
xtra = xtra * 10;
}
startTime = getTime();
for (ix=0; ix<xtra; ix++)
{
for(i=0; i<n1*n1mult; i++)
{
e1[0] = (e1[0] + e1[1] + e1[2] - e1[3]) * t;
e1[1] = (e1[0] + e1[1] - e1[2] + e1[3]) * t;
e1[2] = (e1[0] - e1[1] + e1[2] + e1[3]) * t;
e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3]) * t;
}
t = 1.0f - t;
if (ix == 0) results[section] = e1[3];
}
t = t0;
endTime = getTime();
runTime = endTime - startTime;
System.out.printf("startTime: %f endTime: %f runTime: %f\n", startTime, endTime, runTime );
}
while (runTime < 1.0);
Check = Check + e1[3];
loop_time[section] = runTime / (double)n1mult / (double)xtra;
loop_mflops[section] = (double)(n1*16) / 1000000.0 / loop_time[section];
loop_mops[section] = 0.0;
titles[section] = "N1 floating point";
TimeUsed = TimeUsed + loop_time[section];
break;
}
}
public static double getTime()
{
double q;
long itime;
itime = System.currentTimeMillis();
if(itime<1000000) {
System.exit(1);
}
//System.out.printf("time long value %d\n", itime);
q = (double) itime;
if(q < 1.0f) {
System.exit(5);
}
//System.out.printf("time float value %f\n", q);
return q / 1000.0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment