summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/softfloat3/source/f128M_sub.c
blob: 1b609fdab092caba3c8a02c7a23a1fed148c4247 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*============================================================================

This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
Package, Release 3e, by John R. Hauser.

Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice,
    this list of conditions, and the following disclaimer.

 2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions, and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

 3. Neither the name of the University nor the names of its contributors may
    be used to endorse or promote products derived from this software without
    specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=============================================================================*/

#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "softfloat.h"

#ifdef SOFTFLOAT_FAST_INT64

void
 f128M_sub( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr )
{
    const uint64_t *aWPtr, *bWPtr;
    uint_fast64_t uiA64, uiA0;
    bool signA;
    uint_fast64_t uiB64, uiB0;
    bool signB;
#if ! defined INLINE_LEVEL || (INLINE_LEVEL < 2)
    float128_t
        (*magsFuncPtr)(
            uint_fast64_t, uint_fast64_t, uint_fast64_t, uint_fast64_t, bool );
#endif

    aWPtr = (const uint64_t *) aPtr;
    bWPtr = (const uint64_t *) bPtr;
    uiA64 = aWPtr[indexWord( 2, 1 )];
    uiA0  = aWPtr[indexWord( 2, 0 )];
    signA = signF128UI64( uiA64 );
    uiB64 = bWPtr[indexWord( 2, 1 )];
    uiB0  = bWPtr[indexWord( 2, 0 )];
    signB = signF128UI64( uiB64 );
#if defined INLINE_LEVEL && (2 <= INLINE_LEVEL)
    if ( signA == signB ) {
        *zPtr = softfloat_subMagsF128( uiA64, uiA0, uiB64, uiB0, signA );
    } else {
        *zPtr = softfloat_addMagsF128( uiA64, uiA0, uiB64, uiB0, signA );
    }
#else
    magsFuncPtr =
        (signA == signB) ? softfloat_subMagsF128 : softfloat_addMagsF128;
    *zPtr = (*magsFuncPtr)( uiA64, uiA0, uiB64, uiB0, signA );
#endif

}

#else

void
 f128M_sub( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr )
{

    softfloat_addF128M(
        (const uint32_t *) aPtr,
        (const uint32_t *) bPtr,
        (uint32_t *) zPtr,
        true
    );

}

