相关疑难解决方法(0)

为什么要快速运行glibc的问题太复杂了?

我在这里浏览strlen代码,想知道是否真的需要代码中使用的优化?例如,为什么下面这样的东西不能同样好或更好?

unsigned long strlen(char s[]) {
    unsigned long i;
    for (i = 0; s[i] != '\0'; i++)
        continue;
    return i;
}
Run Code Online (Sandbox Code Playgroud)

较简单的代码对编译器进行优化是否更好或更容易?

strlen链接后面页面上的代码如下所示:

/* Copyright (C) 1991, 1993, 1997, 2000, 2003 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Written by Torbjorn Granlund (tege@sics.se),
   with help from Dan Sahlin (dan@sics.se);
   commentary by Jim Blandy (jimb@ai.mit.edu).

   The GNU C Library is free software; you can redistribute it and/or
   modify it under …
Run Code Online (Sandbox Code Playgroud)

c optimization portability glibc strlen

283
推荐指数
7
解决办法
5万
查看次数

如何强制gcc内联函数?

是否__attribute__((always_inline))强制函数由gcc内联?

gcc inline compiler-flags

57
推荐指数
6
解决办法
5万
查看次数

按段比较 64 位整数

我有两个 64 位整数xy. 每个代表5个无符号短整数:前10位代表第一个整数,接下来的13位代表第二个整数,接下来的16位代表第三个整数,接下来的14位代表第四个整数,其余位代表第 5 个整数。

x0x1x2x3x4是构成5个短整型x。设y0y1y2y3y4是构成5个短整型y。我需要知道是否x0 < y0AND x1 < y1AND x2 < y2AND x3 < y3AND x4 < y4

我认为最简单的解决方案是转移:

bool allLess(std::size_t x, std::size_t y)
{
  if(x >= y) return 0;
  int shift[] = {10, 13, 16, 14};
  for(int i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

c++ bit-manipulation swar

5
推荐指数
1
解决办法
262
查看次数