小编Ale*_*eks的帖子

SIMD或不SIMD - 跨平台

我需要知道如何以某种方式编写一些可并行化问题的C++跨平台实现,以便我可以利用SIMD(SSE,SPU等)(如果可用).同时我希望能够在运行时在SIMD之间切换而不是SIMD.

你会如何建议我解决这个问题? (当然我不想为所有可能的选项多次实现该问题)

我可以看到这对C++来说可能不是一件容易的事,但我相信我错过了一些东西.到目前为止,我的想法看起来像这样......类cStream将是单个字段的数组.使用多个cStream我可以实现SoA(阵列结构).然后使用一些函数我可以伪造我需要在整个cStream上执行的Lambda函数.

// just for example I'm not expecting this code to compile
cStream a; // something like float[1024]
cStream b;
cStream c;

void Foo()
{
    for_each(
        AssignSIMD(c, MulSIMD(AddSIMD(a, b), a)));
}
Run Code Online (Sandbox Code Playgroud)

其中for_each将负责增加流的当前指针以及使用SIMD和没有SIMD内联仿函数的主体.

像这样的事情:

// just for example I'm not expecting this code to compile
for_each(functor<T> f)
{
#ifdef USE_SIMD
    if (simdEnabled)
        real_for_each(f<true>()); // true means use SIMD
    else
#endif
        real_for_each(f<false>());
}
Run Code Online (Sandbox Code Playgroud)

请注意,如果启用SIMD,则检查一次,并且循环位于主仿函数周围.

c++ metaprogramming simd functor

12
推荐指数
1
解决办法
2823
查看次数

C++将一个基指针转换为接口指针

这是我的设置的一些伪代码:

class IMyClass { ... }; // pure virtual class
class CMyBaseClass { .... };
class CMyClass : public CMyBaseClass, public IMyClass { ... }
Run Code Online (Sandbox Code Playgroud)

然后我收集了CMyBaseClass*.我有自定义RTTI,它允许我找出一个类是否实现给定的接口.所以我可以找到哪些对象有IMyClass实现.我的问题是我无法将其强制转换为该界面.我不想使用标准RTTI和动态强制转换.

我正在考虑在我的自定义RTTI中存储一些指针差异,以便在一对类之间进行转换,但我还没有弄清楚让我开心的实现.

还有其他方法吗?

c++ casting rtti

3
推荐指数
1
解决办法
2900
查看次数

我的应用程序开始颠倒了

我已经工作了一段时间并已发布游戏的引擎现在正在颠倒我的当前项目并立即按照它想象的方式旋转UIView.我用代码创建接口,这是关于它的样子:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{    
    ...

    CGRect screenBounds = [[UIScreen mainScreen] applicationFrame]; 
    CGRect windowBounds = screenBounds; 
    windowBounds.origin.y = 0.0;
    UIWindow* win = [[UIWindow alloc] initWithFrame:windowBounds];  
    win.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    UIMyView* view = [[UIMyView alloc] initWithFrame:screenBounds]; 
    UIMyViewController* controller = [[UIMyViewController alloc] init]; 
    controller.view = view; 

    view.multipleTouchEnabled = true;   
    view.windowWrapper = this;  
    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    [win addSubview:view];

    ...
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
{
    s32 validOrientations = ((cViewMM*)(self.view)).windowWrapper->GetValidOrientations();
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait && (validOrientations & 0x01))
        return true;

    if …
Run Code Online (Sandbox Code Playgroud)

iphone orientation ios

3
推荐指数
1
解决办法
4906
查看次数

标签 统计

c++ ×2

casting ×1

functor ×1

ios ×1

iphone ×1

metaprogramming ×1

orientation ×1

rtti ×1

simd ×1