mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-23 23:49:02 +00:00
Initial open source release of OpenCL 2.0 CTS.
This commit is contained in:
40
test_conformance/conversions/CMakeLists.txt
Normal file
40
test_conformance/conversions/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
set(MODULE_NAME CONVERSIONS)
|
||||
|
||||
# VS2005 AMD64 WAR (basic_test_conversions.c causes internal compiler error)
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS_RELEASE "/Od /Ob0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "/Od /Ob0")
|
||||
else(MSVC)
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O0")
|
||||
endif(MSVC)
|
||||
|
||||
set (${MODULE_NAME}_SOURCES
|
||||
Sleep.c test_conversions.c basic_test_conversions.c
|
||||
../../test_common/harness/ThreadPool.c
|
||||
../../test_common/harness/rounding_mode.c
|
||||
../../test_common/harness/mt19937.c
|
||||
../../test_common/harness/msvc9.c
|
||||
../../test_common/harness/mingw_compat.c
|
||||
../../test_common/harness/errorHelpers.c
|
||||
../../test_common/harness/kernelHelpers.c
|
||||
../../test_common/harness/testHarness.c
|
||||
)
|
||||
|
||||
if(ANDROID)
|
||||
list(APPEND CONVERSIONS_SOURCES fplib.c)
|
||||
endif(ANDROID)
|
||||
|
||||
if(WIN32)
|
||||
set_source_files_properties(
|
||||
${MODULE_NAME}_SOURCES
|
||||
PROPERTIES LANGUAGE CXX)
|
||||
endif(WIN32)
|
||||
|
||||
if(NOT ANDROID)
|
||||
set_source_files_properties(
|
||||
Sleep.c test_conversions.c basic_test_conversions.c
|
||||
COMPILE_FLAGS -msse2)
|
||||
endif(NOT ANDROID)
|
||||
|
||||
include(../CMakeCommon.txt)
|
||||
17
test_conformance/conversions/Jamfile
Normal file
17
test_conformance/conversions/Jamfile
Normal file
@@ -0,0 +1,17 @@
|
||||
project
|
||||
: requirements
|
||||
# <toolset>gcc:<cflags>-xc++
|
||||
<toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_conversions
|
||||
: basic_test_conversions.c
|
||||
Sleep.c
|
||||
test_conversions.c
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_conversions
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/conversions
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/conversions
|
||||
;
|
||||
50
test_conformance/conversions/Makefile
Normal file
50
test_conformance/conversions/Makefile
Normal file
@@ -0,0 +1,50 @@
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
# We do not use dependencies in this Makefile
|
||||
|
||||
SRCFILES = Sleep.c test_conversions.c ../../test_common/harness/mt19937.c ../../test_common/harness/ThreadPool.c ../../test_common/harness/rounding_mode.c
|
||||
|
||||
CC = c++
|
||||
|
||||
CFLAGS = -g -Wall -Wshorten-64-to-32 $(COMPILERFLAGS) \
|
||||
${RC_CFLAGS} ${USE_ATF}
|
||||
|
||||
INCLUDES = -I../../test_common/harness \
|
||||
${RC_CFLAGS} ${ATF}
|
||||
|
||||
LIBRARIES = -framework OpenCL -framework CoreFoundation -framework IOKit
|
||||
|
||||
release:
|
||||
echo "Build Release"
|
||||
$(CC) -c basic_test_conversions.c -Os $(CFLAGS) -o basic_test_conversions.o
|
||||
$(CC) $(SRCFILES) -Os $(CFLAGS) basic_test_conversions.o -o test_conversions $(INCLUDES) $(LIBRARIES)
|
||||
|
||||
debug:
|
||||
echo "Build Debug"
|
||||
$(CC) -c basic_test_conversions.c -O0 $(CFLAGS) -o basic_test_conversions.o
|
||||
$(CC) test_conversions.c -c -O0 -g $(CFLAGS) $(INCLUDES) -o test_conversions.o
|
||||
$(CC) Sleep.c -c -O0 -g $(CFLAGS) $(INCLUDES) -o Sleep.o
|
||||
$(CC) ../../test_common/harness/mt19937.c -c -O0 -g $(INCLUDES) $(CFLAGS) -o mt19937.o
|
||||
$(CC) ../../test_common/harness/ThreadPool.c -c -O0 -g $(INCLUDES) $(CFLAGS) -o ThreadPool.o
|
||||
$(CC) ../../test_common/harness/rounding_mode.c -c -O0 -g $(INCLUDES) $(CFLAGS) -o rounding_mode.o
|
||||
$(CC) *.o -g -O0 -o test_conversions_debug $(LIBRARIES) -arch i386 -arch x86_64
|
||||
|
||||
clean:
|
||||
rm -f test_conversions
|
||||
rm -f *.o
|
||||
rm -f test_conversions_debug
|
||||
|
||||
test: release
|
||||
arch -i386 ./test_conversions -c > cpu.out &
|
||||
arch -i386 ./test_conversions -g > gpu.out &
|
||||
echo "Testing 32-bit mode conversions for CPU and GPU, which takes a day or three. Results may be found in cpu.out and gpu.out\n"
|
||||
|
||||
test64: release
|
||||
arch -x86_64 ./test_conversions_64 -c > cpu64.out &
|
||||
arch -x86_64 ./test_conversions_64 -g > gpu64.out &
|
||||
echo "Testing 64-bit mode conversions for CPU and GPU, which takes a day or three. Results may be found in cpu64.out and gpu64.out\n"
|
||||
|
||||
all: release
|
||||
120
test_conformance/conversions/Sleep.c
Normal file
120
test_conformance/conversions/Sleep.c
Normal file
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#if defined( __APPLE__ )
|
||||
|
||||
#include "Sleep.h"
|
||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||
#include <IOKit/IOMessage.h>
|
||||
#include "basic_test_conversions.h"
|
||||
|
||||
#define UNUSED __attribute__((unused))
|
||||
|
||||
struct
|
||||
{
|
||||
io_connect_t connection;
|
||||
IONotificationPortRef port;
|
||||
io_object_t iterator;
|
||||
}sleepInfo;
|
||||
|
||||
void sleepCallback( void * refcon,
|
||||
io_service_t service,
|
||||
natural_t messageType,
|
||||
void * messageArgument );
|
||||
|
||||
void sleepCallback( void * refcon UNUSED,
|
||||
io_service_t service UNUSED,
|
||||
natural_t messageType,
|
||||
void * messageArgument )
|
||||
{
|
||||
|
||||
IOReturn result;
|
||||
/*
|
||||
service -- The IOService whose state has changed.
|
||||
messageType -- A messageType enum, defined by IOKit/IOMessage.h or by the IOService's family.
|
||||
messageArgument -- An argument for the message, dependent on the messageType.
|
||||
*/
|
||||
switch ( messageType )
|
||||
{
|
||||
case kIOMessageSystemWillSleep:
|
||||
// Handle demand sleep (such as sleep caused by running out of
|
||||
// batteries, closing the lid of a laptop, or selecting
|
||||
// sleep from the Apple menu.
|
||||
IOAllowPowerChange(sleepInfo.connection,(long)messageArgument);
|
||||
vlog( "Hard sleep occurred.\n" );
|
||||
break;
|
||||
case kIOMessageCanSystemSleep:
|
||||
// In this case, the computer has been idle for several minutes
|
||||
// and will sleep soon so you must either allow or cancel
|
||||
// this notification. Important: if you don’t respond, there will
|
||||
// be a 30-second timeout before the computer sleeps.
|
||||
// IOCancelPowerChange(root_port,(long)messageArgument);
|
||||
result = IOCancelPowerChange(sleepInfo.connection,(long)messageArgument);
|
||||
if( kIOReturnSuccess != result )
|
||||
vlog( "sleep prevention failed. (%d)\n", result);
|
||||
break;
|
||||
case kIOMessageSystemHasPoweredOn:
|
||||
// Handle wakeup.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PreventSleep( void )
|
||||
{
|
||||
vlog( "Disabling sleep... " );
|
||||
sleepInfo.iterator = (io_object_t) 0;
|
||||
sleepInfo.port = NULL;
|
||||
sleepInfo.connection = IORegisterForSystemPower
|
||||
(
|
||||
&sleepInfo, //void * refcon,
|
||||
&sleepInfo.port, //IONotificationPortRef * thePortRef,
|
||||
sleepCallback, //IOServiceInterestCallback callback,
|
||||
&sleepInfo.iterator //io_object_t * notifier
|
||||
);
|
||||
|
||||
if( (io_connect_t) 0 == sleepInfo.connection )
|
||||
vlog( "failed.\n" );
|
||||
else
|
||||
vlog( "done.\n" );
|
||||
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(),
|
||||
IONotificationPortGetRunLoopSource(sleepInfo.port),
|
||||
kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
void ResumeSleep( void )
|
||||
{
|
||||
IOReturn result = IODeregisterForSystemPower ( &sleepInfo.iterator );
|
||||
if( 0 != result )
|
||||
vlog( "Got error %d restoring sleep \n", result );
|
||||
else
|
||||
vlog( "Sleep restored.\n" );
|
||||
}
|
||||
|
||||
#else /* not __APPLE__ */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void PreventSleep( void ) {}
|
||||
void ResumeSleep( void ) {}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif //__cplusplus
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
32
test_conformance/conversions/Sleep.h
Normal file
32
test_conformance/conversions/Sleep.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef SLEEP_H
|
||||
#define SLEEP_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void PreventSleep( void );
|
||||
void ResumeSleep( void );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif //__cplusplus
|
||||
|
||||
#endif /* SLEEP_H */
|
||||
|
||||
|
||||
2246
test_conformance/conversions/basic_test_conversions.c
Normal file
2246
test_conformance/conversions/basic_test_conversions.c
Normal file
File diff suppressed because it is too large
Load Diff
73
test_conformance/conversions/basic_test_conversions.h
Normal file
73
test_conformance/conversions/basic_test_conversions.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef BASIC_TEST_CONVERSIONS_H
|
||||
#define BASIC_TEST_CONVERSIONS_H
|
||||
|
||||
#include "../../test_common/harness/compat.h"
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../../test_common/harness/errorHelpers.h"
|
||||
#include "../../test_common/harness/rounding_mode.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined( __APPLE__ )
|
||||
#include <OpenCL/opencl.h>
|
||||
#else
|
||||
#include <CL/opencl.h>
|
||||
#endif
|
||||
|
||||
#include "../../test_common/harness/mt19937.h"
|
||||
|
||||
typedef void (*Convert)( void *dest, void *src, size_t );
|
||||
|
||||
#define kVectorSizeCount 6
|
||||
#define kMaxVectorSize 16
|
||||
|
||||
typedef enum
|
||||
{
|
||||
kUnsaturated = 0,
|
||||
kSaturated,
|
||||
|
||||
kSaturationModeCount
|
||||
}SaturationMode;
|
||||
|
||||
extern Convert gConversions[kTypeCount][kTypeCount]; // [dest format][source format]
|
||||
extern Convert gSaturatedConversions[kTypeCount][kTypeCount]; // [dest format][source format]
|
||||
extern const char *gTypeNames[ kTypeCount ];
|
||||
extern const char *gRoundingModeNames[ kRoundingModeCount ]; // { "", "_rte", "_rtp", "_rtn", "_rtz" }
|
||||
extern const char *gSaturationNames[ kSaturationModeCount ]; // { "", "_sat" }
|
||||
extern const char *gVectorSizeNames[kVectorSizeCount]; // { "", "2", "4", "8", "16" }
|
||||
extern size_t gTypeSizes[ kTypeCount ];
|
||||
extern int gIsEmbedded;
|
||||
|
||||
//Functions for clamping floating point numbers into the representable range for the type
|
||||
typedef float (*clampf)( float );
|
||||
typedef double (*clampd)( double );
|
||||
|
||||
extern clampf gClampFloat[ kTypeCount ][kRoundingModeCount];
|
||||
extern clampd gClampDouble[ kTypeCount ][kRoundingModeCount];
|
||||
|
||||
typedef void (*InitDataFunc)( void *dest, SaturationMode, RoundingMode, Type destType, uint64_t start, int count, MTdata d );
|
||||
extern InitDataFunc gInitFunctions[ kTypeCount ];
|
||||
|
||||
typedef int (*CheckResults)( void *out1, void *out2, void *allowZ, uint32_t count, int vectorSize );
|
||||
extern CheckResults gCheckResults[ kTypeCount ];
|
||||
|
||||
#endif /* BASIC_TEST_CONVERSIONS_H */
|
||||
|
||||
221
test_conformance/conversions/fplib.c
Normal file
221
test_conformance/conversions/fplib.c
Normal file
@@ -0,0 +1,221 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include "fplib.h"
|
||||
|
||||
#define FLT_MANT_DIG 24
|
||||
#define as_float(x) (*((float *)(&x)))
|
||||
#define as_long(x) (*((int64_t *)(&x)))
|
||||
|
||||
static uint32_t clz(uint64_t value)
|
||||
{
|
||||
uint32_t num_zeros;
|
||||
|
||||
for( num_zeros = 0; num_zeros < (sizeof(uint64_t)*8); num_zeros++)
|
||||
{
|
||||
if(0x8000000000000000 & (value << num_zeros))
|
||||
break;
|
||||
}
|
||||
return num_zeros;
|
||||
}
|
||||
|
||||
float qcom_s64_2_f32(int64_t data, bool sat, roundingMode rnd)
|
||||
{
|
||||
switch (rnd) {
|
||||
case qcomRTZ: {
|
||||
int sign = 0;
|
||||
if (!data)
|
||||
return 0.0f;
|
||||
if (data < 0){
|
||||
data = - data;
|
||||
sign = 1;
|
||||
}
|
||||
uint32_t exponent = (127 + 64 - clz(data) - 1) << (FLT_MANT_DIG - 1); //add 1 for the implied 1.0 in normalized fp32 numbers
|
||||
int mantShift = 40 - clz(data);
|
||||
uint32_t mantissa;
|
||||
if (mantShift >= 0)
|
||||
mantissa = (uint32_t)((uint64_t)data >> mantShift);
|
||||
else
|
||||
mantissa = (uint32_t)((uint64_t)data << -mantShift);
|
||||
mantissa &= 0x7fffff;//mask off the leading 1
|
||||
|
||||
uint32_t result = exponent | mantissa;
|
||||
if (sign)
|
||||
result |= 0x80000000;
|
||||
return as_float(result);
|
||||
break;
|
||||
}
|
||||
case qcomRTE: return (float)(data); break;
|
||||
case qcomRTP: {
|
||||
int sign = 0;
|
||||
int inExact = 0;
|
||||
uint32_t f = 0xdf000000;
|
||||
if (!data)
|
||||
return 0.0f;
|
||||
if (data == 0x8000000000000000)
|
||||
return as_float(f);
|
||||
if (data < 0){
|
||||
data = - data;
|
||||
sign = 1;
|
||||
}
|
||||
uint32_t exponent = (127 + 64 - clz(data) - 1) << (FLT_MANT_DIG - 1); //add 1 for the implied 1.0 in normalized fp32 numbers
|
||||
int mantShift = 40 - clz(data);
|
||||
uint32_t mantissa;
|
||||
if (mantShift >= 0){
|
||||
uint64_t temp = (uint64_t)data >> mantShift;
|
||||
uint64_t mask = (1 << mantShift) - 1;
|
||||
if ((temp << mantShift) != data)
|
||||
inExact = 1;
|
||||
mantissa = (uint32_t)temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
mantissa = (uint32_t)((uint64_t)data << -mantShift);
|
||||
}
|
||||
mantissa &= 0x7fffff;//mask off the leading 1
|
||||
|
||||
uint32_t result = exponent | mantissa;
|
||||
if (sign)
|
||||
result |= 0x80000000;
|
||||
if (sign)
|
||||
return as_float(result); // for negative inputs return rtz results
|
||||
else
|
||||
{
|
||||
if(inExact)
|
||||
{ // for positive inputs return higher next fp
|
||||
uint32_t high_float = 0x7f7fffff;
|
||||
return nextafterf(as_float(result), as_float(high_float)); // could be simplified with some inc and carry operation
|
||||
}
|
||||
else
|
||||
return as_float(result);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case qcomRTN: {
|
||||
int sign = 0;
|
||||
int inExact = 0;
|
||||
uint32_t f = 0xdf000000;
|
||||
if (!data)
|
||||
return 0.0f;
|
||||
if (data == 0x8000000000000000)
|
||||
return as_float(f);
|
||||
if (data < 0){
|
||||
data = - data;
|
||||
sign = 1;
|
||||
}
|
||||
uint32_t exponent = (127 + 64 - clz(data) - 1) << (FLT_MANT_DIG - 1); //add 1 for the implied 1.0 in normalized fp32 numbers
|
||||
int mantShift = 40 - clz(data);
|
||||
uint32_t mantissa;
|
||||
if (mantShift >= 0){
|
||||
uint64_t temp = (uint64_t)data >> mantShift;
|
||||
uint64_t mask = (1 << mantShift) - 1;
|
||||
if (temp << mantShift != data)
|
||||
inExact = 1;
|
||||
mantissa = (uint32_t)temp;
|
||||
}
|
||||
else
|
||||
mantissa = (uint32_t)((uint64_t)data << -mantShift);
|
||||
mantissa &= 0x7fffff;//mask off the leading 1
|
||||
|
||||
uint32_t result = exponent | mantissa;
|
||||
if (sign)
|
||||
result |= 0x80000000;
|
||||
if (!sign)
|
||||
return as_float(result); // for positive inputs return RTZ result
|
||||
else{
|
||||
if(inExact){ // for negative inputs find the lower next fp number
|
||||
uint32_t low_float = 0xff7fffff;
|
||||
return nextafterf(as_float(result), as_float(low_float)); // could be simplified with some inc and carry operation
|
||||
}
|
||||
else
|
||||
return as_float(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float qcom_u64_2_f32(uint64_t data, bool sat, roundingMode rnd)
|
||||
{
|
||||
switch (rnd) {
|
||||
case qcomRTZ: {
|
||||
if (!data)
|
||||
return 0.0f;
|
||||
uint32_t exponent = (127 + 64 - clz(data) - 1) << (FLT_MANT_DIG - 1); //add 1 for the implied 1.0 in normalized fp32 numbers
|
||||
int mantShift = 40 - clz(data);
|
||||
uint32_t mantissa;
|
||||
if (mantShift >= 0)
|
||||
mantissa = (uint32_t)(data >> mantShift);
|
||||
else
|
||||
mantissa = (uint32_t)(data << -mantShift);
|
||||
mantissa &= 0x7fffff;//mask off the leading 1
|
||||
|
||||
uint32_t result = exponent | mantissa;
|
||||
return as_float(result);
|
||||
break;
|
||||
}
|
||||
case qcomRTE: return (float)(data); break;
|
||||
case qcomRTP: {
|
||||
int inExact = 0;
|
||||
if (!data)
|
||||
return 0.0f;
|
||||
uint32_t exponent = (127 + 64 - clz(data) - 1) << (FLT_MANT_DIG - 1); //add 1 for the implied 1.0 in normalized fp32 numbers
|
||||
int mantShift = 40 - clz(data);
|
||||
uint32_t mantissa;
|
||||
if (mantShift >= 0){
|
||||
uint64_t temp = data >> mantShift;
|
||||
uint64_t mask = (1 << mantShift) - 1;
|
||||
if (temp << mantShift != data)
|
||||
inExact = 1;
|
||||
mantissa = (uint32_t)temp;
|
||||
}
|
||||
else
|
||||
mantissa = (uint32_t)(data << -mantShift);
|
||||
mantissa &= 0x7fffff;//mask off the leading 1
|
||||
|
||||
uint32_t result = exponent | mantissa;
|
||||
if(inExact){ // for positive inputs return higher next fp
|
||||
uint32_t high_float = 0x7f7fffff;
|
||||
return nextafterf(as_float(result), as_float(high_float)); // could be simplified with some inc and carry operation
|
||||
}
|
||||
else
|
||||
return as_float(result);
|
||||
}
|
||||
case qcomRTN: {
|
||||
int inExact = 0;
|
||||
if (!data)
|
||||
return 0.0f;
|
||||
uint32_t exponent = (127 + 64 - clz(data) - 1) << (FLT_MANT_DIG - 1); //add 1 for the implied 1.0 in normalized fp32 numbers
|
||||
int mantShift = 40 - clz(data);
|
||||
uint32_t mantissa;
|
||||
if (mantShift >= 0){
|
||||
uint64_t temp = (uint64_t)data >> mantShift;
|
||||
uint64_t mask = (1 << mantShift) - 1;
|
||||
if (temp << mantShift != data)
|
||||
inExact = 1;
|
||||
mantissa = (uint32_t)temp;
|
||||
}
|
||||
else
|
||||
mantissa = (uint32_t)((uint64_t)data << -mantShift);
|
||||
mantissa &= 0x7fffff;//mask off the leading 1
|
||||
|
||||
uint32_t result = exponent | mantissa;
|
||||
return as_float(result); // for positive inputs return RTZ result
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
29
test_conformance/conversions/fplib.h
Normal file
29
test_conformance/conversions/fplib.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
qcomRTZ = 0,
|
||||
qcomRTE,
|
||||
qcomRTP,
|
||||
qcomRTN,
|
||||
|
||||
qcomRoundingModeCount
|
||||
}roundingMode;
|
||||
|
||||
float qcom_u64_2_f32(uint64_t data, bool sat, roundingMode rnd);
|
||||
float qcom_s64_2_f32(int64_t data, bool sat, roundingMode rnd);
|
||||
16
test_conformance/conversions/run_batch
Normal file
16
test_conformance/conversions/run_batch
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/csh
|
||||
#
|
||||
# This runs the conversions in 32- and 64-bit modes, split into 9 processes for better throughput.
|
||||
# It is intended to allow for quicker debugging turnaround for code development purposes
|
||||
#
|
||||
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 0 100 > 0_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 0 100 > 0_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 100 100 > 1_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 100 100 > 1_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 200 100 > 2_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 200 100 > 2_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 300 100 > 3_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 300 100 > 3_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 400 100 > 4_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 400 100 > 4_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 500 100 > 5_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 500 100 > 5_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 600 100 > 6_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 600 100 > 6_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 700 100 > 7_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 700 100 > 7_64.txt &
|
||||
/usr/bin/arch -i386 ./test_conversions CL_DEVICE_TYPE_CPU 800 100 > 8_32.txt; /usr/bin/arch -x86_64 ./test_conversions CL_DEVICE_TYPE_CPU 800 100 > 8_64.txt &
|
||||
|
||||
1901
test_conformance/conversions/test_conversions.c
Normal file
1901
test_conformance/conversions/test_conversions.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user