Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
fb1f67a7
Commit
fb1f67a7
authored
Aug 12, 2016
by
Umair Khan
Committed by
Thilo Borgmann
Aug 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avutil: Softfloat implementation for IEEE 754 floating point
Signed-off-by:
Umair Khan
<
omerjerk@gmail.com
>
parent
eb5f4b14
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
+115
-0
softfloat_ieee754.h
libavutil/softfloat_ieee754.h
+115
-0
No files found.
libavutil/softfloat_ieee754.h
0 → 100644
View file @
fb1f67a7
/*
* Copyright (c) 2016 Umair Khan <omerjerk@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_SOFTFLOAT_IEEE754_H
#define AVUTIL_SOFTFLOAT_IEEE754_H
#include <stdint.h>
#define EXP_BIAS 127
#define MANT_BITS 23
typedef
struct
SoftFloat_IEEE754
{
int32_t
sign
;
uint64_t
mant
;
int32_t
exp
;
}
SoftFloat_IEEE754
;
static
const
SoftFloat_IEEE754
FLOAT_0
=
{
0
,
0
,
-
126
};
static
const
SoftFloat_IEEE754
FLOAT_1
=
{
0
,
0
,
0
};
/** Normalize the softfloat as defined by IEEE 754 single-recision floating
* point specification
*/
static
SoftFloat_IEEE754
av_normalize_sf_ieee754
(
SoftFloat_IEEE754
sf
)
{
while
(
sf
.
mant
>=
0x1000000UL
)
{
sf
.
exp
++
;
sf
.
mant
>>=
1
;
}
sf
.
mant
&=
0x007fffffUL
;
return
sf
;
}
/** Convert integer to softfloat.
* @return softfloat with value n * 2^e
*/
static
SoftFloat_IEEE754
av_int2sf_ieee754
(
int64_t
n
,
int
e
)
{
int
sign
=
0
;
if
(
n
<
0
)
{
sign
=
1
;
n
*=
-
1
;
}
return
av_normalize_sf_ieee754
((
SoftFloat_IEEE754
)
{
sign
,
n
<<
MANT_BITS
,
0
+
e
});
}
/** Make a softfloat out of the bitstream. Assumes the bits are in the form as defined
* by the IEEE 754 spec.
*/
static
SoftFloat_IEEE754
av_bits2sf_ieee754
(
uint32_t
n
)
{
return
((
SoftFloat_IEEE754
)
{
(
n
&
0x80000000UL
),
(
n
&
0x7FFFFFUL
),
(
n
&
0x7F800000UL
)
});
}
/** Convert the softfloat to integer
*/
static
int
av_sf2int_ieee754
(
SoftFloat_IEEE754
a
)
{
if
(
a
.
exp
>=
0
)
return
a
.
mant
<<
a
.
exp
;
else
return
a
.
mant
>>
(
-
a
.
exp
);
}
/** Divide a by b. b should not be zero.
* @return normalized result
*/
static
SoftFloat_IEEE754
av_div_sf_ieee754
(
SoftFloat_IEEE754
a
,
SoftFloat_IEEE754
b
)
{
int32_t
mant
,
exp
,
sign
;
a
=
av_normalize_sf_ieee754
(
a
);
b
=
av_normalize_sf_ieee754
(
b
);
sign
=
a
.
sign
^
b
.
sign
;
mant
=
((((
uint64_t
)
(
a
.
mant
|
0x00800000UL
))
<<
MANT_BITS
)
/
(
b
.
mant
|
0x00800000UL
));
exp
=
a
.
exp
-
b
.
exp
;
return
av_normalize_sf_ieee754
((
SoftFloat_IEEE754
)
{
sign
,
mant
,
exp
});
}
/** Multiply a with b
* #return normalized result
*/
static
SoftFloat_IEEE754
av_mul_sf_ieee754
(
SoftFloat_IEEE754
a
,
SoftFloat_IEEE754
b
)
{
int32_t
sign
,
mant
,
exp
;
a
=
av_normalize_sf_ieee754
(
a
);
b
=
av_normalize_sf_ieee754
(
b
);
sign
=
a
.
sign
^
b
.
sign
;
mant
=
(((
uint64_t
)(
a
.
mant
|
0x00800000UL
)
*
(
uint64_t
)(
b
.
mant
|
0x00800000UL
))
>>
MANT_BITS
);
exp
=
a
.
exp
+
b
.
exp
;
return
av_normalize_sf_ieee754
((
SoftFloat_IEEE754
)
{
sign
,
mant
,
exp
});
}
/** Compare a with b strictly
* @returns 1 if the a and b are equal, 0 otherwise.
*/
static
int
av_cmp_sf_ieee754
(
SoftFloat_IEEE754
a
,
SoftFloat_IEEE754
b
)
{
a
=
av_normalize_sf_ieee754
(
a
);
b
=
av_normalize_sf_ieee754
(
b
);
if
(
a
.
sign
!=
b
.
sign
)
return
0
;
if
(
a
.
mant
!=
b
.
mant
)
return
0
;
if
(
a
.
exp
!=
b
.
exp
)
return
0
;
return
1
;
}
#endif
/*AVUTIL_SOFTFLOAT_IEEE754_H*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment