Skip to content

Commit

Permalink
try override
Browse files Browse the repository at this point in the history
Signed-off-by: before-Sunrise <[email protected]>
  • Loading branch information
before-Sunrise committed Jan 26, 2025
1 parent e7e28e9 commit 4741726
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 92 deletions.
2 changes: 1 addition & 1 deletion be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ endif()

set(STARROCKS_LINK_LIBS ${STARROCKS_LINK_LIBS}
${WL_LINK_STATIC} -lbfd
${WL_LINK_DYNAMIC} -lresolv -liberty -lc -lm -ldl -rdynamic -pthread -Wl,-wrap=__cxa_throw
${WL_LINK_DYNAMIC} -lresolv -liberty -lc -lm -ldl -rdynamic -pthread -Wl,-wrap,__cxa_throw -Wl,-wrap,__floattidf
)

# link gcov if WITH_GCOV is on
Expand Down
183 changes: 92 additions & 91 deletions be/src/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,100 +18,101 @@ set(LIBRARY_OUTPUT_PATH "${BUILD_DIR}/src/runtime")
set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/src/runtime")

set(RUNTIME_FILES
broker_mgr.cpp
buffer_control_block.cpp
buffer_control_result_writer.cpp
client_cache.cpp
local_pass_through_buffer.cpp
data_stream_mgr.cpp
sender_queue.cpp
data_stream_sender.cpp
multi_cast_data_stream_sink.cpp
datetime_value.cpp
descriptors.cpp
exec_env.cpp
global_variables.cpp
user_function_cache.cpp
jdbc_driver_manager.cpp
mem_pool.cpp
plan_fragment_executor.cpp
result_sink.cpp
result_buffer_mgr.cpp
runtime_state.cpp
string_value.cpp
decimalv2_value.cpp
fragment_mgr.cpp
load_path_mgr.cpp
dummy_load_path_mgr.cpp
types.cpp
agg_state_desc.cpp
mem_tracker.cpp
data_stream_recvr.cpp
export_sink.cpp
load_channel_mgr.cpp
load_channel.cpp
local_tablets_channel.cpp
snapshot_loader.cpp
query_statistics.cpp
message_body_sink.cpp
stream_load/transaction_mgr.cpp
stream_load/stream_load_context.cpp
stream_load/stream_load_executor.cpp
stream_load/stream_load_pipe.cpp
stream_load/time_bounded_stream_load_pipe.cpp
batch_write/isomorphic_batch_write.cpp
batch_write/batch_write_mgr.cpp
batch_write/batch_write_util.cpp
routine_load/data_consumer.cpp
routine_load/data_consumer_group.cpp
routine_load/data_consumer_pool.cpp
routine_load/routine_load_task_executor.cpp
small_file_mgr.cpp
record_batch_queue.cpp
result_queue_mgr.cpp
memory_scratch_sink.cpp
external_scan_context_mgr.cpp
mysql_result_writer.cpp
http_result_writer.cpp
file_result_writer.cpp
statistic_result_writer.cpp
metadata_result_writer.cpp
variable_result_writer.cpp
arrow_result_writer.cpp
memory/roaring_hook.cpp
memory/system_allocator.cpp
memory/mem_chunk_allocator.cpp
memory/column_allocator.cpp
chunk_cursor.cpp
sorted_chunks_merger.cpp
tablets_channel.cpp
time_types.cpp
runtime_filter_worker.cpp
global_dict/decoder.cpp
global_dict/parser.cpp
global_dict/miscs.cpp
global_dict/types.cpp
current_thread.cpp
runtime_filter_cache.cpp
lake_tablets_channel.cpp
lake_snapshot_loader.cpp
profile_report_worker.cpp
schema_table_sink.cpp
command_executor.cpp
iceberg_table_sink.cpp
hive_table_sink.cpp
table_function_table_sink.cpp
blackhole_table_sink.cpp
dictionary_cache_sink.cpp
type_pack.cpp
customized_result_writer.cpp
broker_mgr.cpp
buffer_control_block.cpp
buffer_control_result_writer.cpp
client_cache.cpp
local_pass_through_buffer.cpp
data_stream_mgr.cpp
sender_queue.cpp
data_stream_sender.cpp
multi_cast_data_stream_sink.cpp
datetime_value.cpp
descriptors.cpp
exec_env.cpp
global_variables.cpp
user_function_cache.cpp
jdbc_driver_manager.cpp
mem_pool.cpp
plan_fragment_executor.cpp
result_sink.cpp
result_buffer_mgr.cpp
runtime_state.cpp
string_value.cpp
decimalv2_value.cpp
fragment_mgr.cpp
load_path_mgr.cpp
dummy_load_path_mgr.cpp
types.cpp
agg_state_desc.cpp
mem_tracker.cpp
data_stream_recvr.cpp
export_sink.cpp
load_channel_mgr.cpp
load_channel.cpp
local_tablets_channel.cpp
snapshot_loader.cpp
query_statistics.cpp
message_body_sink.cpp
stream_load/transaction_mgr.cpp
stream_load/stream_load_context.cpp
stream_load/stream_load_executor.cpp
stream_load/stream_load_pipe.cpp
stream_load/time_bounded_stream_load_pipe.cpp
batch_write/isomorphic_batch_write.cpp
batch_write/batch_write_mgr.cpp
batch_write/batch_write_util.cpp
routine_load/data_consumer.cpp
routine_load/data_consumer_group.cpp
routine_load/data_consumer_pool.cpp
routine_load/routine_load_task_executor.cpp
small_file_mgr.cpp
record_batch_queue.cpp
result_queue_mgr.cpp
memory_scratch_sink.cpp
external_scan_context_mgr.cpp
mysql_result_writer.cpp
http_result_writer.cpp
file_result_writer.cpp
statistic_result_writer.cpp
metadata_result_writer.cpp
variable_result_writer.cpp
arrow_result_writer.cpp
memory/roaring_hook.cpp
memory/system_allocator.cpp
memory/mem_chunk_allocator.cpp
memory/column_allocator.cpp
chunk_cursor.cpp
sorted_chunks_merger.cpp
tablets_channel.cpp
time_types.cpp
runtime_filter_worker.cpp
global_dict/decoder.cpp
global_dict/parser.cpp
global_dict/miscs.cpp
global_dict/types.cpp
current_thread.cpp
runtime_filter_cache.cpp
lake_tablets_channel.cpp
lake_snapshot_loader.cpp
profile_report_worker.cpp
schema_table_sink.cpp
command_executor.cpp
iceberg_table_sink.cpp
hive_table_sink.cpp
table_function_table_sink.cpp
blackhole_table_sink.cpp
dictionary_cache_sink.cpp
type_pack.cpp
customized_result_writer.cpp
int128_to_double.cpp
)

