diff options
author | eadler <eadler@FreeBSD.org> | 2014-02-04 03:36:42 +0000 |
---|---|---|
committer | eadler <eadler@FreeBSD.org> | 2014-02-04 03:36:42 +0000 |
commit | ec294fd7f5fc5de11ed889d6c2d701f918d1ecfb (patch) | |
tree | 7e76e370b9406b0383b17bd343084addb4ad6a25 /sys/powerpc/fpu | |
parent | d374d7f398b846dc59d8a5ec3c7bfb318cf880af (diff) | |
download | FreeBSD-src-ec294fd7f5fc5de11ed889d6c2d701f918d1ecfb.zip FreeBSD-src-ec294fd7f5fc5de11ed889d6c2d701f918d1ecfb.tar.gz |
MFC r258779,r258780,r258787,r258822:
Fix undefined behavior: (1 << 31) is not defined as 1 is an int and this
shifts into the sign bit. Instead use (1U << 31) which gets the
expected result.
Similar to the (1 << 31) case it is not defined to do (2 << 30).
This fix is not ideal as it assumes a 32 bit int, but does fix the issue
for most cases.
A similar change was made in OpenBSD.
Diffstat (limited to 'sys/powerpc/fpu')
-rw-r--r-- | sys/powerpc/fpu/fpu_emu.c | 6 | ||||
-rw-r--r-- | sys/powerpc/fpu/fpu_sqrt.c | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/sys/powerpc/fpu/fpu_emu.c b/sys/powerpc/fpu/fpu_emu.c index 66cc215..8cfc2a3 100644 --- a/sys/powerpc/fpu/fpu_emu.c +++ b/sys/powerpc/fpu/fpu_emu.c @@ -500,7 +500,7 @@ fpu_execute(struct trapframe *tf, struct fpemu *fe, union instr *insn) memcpy(&fs->fpreg[rt], &fs->fpreg[rb], sizeof(double)); a = (int *)&fs->fpreg[rt]; - *a ^= (1 << 31); + *a ^= (1U << 31); break; case OPC63_MCRFS: FPU_EMU_EVCNT_INCR(mcrfs); @@ -547,7 +547,7 @@ fpu_execute(struct trapframe *tf, struct fpemu *fe, union instr *insn) memcpy(&fs->fpreg[rt], &fs->fpreg[rb], sizeof(double)); a = (int *)&fs->fpreg[rt]; - *a |= (1 << 31); + *a |= (1U << 31); break; case OPC63_FABS: FPU_EMU_EVCNT_INCR(fabs); @@ -555,7 +555,7 @@ fpu_execute(struct trapframe *tf, struct fpemu *fe, union instr *insn) memcpy(&fs->fpreg[rt], &fs->fpreg[rb], sizeof(double)); a = (int *)&fs->fpreg[rt]; - *a &= ~(1 << 31); + *a &= ~(1U << 31); break; case OPC63_MFFS: FPU_EMU_EVCNT_INCR(mffs); diff --git a/sys/powerpc/fpu/fpu_sqrt.c b/sys/powerpc/fpu/fpu_sqrt.c index 963a193..59cb3ab 100644 --- a/sys/powerpc/fpu/fpu_sqrt.c +++ b/sys/powerpc/fpu/fpu_sqrt.c @@ -274,7 +274,7 @@ fpu_sqrt(struct fpemu *fe) * double x correctly while doing the `known q=1.0'. * * We do this one mantissa-word at a time, as noted above, to - * save work. To avoid `(1 << 31) << 1', we also do the top bit + * save work. To avoid `(1U << 31) << 1', we also do the top bit * outside of each per-word loop. * * The calculation `t = y + bit' breaks down into `t0 = y0, ..., |