Project

General

Profile

Bug #4318

Floating point exception service likely to be only partially working

Added by Jim Kowalkowski over 7 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Category:
Infrastructure
Target version:
Start date:
02/02/2015
Due date:
% Done:

100%

Estimated time:
3.00 h
Spent time:
Occurs In:
Scope:
Internal
Experiment:
-
SSI Package:
art
Duration:

Description

In preparing example code to generate an abort on divide-by-zero, I took the controlFpe() code out of art to demonstrate in a standard alone program. This code did not produce the interrupt as excepted for the simple program:

double func(double x, double y) {
return (x/y);
}

int main() {
printf("answer=%f\n",func(5,0));
return 0;
}

After some checking, it turns out that we are not setting mxcsr to turn on the exception bits for the other SSE floating point unit. I actually thought this was fixed long ago. Here is example code that will turn on the divide by zero exception on both Linux and on the Mac

#include <fenv.h>
#include <stdio.h>
#include <stdlib.h>

#if (defined(i386) || defined(x86_64))
#ifdef linux
#include <fpu_control.h>
#define SET_CONTROL_EX(env,ex) env.__control_word &= ~(ex)
#else
// next two lines probably not necesary
#include <architecture/i386/fpu.h>
#pragma STDC FENV_ACCESS ON
#define SET_CONTROL_EX(env,ex) env.__control &= ~(ex)
#endif
#else
#error architecture not valid
#endif

void enable() {
fprintf(stderr,"enable called\n");
fenv_t env;
if(fegetenv(&env)!=0) fprintf(stderr,"getenv failed\n");
SET_CONTROL_EX(env,FE_DIVBYZERO);
env.__mxcsr &= ~(0x0200);
if(fesetenv(&env)!=0) fprintf(stderr,"setenv failed\n");
}

The code in FloatingPointControl_service.cc needs to be adjusted to set the mxcsr correctly.

I did not find any worthwhile standard #defines for the MXCSR bit definitions, but did not spent a lot of time looking. Here are the bit definitions for mxcsr (from a web page):

The MXCSR register is a 32-bit register containing flags for control and status information regarding SSE instructions. As of SSE3, only bits 0-15 have been defined.

Pnemonic Bit Location Description
FZ bit 15 Flush To Zero
R+ bit 14 Round Positive
R- bit 13 Round Negative
RZ bits 13 and 14 Round To Zero
RN bits 13 and 14 are 0 Round To Nearest
PM bit 12 Precision Mask
UM bit 11 Underflow Mask
OM bit 10 Overflow Mask
ZM bit 9 Divide By Zero Mask
DM bit 8 Denormal Mask
IM bit 7 Invalid Operation Mask
DAZ bit 6 Denormals Are Zero
PE bit 5 Precision Flag
UE bit 4 Underflow Flag
OE bit 3 Overflow Flag
ZE bit 2 Divide By Zero Flag
DE bit 1 Denormal Flag
IE bit 0 Invalid Operation Flag


Related issues

Related to art - Bug #919: Investigate report of problem with floating point exception control service.Rejected02/01/2011

History

#1 Updated by Christopher Green about 7 years ago

  • Due date changed from 07/18/2013 to 09/30/2013
  • Status changed from New to Accepted
  • Target version set to 1.09.00
  • Scope set to Internal
  • Experiment - added
  • SSI Package art added

#2 Updated by Christopher Green over 6 years ago

  • Target version changed from 1.09.00 to 521

#3 Updated by Christopher Green over 6 years ago

  • Target version changed from 521 to 1.10.00

#4 Updated by Christopher Green over 6 years ago

  • Target version changed from 1.10.00 to 1.14.00

#5 Updated by Christopher Green over 6 years ago

  • Target version changed from 1.14.00 to 1.13.00

#6 Updated by Christopher Green over 5 years ago

  • Status changed from Accepted to Assigned
  • Assignee set to Jim Kowalkowski

#7 Updated by Jim Kowalkowski over 5 years ago

  • Status changed from Assigned to Resolved
  • % Done changed from 0 to 100

#8 Updated by Jim Kowalkowski over 5 years ago

I had to reactivate an old test and update it (from Framework/Services/Basic). I modified It to test that the divide by zero error actually occurs. The updated floating point control code should also work fine on Mac OS X.

#9 Updated by Kyle Knoepfel over 5 years ago

  • Due date deleted (09/30/2013)
  • Start date changed from 07/11/2013 to 02/02/2015

#10 Updated by Christopher Green over 5 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF