Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e3119887
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e3119887
编写于
11月 30, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 30, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18574 from taosdata/fix/TD-20803
fix(query): fix avg calculation error after SIMD optimize
上级
1c30823b
40489889
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
80 addition
and
31 deletion
+80
-31
source/libs/function/src/detail/tavgfunction.c
source/libs/function/src/detail/tavgfunction.c
+80
-31
未找到文件。
source/libs/function/src/detail/tavgfunction.c
浏览文件 @
e3119887
...
@@ -133,6 +133,14 @@ static void i8VectorSumAVX2(const int8_t* plist, int32_t numOfRows, int32_t type
...
@@ -133,6 +133,14 @@ static void i8VectorSumAVX2(const int8_t* plist, int32_t numOfRows, int32_t type
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
p
+=
width
;
p
+=
width
;
}
}
// let sum up the final results
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
rounds
*
width
];
}
}
else
{
}
else
{
const
uint8_t
*
p
=
(
const
uint8_t
*
)
plist
;
const
uint8_t
*
p
=
(
const
uint8_t
*
)
plist
;
...
@@ -142,16 +150,16 @@ static void i8VectorSumAVX2(const int8_t* plist, int32_t numOfRows, int32_t type
...
@@ -142,16 +150,16 @@ static void i8VectorSumAVX2(const int8_t* plist, int32_t numOfRows, int32_t type
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
p
+=
width
;
p
+=
width
;
}
}
}
// let sum up the final results
// let sum up the final results
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
const
uint64_t
*
q
=
(
const
u
int64_t
*
)
&
sum
;
pRes
->
sum
.
i
sum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
pRes
->
sum
.
u
sum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
int32_t
startIndex
=
rounds
*
width
;
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
startIndex
];
pRes
->
sum
.
usum
+=
(
uint8_t
)
plist
[
j
+
rounds
*
width
];
}
}
}
#endif
#endif
}
}
...
@@ -176,8 +184,16 @@ static void i16VectorSumAVX2(const int16_t* plist, int32_t numOfRows, int32_t ty
...
@@ -176,8 +184,16 @@ static void i16VectorSumAVX2(const int16_t* plist, int32_t numOfRows, int32_t ty
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
p
+=
width
;
p
+=
width
;
}
}
// let sum up the final results
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
rounds
*
width
];
}
}
else
{
}
else
{
const
uint
8_t
*
p
=
(
const
uint8
_t
*
)
plist
;
const
uint
16_t
*
p
=
(
const
uint16
_t
*
)
plist
;
for
(
int32_t
i
=
0
;
i
<
rounds
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
rounds
;
++
i
)
{
__m128i
val
=
_mm_lddqu_si128
((
__m128i
*
)
p
);
__m128i
val
=
_mm_lddqu_si128
((
__m128i
*
)
p
);
...
@@ -185,16 +201,16 @@ static void i16VectorSumAVX2(const int16_t* plist, int32_t numOfRows, int32_t ty
...
@@ -185,16 +201,16 @@ static void i16VectorSumAVX2(const int16_t* plist, int32_t numOfRows, int32_t ty
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
p
+=
width
;
p
+=
width
;
}
}
}
// let sum up the final results
// let sum up the final results
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
const
uint64_t
*
q
=
(
const
u
int64_t
*
)
&
sum
;
pRes
->
sum
.
i
sum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
pRes
->
sum
.
u
sum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
int32_t
startIndex
=
rounds
*
width
;
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
startIndex
];
pRes
->
sum
.
usum
+=
(
uint16_t
)
plist
[
j
+
rounds
*
width
];
}
}
}
#endif
#endif
}
}
...
@@ -219,6 +235,14 @@ static void i32VectorSumAVX2(const int32_t* plist, int32_t numOfRows, int32_t ty
...
@@ -219,6 +235,14 @@ static void i32VectorSumAVX2(const int32_t* plist, int32_t numOfRows, int32_t ty
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
p
+=
width
;
p
+=
width
;
}
}
// let sum up the final results
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
rounds
*
width
];
}
}
else
{
}
else
{
const
uint32_t
*
p
=
(
const
uint32_t
*
)
plist
;
const
uint32_t
*
p
=
(
const
uint32_t
*
)
plist
;
...
@@ -228,16 +252,16 @@ static void i32VectorSumAVX2(const int32_t* plist, int32_t numOfRows, int32_t ty
...
@@ -228,16 +252,16 @@ static void i32VectorSumAVX2(const int32_t* plist, int32_t numOfRows, int32_t ty
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
sum
=
_mm256_add_epi64
(
sum
,
extVal
);
p
+=
width
;
p
+=
width
;
}
}
}
// let sum up the final results
// let sum up the final results
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
const
uint64_t
*
q
=
(
const
u
int64_t
*
)
&
sum
;
pRes
->
sum
.
i
sum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
pRes
->
sum
.
u
sum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
int32_t
startIndex
=
rounds
*
width
;
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
startIndex
];
pRes
->
sum
.
usum
+=
(
uint32_t
)
plist
[
j
+
rounds
*
width
];
}
}
}
#endif
#endif
}
}
...
@@ -262,13 +286,22 @@ static void i64VectorSumAVX2(const int64_t* plist, int32_t numOfRows, SAvgRes* p
...
@@ -262,13 +286,22 @@ static void i64VectorSumAVX2(const int64_t* plist, int32_t numOfRows, SAvgRes* p
}
}
// let sum up the final results
// let sum up the final results
if
(
type
==
TSDB_DATA_TYPE_BIGINT
)
{
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
int32_t
startIndex
=
rounds
*
width
;
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
startIndex
];
pRes
->
sum
.
isum
+=
plist
[
j
+
rounds
*
width
];
}
}
else
{
const
uint64_t
*
q
=
(
const
uint64_t
*
)
&
sum
;
pRes
->
sum
.
usum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
usum
+=
(
uint64_t
)
plist
[
j
+
rounds
*
width
];
}
}
}
#endif
#endif
}
}
...
@@ -502,7 +535,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
...
@@ -502,7 +535,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
i8VectorSumAVX2
(
plist
,
numOfRows
,
type
,
pAvgRes
);
i8VectorSumAVX2
(
plist
,
numOfRows
,
type
,
pAvgRes
);
}
else
{
}
else
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
pAvgRes
->
sum
.
usum
+=
plist
[
i
];
if
(
type
==
TSDB_DATA_TYPE_TINYINT
)
{
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
}
else
{
pAvgRes
->
sum
.
usum
+=
(
uint8_t
)
plist
[
i
];
}
}
}
}
}
break
;
break
;
...
@@ -517,7 +554,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
...
@@ -517,7 +554,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
i16VectorSumAVX2
(
plist
,
numOfRows
,
type
,
pAvgRes
);
i16VectorSumAVX2
(
plist
,
numOfRows
,
type
,
pAvgRes
);
}
else
{
}
else
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
type
==
TSDB_DATA_TYPE_SMALLINT
)
{
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
}
else
{
pAvgRes
->
sum
.
usum
+=
(
uint16_t
)
plist
[
i
];
}
}
}
}
}
break
;
break
;
...
@@ -532,7 +573,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
...
@@ -532,7 +573,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
i32VectorSumAVX2
(
plist
,
numOfRows
,
type
,
pAvgRes
);
i32VectorSumAVX2
(
plist
,
numOfRows
,
type
,
pAvgRes
);
}
else
{
}
else
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
type
==
TSDB_DATA_TYPE_INT
)
{
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
}
else
{
pAvgRes
->
sum
.
usum
+=
(
uint32_t
)
plist
[
i
];
}
}
}
}
}
break
;
break
;
...
@@ -547,7 +592,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
...
@@ -547,7 +592,11 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
i64VectorSumAVX2
(
plist
,
numOfRows
,
pAvgRes
);
i64VectorSumAVX2
(
plist
,
numOfRows
,
pAvgRes
);
}
else
{
}
else
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
type
==
TSDB_DATA_TYPE_BIGINT
)
{
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
pAvgRes
->
sum
.
isum
+=
plist
[
i
];
}
else
{
pAvgRes
->
sum
.
isum
+=
(
uint64_t
)
plist
[
i
];
}
}
}
}
}
break
;
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录