new option to choose single or double precision floats pyrit
authorRadek Brich <radek.brich@devl.cz>
Fri, 11 Apr 2008 12:46:36 +0200
branchpyrit
changeset 67 249553e1d4fe
parent 66 c5b89d16497a
child 68 2c154aad7f33
new option to choose single or double precision floats
SConstruct
src/raytracer.cc
--- a/SConstruct	Fri Apr 11 00:13:59 2008 +0200
+++ b/SConstruct	Fri Apr 11 12:46:36 2008 +0200
@@ -31,11 +31,12 @@
 
 import os, sys
 env = Environment(ENV = {'PATH' : os.environ['PATH']})
-Decider('MD5-timestamp')
+#Decider('MD5-timestamp')
 
 opt = Options(['.optioncache'])
 opt.AddOptions(
 	BoolOption('intelc', 'use Intel C++ Compiler, if available', True),
+	('precision', 'floating point number precision (single/double)', "single"),
 	('flags', 'add additional compiler flags', ""),
 )
 if env['PLATFORM'] == 'win32':
@@ -70,7 +71,7 @@
 	context.Result(cpu)
 	return True
 
-intelc = Tool("intelc").exists(env)
+intelc = Tool("intelc").exists(env) == True
 def CheckIntelC(context):
 	global intelc
 	context.Message('Checking for Intel C++ Compiler... ')
@@ -110,29 +111,35 @@
 elif gcc:
 	cc = 'gcc'
 
-cpu_flags = ''
+add_flags = ''
 if cc == 'gcc':
-	cpu_flags += '-ffast-math '
+	add_flags += '-ffast-math '
 if cpu == 'core2':
 	if (cc == 'intelc' or gccversion[:3] == '4.3'):
-		cpu_flags += '-march=core2 -mtune=core2 '
+		add_flags += '-march=core2 -mtune=core2 '
 	if cc == 'intelc':
-		cpu_flags += '-xT '
+		add_flags += '-xT '
 	if cc == 'gcc':
-		cpu_flags += '-msse3 -mfpmath=sse '
-cpu_flags += env['flags']
+		add_flags += '-msse3 -mfpmath=sse '
+
+if env['precision'] == 'double':
+	add_flags += '-DPYRIT_DOUBLE '
+elif cc == 'gcc':
+	add_flags += '-fsingle-precision-constant '
+
+add_flags += env['flags']
 
 if cc == 'intelc':
-	env.Append(CCFLAGS="-O3 -w1 " + cpu_flags)
+	env.Append(CCFLAGS="-O3 -w1 " + add_flags)
 elif cc == 'gcc':
-	env.Append(CCFLAGS="-O3 -Wall -pipe " + cpu_flags)
+	env.Append(CCFLAGS="-O3 -Wall -pipe " + add_flags)
 	# CCFLAGS= -fno-strict-aliasing
 else:
 	print "No supported compiler found."
 	Exit(1)
 
 print "Using compiler: " + cc
-print "Additional flags: " + cpu_flags
+print "Additional flags: " + add_flags
 
 # pthread
 if env['PLATFORM'] == 'win32':
@@ -140,8 +147,6 @@
 else:
 	env.Append(CCFLAGS="-pthread ")
 
-# float: -fsingle-precision-constant
-# double: -DPYRIT_DOUBLE
 (lib, pymodule) = SConscript('src/SConscript', build_dir='build/lib', duplicate=0, exports='env')
 
 SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0, exports='env lib')
--- a/src/raytracer.cc	Fri Apr 11 00:13:59 2008 +0200
+++ b/src/raytracer.cc	Fri Apr 11 12:46:36 2008 +0200
@@ -26,7 +26,7 @@
 
 #include <pthread.h>
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include "raytracer.h"
 
 int pyrit_verbosity = 2;