#endif
class="w"> for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) { uint8_t mask = 1 << irq; /* is this IRQ in service and not cascading and sfnm? */ if ((m_isr & mask) && !(m_master && m_cascade && m_nested && (m_slave & mask))) { if (LOG_GENERAL) { logerror("pic8259_timerproc() %s: PIC IRQ #%d still in service\n", tag(), irq); } break; } /* is this IRQ pending and enabled? */ if ((m_state == STATE_READY) && (m_irr & mask) && !(m_imr & mask)) { if (LOG_GENERAL) { logerror("pic8259_timerproc() %s: PIC triggering IRQ #%d\n", tag(), irq); } m_out_int_func(1); return; } // if sfnm and in-service don't continue if((m_isr & mask) && m_master && m_cascade && m_nested && (m_slave & mask)) break; } m_out_int_func(0); } void pic8259_device::set_irq_line(int irq, int state) { uint8_t mask = (1 << irq); if (state) { /* setting IRQ line */ if (LOG_GENERAL) logerror("pic8259_set_irq_line() %s: PIC set IRQ line #%d\n", tag(), irq); if(m_level_trig_mode || (!m_level_trig_mode && !(m_irq_lines & mask))) { m_irr |= mask; } m_irq_lines |= mask; } else { /* clearing IRQ line */ if (LOG_GENERAL) { logerror("pic8259_device::set_irq_line() %s: PIC cleared IRQ line #%d\n", tag(), irq); } m_irq_lines &= ~mask; m_irr &= ~mask; } set_timer(); } uint32_t pic8259_device::acknowledge() { for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) { uint8_t mask = 1 << irq; /* is this IRQ pending and enabled? */ if ((m_irr & mask) && !(m_imr & mask)) { if (LOG_GENERAL) { logerror("pic8259_acknowledge() %s: PIC acknowledge IRQ #%d\n", tag(), irq); } if (!m_level_trig_mode) { m_irr &= ~mask; } if (!m_auto_eoi) { m_isr |= mask; } set_timer(); if ((m_cascade!=0) && (m_master!=0) && (mask & m_slave)) { // it's from slave device return m_read_slave_ack_func(irq); } else { if (m_is_x86) { /* For x86 mode*/ return irq + m_base; } else { /* in case of 8080/85) */ return 0xcd0000 + (m_vector_addr_high << 8) + m_vector_addr_low + (irq << (3-m_vector_size)); } } } } logerror("Spurious IRQ\n"); if(m_is_x86) return m_base + 7; return 0xcd0000 + (m_vector_addr_high << 8) + m_vector_addr_low + (7 << (3-m_vector_size)); } IRQ_CALLBACK_MEMBER(pic8259_device::inta_cb) { return acknowledge(); } READ8_MEMBER( pic8259_device::read ) { /* NPW 18-May-2003 - Changing 0xFF to 0x00 as per Ruslan */ uint8_t data = 0x00; switch(offset) { case 0: /* PIC acknowledge IRQ */ if ( m_ocw3 & 0x04 ) { /* Polling mode */ if ( m_irr & ~m_imr ) { /* check the various IRQs */ for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) { if ( ( 1 << irq ) & m_irr & ~m_imr ) { data = 0x80 | irq; break; } } acknowledge(); } } else { switch ( m_ocw3 & 0x03 ) { case 2: data = m_irr; break; case 3: data = m_isr & ~m_imr; break; default: data = 0x00; break; } } break; case 1: /* PIC mask register */ data = m_imr; break; } return data; } WRITE8_MEMBER( pic8259_device::write ) { switch(offset) { case 0: /* PIC acknowledge IRQ */ if (data & 0x10) { /* write ICW1 - this pretty much resets the chip */ if (LOG_ICW) { logerror("pic8259_device::write() %s: ICW1; data=0x%02X\n", tag(), data); } m_imr = 0x00; m_isr = 0x00; m_irr = 0x00; m_level_trig_mode = (data & 0x08) ? 1 : 0; m_vector_size = (data & 0x04) ? 1 : 0; m_cascade = (data & 0x02) ? 0 : 1; m_icw4_needed = (data & 0x01) ? 1 : 0; m_vector_addr_low = (data & 0xe0); m_state = STATE_ICW2; m_out_int_func(0); } else if (m_state == STATE_READY) { if ((data & 0x98) == 0x08) { /* write OCW3 */ if (LOG_OCW) { logerror("pic8259_device::write() %s: OCW3; data=0x%02X\n", tag(), data); } m_ocw3 = data; } else if ((data & 0x18) == 0x00) { int n = data & 7; uint8_t mask = 1 << n; /* write OCW2 */ if (LOG_OCW) { logerror("pic8259_device::write() %s: OCW2; data=0x%02X\n", tag(), data); } switch (data & 0xe0) { case 0x00: m_prio = 0; break; case 0x20: for (n = 0, mask = 1<<m_prio; n < 8; n++, mask = (mask<<1) | (mask>>7)) { if (m_isr & mask) { m_isr &= ~mask; break; } } break; case 0x40: break; case 0x60: if( m_isr & mask ) { m_isr &= ~mask; } break; case 0x80: m_prio = (m_prio + 1) & 7; break; case 0xa0: for (n = 0, mask = 1<<m_prio; n < 8; n++, mask = (mask<<1) | (mask>>7)) { if( m_isr & mask ) { m_isr &= ~mask; m_prio = (m_prio + 1) & 7; break; } } break; case 0xc0: m_prio = (n + 1) & 7; break; case 0xe0: if( m_isr & mask ) { m_isr &= ~mask; m_prio = (n + 1) & 7; } break; } } } break; case 1: switch(m_state) { case STATE_ICW1: break; case STATE_ICW2: /* write ICW2 */ if (LOG_ICW) { logerror("pic8259_device::write() %s: ICW2; data=0x%02X\n", tag(), data); } m_base = data & 0xf8; m_vector_addr_high = data ; if (m_cascade) { m_state = STATE_ICW3; } else { m_state = m_icw4_needed ? STATE_ICW4 : STATE_READY; } break; case STATE_ICW3: /* write ICW3 */ if (LOG_ICW) { logerror("pic8259_device::write() %s: ICW3; data=0x%02X\n", tag(), data); } m_slave = data; m_state = m_icw4_needed ? STATE_ICW4 : STATE_READY; break; case STATE_ICW4: /* write ICW4 */ if (LOG_ICW) { logerror("pic8259_device::write() %s: ICW4; data=0x%02X\n", tag(), data); } m_nested = (data & 0x10) ? 1 : 0; m_mode = (data >> 2) & 3; m_auto_eoi = (data & 0x02) ? 1 : 0; m_is_x86 = (data & 0x01) ? 1 : 0; m_state = STATE_READY; break; case STATE_READY: /* write OCW1 - set interrupt mask register */ if (LOG_OCW) { logerror("pic8259_device::write(): OCW1; data=0x%02X\n", data); } //printf("%s %02x\n",m_master ? "master pic8259 mask" : "slave pic8259 mask",data); m_imr = data; break; } break; } set_timer(); } //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- void pic8259_device::device_start() { // resolve callbacks m_out_int_func.resolve_safe(); m_sp_en_func.resolve_safe(1); m_read_slave_ack_func.resolve_safe(0); // Register save state items save_item(NAME(m_state)); save_item(NAME(m_isr)); save_item(NAME(m_irr)); save_item(NAME(m_prio)); save_item(NAME(m_imr)); save_item(NAME(m_irq_lines)); save_item(NAME(m_input)); save_item(NAME(m_ocw3)); save_item(NAME(m_master)); save_item(NAME(m_level_trig_mode)); save_item(NAME(m_vector_size)); save_item(NAME(m_cascade)); save_item(NAME(m_icw4_needed)); save_item(NAME(m_vector_addr_low)); save_item(NAME(m_base)); save_item(NAME(m_vector_addr_high)); save_item(NAME(m_slave)); save_item(NAME(m_nested)); save_item(NAME(m_mode)); save_item(NAME(m_auto_eoi)); save_item(NAME(m_is_x86)); } //------------------------------------------------- // device_reset - device-specific reset //------------------------------------------------- void pic8259_device::device_reset() { m_state = STATE_READY; m_isr = 0; m_irr = 0; m_irq_lines = 0; m_prio = 0; m_imr = 0; m_input = 0; m_ocw3 = 2; m_level_trig_mode = 0; m_vector_size = 0; m_cascade = 0; m_icw4_needed = 0; m_base = 0; m_slave = 0; m_nested = 0; m_mode = 0; m_auto_eoi = 0; m_is_x86 = 0; m_vector_addr_low = 0; m_vector_addr_high = 0; m_master = m_sp_en_func(); } const device_type PIC8259 = &device_creator<pic8259_device>; pic8259_device::pic8259_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, PIC8259, "8259 PIC", tag, owner, clock, "pit8259", __FILE__) , m_out_int_func(*this) , m_sp_en_func(*this) , m_read_slave_ack_func(*this) , m_irr(0) , m_irq_lines(0) , m_level_trig_mode(0) { }