set(RUNTIME_FILES ${RUNTIME_FILES}
mysql_table_writer.cpp
mysql_table_sink.cpp
mysql_table_writer.cpp
mysql_table_sink.cpp
)

add_library(Runtime STATIC
${RUNTIME_FILES}
)
${RUNTIME_FILES}
)
90 changes: 90 additions & 0 deletions be/src/runtime/int128_to_double.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// 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
//
// https://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 "runtime/int128_to_double.h"

#include <climits>
#include <cstdint>

#include "integer_overflow_arithmetics.h"
namespace starrocks {
double __wrap___floattidf(__int128 a) {
typedef double dst_t;
typedef uint64_t dst_rep_t;
typedef __uint128_t usrc_t;
#define DST_REP_C UINT64_C

enum {
dstSigBits = 52,
};

if (a == 0) return 0.0;

enum {
dstMantDig = dstSigBits + 1,
srcBits = sizeof(__int128) * CHAR_BIT,
srcIsSigned = ((__int128)-1) < 0,
};

const __int128 s = srcIsSigned ? a >> (srcBits - 1) : 0;

a = (usrc_t)(a ^ s) - s;
int sd = srcBits - clz128(a); // number of significant digits
int e = sd - 1; // exponent
if (sd > dstMantDig) {
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
// 12345678901234567890123456
// 1 = msb 1 bit
// P = bit dstMantDig-1 bits to the right of 1
// Q = bit dstMantDig bits to the right of 1
// R = "or" of all bits to the right of Q
if (sd == dstMantDig + 1) {
a <<= 1;
} else if (sd == dstMantDig + 2) {
// Do nothing.
} else {
a = ((usrc_t)a >> (sd - (dstMantDig + 2))) |
((a & ((usrc_t)(-1) >> ((srcBits + dstMantDig + 2) - sd))) != 0);
}
// finish:
a |= (a & 4) != 0; // Or P into R
++a; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to dstMantDig or dstMantDig+1 bits
if (a & ((usrc_t)1 << dstMantDig)) {
a >>= 1;
++e;
}
// a is now rounded to dstMantDig bits
} else {
a <<= (dstMantDig - sd);
// a is now rounded to dstMantDig bits
}
const int dstBits = sizeof(dst_t) * CHAR_BIT;
const dst_rep_t dstSignMask = DST_REP_C(1) << (dstBits - 1);
const int dstExpBits = dstBits - dstSigBits - 1;
const int dstExpBias = (1 << (dstExpBits - 1)) - 1;
const dst_rep_t dstSignificandMask = (DST_REP_C(1) << dstSigBits) - 1;
// Combine sign, exponent, and mantissa.
const dst_rep_t result = ((dst_rep_t)s & dstSignMask) | ((dst_rep_t)(e + dstExpBias) << dstSigBits) |
((dst_rep_t)(a)&dstSignificandMask);

const union {
dst_t f;
dst_rep_t i;
} rep = {.i = result};
return rep.f;
}
} // namespace starrocks
18 changes: 18 additions & 0 deletions be/src/runtime/int128_to_double.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// 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
//
// https://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.
namespace starrocks {
extern "C" {
double __wrap___floattidf(__int128 a);
}
} // namespace starrocks

0 comments on commit 4741726

Please sign in to comment.